scheme interaction mode
[bpt/emacs.git] / lisp / org / ob-ledger.el
CommitLineData
afe98dfa
CD
1;;; ob-ledger.el --- org-babel functions for ledger evaluation
2
ba318903 3;; Copyright (C) 2010-2014 Free Software Foundation, Inc.
afe98dfa
CD
4
5;; Author: Eric S Fraga
6;; Keywords: literate programming, reproducible research, accounting
7;; Homepage: http://orgmode.org
afe98dfa
CD
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 <http://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;;
27e428e7 32;; 2) we are generally only going to return output from the ledger program
afe98dfa
CD
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
47called by `org-babel-execute-src-block'."
48 (message "executing Ledger source code block")
49 (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
50 (cmdline (cdr (assoc :cmdline params)))
51 (in-file (org-babel-temp-file "ledger-"))
52 (out-file (org-babel-temp-file "ledger-output-")))
53 (with-temp-file in-file (insert body))
3ab2c837 54 (message "%s" (concat "ledger"
8223b1d2
BG
55 " -f " (org-babel-process-file-name in-file)
56 " " cmdline))
afe98dfa
CD
57 (with-output-to-string
58 (shell-command (concat "ledger"
59 " -f " (org-babel-process-file-name in-file)
60 " " cmdline
61 " > " (org-babel-process-file-name out-file))))
62 (with-temp-buffer (insert-file-contents out-file) (buffer-string))))
63
64(defun org-babel-prep-session:ledger (session params)
65 (error "Ledger does not support sessions"))
66
67(provide 'ob-ledger)
68
5b409b39 69
afe98dfa
CD
70
71;;; ob-ledger.el ends here