diff options
author | Craig Earls <enderw88@gmail.com> | 2013-02-04 10:08:34 -0700 |
---|---|---|
committer | Craig Earls <enderw88@gmail.com> | 2013-02-04 10:08:34 -0700 |
commit | c4c088b55b2528292cf8b84eb36632f7d4343075 (patch) | |
tree | 8bfde48a2cb12af623278c501e1f28231f5b5b3d /lisp | |
parent | 595a8afa44ad3f30995556fbee36ac16024e7c23 (diff) | |
download | ledger-c4c088b55b2528292cf8b84eb36632f7d4343075.tar.gz ledger-c4c088b55b2528292cf8b84eb36632f7d4343075.tar.bz2 ledger-c4c088b55b2528292cf8b84eb36632f7d4343075.zip |
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.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ldg-post.el | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 14a8cdad..dc033bf8 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -156,16 +156,23 @@ This is done so that the last digit falls in COLUMN, which defaults to 52." (defun ledger-post-edit-amount () (interactive) (goto-char (line-beginning-position)) - (when (re-search-forward ledger-post-line-regexp (line-end-position) t) - (goto-char (match-end ledger-regex-post-line-group-account)) - (when (re-search-forward "[-.,0-9]+" (line-end-position) t) - (let ((val (match-string 0))) - (goto-char (match-beginning 0)) - (delete-region (match-beginning 0) (match-end 0)) - (calc) - (while (string-match "," val) - (setq val (replace-match "" nil nil val))) - (calc-eval val 'push))))) + (when (re-search-forward ledger-post-line-regexp (line-end-position) t) + (goto-char (match-end ledger-regex-post-line-group-account)) ;go to the and of the account + (let ((end-of-amount (re-search-forward "[-.,0-9]+" (line-end-position) t))) ;determine if the is an amount to edit + (if end-of-amount + (let ((val (match-string 0))) + (goto-char (match-beginning 0)) + (delete-region (match-beginning 0) (match-end 0)) + (calc) + (while (string-match "," val) + (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 () (interactive) |