summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2014-09-04 22:31:34 -0700
committerCraig Earls <enderw88@gmail.com>2014-09-04 22:31:34 -0700
commitd3d5c333f5a379a3fe3cbbf43a1098a44ed9b1be (patch)
tree5330fdced6aa0af1b704660a5935396c54a96304 /lisp
parent91fc39c68da0d7a1affefcbe591b17c185501134 (diff)
downloadfork-ledger-d3d5c333f5a379a3fe3cbbf43a1098a44ed9b1be.tar.gz
fork-ledger-d3d5c333f5a379a3fe3cbbf43a1098a44ed9b1be.tar.bz2
fork-ledger-d3d5c333f5a379a3fe3cbbf43a1098a44ed9b1be.zip
improved xact iteration so fontify-whole-buffer doesn't miss xact separated by more than a single empty line
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ledger-fontify.el8
-rw-r--r--lisp/ledger-xact.el26
2 files changed, 30 insertions, 4 deletions
diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el
index 83c8753c..86fd35c5 100644
--- a/lisp/ledger-fontify.el
+++ b/lisp/ledger-fontify.el
@@ -40,14 +40,14 @@
(save-excursion
(message "Ledger fontify whole buffer")
(goto-char (point-min))
+
(while (not (eobp))
- (cond ((looking-at ledger-xact-start-regex)
+ (cond ((looking-at ledger-xact-start-regex)
(ledger-fontify-xact-at (point)))
((looking-at ledger-directive-start-regex)
(ledger-fontify-directive-at (point))))
-
- (forward-paragraph)
- (forward-char))))
+ (ledger-xact-next-xact-or-directive) ;; gets to beginning of next xact
+ )))
(defun ledger-fontify-activate ()
"add hook to fontify after buffer changes"
diff --git a/lisp/ledger-xact.el b/lisp/ledger-xact.el
index 1268af99..b16e5d85 100644
--- a/lisp/ledger-xact.el
+++ b/lisp/ledger-xact.el
@@ -206,6 +206,32 @@ correct chronological place in the buffer."
(insert (car args) " \n\n")
(end-of-line -1)))))
+(defun ledger-xact-start-xact-or-directive-p ()
+ "return t if at the beginning of an empty line or line
+beginning with whitespace"
+ (not (looking-at "[ \t]\\|\\(^$\\)")))
+
+(defun ledger-xact-next-xact-or-directive ()
+ "move to the beginning of the next xact"
+ (interactive)
+ (beginning-of-line)
+ (if (ledger-xact-start-xact-or-directive-p) ; if we are the start of an xact, move forward to the next xact
+ (progn
+ (forward-line)
+ (if (not (ledger-xact-start-xact-or-directive-p)) ; we have moved forward and are not at another xact, recurse forward
+ (ledger-xact-next-xact-or-directive)))
+ (while (not (or (eobp) ; we didn't start off at the beginning of an xact
+ (ledger-xact-start-xact-or-directive-p)))
+ (forward-line))))
+
+(defun ledger-xact-next-xact ()
+ (interactive)
+ (beginning-of-line)
+ (if (looking-at ledger-xact-start-regex)
+ (forward-line))
+ (re-search-forward ledger-xact-start-regex)
+ (forward-line -1))
+
(provide 'ledger-xact)