Release 7.3
[org-mode/org-mode-NeilSmithlineMods.git] / lisp / ob-ledger.el
blob33ec9d3a89858623c8ea27f79246b1bf4fa2a676
1 ;;; ob-ledger.el --- org-babel functions for ledger evaluation
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
5 ;; Author: Eric S Fraga
6 ;; Keywords: literate programming, reproducible research, accounting
7 ;; Homepage: http://orgmode.org
8 ;; Version: 7.3
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Org-Babel support for evaluating ledger entries.
29 ;; This differs from most standard languages in that
31 ;; 1) there is no such thing as a "session" in ledger
33 ;; 2) we are generally only going to return output from the leger program
35 ;; 3) we are adding the "cmdline" header argument
37 ;; 4) there are no variables
39 ;;; Code:
40 (require 'ob)
42 (defvar org-babel-default-header-args:ledger
43 '((:results . "output") (:cmdline . "bal"))
44 "Default arguments to use when evaluating a ledger source block.")
46 (defun org-babel-execute:ledger (body params)
47 "Execute a block of Ledger entries with org-babel. This function is
48 called by `org-babel-execute-src-block'."
49 (message "executing Ledger source code block")
50 (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
51 (cmdline (cdr (assoc :cmdline params)))
52 (in-file (org-babel-temp-file "ledger-"))
53 (out-file (org-babel-temp-file "ledger-output-")))
54 (with-temp-file in-file (insert body))
55 (message (concat "ledger"
56 " -f " (org-babel-process-file-name in-file)
57 " " cmdline))
58 (with-output-to-string
59 (shell-command (concat "ledger"
60 " -f " (org-babel-process-file-name in-file)
61 " " cmdline
62 " > " (org-babel-process-file-name out-file))))
63 (with-temp-buffer (insert-file-contents out-file) (buffer-string))))
65 (defun org-babel-prep-session:ledger (session params)
66 (error "Ledger does not support sessions"))
68 (provide 'ob-ledger)
70 ;; arch-tag: 7bbb529e-95a1-4236-9d29-b0000b918c7c
72 ;;; ob-ledger.el ends here