Fix cl-defun keyword arg parsing. Please bootstrap.
[emacs.git] / lisp / org / ob-ledger.el
blob806fec61bebd247507fcae0b1dcc78951e0967c9
1 ;;; ob-ledger.el --- org-babel functions for ledger evaluation
3 ;; Copyright (C) 2010-2014 Free Software Foundation, Inc.
5 ;; Author: Eric S Fraga
6 ;; Keywords: literate programming, reproducible research, accounting
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
26 ;; Org-Babel support for evaluating ledger entries.
28 ;; This differs from most standard languages in that
30 ;; 1) there is no such thing as a "session" in ledger
32 ;; 2) we are generally only going to return output from the ledger program
34 ;; 3) we are adding the "cmdline" header argument
36 ;; 4) there are no variables
38 ;;; Code:
39 (require 'ob)
41 (defvar org-babel-default-header-args:ledger
42 '((:results . "output") (:cmdline . "bal"))
43 "Default arguments to use when evaluating a ledger source block.")
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 ((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))
54 (message "%s" (concat "ledger"
55 " -f " (org-babel-process-file-name in-file)
56 " " cmdline))
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))))
64 (defun org-babel-prep-session:ledger (session params)
65 (error "Ledger does not support sessions"))
67 (provide 'ob-ledger)
71 ;;; ob-ledger.el ends here