all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 40337@debbugs.gnu.org
Cc: stefan monnier <monnier@iro.umontreal.ca>
Subject: bug#40337: 28.0.50; Enable case-fold-search in hi-lock
Date: Tue, 31 Mar 2020 01:32:55 +0300	[thread overview]
Message-ID: <87a73xtsqw.fsf@mail.linkov.net> (raw)

X-Debbugs-Cc: Stefan Monnier <monnier@iro.umontreal.ca>

A new defcustom hi-lock-case-fold-search is intended to fix
the long-standing deficiency in hi-lock.el to avoid such
ugly hacks as in hi-lock-process-phrase:

    ;; FIXME fragile; better to just bind case-fold-search?  (Bug#7161)
    (setq mod-phrase
          (replace-regexp-in-string
           "\\(^\\|\\s-\\)\\([a-z]\\)"
           (lambda (m) (format "%s[%s%s]"
                               (match-string 1 m)
                               (upcase (match-string 2 m))
                               (match-string 2 m))) phrase))

and in isearch--highlight-regexp-or-lines:

		       ;; Turn isearch-string into a case-insensitive
		       ;; regexp.
		       (mapconcat
			(lambda (c)
			  (let ((s (string c)))
			    (if (string-match "[[:alpha:]]" s)
				(format "[%s%s]" (upcase s) (downcase s))
			      (regexp-quote s))))
			isearch-string "")

Also these hacks fail when hi-lock is called from isearch by
isearch-highlight-regexp when regexp-based char-fold is enabled -
hi-lock highlights less matches than are lazy-highlighted in isearch,
it doesn't take into account the value of isearch-case-fold-search
and these hacks are unable to change the regexp generated by char-fold.

But when a new option hi-lock-case-fold-search is enabled, it updates
font-lock-keywords-case-fold-search that makes hi-lock matches
case-insensitive:

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index de258935e1..9394e2e157 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -135,6 +135,11 @@ hi-lock-file-patterns-policy
 ;; It can have a function value.
 (put 'hi-lock-file-patterns-policy 'risky-local-variable t)
 
+(defcustom hi-lock-case-fold-search t
+  "Non-nil means the patterns for `font-lock' are case-insensitive."
+  :type 'boolean
+  :version "28.1")
+
 (defcustom hi-lock-auto-select-face nil
   "Non-nil means highlighting commands do not prompt for the face to use.
 Instead, each hi-lock command will cycle through the faces in
@@ -394,6 +399,7 @@ hi-lock-mode
       (progn
 	(define-key-after menu-bar-edit-menu [hi-lock]
 	  (cons "Regexp Highlighting" hi-lock-menu))
+        (setq-local font-lock-keywords-case-fold-search hi-lock-case-fold-search)
 	(hi-lock-find-patterns)
         (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook nil t)
         ;; Remove regexps from font-lock-keywords (bug#13891).





             reply	other threads:[~2020-03-30 22:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30 22:32 Juri Linkov [this message]
2020-03-31  3:05 ` bug#40337: 28.0.50; Enable case-fold-search in hi-lock Stefan Monnier
2020-04-02 21:31   ` Juri Linkov
2020-04-02 23:02     ` Stefan Monnier
2020-04-05 23:12       ` Juri Linkov
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

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

  git send-email \
    --in-reply-to=87a73xtsqw.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.