diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index 64b84cdf859..de4384054ef 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -122,9 +122,10 @@ hi-lock-file-patterns-policy "Specify when hi-lock should use patterns found in file. If `ask', prompt when patterns found in buffer; if bound to a function, 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 -patterns." +as first argument); if `always', use file patterns without prompt; +if nil or `never' or anything else, don't use file patterns." :type '(choice (const :tag "Do not use file patterns" never) + (const :tag "Always use file patterns" always) (const :tag "Ask about file patterns" ask) (function :tag "Function to check file patterns")) :group 'hi-lock @@ -334,8 +335,8 @@ hi-lock-mode (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 loaded the patterns are read if `hi-lock-file-patterns-policy' is - `ask' and the user responds y to the prompt, or if - `hi-lock-file-patterns-policy' is bound to a function and that + `always' or if it's `ask' and the user responds y to the prompt, + or if `hi-lock-file-patterns-policy' is bound to a function and that function returns t. \\[hi-lock-find-patterns] @@ -852,6 +853,7 @@ hi-lock-find-patterns (funcall hi-lock-file-patterns-policy all-patterns)) ((eq hi-lock-file-patterns-policy 'ask) (y-or-n-p "Add patterns from this buffer to hi-lock? ")) + ((eq hi-lock-file-patterns-policy 'always) t) (t nil))) (hi-lock-set-file-patterns all-patterns) (if (called-interactively-p 'interactive) @@ -866,12 +868,16 @@ hi-lock-font-lock-hook (defun hi-lock-revert-buffer-rehighlight () "Rehighlight hi-lock patterns after `revert-buffer'. Apply the previous patterns after reverting the buffer." - (when-let ((patterns hi-lock-interactive-lighters)) - (lambda () - (when hi-lock-interactive-lighters - (hi-lock-unface-buffer t)) - (dolist (pattern (reverse patterns)) - (highlight-regexp (car pattern) (cadr (nth 1 (caddr pattern)))))))) + (let ((policy (if hi-lock-file-patterns 'always 'never)) + (patterns hi-lock-interactive-lighters)) + (when patterns + (lambda () + (unless hi-lock-mode + (let ((hi-lock-file-patterns-policy policy)) + (when hi-lock-interactive-lighters + (hi-lock-unface-buffer t)) + (dolist (pattern (reverse patterns)) + (highlight-regexp (car pattern) (cadr (nth 1 (caddr pattern))))))))))) (defvar hi-lock--hashcons-hash (make-hash-table :test 'equal :weakness t)