From 4deaeb02c9dfb3f1bf51e998b85b0a433ac9f212 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sun, 24 Aug 2014 18:37:24 -0700 Subject: Set up fontification independent of font-lock. Basic functionality in place. need to test further and expand detail fortification. --- lisp/ledger-fontify.el | 173 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 lisp/ledger-fontify.el (limited to 'lisp/ledger-fontify.el') diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el new file mode 100644 index 00000000..ff194649 --- /dev/null +++ b/lisp/ledger-fontify.el @@ -0,0 +1,173 @@ +;;; ledger-fontify.el --- Provide custom fontification for ledger-mode + + +;; Copyright (C) 2014 Craig P. Earls (enderw88 at gmail dot com) + +;; This file is not part of GNU Emacs. + +;; This is free software; you can redistribute it and/or modify it under +;; the terms of the GNU General Public License as published by the Free +;; Software Foundation; either version 2, or (at your option) any later +;; version. +;; +;; This is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +;; for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +;; MA 02110-1301 USA. + +;;; Commentary: +;; Font-lock-mode doesn't handle multiline syntax very well. This +;; code provides font lock that is sensitive to overall transaction +;; states + + +(provide 'ledger-fontify) + +(defcustom ledger-fontify-xact-state-overrides t + "If t the overall xact state (cleard, pending, nil) will + control the font of the entire transaction, not just the payee + line." + :type 'boolean + :group 'ledger-fontification) + +(defun ledger-fontify-whole-buffer () + (interactive) + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (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)))) + +(defun ledger-fontify-activate () + "add hook to fontify after buffer changes" + (interactive) + (if (string= (format-mode-line 'mode-name) "Ledger") + (progn + (add-hook 'post-command-hook 'ledger-fontify-buffer-part) + ;; this is a silly work around to emacs bug 16796 wherein + ;; after-change-functions is randomly reset to nil. Before + ;; each change make sure after-change-functions is properly + ;; set. +; (add-hook 'before-change-functions 'ledger-fontify-ensure-after-change-hook) + ))) + +;; (defun ledger-fontify-ensure-after-change-hook (beg end) +;; (if (string= (format-mode-line 'mode-name) "Ledger") +;; (add-hook 'after-change-functions 'ledger-fontify-buffer-part))) + +(defun ledger-fontify-buffer-part () + (save-excursion + (backward-paragraph) + (forward-char) + (cond ((looking-at ledger-xact-start-regex) + (ledger-fontify-xact-at (point))) + ((looking-at ledger-directive-start-regex) + (ledger-fontify-directive-at (point)))))) + +(defun ledger-fontify-xact-at (position) + (interactive "d") + (let ((extents (ledger-find-xact-extents position)) + (state (ledger-transaction-state))) + (if (and ledger-fontify-xact-state-overrides state) + (cond ((eq state 'cleared) + (ledger-fontify-set-face extents 'ledger-font-xact-cleared-face)) + ((eq state 'pending) + (ledger-fontify-set-face extents 'ledger-font-xact-pending-face))) + (ledger-fontify-xact-by-line extents)))) + +(defun ledger-fontify-xact-by-line (extends) + "do line-by-line detailed fontification of xact" + (save-excursion + (ledger-fontify-xact-start (car extents)))) + +(defun ledger-fontify-xact-start (pos) + (interactive "d") + (goto-char pos) + (let ((state nil)) + (re-search-forward ledger-xact-start-regex) + (ledger-fontify-set-face (list (match-beginning 1) (match-end 1)) 'ledger-font-posting-date-face) + (save-match-data (setq state (ledger-state-from-string (s-trim (match-string 5))))) + (ledger-fontify-set-face (list (match-beginning 7) (match-end 7)) + (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 8) + (match-end 8)) 'ledger-font-comment-face))) + +(defun ledger-fontify-directive-at (position) + (interactive "d") + (let ((extents (ledger-find-xact-extents position)) + (face 'ledger-font-default-face)) + (cond ((looking-at "=") + (setq face 'ledger-font-auto-xact-face)) + ((looking-at "~") + (setq face 'ledger-font-periodic-xact-face)) + ((looking-at "[;#%|\\*]") + (setq face 'ledger-font-comment-face)) + ((looking-at "\\(year\\)\\|Y") + (setq face 'ledger-font-year-directive-face)) + ((looking-at "account") + (setq face 'ledger-font-account-directive-face)) + ((looking-at "apply") + (setq face 'ledger-font-apply-directive-face)) + ((looking-at "alias") + (setq face 'ledger-font-alias-directive-face)) + ((looking-at "assert") + (setq face 'ledger-font-assert-directive-face)) + ((looking-at "\\(bucket\\)\\|A") + (setq face 'ledger-font-bucket-directive-face)) + ((looking-at "capture") + (setq face 'ledger-font-capture-directive-face)) + ((looking-at "check") + (setq face 'ledger-font-check-directive-face)) + ((looking-at "commodity") + (setq face 'ledger-font-commodity-directive-face)) + ((looking-at "define") + (setq face 'ledger-font-define-directive-face)) + ((looking-at "end") + (setq face 'ledger-font-end-directive-face)) + ((looking-at "expr") + (setq face 'ledger-font-expr-directive-face)) + ((looking-at "fixed") + (setq face 'ledger-font-fixed-directive-face)) + ((looking-at "include") + (setq face 'ledger-font-include-directive-face)) + ((looking-at "payee") + (setq face 'ledger-font-payee-directive-face)) + ((looking-at "tag") + (setq face 'ledger-font-tag-directive-face))) + (ledger-fontify-set-face extents face))) + +(defun ledger-fontify-set-face (extents face) + (put-text-property (car extents) (cadr extents) 'face face)) + + +(defun s-trim-left (s) + "Remove whitespace at the beginning of S." + (if (string-match "\\`[ \t\n\r]+" s) + (replace-match "" t t s) + s)) + +(defun s-trim-right (s) + "Remove whitespace at the end of S." + (if (string-match "[ \t\n\r]+\\'" s) + (replace-match "" t t s) + s)) + +(defun s-trim (s) + "Remove whitespace at the beginning and end of S." + (s-trim-left (s-trim-right s))) +;;; ledger-fontify.el ends here -- cgit v1.2.3 From 4a003b5828fadd47cbea4144ca5352bf6ad4941c Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Sun, 24 Aug 2014 21:38:29 -0700 Subject: fontifying xact starts and postings. initial testing looks better than previous font-lock methods. Need run time and performance testing. --- lisp/ledger-fontify.el | 41 ++++++++++++++++++++++++++++------------- lisp/ledger-regex.el | 14 ++++++++------ 2 files changed, 36 insertions(+), 19 deletions(-) (limited to 'lisp/ledger-fontify.el') diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index ff194649..1023cd85 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -53,17 +53,7 @@ (interactive) (if (string= (format-mode-line 'mode-name) "Ledger") (progn - (add-hook 'post-command-hook 'ledger-fontify-buffer-part) - ;; this is a silly work around to emacs bug 16796 wherein - ;; after-change-functions is randomly reset to nil. Before - ;; each change make sure after-change-functions is properly - ;; set. -; (add-hook 'before-change-functions 'ledger-fontify-ensure-after-change-hook) - ))) - -;; (defun ledger-fontify-ensure-after-change-hook (beg end) -;; (if (string= (format-mode-line 'mode-name) "Ledger") -;; (add-hook 'after-change-functions 'ledger-fontify-buffer-part))) + (add-hook 'post-command-hook 'ledger-fontify-buffer-part)))) (defun ledger-fontify-buffer-part () (save-excursion @@ -85,10 +75,13 @@ (ledger-fontify-set-face extents 'ledger-font-xact-pending-face))) (ledger-fontify-xact-by-line extents)))) -(defun ledger-fontify-xact-by-line (extends) +(defun ledger-fontify-xact-by-line (extents) "do line-by-line detailed fontification of xact" (save-excursion - (ledger-fontify-xact-start (car extents)))) + (ledger-fontify-xact-start (car extents)) + (while (< (point) (cadr extents)) + (ledger-fontify-posting (point)) + (forward-line)))) (defun ledger-fontify-xact-start (pos) (interactive "d") @@ -107,6 +100,28 @@ (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-account-cleared-face) + ((eq state 'cleared) + 'ledger-font-posting-account-pending-face) + (t + 'ledger-font-posting-amount-face))) + (ledger-fontify-set-face (list (match-beginning 5) (match-end 5)) + 'ledger-font-comment-face))) + (defun ledger-fontify-directive-at (position) (interactive "d") (let ((extents (ledger-find-xact-extents position)) diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el index 49a2b114..bc7e926b 100644 --- a/lisp/ledger-regex.el +++ b/lisp/ledger-regex.el @@ -341,12 +341,14 @@ )) (defconst ledger-posting-regex - (concat "^[ \t]+" ;; initial white space - "\\(" - "\\([[:word:]: ]*?\n?\\) " ;; account, subexpr 2 - "\\(.*?\\)" ;; amount, subexpr 3 - "\\(\n\\|\\(;.*\\)\\)" ;; comment, subexpr 5 - "\\)")) + (concat "^[ \t]+ ?" ;; initial white space + "\\([*!]\\)? ?" ;; state, subexpr 1 + "\\([[:word:]: ]+\\(\n\\|[ \t][ \t]\\)\\)" ;; account, subexpr 2 + "\\([^;\n]*\\)" ;; amount, subexpr 4 + "\\(.*\\)" ;; comment, subexpr 5 + )) + + (defconst ledger-directive-start-regex "[=~;#%|\\*[A-Za-z]") -- cgit v1.2.3 From 403ca4f1a5b4a11eb4168e2e62709f4a09c3c202 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 26 Aug 2014 18:33:41 -0700 Subject: Not working well, try something else on new-fontification-scheme-2 --- lisp/ledger-fontify.el | 20 +++++++++++++++++--- lisp/ledger-mode.el | 12 ++++++++---- lisp/ledger-regex.el | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) (limited to 'lisp/ledger-fontify.el') diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index 1023cd85..83c8753c 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -38,6 +38,7 @@ (defun ledger-fontify-whole-buffer () (interactive) (save-excursion + (message "Ledger fontify whole buffer") (goto-char (point-min)) (while (not (eobp)) (cond ((looking-at ledger-xact-start-regex) @@ -53,13 +54,26 @@ (interactive) (if (string= (format-mode-line 'mode-name) "Ledger") (progn - (add-hook 'post-command-hook 'ledger-fontify-buffer-part)))) + (add-hook 'after-change-functions 'ledger-fontify-buffer-part) +; (add-hook 'before-change-functions 'ledger-fontify-ensure-activation) + (message "ledger-fontify-activate called")))) -(defun ledger-fontify-buffer-part () +(defun ledger-fontify-ensure-activation (beg end) + (if (string= (format-mode-line 'mode-name) "Ledger") + (add-hook 'after-change-functions 'ledger-fontify-buffer-part))) + +(defun ledger-fontify-buffer-part (beg end len) (save-excursion + (message (concat "ledger-fontify-buffer-part: " + (int-to-string beg) " " + (int-to-string end) " " + (int-to-string len) + )) +; (goto-char beg) (backward-paragraph) (forward-char) - (cond ((looking-at ledger-xact-start-regex) + (cond ((or (looking-at ledger-xact-start-regex) + (looking-at ledger-posting-regex)) (ledger-fontify-xact-at (point))) ((looking-at ledger-directive-start-regex) (ledger-fontify-directive-at (point)))))) diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 9291bf8f..18928fe0 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -320,8 +320,8 @@ With a prefix argument, remove the effective date. " (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) (add-hook 'after-save-hook 'ledger-report-redo) - (ledger-fontify-whole-buffer) - (ledger-fontify-activate) + ;(ledger-fontify-whole-buffer) + ;(ledger-fontify-activate) ;(add-hook 'after-save-hook) (add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t) @@ -329,8 +329,12 @@ With a prefix argument, remove the effective date. " (ledger-init-load-init-file) - (set (make-local-variable 'indent-region-function) 'ledger-post-align-postings) - (run-mode-hooks)) + (setq font-lock-defaults + '(nil t nil nil nil + (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer) + (font-lock-fontify-region-function . ledger-fontify-buffer-part))) + + (set (make-local-variable 'indent-region-function) 'ledger-post-align-postings)) (defun ledger-set-year (newyear) diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el index bc7e926b..460b50ce 100644 --- a/lisp/ledger-regex.el +++ b/lisp/ledger-regex.el @@ -336,7 +336,7 @@ (concat ledger-iso-date-regexp ;; subexp 1 " ?\\([ *!]\\)" ;; mark, subexp 5 " ?\\((.*)\\)?" ;; code, subexp 6 - " ?\\([[:word:] ]+\\)" ;; desc, subexp 7 + " ?\\([^;\n]+\\)" ;; desc, subexp 7 "\\(\n\\|;.*\\)" ;; comment, subexp 8 )) -- cgit v1.2.3 From d3d5c333f5a379a3fe3cbbf43a1098a44ed9b1be Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Thu, 4 Sep 2014 22:31:34 -0700 Subject: improved xact iteration so fontify-whole-buffer doesn't miss xact separated by more than a single empty line --- lisp/ledger-fontify.el | 8 ++++---- lisp/ledger-xact.el | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'lisp/ledger-fontify.el') 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) -- cgit v1.2.3 From fec5ecb4f34bca2fbfe7f7ee5c1e99a9527db01e Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 5 Sep 2014 20:12:03 -0700 Subject: meh. Still chugging along. --- lisp/ledger-fontify.el | 13 +++++++------ lisp/ledger-mode.el | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'lisp/ledger-fontify.el') diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index 86fd35c5..f282167e 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -54,8 +54,9 @@ (interactive) (if (string= (format-mode-line 'mode-name) "Ledger") (progn + (ledger-fontify-whole-buffer) (add-hook 'after-change-functions 'ledger-fontify-buffer-part) -; (add-hook 'before-change-functions 'ledger-fontify-ensure-activation) + (add-hook 'before-change-functions 'ledger-fontify-ensure-activation) (message "ledger-fontify-activate called")))) (defun ledger-fontify-ensure-activation (beg end) @@ -64,11 +65,11 @@ (defun ledger-fontify-buffer-part (beg end len) (save-excursion - (message (concat "ledger-fontify-buffer-part: " - (int-to-string beg) " " - (int-to-string end) " " - (int-to-string len) - )) + ;; (message (concat "ledger-fontify-buffer-part: " + ;; (int-to-string beg) " " + ;; (int-to-string end) " " + ;; (int-to-string len) + ;; )) ; (goto-char beg) (backward-paragraph) (forward-char) diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 0e8ad088..46b7e677 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -329,10 +329,11 @@ With a prefix argument, remove the effective date. " ;; (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer) ;; (font-lock-fontify-region-function . ledger-fontify-buffer-part))) - (setq-local font-lock-defaults `(,ledger-font-lock-keywords nil t nil nil - (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer))) + ;; (setq-local font-lock-defaults `(,ledger-font-lock-keywords nil t nil nil + ;; (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer))) - (setq-local indent-region-function 'ledger-post-align-postings)) + (setq-local indent-region-function 'ledger-post-align-postings) + (ledger-fontify-activate)) (defun ledger-set-year (newyear) -- cgit v1.2.3 From 991d162fb0a17305f8f43d9bf1f566d8227b54ec Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 5 Sep 2014 21:45:36 -0700 Subject: jit-lock is now calling ledger-fontify-buffer-part, but font-lock-fontify-region is still being called and fighting with it. --- lisp/ledger-fontify.el | 2 +- lisp/ledger-fonts.el | 84 +++++++++++++++++++++++++------------------------- lisp/ledger-mode.el | 58 ++++++++++++++++++++++++++-------- 3 files changed, 89 insertions(+), 55 deletions(-) (limited to 'lisp/ledger-fontify.el') diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index f282167e..7621b448 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -63,7 +63,7 @@ (if (string= (format-mode-line 'mode-name) "Ledger") (add-hook 'after-change-functions 'ledger-fontify-buffer-part))) -(defun ledger-fontify-buffer-part (beg end len) +(defun ledger-fontify-buffer-part (beg end) (save-excursion ;; (message (concat "ledger-fontify-buffer-part: " ;; (int-to-string beg) " " diff --git a/lisp/ledger-fonts.el b/lisp/ledger-fonts.el index 5725db09..0c3b9861 100644 --- a/lisp/ledger-fonts.el +++ b/lisp/ledger-fonts.el @@ -228,48 +228,48 @@ :group 'ledger-faces) -;; (defvar ledger-font-lock-keywords -;; `( ;; (,ledger-other-entries-regex 1 -;; ;; ledger-font-other-face) -;; (,ledger-comment-regex 0 -;; 'ledger-font-comment-face) -;; (,ledger-amount-regex 0 -;; 'ledger-font-posting-amount-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 -;; 'ledger-font-payee-cleared-face) ; Works -;; (,ledger-payee-uncleared-regex 2 -;; 'ledger-font-payee-uncleared-face) ; Works -;; (,ledger-account-cleared-regex 2 -;; 'ledger-font-posting-account-cleared-face) ; Works -;; (,ledger-account-pending-regex 2 -;; 'ledger-font-posting-account-pending-face) ; Works -;; (,ledger-account-any-status-regex 2 -;; 'ledger-font-posting-account-face) ; Works -;; (,ledger-other-entries-regex 1 -;; 'ledger-font-other-face)) -;; "Expressions to highlight in Ledger mode.") - -(defvar ledger-font-lock-keywords - `(("account" . ledger-font-account-directive-face) - ("apply" . ledger-font-apply-directive-face) - ("alias" . ledger-font-alias-directive-face) - ("assert" . ledger-font-assert-directive-face) - ("bucket" . ledger-font-bucket-directive-face) - ("capture" . ledger-font-capture-directive-face) - ("check" . ledger-font-check-directive-face) - ("commodity" . ledger-font-commodity-directive-face) - ("define" . ledger-font-define-directive-face) - ("end" . ledger-font-end-directive-face) - ("expr" . ledger-font-expr-directive-face) - ("fixed" . ledger-font-fixed-directive-face) - ("include" . ledger-font-include-directive-face) - ("payee" . ledger-font-payee-directive-face) - ("tag" . ledger-font-tag-directive-face) - ("year" . ledger-font-year-directive-face)) - "Expressions to highlight in Ledger mode.") + ;; (defvar ledger-font-lock-keywords + ;; `( ;; (,ledger-other-entries-regex 1 + ;; ;; ledger-font-other-face) + ;; (,ledger-comment-regex 0 + ;; 'ledger-font-comment-face) + ;; (,ledger-amount-regex 0 + ;; 'ledger-font-posting-amount-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 + ;; 'ledger-font-payee-cleared-face) ; Works + ;; (,ledger-payee-uncleared-regex 2 + ;; 'ledger-font-payee-uncleared-face) ; Works + ;; (,ledger-account-cleared-regex 2 + ;; 'ledger-font-posting-account-cleared-face) ; Works + ;; (,ledger-account-pending-regex 2 + ;; 'ledger-font-posting-account-pending-face) ; Works + ;; (,ledger-account-any-status-regex 2 + ;; 'ledger-font-posting-account-face) ; Works + ;; (,ledger-other-entries-regex 1 + ;; 'ledger-font-other-face)) + ;; "Expressions to highlight in Ledger mode.") + + (defvar ledger-font-lock-keywords + `(("account" . ledger-font-account-directive-face) + ("apply" . ledger-font-apply-directive-face) + ("alias" . ledger-font-alias-directive-face) + ("assert" . ledger-font-assert-directive-face) + ("bucket" . ledger-font-bucket-directive-face) + ("capture" . ledger-font-capture-directive-face) + ("check" . ledger-font-check-directive-face) + ("commodity" . ledger-font-commodity-directive-face) + ("define" . ledger-font-define-directive-face) + ("end" . ledger-font-end-directive-face) + ("expr" . ledger-font-expr-directive-face) + ("fixed" . ledger-font-fixed-directive-face) + ("include" . ledger-font-include-directive-face) + ("payee" . ledger-font-payee-directive-face) + ("tag" . ledger-font-tag-directive-face) + ("year" . ledger-font-year-directive-face)) + "Expressions to highlight in Ledger mode.") diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 46b7e677..1f6d8c32 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -307,16 +307,58 @@ With a prefix argument, remove the effective date. " ["Kill Report" ledger-report-kill ledger-works])) ;;;###autoload +;; (define-derived-mode ledger-mode text-mode "Ledger" +;; "A mode for editing ledger data files." +;; (ledger-check-version) +;; (ledger-schedule-check-available) +;; ;;(ledger-post-setup) + +;; (setq-local pcomplete-parse-arguments-function 'ledger-parse-arguments) +;; (setq-local pcomplete-command-completion-function 'ledger-complete-at-point) +;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) + +;; (add-hook 'after-save-hook 'ledger-report-redo) + +;; (add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t) +;; (add-hook 'before-revert-hook 'ledger-occur-remove-all-overlays nil t) + +;; (ledger-init-load-init-file) + +;; ;; (setq font-lock-defaults +;; ;; `(,ledger-font-lock-keywords t nil nil nil +;; ;; (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer) +;; ;; (font-lock-fontify-region-function . ledger-fontify-buffer-part))) + +;; ;; (setq-local font-lock-defaults `(,ledger-font-lock-keywords nil t nil nil +;; ;; (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer))) + +;; (setq-local indent-region-function 'ledger-post-align-postings)) + (define-derived-mode ledger-mode text-mode "Ledger" "A mode for editing ledger data files." (ledger-check-version) (ledger-schedule-check-available) ;;(ledger-post-setup) - (setq-local pcomplete-parse-arguments-function 'ledger-parse-arguments) - (setq-local pcomplete-command-completion-function 'ledger-complete-at-point) - (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) + ;; (set-syntax-table ledger-mode-syntax-table) + ;; (set (make-local-variable 'comment-start) "; ") + ;; (set (make-local-variable 'comment-end) "") + ;; (set (make-local-variable 'indent-tabs-mode) nil) + + (if (boundp 'font-lock-defaults) + (setq-local font-lock-defaults + '(ledger-font-lock-keywords t t))) + + ;; (setq font-lock-extend-region-functions + ;; (list #'font-lock-extend-region-wholelines)) + ;; (setq font-lock-multiline nil) + (jit-lock-register 'ledger-fontify-buffer-part) + (jit-lock-unregister 'font-lock-fontify-region) + + (setq-local pcomplete-parse-arguments-function 'ledger-parse-arguments) + (setq-local pcomplete-command-completion-function 'ledger-complete-at-point) + (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) (add-hook 'after-save-hook 'ledger-report-redo) (add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t) @@ -324,16 +366,8 @@ With a prefix argument, remove the effective date. " (ledger-init-load-init-file) - ;; (setq font-lock-defaults - ;; `(,ledger-font-lock-keywords t nil nil nil - ;; (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer) - ;; (font-lock-fontify-region-function . ledger-fontify-buffer-part))) - - ;; (setq-local font-lock-defaults `(,ledger-font-lock-keywords nil t nil nil - ;; (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer))) + (setq-local indent-region-function 'ledger-post-align-postings)) - (setq-local indent-region-function 'ledger-post-align-postings) - (ledger-fontify-activate)) (defun ledger-set-year (newyear) -- cgit v1.2.3 From 77e77f39dcb99df410e969f7bd6c574e4d05dbe8 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Fri, 5 Sep 2014 21:59:23 -0700 Subject: Solved the fight between jit-lock. But for some reason it isn't calling it for all regions in the buffer. --- lisp/ledger-fontify.el | 2 +- lisp/ledger-mode.el | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lisp/ledger-fontify.el') diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index 7621b448..f282167e 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -63,7 +63,7 @@ (if (string= (format-mode-line 'mode-name) "Ledger") (add-hook 'after-change-functions 'ledger-fontify-buffer-part))) -(defun ledger-fontify-buffer-part (beg end) +(defun ledger-fontify-buffer-part (beg end len) (save-excursion ;; (message (concat "ledger-fontify-buffer-part: " ;; (int-to-string beg) " " diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 1f6d8c32..94b1f591 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -347,14 +347,15 @@ With a prefix argument, remove the effective date. " (if (boundp 'font-lock-defaults) (setq-local font-lock-defaults - '(ledger-font-lock-keywords t t))) + '(ledger-font-lock-keywords t t nil nil + (font-lock-fontify-region-function . ledger-fontify-buffer-part)))) ;; (setq font-lock-extend-region-functions ;; (list #'font-lock-extend-region-wholelines)) ;; (setq font-lock-multiline nil) - (jit-lock-register 'ledger-fontify-buffer-part) - (jit-lock-unregister 'font-lock-fontify-region) + ;(jit-lock-register 'ledger-fontify-buffer-part) + ;(jit-lock-unregister 'font-lock-fontify-region) (setq-local pcomplete-parse-arguments-function 'ledger-parse-arguments) (setq-local pcomplete-command-completion-function 'ledger-complete-at-point) -- cgit v1.2.3 From 57e2ec55ebaf97a285d31391425db58a68a578fb Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 8 Sep 2014 20:31:45 -0700 Subject: Seems to be working. I wasn't ensuring I caught all the xacts in a region specified by hit lock. Now I need to prune code --- lisp/ledger-fontify.el | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'lisp/ledger-fontify.el') diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index f282167e..7b9e121b 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -65,19 +65,17 @@ (defun ledger-fontify-buffer-part (beg end len) (save-excursion - ;; (message (concat "ledger-fontify-buffer-part: " - ;; (int-to-string beg) " " - ;; (int-to-string end) " " - ;; (int-to-string len) - ;; )) -; (goto-char beg) - (backward-paragraph) - (forward-char) - (cond ((or (looking-at ledger-xact-start-regex) - (looking-at ledger-posting-regex)) - (ledger-fontify-xact-at (point))) - ((looking-at ledger-directive-start-regex) - (ledger-fontify-directive-at (point)))))) + (unless beg (setq beg (point-min))) + (unless end (setq end (point-max))) + (unless len (setq len (- end beg))) + (goto-char beg) + (while (< (point) end) + (cond ((or (looking-at ledger-xact-start-regex) + (looking-at ledger-posting-regex)) + (ledger-fontify-xact-at (point))) + ((looking-at ledger-directive-start-regex) + (ledger-fontify-directive-at (point)))) + (ledger-xact-next-xact-or-directive)))) (defun ledger-fontify-xact-at (position) (interactive "d") -- cgit v1.2.3 From ad87ab16e4c25caa4b52a2905778ae4a275d69f9 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 8 Sep 2014 20:36:11 -0700 Subject: New fortification is working. Code pruned. --- lisp/ledger-fontify.el | 54 +++++++++++++++++++++++++------------------------- lisp/ledger-fonts.el | 25 ----------------------- lisp/ledger-mode.el | 39 ------------------------------------ 3 files changed, 27 insertions(+), 91 deletions(-) (limited to 'lisp/ledger-fontify.el') diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el index 7b9e121b..548881aa 100644 --- a/lisp/ledger-fontify.el +++ b/lisp/ledger-fontify.el @@ -35,33 +35,33 @@ :type 'boolean :group 'ledger-fontification) -(defun ledger-fontify-whole-buffer () - (interactive) - (save-excursion - (message "Ledger fontify whole buffer") - (goto-char (point-min)) - - (while (not (eobp)) - (cond ((looking-at ledger-xact-start-regex) - (ledger-fontify-xact-at (point))) - ((looking-at ledger-directive-start-regex) - (ledger-fontify-directive-at (point)))) - (ledger-xact-next-xact-or-directive) ;; gets to beginning of next xact - ))) - -(defun ledger-fontify-activate () - "add hook to fontify after buffer changes" - (interactive) - (if (string= (format-mode-line 'mode-name) "Ledger") - (progn - (ledger-fontify-whole-buffer) - (add-hook 'after-change-functions 'ledger-fontify-buffer-part) - (add-hook 'before-change-functions 'ledger-fontify-ensure-activation) - (message "ledger-fontify-activate called")))) - -(defun ledger-fontify-ensure-activation (beg end) - (if (string= (format-mode-line 'mode-name) "Ledger") - (add-hook 'after-change-functions 'ledger-fontify-buffer-part))) +;; (defun ledger-fontify-whole-buffer () +;; (interactive) +;; (save-excursion +;; (message "Ledger fontify whole buffer") +;; (goto-char (point-min)) + +;; (while (not (eobp)) +;; (cond ((looking-at ledger-xact-start-regex) +;; (ledger-fontify-xact-at (point))) +;; ((looking-at ledger-directive-start-regex) +;; (ledger-fontify-directive-at (point)))) +;; (ledger-xact-next-xact-or-directive) ;; gets to beginning of next xact +;; ))) + +;; (defun ledger-fontify-activate () +;; "add hook to fontify after buffer changes" +;; (interactive) +;; (if (string= (format-mode-line 'mode-name) "Ledger") +;; (progn +;; (ledger-fontify-whole-buffer) +;; (add-hook 'after-change-functions 'ledger-fontify-buffer-part) +;; (add-hook 'before-change-functions 'ledger-fontify-ensure-activation) +;; (message "ledger-fontify-activate called")))) + +;; (defun ledger-fontify-ensure-activation (beg end) +;; (if (string= (format-mode-line 'mode-name) "Ledger") +;; (add-hook 'after-change-functions 'ledger-fontify-buffer-part))) (defun ledger-fontify-buffer-part (beg end len) (save-excursion diff --git a/lisp/ledger-fonts.el b/lisp/ledger-fonts.el index 0c3b9861..b5495460 100644 --- a/lisp/ledger-fonts.el +++ b/lisp/ledger-fonts.el @@ -227,31 +227,6 @@ "Default face for pending (!) transactions in the reconcile window" :group 'ledger-faces) - - ;; (defvar ledger-font-lock-keywords - ;; `( ;; (,ledger-other-entries-regex 1 - ;; ;; ledger-font-other-face) - ;; (,ledger-comment-regex 0 - ;; 'ledger-font-comment-face) - ;; (,ledger-amount-regex 0 - ;; 'ledger-font-posting-amount-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 - ;; 'ledger-font-payee-cleared-face) ; Works - ;; (,ledger-payee-uncleared-regex 2 - ;; 'ledger-font-payee-uncleared-face) ; Works - ;; (,ledger-account-cleared-regex 2 - ;; 'ledger-font-posting-account-cleared-face) ; Works - ;; (,ledger-account-pending-regex 2 - ;; 'ledger-font-posting-account-pending-face) ; Works - ;; (,ledger-account-any-status-regex 2 - ;; 'ledger-font-posting-account-face) ; Works - ;; (,ledger-other-entries-regex 1 - ;; 'ledger-font-other-face)) - ;; "Expressions to highlight in Ledger mode.") - (defvar ledger-font-lock-keywords `(("account" . ledger-font-account-directive-face) ("apply" . ledger-font-apply-directive-face) diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 94b1f591..08cbb950 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -307,56 +307,17 @@ With a prefix argument, remove the effective date. " ["Kill Report" ledger-report-kill ledger-works])) ;;;###autoload -;; (define-derived-mode ledger-mode text-mode "Ledger" -;; "A mode for editing ledger data files." -;; (ledger-check-version) -;; (ledger-schedule-check-available) -;; ;;(ledger-post-setup) - -;; (setq-local pcomplete-parse-arguments-function 'ledger-parse-arguments) -;; (setq-local pcomplete-command-completion-function 'ledger-complete-at-point) -;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) - -;; (add-hook 'after-save-hook 'ledger-report-redo) - -;; (add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t) -;; (add-hook 'before-revert-hook 'ledger-occur-remove-all-overlays nil t) - -;; (ledger-init-load-init-file) - -;; ;; (setq font-lock-defaults -;; ;; `(,ledger-font-lock-keywords t nil nil nil -;; ;; (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer) -;; ;; (font-lock-fontify-region-function . ledger-fontify-buffer-part))) - -;; ;; (setq-local font-lock-defaults `(,ledger-font-lock-keywords nil t nil nil -;; ;; (font-lock-fontify-buffer-function . ledger-fontify-whole-buffer))) - -;; (setq-local indent-region-function 'ledger-post-align-postings)) (define-derived-mode ledger-mode text-mode "Ledger" "A mode for editing ledger data files." (ledger-check-version) (ledger-schedule-check-available) - ;;(ledger-post-setup) - - ;; (set-syntax-table ledger-mode-syntax-table) - ;; (set (make-local-variable 'comment-start) "; ") - ;; (set (make-local-variable 'comment-end) "") - ;; (set (make-local-variable 'indent-tabs-mode) nil) (if (boundp 'font-lock-defaults) (setq-local font-lock-defaults '(ledger-font-lock-keywords t t nil nil (font-lock-fontify-region-function . ledger-fontify-buffer-part)))) - ;; (setq font-lock-extend-region-functions - ;; (list #'font-lock-extend-region-wholelines)) - ;; (setq font-lock-multiline nil) - - ;(jit-lock-register 'ledger-fontify-buffer-part) - ;(jit-lock-unregister 'font-lock-fontify-region) - (setq-local pcomplete-parse-arguments-function 'ledger-parse-arguments) (setq-local pcomplete-command-completion-function 'ledger-complete-at-point) (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) -- cgit v1.2.3