(ledger-reconcile): If a prefix argument is passed to C-c C-r
(ledger-reconcile), then it will attempt to use the auto-reconciler to pre-mark the uncleared transactions. Note that if it fails, and the uncleared list is long, it might appear to hang. It's far from fool-proof, but when it does work, it's like magic!
This commit is contained in:
parent
8f928b3bd9
commit
c240ec23fa
1 changed files with 37 additions and 5 deletions
42
ledger.el
42
ledger.el
|
|
@ -272,7 +272,7 @@ Return the difference in the format of a time value."
|
||||||
"]"))))))
|
"]"))))))
|
||||||
(force-mode-line-update))
|
(force-mode-line-update))
|
||||||
|
|
||||||
(defun ledger-reconcile-toggle ()
|
(defun ledger-reconcile-toggle (&optional no-update)
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((where (get-text-property (point) 'where))
|
(let ((where (get-text-property (point) 'where))
|
||||||
(account ledger-acct)
|
(account ledger-acct)
|
||||||
|
|
@ -289,10 +289,11 @@ Return the difference in the format of a time value."
|
||||||
(line-end-position)
|
(line-end-position)
|
||||||
(list 'face)))
|
(list 'face)))
|
||||||
(forward-line)
|
(forward-line)
|
||||||
(ledger-update-balance-display)))
|
(unless no-update
|
||||||
|
(ledger-update-balance-display))))
|
||||||
|
|
||||||
(defun ledger-reconcile (account)
|
(defun ledger-reconcile (account &optional arg)
|
||||||
(interactive "sAccount to reconcile: ")
|
(interactive "sAccount to reconcile: \nP")
|
||||||
(let* ((items (save-excursion
|
(let* ((items (save-excursion
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(ledger-parse-entries account)))
|
(ledger-parse-entries account)))
|
||||||
|
|
@ -314,7 +315,38 @@ Return the difference in the format of a time value."
|
||||||
'where (nth 0 item)))
|
'where (nth 0 item)))
|
||||||
(set-text-properties beg (1- (point))
|
(set-text-properties beg (1- (point))
|
||||||
(list 'where (nth 0 item)))))
|
(list 'where (nth 0 item)))))
|
||||||
(goto-char (point-min))))))
|
(goto-char (point-min)))
|
||||||
|
(when arg
|
||||||
|
(let (cleared)
|
||||||
|
;; attempt to auto-reconcile in the background
|
||||||
|
(with-temp-buffer
|
||||||
|
(let ((exit-code
|
||||||
|
(ledger-run-ledger
|
||||||
|
"--format" "\"%B\\n\"" "reconcile"
|
||||||
|
(concat "\"" account "\"")
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert (read-string "Reconcile account to: "))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (re-search-forward "\\([&$]\\)" nil t)
|
||||||
|
(replace-match "\\\\\\1"))
|
||||||
|
(buffer-string)))))
|
||||||
|
(when (= 0 exit-code)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (not (eobp))
|
||||||
|
(setq cleared
|
||||||
|
(cons (1+ (read (current-buffer))) cleared))
|
||||||
|
(forward-line)))))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(setq cleared (mapcar 'copy-marker (nreverse cleared))))
|
||||||
|
(dolist (pos cleared)
|
||||||
|
(while (and (not (eobp))
|
||||||
|
(/= pos (get-text-property (point) 'where)))
|
||||||
|
(forward-line))
|
||||||
|
(unless (eobp)
|
||||||
|
(ledger-reconcile-toggle t)))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(ledger-update-balance-display))))))
|
||||||
|
|
||||||
(defun ledger-align-dollars (&optional column)
|
(defun ledger-align-dollars (&optional column)
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue