unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 40337@debbugs.gnu.org
Subject: bug#40337: 28.0.50; Enable case-fold-search in hi-lock
Date: Mon, 06 Apr 2020 02:12:13 +0300	[thread overview]
Message-ID: <87mu7ptsqm.fsf@mail.linkov.net> (raw)
In-Reply-To: <jwvpncplcib.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 02 Apr 2020 19:02:33 -0400")

[-- Attachment #1: Type: text/plain, Size: 1407 bytes --]

> 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𝐟𝑓𝒇𝒻𝓯𝔣𝕗𝖋𝖿𝗳𝘧𝙛𝚏]\)): 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: hi-lock-remove-keywords.patch --]
[-- Type: text/x-diff, Size: 1584 bytes --]

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)))

  reply	other threads:[~2020-04-05 23:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30 22:32 bug#40337: 28.0.50; Enable case-fold-search in hi-lock Juri Linkov
2020-03-31  3:05 ` Stefan Monnier
2020-04-02 21:31   ` Juri Linkov
2020-04-02 23:02     ` Stefan Monnier
2020-04-05 23:12       ` Juri Linkov [this message]
2020-04-07  0:08         ` Juri Linkov
2020-04-07  3:33         ` Stefan Monnier
2020-04-11 23:45           ` Juri Linkov
2020-04-12  3:17 ` Paul Eggert
2020-04-12 23:41   ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mu7ptsqm.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=40337@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).