diff options
author | Craig Earls <enderw88@gmail.com> | 2014-11-11 19:54:43 -0700 |
---|---|---|
committer | Craig Earls <enderw88@gmail.com> | 2014-11-11 19:54:43 -0700 |
commit | a3f3aa304fcfb19fc716c5eaf33a6e152bb3aa71 (patch) | |
tree | ec3c8cd1d61b19c69ed50137a20e4c42eeb24a4c /lisp | |
parent | e54d7392bfafa51e657f92ee1a1feb68f7f2b123 (diff) | |
download | fork-ledger-a3f3aa304fcfb19fc716c5eaf33a6e152bb3aa71.tar.gz fork-ledger-a3f3aa304fcfb19fc716c5eaf33a6e152bb3aa71.tar.bz2 fork-ledger-a3f3aa304fcfb19fc716c5eaf33a6e152bb3aa71.zip |
Smash a bug that cause the status on a posting with no amount to bleed into the next line.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ledger-fontify.el | 69 | ||||
-rw-r--r-- | lisp/ledger-navigate.el | 2 | ||||
-rw-r--r-- | lisp/ledger-regex.el | 5 |
3 files changed, 53 insertions, 23 deletions
diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index d876e5e3..309cbc3b 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -63,6 +63,7 @@ (defun ledger-fontify-xact-by-line (extents) "do line-by-line detailed fontification of xact" + (interactive) (save-excursion (ledger-fontify-xact-start (car extents)) (while (< (point) (cadr extents)) @@ -92,27 +93,55 @@ Fontify the first line of an xact" (ledger-fontify-set-face (list (match-beginning 8) (match-end 8)) 'ledger-font-comment-face))) + (defun ledger-fontify-posting (pos) - (let ((state nil)) - (re-search-forward ledger-posting-regex) - (if (match-string 1) - (save-match-data (setq state (ledger-state-from-string (s-trim (match-string 1)))))) - (ledger-fontify-set-face (list (match-beginning 0) (match-end 2)) - (cond ((eq state 'cleared) - 'ledger-font-posting-account-cleared-face) - ((eq state 'pending) - 'ledger-font-posting-account-pending-face) - (t - 'ledger-font-posting-account-face))) - (ledger-fontify-set-face (list (match-beginning 4) (match-end 4)) - (cond ((eq state 'cleared) - 'ledger-font-posting-amount-cleared-face) - ((eq state 'pending) - 'ledger-font-posting-amount-pending-face) - (t - 'ledger-font-posting-amount-face))) - (ledger-fontify-set-face (list (match-beginning 5) (match-end 5)) - 'ledger-font-comment-face))) + (let* ((state nil) + (end-of-line-comment nil) + (end (progn (end-of-line) + (point))) + (start (progn (beginning-of-line) + (point)))) + + ;; Look for a posting status flag + (save-match-data ;; must use save-match-data to shadow the search + ;; results. If there is no status flag then the + ;; search below will fail and NOT clear the match + ;; data. So if the previous line did have a + ;; status flag it is still sitting in the match + ;; data, causing the current line to be fontified + ;; like the previous line. Don't ask how long + ;; that took to figure out + (re-search-forward " \\([*!]\\) " end t) + (if (match-string 1) + (setq state (ledger-state-from-string (s-trim (match-string 1)))))) + (beginning-of-line) + (re-search-forward "[[:graph:]]\\([ \t][ \t]\\)" end 'end) ;; find the end of the account, or end of line + + (when (<= (point) end) ;; we are still on the line + (ledger-fontify-set-face (list start (point)) + (cond ((eq state 'cleared) + 'ledger-font-posting-account-cleared-face) + ((eq state 'pending) + 'ledger-font-posting-account-pending-face) + (t + 'ledger-font-posting-account-face))) + + + (when (< (point) end) ;; there is still more to fontify + (setq start (point)) ;; update start of next font region + (setq end-of-line-comment (re-search-forward ";" end 'end)) ;; find the end of the line, or start of a comment + (ledger-fontify-set-face (list start (point) ) + (cond ((eq state 'cleared) + 'ledger-font-posting-amount-cleared-face) + ((eq state 'pending) + 'ledger-font-posting-amount-pending-face) + (t + 'ledger-font-posting-amount-face))) + (when end-of-line-comment + (setq start (point)) + (end-of-line) + (ledger-fontify-set-face (list (- start 1) (point)) ;; subtract 1 from start because we passed the semi-colon + 'ledger-font-comment-face)))))) (defun ledger-fontify-directive-at (position) (let ((extents (ledger-navigate-find-element-extents position)) diff --git a/lisp/ledger-navigate.el b/lisp/ledger-navigate.el index 97a545b3..d4e70984 100644 --- a/lisp/ledger-navigate.el +++ b/lisp/ledger-navigate.el @@ -65,7 +65,7 @@ beginning with whitespace" (interactive) ;; need to start at the beginning of a line incase we are in the first line of an xact already. (beginning-of-line) - (let ((sreg (concat "\\(~\\|" ledger-iso-date-regexp "\\)"))) + (let ((sreg (concat "^\\(~\\|" ledger-iso-date-regexp "\\)"))) (unless (looking-at sreg) (re-search-backward sreg nil t) (beginning-of-line))) diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el index 238cfc66..b13647b5 100644 --- a/lisp/ledger-regex.el +++ b/lisp/ledger-regex.el @@ -333,7 +333,8 @@ "\\)")) (defconst ledger-xact-start-regex - (concat ledger-iso-date-regexp ;; subexp 1 + (concat "^" ledger-iso-date-regexp ;; subexp 1 + ;; "\\(=" ledger-iso-date-regexp "\\)?" " ?\\([ *!]\\)" ;; mark, subexp 5 " ?\\((.*)\\)?" ;; code, subexp 6 " ?\\([^;\n]+\\)" ;; desc, subexp 7 @@ -343,7 +344,7 @@ (defconst ledger-posting-regex (concat "^[ \t]+ ?" ;; initial white space "\\([*!]\\)? ?" ;; state, subexpr 1 - "\\(.+?\\(\n\\|[ \t][ \t]\\)\\)" ;; account, subexpr 2 + "\\([[:print:]]+\\([ \t][ \t]\\)\\)" ;; account, subexpr 2 "\\([^;\n]*\\)" ;; amount, subexpr 4 "\\(.*\\)" ;; comment, subexpr 5 )) |