diff options
| author | Juri Linkov | 2024-06-27 09:52:06 +0300 |
|---|---|---|
| committer | Juri Linkov | 2024-06-27 09:52:06 +0300 |
| commit | e45173d114e37d5a652b5393ce7bcab1acea3f1a (patch) | |
| tree | 239a09933d9f9b550687081dbfc3bafdf2116d33 | |
| parent | d6afb017debb9cc1a88a129eea688e2f2bbf402a (diff) | |
| download | emacs-e45173d114e37d5a652b5393ce7bcab1acea3f1a.tar.gz emacs-e45173d114e37d5a652b5393ce7bcab1acea3f1a.zip | |
* lisp/hi-lock.el (hi-lock-file-patterns-policy): Add value 'always'.
(hi-lock-mode): Update docstring.
(hi-lock-find-patterns): Return t for value 'always'.
(hi-lock-revert-buffer-rehighlight): Rewrite to correctly handle
all possible cases (bug#57534).
| -rw-r--r-- | lisp/hi-lock.el | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index 64b84cdf859..648a3316323 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el | |||
| @@ -122,9 +122,10 @@ calls." | |||
| 122 | "Specify when hi-lock should use patterns found in file. | 122 | "Specify when hi-lock should use patterns found in file. |
| 123 | If `ask', prompt when patterns found in buffer; if bound to a function, | 123 | If `ask', prompt when patterns found in buffer; if bound to a function, |
| 124 | use patterns when function returns t (function is called with patterns | 124 | use patterns when function returns t (function is called with patterns |
| 125 | as first argument); if nil or `never' or anything else, don't use file | 125 | as first argument); if `always', use file patterns without prompt; |
| 126 | patterns." | 126 | if nil or `never' or anything else, don't use file patterns." |
| 127 | :type '(choice (const :tag "Do not use file patterns" never) | 127 | :type '(choice (const :tag "Do not use file patterns" never) |
| 128 | (const :tag "Always use file patterns" always) | ||
| 128 | (const :tag "Ask about file patterns" ask) | 129 | (const :tag "Ask about file patterns" ask) |
| 129 | (function :tag "Function to check file patterns")) | 130 | (function :tag "Function to check file patterns")) |
| 130 | :group 'hi-lock | 131 | :group 'hi-lock |
| @@ -334,8 +335,8 @@ which can be called interactively, are: | |||
| 334 | (See `font-lock-keywords'.) They may be edited and re-loaded with \\[hi-lock-find-patterns], | 335 | (See `font-lock-keywords'.) They may be edited and re-loaded with \\[hi-lock-find-patterns], |
| 335 | any valid `font-lock-keywords' form is acceptable. When a file is | 336 | any valid `font-lock-keywords' form is acceptable. When a file is |
| 336 | loaded the patterns are read if `hi-lock-file-patterns-policy' is | 337 | loaded the patterns are read if `hi-lock-file-patterns-policy' is |
| 337 | `ask' and the user responds y to the prompt, or if | 338 | `always', or if it's `ask' and the user responds y to the prompt, |
| 338 | `hi-lock-file-patterns-policy' is bound to a function and that | 339 | or if `hi-lock-file-patterns-policy' is bound to a function and that |
| 339 | function returns t. | 340 | function returns t. |
| 340 | 341 | ||
| 341 | \\[hi-lock-find-patterns] | 342 | \\[hi-lock-find-patterns] |
| @@ -852,6 +853,7 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock search." | |||
| 852 | (funcall hi-lock-file-patterns-policy all-patterns)) | 853 | (funcall hi-lock-file-patterns-policy all-patterns)) |
| 853 | ((eq hi-lock-file-patterns-policy 'ask) | 854 | ((eq hi-lock-file-patterns-policy 'ask) |
| 854 | (y-or-n-p "Add patterns from this buffer to hi-lock? ")) | 855 | (y-or-n-p "Add patterns from this buffer to hi-lock? ")) |
| 856 | ((eq hi-lock-file-patterns-policy 'always) t) | ||
| 855 | (t nil))) | 857 | (t nil))) |
| 856 | (hi-lock-set-file-patterns all-patterns) | 858 | (hi-lock-set-file-patterns all-patterns) |
| 857 | (if (called-interactively-p 'interactive) | 859 | (if (called-interactively-p 'interactive) |
| @@ -866,12 +868,28 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock search." | |||
| 866 | (defun hi-lock-revert-buffer-rehighlight () | 868 | (defun hi-lock-revert-buffer-rehighlight () |
| 867 | "Rehighlight hi-lock patterns after `revert-buffer'. | 869 | "Rehighlight hi-lock patterns after `revert-buffer'. |
| 868 | Apply the previous patterns after reverting the buffer." | 870 | Apply the previous patterns after reverting the buffer." |
| 869 | (when-let ((patterns hi-lock-interactive-lighters)) | 871 | (when (or hi-lock-interactive-lighters hi-lock-file-patterns) |
| 870 | (lambda () | 872 | (let ((patterns hi-lock-interactive-lighters) |
| 871 | (when hi-lock-interactive-lighters | 873 | (policy (if hi-lock-file-patterns 'always 'never)) |
| 872 | (hi-lock-unface-buffer t)) | 874 | rehighlight) |
| 873 | (dolist (pattern (reverse patterns)) | 875 | (lambda () |
| 874 | (highlight-regexp (car pattern) (cadr (nth 1 (caddr pattern)))))))) | 876 | ;; When using revert-buffer without preserve-modes |
| 877 | (unless hi-lock-mode | ||
| 878 | ;; Don't ask about file patterns again | ||
| 879 | (let ((hi-lock-file-patterns-policy policy)) | ||
| 880 | (hi-lock-mode 1)) | ||
| 881 | (setq rehighlight t)) | ||
| 882 | ;; When hi-lock overlays were relocated to the top | ||
| 883 | (when (seq-some (lambda (o) (overlay-get o 'hi-lock-overlay)) | ||
| 884 | (overlays-in (point-min) (point-min))) | ||
| 885 | (hi-lock-unface-buffer t) | ||
| 886 | (setq rehighlight t)) | ||
| 887 | (when rehighlight | ||
| 888 | (dolist (pattern (reverse patterns)) | ||
| 889 | (let ((face (hi-lock-keyword->face (cdr pattern)))) | ||
| 890 | (highlight-regexp (car pattern) face) | ||
| 891 | (setq hi-lock--unused-faces | ||
| 892 | (remove (face-name face) hi-lock--unused-faces))))))))) | ||
| 875 | 893 | ||
| 876 | (defvar hi-lock--hashcons-hash | 894 | (defvar hi-lock--hashcons-hash |
| 877 | (make-hash-table :test 'equal :weakness t) | 895 | (make-hash-table :test 'equal :weakness t) |