* lisp/hi-lock.el (hi-lock--regexps-at-point): Fix bug (bug#60241).

Handle two cases: when a pattern is a regexp or a function.
This commit is contained in:
Juri Linkov 2022-12-29 19:45:12 +02:00
parent 60418e6f09
commit 0aea1cf819

View file

@ -569,24 +569,29 @@ the major mode specifies support for Font Lock."
(when (and face-before face-after (not (eq face-before face-after)))
(setq face-before nil))
(when (or face-after face-before)
(let* ((hi-text
(buffer-substring-no-properties
(if face-before
(let* ((beg (if face-before
(or (previous-single-property-change (point) 'face)
(point-min))
(point))
(if face-after
(point)))
(end (if face-after
(or (next-single-property-change (point) 'face)
(point-max))
(point)))))
(point))))
;; Compute hi-lock patterns that match the
;; highlighted text at point. Use this later in
;; during completing-read.
(dolist (hi-lock-pattern hi-lock-interactive-patterns)
(let ((regexp (or (car (rassq hi-lock-pattern hi-lock-interactive-lighters))
(let ((pattern (or (rassq hi-lock-pattern hi-lock-interactive-lighters)
(car hi-lock-pattern))))
(if (string-match regexp hi-text)
(push regexp regexps)))))))
(cond
((stringp pattern)
(when (string-match pattern (buffer-substring-no-properties beg end))
(push pattern regexps)))
((functionp (cadr pattern))
(save-excursion
(goto-char beg)
(when (funcall (cadr pattern) end)
(push (car pattern) regexps))))))))))
regexps))
(defvar-local hi-lock--unused-faces nil