summaryrefslogtreecommitdiff
path: root/lisp/ldg-exec.el
blob: d740fccc7e491d258f139bb8f910102a7aa33ad3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(defgroup ledger-binary 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)

(defvar ledger-delete-after nil)

(defun ledger-run-ledger (buffer &rest args)
  "run ledger with supplied arguments"
  ;; Let's try again, just in case they moved it while we were sleeping.
  (cond
   ((null ledger-binary-path)
    (error "The variable `ledger-binary-path' has not been set"))
   (t
    (let ((buf (current-buffer)))
      (with-current-buffer buffer
	(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 ledger-delete-after
			       buf nil "-f" "-")
			 args))))))))

(defun ledger-run-ledger-and-delete (buffer &rest args)
  (let ((ledger-delete-after t))
    (apply #'ledger-run-ledger buffer args)))

(provide 'ldg-exec)