diff options
-rw-r--r-- | lisp/ldg-fonts.el | 30 | ||||
-rw-r--r-- | lisp/ldg-mode.el | 4 | ||||
-rw-r--r-- | lisp/ldg-regex.el | 7 |
3 files changed, 40 insertions, 1 deletions
diff --git a/lisp/ldg-fonts.el b/lisp/ldg-fonts.el index 8ba84c84..fc0b7813 100644 --- a/lisp/ldg-fonts.el +++ b/lisp/ldg-fonts.el @@ -115,6 +115,7 @@ ;; ledger-font-other-face) (,ledger-comment-regex 0 'ledger-font-comment-face) + (,ledger-multiline-comment-regex 0 'ledger-font-comment-face) (,ledger-payee-pending-regex 2 'ledger-font-payee-pending-face) ; Works (,ledger-payee-cleared-regex 2 @@ -130,7 +131,34 @@ (,ledger-other-entries-regex 1 'ledger-font-other-face)) "Expressions to highlight in Ledger mode.") - + +(defun ledger-extend-region-multiline-comment () + "Adjusts the variables font-lock-beg and font-lock-end if they + fall within a multiline comment. Returns non-nil if an + adjustment is made." + (let (beg end) + ;; fix beg + (save-excursion + (goto-char font-lock-beg) + (end-of-line) + (when (re-search-backward ledger-multiline-comment-start-regex nil t) + (setq beg (point)) + (re-search-forward ledger-multiline-comment-regex nil t) + (if (and (>= (point) font-lock-beg) + (/= beg font-lock-beg)) + (setq font-lock-beg beg) + (setq beg nil)))) + ;; fix end + (save-excursion + (goto-char font-lock-end) + (end-of-line) + (when (re-search-backward ledger-multiline-comment-start-regex nil t) + (re-search-forward ledger-multiline-comment-regex nil t) + (setq end (point)) + (if (> end font-lock-end) + (setq font-lock-end end) + (setq end nil)))) + (or beg end))) (provide 'ldg-fonts) diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 2b707e26..160296c3 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -110,6 +110,10 @@ Can indent, complete or align depending on context." (if (boundp 'font-lock-defaults) (set (make-local-variable 'font-lock-defaults) '(ledger-font-lock-keywords nil t))) + (setq font-lock-extend-region-functions + (list #'font-lock-extend-region-wholelines + #'ledger-extend-region-multiline-comment)) + (setq font-lock-multiline nil) (set (make-local-variable 'pcomplete-parse-arguments-function) 'ledger-parse-arguments) diff --git a/lisp/ldg-regex.el b/lisp/ldg-regex.el index c9e60e71..cdd06d39 100644 --- a/lisp/ldg-regex.el +++ b/lisp/ldg-regex.el @@ -45,6 +45,13 @@ (defconst ledger-comment-regex "^[;#|\\*%].*\\|[ \t]+;.*") +(defconst ledger-multiline-comment-start-regex + "^!comment$") +(defconst ledger-multiline-comment-end-regex + "^!end_comment$") +(defconst ledger-multiline-comment-regex + "^!comment\n\\(.*\n\\)*?!end_comment$") + (defconst ledger-payee-any-status-regex "^[0-9]+[-/][-/.=0-9]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.+?\\)\\s-*\\(;\\|$\\)") |