diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-12 04:32:02 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-12 04:32:02 -0400 |
commit | 5f1a858941adc17fcf714c7b6b176aeae727c436 (patch) | |
tree | 846efb794cb76fdc4c63fa4c6ab554b83af49f07 /lisp/ldg-exec.el | |
parent | 7ca8149ec5c7fa88d98df83e6260210372223036 (diff) | |
parent | cb047c013df0eaf1c5e9edd67bbb6b6fa537d2a0 (diff) | |
download | fork-ledger-5f1a858941adc17fcf714c7b6b176aeae727c436.tar.gz fork-ledger-5f1a858941adc17fcf714c7b6b176aeae727c436.tar.bz2 fork-ledger-5f1a858941adc17fcf714c7b6b176aeae727c436.zip |
Merge branch 'next'
Diffstat (limited to 'lisp/ldg-exec.el')
-rw-r--r-- | lisp/ldg-exec.el | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lisp/ldg-exec.el b/lisp/ldg-exec.el new file mode 100644 index 00000000..3881f8e9 --- /dev/null +++ b/lisp/ldg-exec.el @@ -0,0 +1,34 @@ +(defgroup ledger-exec nil + "Interface to the Ledger command-line accounting program." + :group 'ledger) + +(defcustom ledger-binary-path "ledger" + "Path to the ledger executable." + :type 'file + :group 'ledger) + +(defun ledger-exec-ledger (input-buffer &optional output-buffer &rest args) + "Run Ledger." + (if (null ledger-binary-path) + (error "The variable `ledger-binary-path' has not been set")) + (let ((buf (or input-buffer (current-buffer))) + (outbuf (or output-buffer + (generate-new-buffer " *ledger-tmp*")))) + (with-current-buffer buf + (let ((coding-system-for-write 'utf-8) + (coding-system-for-read 'utf-8)) + (apply #'call-process-region + (append (list (point-min) (point-max) + ledger-binary-path nil outbuf nil "-f" "-") + args))) + outbuf))) + +(defun ledger-exec-read (&optional input-buffer &rest args) + (with-current-buffer + (apply #'ledger-exec-ledger input-buffer nil "emacs" args) + (goto-char (point-min)) + (prog1 + (read (current-buffer)) + (kill-buffer (current-buffer))))) + +(provide 'ldg-exec) |