commit | author | age
|
76bbd0
|
1 |
;;; ob-ledger.el --- Babel Functions for Ledger -*- lexical-binding: t; -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2010-2018 Free Software Foundation, Inc. |
|
4 |
|
|
5 |
;; Author: Eric S Fraga |
|
6 |
;; Keywords: literate programming, reproducible research, accounting |
|
7 |
;; Homepage: https://orgmode.org |
|
8 |
|
|
9 |
;; This file is part of GNU Emacs. |
|
10 |
|
|
11 |
;; GNU Emacs is free software: you can redistribute it and/or modify |
|
12 |
;; it under the terms of the GNU General Public License as published by |
|
13 |
;; the Free Software Foundation, either version 3 of the License, or |
|
14 |
;; (at your option) any later version. |
|
15 |
|
|
16 |
;; GNU Emacs is distributed in the hope that it will be useful, |
|
17 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
;; GNU General Public License for more details. |
|
20 |
|
|
21 |
;; You should have received a copy of the GNU General Public License |
|
22 |
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. |
|
23 |
|
|
24 |
;;; Commentary: |
|
25 |
|
|
26 |
;; Org-Babel support for evaluating ledger entries. |
|
27 |
;; |
|
28 |
;; This differs from most standard languages in that |
|
29 |
;; |
|
30 |
;; 1) there is no such thing as a "session" in ledger |
|
31 |
;; |
|
32 |
;; 2) we are generally only going to return output from the ledger program |
|
33 |
;; |
|
34 |
;; 3) we are adding the "cmdline" header argument |
|
35 |
;; |
|
36 |
;; 4) there are no variables |
|
37 |
|
|
38 |
;;; Code: |
|
39 |
(require 'ob) |
|
40 |
|
|
41 |
(defvar org-babel-default-header-args:ledger |
|
42 |
'((:results . "output") (:cmdline . "bal")) |
|
43 |
"Default arguments to use when evaluating a ledger source block.") |
|
44 |
|
|
45 |
(defun org-babel-execute:ledger (body params) |
|
46 |
"Execute a block of Ledger entries with org-babel. This function is |
|
47 |
called by `org-babel-execute-src-block'." |
|
48 |
(message "executing Ledger source code block") |
|
49 |
(let ((cmdline (cdr (assq :cmdline params))) |
|
50 |
(in-file (org-babel-temp-file "ledger-")) |
|
51 |
(out-file (org-babel-temp-file "ledger-output-"))) |
|
52 |
(with-temp-file in-file (insert body)) |
|
53 |
(message "%s" (concat "ledger" |
|
54 |
" -f " (org-babel-process-file-name in-file) |
|
55 |
" " cmdline)) |
|
56 |
(with-output-to-string |
|
57 |
(shell-command (concat "ledger" |
|
58 |
" -f " (org-babel-process-file-name in-file) |
|
59 |
" " cmdline |
|
60 |
" > " (org-babel-process-file-name out-file)))) |
|
61 |
(with-temp-buffer (insert-file-contents out-file) (buffer-string)))) |
|
62 |
|
|
63 |
(defun org-babel-prep-session:ledger (_session _params) |
|
64 |
(error "Ledger does not support sessions")) |
|
65 |
|
|
66 |
(provide 'ob-ledger) |
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
;;; ob-ledger.el ends here |