ob-ledger.el 2.5 KB

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