improved xact iteration so fontify-whole-buffer doesn't miss xact separated by more than a single empty line
This commit is contained in:
parent
91fc39c68d
commit
d3d5c333f5
2 changed files with 30 additions and 4 deletions
|
|
@ -40,14 +40,14 @@
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(message "Ledger fontify whole buffer")
|
(message "Ledger fontify whole buffer")
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
|
||||||
(while (not (eobp))
|
(while (not (eobp))
|
||||||
(cond ((looking-at ledger-xact-start-regex)
|
(cond ((looking-at ledger-xact-start-regex)
|
||||||
(ledger-fontify-xact-at (point)))
|
(ledger-fontify-xact-at (point)))
|
||||||
((looking-at ledger-directive-start-regex)
|
((looking-at ledger-directive-start-regex)
|
||||||
(ledger-fontify-directive-at (point))))
|
(ledger-fontify-directive-at (point))))
|
||||||
|
(ledger-xact-next-xact-or-directive) ;; gets to beginning of next xact
|
||||||
(forward-paragraph)
|
)))
|
||||||
(forward-char))))
|
|
||||||
|
|
||||||
(defun ledger-fontify-activate ()
|
(defun ledger-fontify-activate ()
|
||||||
"add hook to fontify after buffer changes"
|
"add hook to fontify after buffer changes"
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,32 @@ correct chronological place in the buffer."
|
||||||
(insert (car args) " \n\n")
|
(insert (car args) " \n\n")
|
||||||
(end-of-line -1)))))
|
(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)
|
(provide 'ledger-xact)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue