mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-11 00:30:17 -08:00
* 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).
This commit is contained in:
parent
d6afb017de
commit
e45173d114
1 changed files with 28 additions and 10 deletions
|
|
@ -122,9 +122,10 @@ calls."
|
||||||
"Specify when hi-lock should use patterns found in file.
|
"Specify when hi-lock should use patterns found in file.
|
||||||
If `ask', prompt when patterns found in buffer; if bound to a function,
|
If `ask', prompt when patterns found in buffer; if bound to a function,
|
||||||
use patterns when function returns t (function is called with patterns
|
use patterns when function returns t (function is called with patterns
|
||||||
as first argument); if nil or `never' or anything else, don't use file
|
as first argument); if `always', use file patterns without prompt;
|
||||||
patterns."
|
if nil or `never' or anything else, don't use file patterns."
|
||||||
:type '(choice (const :tag "Do not use file patterns" never)
|
:type '(choice (const :tag "Do not use file patterns" never)
|
||||||
|
(const :tag "Always use file patterns" always)
|
||||||
(const :tag "Ask about file patterns" ask)
|
(const :tag "Ask about file patterns" ask)
|
||||||
(function :tag "Function to check file patterns"))
|
(function :tag "Function to check file patterns"))
|
||||||
:group 'hi-lock
|
:group 'hi-lock
|
||||||
|
|
@ -334,8 +335,8 @@ which can be called interactively, are:
|
||||||
(See `font-lock-keywords'.) They may be edited and re-loaded with \\[hi-lock-find-patterns],
|
(See `font-lock-keywords'.) They may be edited and re-loaded with \\[hi-lock-find-patterns],
|
||||||
any valid `font-lock-keywords' form is acceptable. When a file is
|
any valid `font-lock-keywords' form is acceptable. When a file is
|
||||||
loaded the patterns are read if `hi-lock-file-patterns-policy' is
|
loaded the patterns are read if `hi-lock-file-patterns-policy' is
|
||||||
`ask' and the user responds y to the prompt, or if
|
`always', or if it's `ask' and the user responds y to the prompt,
|
||||||
`hi-lock-file-patterns-policy' is bound to a function and that
|
or if `hi-lock-file-patterns-policy' is bound to a function and that
|
||||||
function returns t.
|
function returns t.
|
||||||
|
|
||||||
\\[hi-lock-find-patterns]
|
\\[hi-lock-find-patterns]
|
||||||
|
|
@ -852,6 +853,7 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock search."
|
||||||
(funcall hi-lock-file-patterns-policy all-patterns))
|
(funcall hi-lock-file-patterns-policy all-patterns))
|
||||||
((eq hi-lock-file-patterns-policy 'ask)
|
((eq hi-lock-file-patterns-policy 'ask)
|
||||||
(y-or-n-p "Add patterns from this buffer to hi-lock? "))
|
(y-or-n-p "Add patterns from this buffer to hi-lock? "))
|
||||||
|
((eq hi-lock-file-patterns-policy 'always) t)
|
||||||
(t nil)))
|
(t nil)))
|
||||||
(hi-lock-set-file-patterns all-patterns)
|
(hi-lock-set-file-patterns all-patterns)
|
||||||
(if (called-interactively-p 'interactive)
|
(if (called-interactively-p 'interactive)
|
||||||
|
|
@ -866,12 +868,28 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock search."
|
||||||
(defun hi-lock-revert-buffer-rehighlight ()
|
(defun hi-lock-revert-buffer-rehighlight ()
|
||||||
"Rehighlight hi-lock patterns after `revert-buffer'.
|
"Rehighlight hi-lock patterns after `revert-buffer'.
|
||||||
Apply the previous patterns after reverting the buffer."
|
Apply the previous patterns after reverting the buffer."
|
||||||
(when-let ((patterns hi-lock-interactive-lighters))
|
(when (or hi-lock-interactive-lighters hi-lock-file-patterns)
|
||||||
(lambda ()
|
(let ((patterns hi-lock-interactive-lighters)
|
||||||
(when hi-lock-interactive-lighters
|
(policy (if hi-lock-file-patterns 'always 'never))
|
||||||
(hi-lock-unface-buffer t))
|
rehighlight)
|
||||||
(dolist (pattern (reverse patterns))
|
(lambda ()
|
||||||
(highlight-regexp (car pattern) (cadr (nth 1 (caddr pattern))))))))
|
;; When using revert-buffer without preserve-modes
|
||||||
|
(unless hi-lock-mode
|
||||||
|
;; Don't ask about file patterns again
|
||||||
|
(let ((hi-lock-file-patterns-policy policy))
|
||||||
|
(hi-lock-mode 1))
|
||||||
|
(setq rehighlight t))
|
||||||
|
;; When hi-lock overlays were relocated to the top
|
||||||
|
(when (seq-some (lambda (o) (overlay-get o 'hi-lock-overlay))
|
||||||
|
(overlays-in (point-min) (point-min)))
|
||||||
|
(hi-lock-unface-buffer t)
|
||||||
|
(setq rehighlight t))
|
||||||
|
(when rehighlight
|
||||||
|
(dolist (pattern (reverse patterns))
|
||||||
|
(let ((face (hi-lock-keyword->face (cdr pattern))))
|
||||||
|
(highlight-regexp (car pattern) face)
|
||||||
|
(setq hi-lock--unused-faces
|
||||||
|
(remove (face-name face) hi-lock--unused-faces)))))))))
|
||||||
|
|
||||||
(defvar hi-lock--hashcons-hash
|
(defvar hi-lock--hashcons-hash
|
||||||
(make-hash-table :test 'equal :weakness t)
|
(make-hash-table :test 'equal :weakness t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue