all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#40337: 28.0.50; Enable case-fold-search in hi-lock
@ 2020-03-30 22:32 Juri Linkov
  2020-03-31  3:05 ` Stefan Monnier
  2020-04-12  3:17 ` Paul Eggert
  0 siblings, 2 replies; 10+ messages in thread
From: Juri Linkov @ 2020-03-30 22:32 UTC (permalink / raw)
  To: 40337; +Cc: stefan monnier

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





^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-04-12 23:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.