ledger-reconcile-compile-format-string returns a lambda that is used to format the posting data

This commit is contained in:
Craig Earls 2014-07-02 20:50:47 -07:00
parent ad31fb580a
commit fad7e307e7

View file

@ -84,8 +84,10 @@ reconcile-finish will mark all pending posting cleared."
:type 'string :type 'string
:group 'ledger-reconcile) :group 'ledger-reconcile)
(defcustom ledger-reconcile-buffer-line-format "" (defcustom ledger-reconcile-buffer-line-format "%(date)s %-4(code)s %-50(payee)s %-30(account)s %15(amount)s\n"
"Format string for the ledger reconcile posting format. Available fields are date, status, code, payee, account, relatedaccount, amount") "Format string for the ledger reconcile posting format. Available fields are date, status, code, payee, account, amount"
:type 'string
:group 'ledger-reconcile)
(defcustom ledger-reconcile-sort-key "(0)" (defcustom ledger-reconcile-sort-key "(0)"
"Default key for sorting reconcile buffer. Possible values are "Default key for sorting reconcile buffer. Possible values are
@ -312,9 +314,14 @@ POSTING is used in `ledger-clear-whole-transactions' is nil."
(nth 1 emacs-xact) ;; return line-no of xact (nth 1 emacs-xact) ;; return line-no of xact
(nth 0 posting))))) ;; return line-no of posting (nth 0 posting))))) ;; return line-no of posting
(defun ledger-reconcile-format-posting (beg where date code status payee account amount) (defun ledger-reconcile-compile-format-string (fstr)
(insert (format "%s %-4s %-50s %-30s %15s\n" "return a function that implements the format string in fstr"
date code payee account amount))
`(lambda (date code status payee account amount)
(format "%s %-4s %-50s %-30s %15s\n" date code payee account amount)))
(defun ledger-reconcile-format-posting (beg where fmt date code status payee account amount)
(insert (funcall fmt date code status payee account amount))
; Set face depending on cleared status ; Set face depending on cleared status
(if status (if status
@ -329,21 +336,21 @@ POSTING is used in `ledger-clear-whole-transactions' is nil."
(list 'face 'ledger-font-reconciler-uncleared-face (list 'face 'ledger-font-reconciler-uncleared-face
'where where)))) 'where where))))
(defun ledger-reconcile-format-xact (xact) (defun ledger-reconcile-format-xact (xact fmt)
(let ((date-format (or (cdr (assoc "date-format" ledger-environment-alist)) (let ((date-format (or (cdr (assoc "date-format" ledger-environment-alist))
ledger-default-date-format))) ledger-default-date-format)))
(dolist (posting (nthcdr 5 xact)) (dolist (posting (nthcdr 5 xact))
(let ((beg (point)) (let ((beg (point))
(where (ledger-marker-where-xact-is xact posting))) (where (ledger-marker-where-xact-is xact posting)))
(ledger-reconcile-format-posting (ledger-reconcile-format-posting beg
beg where
where fmt
(format-time-string date-format (nth 2 xact)) (format-time-string date-format (nth 2 xact)) ; date
(if (nth 3 xact) (nth 3 xact) "") (if (nth 3 xact) (nth 3 xact) "") ; code
(nth 3 posting) (nth 3 posting) ; status
(truncate-string-to-width (nth 4 xact) 49) (nth 4 xact) ; payee
(nth 1 posting) (nth 1 posting) ; account
(nth 2 posting)))))) (nth 2 posting)))))) ; amount
(defun ledger-do-reconcile (&optional sort) (defun ledger-do-reconcile (&optional sort)
"Return the number of uncleared transactions in the account and display them in the *Reconcile* buffer." "Return the number of uncleared transactions in the account and display them in the *Reconcile* buffer."
@ -361,12 +368,13 @@ POSTING is used in `ledger-clear-whole-transactions' is nil."
(goto-char (point-min)) (goto-char (point-min))
(unless (eobp) (unless (eobp)
(if (looking-at "(") (if (looking-at "(")
(read (current-buffer)))))))) ;current-buffer is the *temp* created above (read (current-buffer))))))) ;current-buffer is the *temp* created above
(fmt (ledger-reconcile-compile-format-string "str")))
(if (and ledger-success (> (length xacts) 0)) (if (and ledger-success (> (length xacts) 0))
(progn (progn
(insert (format ledger-reconcile-buffer-header account)) (insert (format ledger-reconcile-buffer-header account))
(dolist (xact xacts) (dolist (xact xacts)
(ledger-reconcile-format-xact xact)) (ledger-reconcile-format-xact xact fmt))
(goto-char (point-max)) (goto-char (point-max))
(delete-char -1)) ;gets rid of the extra line feed at the bottom of the list (delete-char -1)) ;gets rid of the extra line feed at the bottom of the list
(if ledger-success (if ledger-success