GNU bug report logs -
#40337
28.0.50; Enable case-fold-search in hi-lock
Previous Next
Reported by: Juri Linkov <juri <at> linkov.net>
Date: Mon, 30 Mar 2020 22:54:01 UTC
Severity: normal
Tags: fixed
Fixed in version 28.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 40337 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> I think it's a good interpretation of that docstring. If needed
> we could additionally tweak the docstring to clarify the behavior.
While testing I found a problem: using 'unhighlight-regexp' ('M-s h u')
displays too long prompt:
Regexp to unhighlight (default (closure ((case-fold . t) (subexp . 0) (face . hi-yellow) (regexp . foo) t) (limit) (let ((case-fold-search case-fold)) (re-search-forward regexp limit t)))):
Then I tried to construct a closure *after* adding a plain regexp
to hi-lock-interactive-patterns, i.e. immediately in font-lock-add-keywords.
But this poses another problem: it's not easy to find a closure by regexp
in font-lock-keywords for removing a keyword by font-lock-remove-keywords
in 'unhighlight-regexp'.
I tried the patch below, and sometimes it works, but I know
it's horribly ugly, and it's a wrong direction to search the regexp
in the lexical environment of a closure.
Maybe then better to add an intermediate mapping to hi-lock
like there is in isearch: isearch-message vs isearch-string,
where isearch-message is user-facing representaion,
and isearch-string contains internal data.
This could help to solve another existing problem of using
hi-lock from isearch in char-fold mode, where unhighlight-regexp
displays unreadable prompt too:
Regexp to unhighlight (default \(?:ḟ\|[fᶠḟⓕf𝐟𝑓𝒇𝒻𝓯𝔣𝕗𝖋𝖿𝗳𝘧𝙛𝚏]\)):
[hi-lock-remove-keywords.patch (text/x-diff, inline)]
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index de258935e1..9173b66b7f 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -625,7 +645,12 @@ hi-lock-unface-buffer
;; calls font-lock-set-defaults). This is yet-another bug in
;; font-lock-add/remove-keywords, which we circumvent here by
;; testing `font-lock-fontified' (bug#19796).
- (if font-lock-fontified (font-lock-remove-keywords nil (list keyword)))
+ (when font-lock-fontified
+ (font-lock-remove-keywords nil (list keyword))
+ (dolist (k font-lock-keywords)
+ (when (and (consp k) (consp (car k)) (eq (caar k) 'closure)
+ (equal (car keyword) (cdr (assq 'regexp (cadr (car k))))))
+ (font-lock-remove-keywords nil (list k)))))
(setq hi-lock-interactive-patterns
(delq keyword hi-lock-interactive-patterns))
(remove-overlays
@@ -728,7 +753,13 @@ hi-lock-set-pattern
(push pattern hi-lock-interactive-patterns)
(if (and font-lock-mode (font-lock-specified-p major-mode))
(progn
- (font-lock-add-keywords nil (list pattern) t)
+ (font-lock-add-keywords
+ nil (list (cons
+ (lambda (limit)
+ (let ((case-fold-search case-fold))
+ (re-search-forward (car pattern) limit t)))
+ (cdr pattern)))
+ t)
(font-lock-flush))
(let* ((range-min (- (point) (/ hi-lock-highlight-range 2)))
(range-max (+ (point) (/ hi-lock-highlight-range 2)))
This bug report was last modified 5 years and 38 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.