ob-ledger.el 2.4 KB

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