diff options
author | John Wiegley <johnw@newartisans.com> | 2005-02-09 12:13:21 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:40:56 -0400 |
commit | c240ec23fa55fa5520b611d7f74ca9e19fe8b7d7 (patch) | |
tree | 4d3e6497c7429f668860e453af7c104c7d0e1ced /ledger.el | |
parent | 8f928b3bd9ca9f8a3f3f6ec83a2dae6e3012562d (diff) | |
download | fork-ledger-c240ec23fa55fa5520b611d7f74ca9e19fe8b7d7.tar.gz fork-ledger-c240ec23fa55fa5520b611d7f74ca9e19fe8b7d7.tar.bz2 fork-ledger-c240ec23fa55fa5520b611d7f74ca9e19fe8b7d7.zip |
(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!
Diffstat (limited to 'ledger.el')
-rw-r--r-- | ledger.el | 42 |
1 files changed, 37 insertions, 5 deletions
@@ -272,7 +272,7 @@ Return the difference in the format of a time value." "]")))))) (force-mode-line-update)) -(defun ledger-reconcile-toggle () +(defun ledger-reconcile-toggle (&optional no-update) (interactive) (let ((where (get-text-property (point) 'where)) (account ledger-acct) @@ -289,10 +289,11 @@ Return the difference in the format of a time value." (line-end-position) (list 'face))) (forward-line) - (ledger-update-balance-display))) + (unless no-update + (ledger-update-balance-display)))) -(defun ledger-reconcile (account) - (interactive "sAccount to reconcile: ") +(defun ledger-reconcile (account &optional arg) + (interactive "sAccount to reconcile: \nP") (let* ((items (save-excursion (goto-char (point-min)) (ledger-parse-entries account))) @@ -314,7 +315,38 @@ Return the difference in the format of a time value." 'where (nth 0 item))) (set-text-properties beg (1- (point)) (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) (interactive "p") |