summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2013-02-15 08:54:04 -0700
committerCraig Earls <enderw88@gmail.com>2013-02-15 08:54:04 -0700
commit9d2b2e3cebacb40abadfe6820a0064bbff088d39 (patch)
treefeda9b012d3bb530ccd54856bb4c30e9aa48a154
parent8116ef478160364cde1b33429ae03c81a536ccbf (diff)
downloadfork-ledger-9d2b2e3cebacb40abadfe6820a0064bbff088d39.tar.gz
fork-ledger-9d2b2e3cebacb40abadfe6820a0064bbff088d39.tar.bz2
fork-ledger-9d2b2e3cebacb40abadfe6820a0064bbff088d39.zip
Fixes Bug 897. toggle now works correctly if there are comment lines in the xact
-rw-r--r--lisp/ldg-state.el32
1 files changed, 20 insertions, 12 deletions
diff --git a/lisp/ldg-state.el b/lisp/ldg-state.el
index 3e349e4e..6c66ab24 100644
--- a/lisp/ldg-state.el
+++ b/lisp/ldg-state.el
@@ -73,6 +73,8 @@
'pending)
((eql state-char ?\*)
'cleared)
+ ((eql state-char ?\;)
+ 'comment)
(t
nil)))
@@ -92,7 +94,8 @@ dropped."
new-status cur-status)
;; Uncompact the entry, to make it easier to toggle the
;; transaction
- (save-excursion ;; this excursion unclears the posting
+ (save-excursion ;; this excursion checks state of entire
+ ;; transaction and unclears if marked
(goto-char (car bounds)) ;; beginning of xact
(skip-chars-forward "0-9./= \t") ;; skip the date
(setq cur-status (and (member (char-after) '(?\* ?\!))
@@ -107,15 +110,17 @@ dropped."
(if (search-forward " " (line-end-position) t)
(insert (make-string width ? ))))))
(forward-line)
+ ;; Shift the cleared/pending status to the postings
(while (looking-at "[ \t]")
(skip-chars-forward " \t")
- (insert (ledger-char-from-state cur-status) " ")
- (if (search-forward " " (line-end-position) t)
- (delete-char 2))
- (forward-line))
+ (when (not (eq (ledger-state-from-char (char-after)) 'comment))
+ (insert (ledger-char-from-state cur-status) " ")
+ (if (search-forward " " (line-end-position) t)
+ (delete-char 2)))
+ (forward-line))
(setq new-status nil)))
- ;;this excursion marks the posting pending or cleared
+ ;;this excursion toggles the posting status
(save-excursion
(goto-char (line-beginning-position))
(when (looking-at "[ \t]")
@@ -154,7 +159,9 @@ dropped."
(delete-char 1))))
(setq new-status inserted)))))
- ;; This excursion cleans up the entry so that it displays minimally
+ ;; This excursion cleans up the entry so that it displays
+ ;; minimally. This means that if all posts are cleared, remove
+ ;; the marks and clear the entire transaction.
(save-excursion
(goto-char (car bounds))
(forward-line)
@@ -164,11 +171,12 @@ dropped."
(while (and (not hetero) (looking-at "[ \t]"))
(skip-chars-forward " \t")
(let ((cur-status (ledger-state-from-char (char-after))))
- (if first
- (setq state cur-status
- first nil)
- (if (not (eq state cur-status))
- (setq hetero t))))
+ (if (not (eq cur-status 'comment))
+ (if first
+ (setq state cur-status
+ first nil)
+ (if (not (eq state cur-status))
+ (setq hetero t)))))
(forward-line))
(when (and (not hetero) (not (eq state nil)))
(goto-char (car bounds))