Make reconcile more robust to empty or bad account entries at the prompt.

This commit is contained in:
Craig Earls 2014-12-05 21:30:29 -07:00
parent 3d179c4213
commit a5d4d780dc
2 changed files with 35 additions and 27 deletions

View file

@ -100,7 +100,7 @@
"Read an account from the minibuffer with PROMPT."
(let ((context (ledger-context-at-point)))
(ledger-read-string-with-default prompt
(if (eq (ledger-context-line-type context) 'acct-transaction)
(if (eq (ledger-context-current-field context) 'account)
(regexp-quote (ledger-context-field-value context 'account))
nil))))

View file

@ -438,6 +438,13 @@ moved and recentered. If they aren't strange things happen."
(set-window-buffer (split-window (get-buffer-window buf) nil nil) rbuf)
(pop-to-buffer rbuf)))
(defun ledger-reconcile-check-valid-account (account)
"Check to see if ACCOUNT exists in the ledger file"
(if (> (length account) 0)
(save-excursion
(goto-char (point-min))
(search-forward account nil t))))
(defun ledger-reconcile ()
"Start reconciling, prompt for account."
(interactive)
@ -445,6 +452,7 @@ moved and recentered. If they aren't strange things happen."
(buf (current-buffer))
(rbuf (get-buffer ledger-recon-buffer-name)))
(when (ledger-reconcile-check-valid-account account)
(add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t)
(if rbuf ;; *Reconcile* already exists
@ -475,7 +483,7 @@ moved and recentered. If they aren't strange things happen."
(ledger-occur-mode account ledger-buf)))
(if (> (ledger-reconcile-refresh) 0)
(ledger-reconcile-change-target))
(ledger-display-balance))))
(ledger-display-balance)))))
(defvar ledger-reconcile-mode-abbrev-table)