diff options
author | Steve Purcell <steve@sanityinc.com> | 2014-12-09 16:26:51 +0000 |
---|---|---|
committer | Steve Purcell <steve@sanityinc.com> | 2014-12-09 16:26:51 +0000 |
commit | 01c91130d79b8ed23443507550641ffafae1b88c (patch) | |
tree | 0366a21395565e3d439b27367979e2aee563213f /lisp/ledger-fontify.el | |
parent | b623306591cab200cc7c69fb15ea7fe2dfc81bfd (diff) | |
download | ledger-01c91130d79b8ed23443507550641ffafae1b88c.tar.gz ledger-01c91130d79b8ed23443507550641ffafae1b88c.tar.bz2 ledger-01c91130d79b8ed23443507550641ffafae1b88c.zip |
[emacs] Parse transaction leading lines more robustly
This began with noticing that the code didn't support the (ugly, yet
valid) case of a tab between the date and txn description. I took the
opportunity to make the regexes more consistent along the way.
Diffstat (limited to 'lisp/ledger-fontify.el')
-rw-r--r-- | lisp/ledger-fontify.el | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index d9e74cff..ea873d91 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -76,26 +76,27 @@ (forward-line)))) (defun ledger-fontify-xact-start (pos) - "POS should be at the beginning of a line starting an xact. + "POS should be at the beginning of a line starting an xact. Fontify the first line of an xact" - (goto-char pos) - (beginning-of-line) - (let ((state nil) - (cur-point (point))) - (re-search-forward " ") - (ledger-fontify-set-face (list cur-point (point)) 'ledger-font-posting-date-face) - (beginning-of-line) - (re-search-forward ledger-xact-after-date-regex) - (save-match-data (setq state (ledger-state-from-string (match-string 1)))) - (ledger-fontify-set-face (list (match-beginning 1) (match-end 3)) - (cond ((eq state 'pending) - 'ledger-font-payee-pending-face) - ((eq state 'cleared) - 'ledger-font-payee-cleared-face) - (t - 'ledger-font-payee-uncleared-face))) - (ledger-fontify-set-face (list (match-beginning 4) - (match-end 4)) 'ledger-font-comment-face))) + (goto-char pos) + (let ((line-start (line-beginning-position))) + (goto-char line-start) + (re-search-forward "[ \t]") + (ledger-fontify-set-face (list line-start (match-beginning 0)) 'ledger-font-posting-date-face) + (goto-char line-start) + (re-search-forward ledger-xact-after-date-regex) + (let ((state (save-match-data (ledger-state-from-string (match-string 1))))) + (ledger-fontify-set-face (list (match-beginning 3) (match-end 3)) + (cond ((eq state 'pending) + 'ledger-font-payee-pending-face) + ((eq state 'cleared) + 'ledger-font-payee-cleared-face) + (t + 'ledger-font-payee-uncleared-face)))) + (when (match-beginning 4) + (ledger-fontify-set-face (list (match-beginning 4) + (match-end 4)) 'ledger-font-comment-face)) + (forward-line))) (defun ledger-fontify-posting (pos) "Fontify the posting at POS." |