ob-ledger.el 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.01trans
  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. )
  44. (with-temp-file in-file (insert body))
  45. (message (concat "ledger -f " in-file " " cmdline))
  46. (with-output-to-string
  47. (shell-command (concat "ledger -f " in-file " " cmdline " > " out-file)))
  48. (with-temp-buffer (insert-file-contents out-file) (buffer-string))))
  49. (defun org-babel-prep-session:ledger (session params)
  50. (error "Ledger does not support sessions"))
  51. (provide 'ob-ledger)
  52. ;; arch-tag: 7bbb529e-95a1-4236-9d29-b0000b918c7c
  53. ;;; ob-ledger.el ends here