summaryrefslogtreecommitdiff
path: root/lisp/hi-lock.el
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2017-08-25 00:00:20 +0900
committerTino Calancha <tino.calancha@gmail.com>2017-08-25 00:09:50 +0900
commit303481b4ecd7d422653263389f86c83b4a4c855b (patch)
treeffebda89bb8f5cb6379a803073224c536eb816aa /lisp/hi-lock.el
parent0332a0ef2bbe6954f080cb6c9d3f0cc2517a1ab1 (diff)
downloademacs-303481b4ecd7d422653263389f86c83b4a4c855b.tar.gz
Keep face available if there are no matches
If font-lock-mode is disabled in the current buffer, and there are no matches for REGEXP, then keep FACE available for a next search. * lisp/hi-lock.el (hi-lock-set-pattern): Add FACE into hi-lock--unused-faces if font-lock-mode is disabled and there are no matches. * test/lisp/hi-lock-tests.el (hi-lock-test-set-pattern): Add test.
Diffstat (limited to 'lisp/hi-lock.el')
-rw-r--r--lisp/hi-lock.el8
1 files changed, 6 insertions, 2 deletions
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 5139e01fa84..34300212f02 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -693,7 +693,8 @@ with completion and history."
"Highlight REGEXP with face FACE."
;; Hashcons the regexp, so it can be passed to remove-overlays later.
(setq regexp (hi-lock--hashcons regexp))
- (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
+ (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend)))
+ (no-matches t))
;; Refuse to highlight a text that is already highlighted.
(if (assoc regexp hi-lock-interactive-patterns)
(add-to-list 'hi-lock--unused-faces (face-name face))
@@ -713,11 +714,14 @@ with completion and history."
(save-excursion
(goto-char search-start)
(while (re-search-forward regexp search-end t)
+ (when no-matches (setq no-matches nil))
(let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
(overlay-put overlay 'hi-lock-overlay t)
(overlay-put overlay 'hi-lock-overlay-regexp regexp)
(overlay-put overlay 'face face))
- (goto-char (match-end 0)))))))))
+ (goto-char (match-end 0)))
+ (when no-matches
+ (add-to-list 'hi-lock--unused-faces (face-name face)))))))))
(defun hi-lock-set-file-patterns (patterns)
"Replace file patterns list with PATTERNS and refontify."