ob-core: Make `org-babel-hash-show-time' a defcustom
[org-mode/org-tableheadings.git] / lisp / ob-ledger.el
blobee2ce0a3c580ea8a6669c3cf6c0248337368360b
1 ;;; ob-ledger.el --- Babel Functions for Ledger -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2010-2016 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 ((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))))
63 (defun org-babel-prep-session:ledger (_session _params)
64 (error "Ledger does not support sessions"))
66 (provide 'ob-ledger)
70 ;;; ob-ledger.el ends here