Fixed ledger-post-edit-amount so that it can be called from the and of an account with a null amount.

It automagically determines if the account has two spaces after and if not inserts them.
This commit is contained in:
Craig Earls 2013-02-04 10:08:34 -07:00
parent 595a8afa44
commit c4c088b55b

View file

@ -157,15 +157,22 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
(interactive) (interactive)
(goto-char (line-beginning-position)) (goto-char (line-beginning-position))
(when (re-search-forward ledger-post-line-regexp (line-end-position) t) (when (re-search-forward ledger-post-line-regexp (line-end-position) t)
(goto-char (match-end ledger-regex-post-line-group-account)) (goto-char (match-end ledger-regex-post-line-group-account)) ;go to the and of the account
(when (re-search-forward "[-.,0-9]+" (line-end-position) t) (let ((end-of-amount (re-search-forward "[-.,0-9]+" (line-end-position) t))) ;determine if the is an amount to edit
(let ((val (match-string 0))) (if end-of-amount
(goto-char (match-beginning 0)) (let ((val (match-string 0)))
(delete-region (match-beginning 0) (match-end 0)) (goto-char (match-beginning 0))
(calc) (delete-region (match-beginning 0) (match-end 0))
(while (string-match "," val) (calc)
(setq val (replace-match "" nil nil val))) (while (string-match "," val)
(calc-eval val 'push))))) (setq val (replace-match "" nil nil val))) ;gets rid of commas
(calc-eval val 'push)) ;edit the amount
(progn ;make sure there are two spaces after the account name and go to calc
(if (search-backward " " (- (point) 3) t)
(goto-char (line-end-position))
(insert " "))
(calc))
))))
(defun ledger-post-prev-xact () (defun ledger-post-prev-xact ()
(interactive) (interactive)