GNU bug report logs - #22541
25.0.50; highlight-regexp from isearch is case-sensitive even if case-fold is active

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Dima Kogan <dima@HIDDEN>; dated Wed, 3 Feb 2016 06:30:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 25 May 2017 12:12:06 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu May 25 08:12:06 2017
Received: from localhost ([127.0.0.1]:37029 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1dDrcb-0002Xb-I8
	for submit <at> debbugs.gnu.org; Thu, 25 May 2017 08:12:06 -0400
Received: from mail-pf0-f169.google.com ([209.85.192.169]:36075)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tino.calancha@HIDDEN>) id 1dDrcY-0002X3-Lt
 for 22541 <at> debbugs.gnu.org; Thu, 25 May 2017 08:12:03 -0400
Received: by mail-pf0-f169.google.com with SMTP id m17so165699951pfg.3
 for <22541 <at> debbugs.gnu.org>; Thu, 25 May 2017 05:12:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=8zQ78aITMkEXpNJDgQSbsLt3d5HiPyT4qockjKAUWmw=;
 b=T+4/tyaHIaylrfIBas7IEz6FECBNqsF4FNgsqx03i0ndNWuo+YvSsLvvKvmWt2NrpM
 rUph5E6YAQyZV0oJsqOgTuaDVmDHGb0h+WE7QbWBAkcrMawQmek5cxUm4LKbqcyycANJ
 pGfI3gbbErhaoRnn5EgQFH3Psy5Dnw6MhJYaShEKymlqn+H3ZPZq0G1APfh4Hl8+w/EC
 NBTwL3WCN23dv6JLx/djW4lmZACRTwkUwJUaN8qRLkz2yJ49LNsQ9eujnV/PHZS07AbV
 1VJYPhhIkr6z7ZKJPCloPf5MuYsaa2iG83duAdWfLL3M8OxftC5iVokPf1YDY9ofJhCz
 zxjw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version;
 bh=8zQ78aITMkEXpNJDgQSbsLt3d5HiPyT4qockjKAUWmw=;
 b=gp0xmQeiD6MFL8jE1kYPdqPa5IGQRqzX73r7KhT32wLcdgvS9pr4HMmg49Sd5YWq4o
 jdL3G6ZqTHpcDHzoJrMpYyRQSKyqGizKh0kVrnnk4LOXrz014IExHc2d7D7ns2FiYVGR
 EzZ+HVd74ERFO4GYEzo5yczrtYzG5nH12R2x40HXrRz8G23e13rKnSIL6NOcu8uZGWrs
 gF52kpzpJKugjOy+Hk1W1qWJiQCk3OgI2P6dNpyRqC5V7ZytC+AFXH5G9lJmFJXl75l3
 d+azS0QqsT+mBiCOWr+K2Q1SiwFXs7shW1BHz+6uxZmOWeMYlIoU5Y7pYlYmVWGhq+qj
 vBcA==
X-Gm-Message-State: AODbwcDQXpH7ZWH510IZL7r+MKjE0k9g2qRzUWshA8zBaAf26rWiMzOT
 fGhr7YNYcAQ/Ig==
X-Received: by 10.99.167.75 with SMTP id w11mr45625552pgo.148.1495714316574;
 Thu, 25 May 2017 05:11:56 -0700 (PDT)
Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222])
 by smtp.gmail.com with ESMTPSA id
 c7sm14153157pfk.103.2017.05.25.05.11.53
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Thu, 25 May 2017 05:11:55 -0700 (PDT)
From: Tino Calancha <tino.calancha@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
 <87vapwipy4.fsf@calancha-pc> <87shkyems1.fsf@localhost>
 <87pog112pp.fsf@calancha-pc> <87mvb4yzux.fsf@localhost>
 <87bmrilylu.fsf@calancha-pc> <87fugdfzoq.fsf@localhost>
 <8737bugyxe.fsf@calancha-pc>
Date: Thu, 25 May 2017 21:11:49 +0900
In-Reply-To: <8737bugyxe.fsf@calancha-pc> (Tino Calancha's message of "Wed, 24
 May 2017 22:35:41 +0900")
Message-ID: <87shjt16gq.fsf@calancha-pc>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.8 (--)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org, Dima Kogan <dima@HIDDEN>,
 tino.calancha@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.8 (--)

Tino Calancha <tino.calancha@HIDDEN> writes:

> Juri Linkov <juri@HIDDEN> writes:
>
>>> The new patch, in addition to fix this bug report, it also
>>> helps with the 5. in bug#22520, that is:
>>> emacs -Q
>>> M-s hr t RET RET ; Highlight with regexp "[Tt]"
>>> M-s hu t RET ; Unhighlight the buffer.
>>
>> Thanks, could you find more test cases that still don't work?
> Yes i did.  We need to fold according with `search-upper-case' and
> `case-fold-search' for `hi-lock-face-phrase-buffer' and
> `hi-lock-line-face-buffer' as well.
> I am posting the updated patch in a few days after after test it.
Hi Juri,

I have updated the patch.  It's harder than i expected.
Maybe I am missing something.
Could you take a look on it?

The new patch seems to handle `case-fold-search'
correctly for the 4 commands:

`hi-lock-face-buffer'
`hi-lock-line-face-buffer'
`hi-lock-face-symbol-at-point'
`hi-lock-face-phrase-buffer'.

That's seems true regardless of the value of
(font-lock-specified-p major-mode)

--8<-----------------------------cut here---------------start------------->8---
From 234c6189f9c6f978c7a4039cd2ff186805b1c3f3 Mon Sep 17 00:00:00 2001
From: Juri Linkov <juri@HIDDEN>
Date: Thu, 25 May 2017 11:00:09 +0900
Subject: [PATCH 1/3] highlight-regexp: Honor case-fold-search

* lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern):
Add optional arg CASE-FOLD.  All callers updated.
* lisp/isearch.el (isearch-highlight-regexp): Call hi-lock-face-buffer
with 3 arguments.
---
 lisp/hi-lock.el | 30 +++++++++++++++++++-----------
 lisp/isearch.el |  7 ++++++-
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 5139e01fa8..55ad3ccb58 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -432,7 +432,7 @@ hi-lock-line-face-buffer
 ;;;###autoload
 (defalias 'highlight-regexp 'hi-lock-face-buffer)
 ;;;###autoload
-(defun hi-lock-face-buffer (regexp &optional face)
+(defun hi-lock-face-buffer (regexp &optional face case-fold)
   "Set face of each match of REGEXP to FACE.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
@@ -444,10 +444,11 @@ hi-lock-face-buffer
    (list
     (hi-lock-regexp-okay
      (read-regexp "Regexp to highlight" 'regexp-history-last))
-    (hi-lock-read-face-name)))
+    (hi-lock-read-face-name)
+    case-fold-search))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
-  (hi-lock-set-pattern regexp face))
+  (hi-lock-set-pattern regexp face case-fold))
 
 ;;;###autoload
 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
@@ -689,11 +690,17 @@ hi-lock-read-face-name
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))
 
-(defun hi-lock-set-pattern (regexp face)
+(defun hi-lock-set-pattern (regexp face &optional case-fold)
   "Highlight REGEXP with face FACE."
   ;; Hashcons the regexp, so it can be passed to remove-overlays later.
   (setq regexp (hi-lock--hashcons regexp))
-  (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
+  (let ((pattern (list (if (eq case-fold 'undefined)
+                           regexp
+                         (byte-compile
+                          `(lambda (limit)
+                             (let ((case-fold-search ,case-fold))
+                               (re-search-forward ,regexp limit t)))))
+                       (list 0 (list 'quote face) 'prepend))))
     ;; Refuse to highlight a text that is already highlighted.
     (if (assoc regexp hi-lock-interactive-patterns)
         (add-to-list 'hi-lock--unused-faces (face-name face))
@@ -712,12 +719,13 @@ hi-lock-set-pattern
                      (+ range-max (max 0 (- (point-min) range-min))))))
           (save-excursion
             (goto-char search-start)
-            (while (re-search-forward regexp search-end t)
-              (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
-                (overlay-put overlay 'hi-lock-overlay t)
-                (overlay-put overlay 'hi-lock-overlay-regexp regexp)
-                (overlay-put overlay 'face face))
-              (goto-char (match-end 0)))))))))
+            (let ((case-fold-search case-fold))
+              (while (re-search-forward regexp search-end t)
+                (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
+                  (overlay-put overlay 'hi-lock-overlay t)
+                  (overlay-put overlay 'hi-lock-overlay-regexp regexp)
+                  (overlay-put overlay 'face face))
+                (goto-char (match-end 0))))))))))
 
 (defun hi-lock-set-file-patterns (patterns)
   "Replace file patterns list with PATTERNS and refontify."
diff --git a/lisp/isearch.el b/lisp/isearch.el
index c34739d638..250d37b45e 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1950,7 +1950,12 @@ isearch-highlight-regexp
 			      (regexp-quote s))))
 			isearch-string ""))
 		      (t (regexp-quote isearch-string)))))
-    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
+    (hi-lock-face-buffer regexp (hi-lock-read-face-name)
+                         (if (and (eq isearch-case-fold-search t)
+                                  search-upper-case)
+                             (isearch-no-upper-case-p
+                              isearch-string isearch-regexp)
+                           isearch-case-fold-search)))
   (and isearch-recursive-edit (exit-recursive-edit)))
 
 
-- 
2.11.0

From 705f90014547c446cc7fd1df35f2d8d16e630771 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@HIDDEN>
Date: Thu, 25 May 2017 11:22:06 +0900
Subject: [PATCH 2/3] Fix hi-lock-unface-buffer from last commit

Perform the matches of REGEXP as `isearch-forward' i.e.,
in interactive calls determine the case fold with
`search-upper-case' and `case-fold-search' (Bug#22541).

A call to `hi-lock-unface-buffer' with the input used in
`hi-lock-face-buffer' must unhighlight that pattern,
regardless of the actual internal regexp used (Bug#22520).
* lisp/hi-lock.el (hi-lock-face-buffer): Update docstring.
Determine the case fold with `search-upper-case' and
`case-fold-search'.
(hi-lock--regexps-at-point, hi-lock-unface-buffer):
Handle when pattern is a cons (REGEXP . FUNCTION).
(hi-lock-read-face-name): Update docstring.
(hi-lock--case-insensitive-regexp,
hi-lock--case-insensitive-regexp-p): New defuns.
(hi-lock-set-pattern, hi-lock-unface-buffer): Use them.
* lisp/isearch.el (isearch-highlight-regexp): Delete hack for
case-insensitive search; this is now handled in
hi-lock-face-buffer.
---
 lisp/hi-lock.el | 153 +++++++++++++++++++++++++++++++++++++++++---------------
 lisp/isearch.el |  10 +---
 2 files changed, 115 insertions(+), 48 deletions(-)

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 55ad3ccb58..5862974844 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -434,6 +434,7 @@ 'highlight-regexp
 ;;;###autoload
 (defun hi-lock-face-buffer (regexp &optional face case-fold)
   "Set face of each match of REGEXP to FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
 
@@ -441,11 +442,15 @@ hi-lock-face-buffer
 use overlays for highlighting.  If overlays are used, the
 highlighting will not update as you type."
   (interactive
-   (list
-    (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight" 'regexp-history-last))
-    (hi-lock-read-face-name)
-    case-fold-search))
+   (let* ((regexp
+           (hi-lock-regexp-okay
+            (read-regexp "Regexp to highlight" 'regexp-history-last)))
+          (face (hi-lock-read-face-name))
+          (case-fold
+           (if search-upper-case
+               (isearch-no-upper-case-p regexp t)
+             case-fold-search)))
+     (list regexp face case-fold)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
   (hi-lock-set-pattern regexp face case-fold))
@@ -531,10 +536,17 @@ hi-lock--regexps-at-point
           ;; highlighted text at point.  Use this later in
           ;; during completing-read.
           (dolist (hi-lock-pattern hi-lock-interactive-patterns)
-            (let ((regexp (car hi-lock-pattern)))
-              (if (string-match regexp hi-text)
-                  (push regexp regexps)))))))
-    regexps))
+            (let ((regexp-or-fn (car hi-lock-pattern)))
+              (cond ((stringp regexp-or-fn)
+                     (when (string-match regexp-or-fn hi-text)
+                       (push regexp-or-fn regexps)))
+                    (t
+                     (with-temp-buffer
+                       (insert hi-text)
+                       (goto-char 1)
+                       (when (funcall regexp-or-fn nil)
+                         (push regexp-or-fn regexps)))))))
+    ))) regexps))
 
 (defvar-local hi-lock--unused-faces nil
   "List of faces that is not used and is available for highlighting new text.
@@ -562,13 +574,15 @@ hi-lock-unface-buffer
          (cons
           `keymap
           (cons "Select Pattern to Unhighlight"
-                (mapcar (lambda (pattern)
-                          (list (car pattern)
-                                (format
-                                 "%s (%s)" (car pattern)
-                                 (hi-lock-keyword->face pattern))
-                                (cons nil nil)
-                                (car pattern)))
+                 (mapcar (lambda (pattern)
+                           (let ((regexp (or (car-safe (car pattern))
+                                             (car pattern))))
+                             (list regexp
+                                   (format
+                                    "%s (%s)" regexp
+                                    (hi-lock-keyword->face pattern))
+                                   (cons nil nil)
+                                   regexp)))
                         hi-lock-interactive-patterns))))
         ;; If the user clicks outside the menu, meaning that they
         ;; change their mind, x-popup-menu returns nil, and
@@ -582,16 +596,30 @@ hi-lock-unface-buffer
        (error "No highlighting to remove"))
      ;; Infer the regexp to un-highlight based on cursor position.
      (let* ((defaults (or (hi-lock--regexps-at-point)
-                          (mapcar #'car hi-lock-interactive-patterns))))
-       (list
-        (completing-read (if (null defaults)
-                             "Regexp to unhighlight: "
-                           (format "Regexp to unhighlight (default %s): "
-                                   (car defaults)))
-                         hi-lock-interactive-patterns
-			 nil t nil nil defaults))))))
-  (dolist (keyword (if (eq regexp t) hi-lock-interactive-patterns
-                     (list (assoc regexp hi-lock-interactive-patterns))))
+                          (mapcar (lambda (x)
+                                    (or (car-safe (car x))
+                                        (car x)))
+                                    hi-lock-interactive-patterns)))
+            (regexp (completing-read (if (null defaults)
+                                         "Regexp to unhighlight: "
+                                       (format "Regexp to unhighlight (default %s): "
+                                               (car defaults)))
+                                     hi-lock-interactive-patterns
+			             nil nil nil nil defaults)))
+               (when (and (or (not search-upper-case)
+                              (isearch-no-upper-case-p regexp t))
+                          case-fold-search
+                          (not (hi-lock--case-insensitive-regexp-p regexp)))
+         (setq regexp (hi-lock--case-insensitive-regexp regexp)))
+       (list regexp)))))
+  (let* ((patterns hi-lock-interactive-patterns)
+         (keys (or (assoc regexp patterns)
+                   (assoc
+                    (assoc regexp (mapcar #'car patterns))
+                    patterns))))
+    (dolist (keyword (if (eq regexp t)
+                         patterns
+                       (list keys)))
     (when keyword
       (let ((face (hi-lock-keyword->face keyword)))
         ;; Make `face' the next one to use by default.
@@ -606,8 +634,10 @@ hi-lock-unface-buffer
       (setq hi-lock-interactive-patterns
             (delq keyword hi-lock-interactive-patterns))
       (remove-overlays
-       nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons (car keyword)))
-      (font-lock-flush))))
+       nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons
+                                        (or (car-safe (car keyword))
+                                            (car keyword))))
+      (font-lock-flush)))))
 
 ;;;###autoload
 (defun hi-lock-write-interactive-patterns ()
@@ -690,23 +720,67 @@ hi-lock-read-face-name
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))
 
+(defun hi-lock--case-insensitive-regexp-p (regexp)
+  (let (case-fold-search)
+    (and (string-match-p regexp (downcase regexp))
+         (string-match-p regexp (upcase regexp)))))
+
+(defun hi-lock--case-insensitive-regexp (regexp)
+  "Turn regexp into a case-insensitive regexp."
+  (let ((count 0)
+        (upper-re "[[:upper:]]")
+        (slash-upper-re "\\(\\\\\\)\\([[:upper:]]\\)")
+        case-fold-search)
+    (cond ((or (hi-lock--case-insensitive-regexp-p regexp)
+               (and (string-match upper-re regexp)
+                    (not (string-match slash-upper-re regexp))))
+           regexp)
+          (t
+           (let ((string regexp))
+             (while (string-match slash-upper-re string)
+               (setq string (replace-match "" t t string 1)))
+             (setq regexp string)
+             (mapconcat
+              (lambda (c)
+                (let ((s (string c)))
+                  (cond ((or (eq c ?\\)
+                             (and (= count 1) (string= s (upcase s))))
+                         (setq count (1+ count)) s)
+                        (t
+                         (setq count 0)
+                         (if (string-match "[[:alpha:]]" s)
+	                     (format "[%s%s]" (upcase s) (downcase s))
+	                   (regexp-quote s))))))
+              regexp ""))))))
+
 (defun hi-lock-set-pattern (regexp face &optional case-fold)
-  "Highlight REGEXP with face FACE."
+  "Highlight REGEXP with face FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it."
   ;; Hashcons the regexp, so it can be passed to remove-overlays later.
   (setq regexp (hi-lock--hashcons regexp))
-  (let ((pattern (list (if (eq case-fold 'undefined)
+  (let* ((pattern (list (if (eq case-fold 'undefined)
                            regexp
-                         (byte-compile
-                          `(lambda (limit)
-                             (let ((case-fold-search ,case-fold))
-                               (re-search-forward ,regexp limit t)))))
-                       (list 0 (list 'quote face) 'prepend))))
+                         (cons regexp
+                               (byte-compile
+                                `(lambda (limit)
+                                   (let ((case-fold-search ,case-fold))
+                                     (re-search-forward ,regexp limit t))))))
+                       (list 0 (list 'quote face) 'prepend)))
+         (regexp-fold
+          (cond ((not (consp (car pattern)))
+                 (car pattern))
+                (t
+                 (if (not case-fold)
+                     (caar pattern)
+		   (hi-lock--case-insensitive-regexp (caar pattern)))))))
     ;; Refuse to highlight a text that is already highlighted.
-    (if (assoc regexp hi-lock-interactive-patterns)
+    (if (or (assoc regexp hi-lock-interactive-patterns)
+            (assoc regexp-fold hi-lock-interactive-patterns)
+            (assoc regexp-fold (mapcar #'car hi-lock-interactive-patterns)))
         (add-to-list 'hi-lock--unused-faces (face-name face))
-      (push pattern hi-lock-interactive-patterns)
       (if (and font-lock-mode (font-lock-specified-p major-mode))
-	  (progn
+          (progn
+            (setq pattern (list regexp-fold (list 0 (list 'quote face) 'prepend)))
 	    (font-lock-add-keywords nil (list pattern) t)
 	    (font-lock-flush))
         (let* ((range-min (- (point) (/ hi-lock-highlight-range 2)))
@@ -725,7 +799,8 @@ hi-lock-set-pattern
                   (overlay-put overlay 'hi-lock-overlay t)
                   (overlay-put overlay 'hi-lock-overlay-regexp regexp)
                   (overlay-put overlay 'face face))
-                (goto-char (match-end 0))))))))))
+                (goto-char (match-end 0)))))))
+      (push pattern hi-lock-interactive-patterns))))
 
 (defun hi-lock-set-file-patterns (patterns)
   "Replace file patterns list with PATTERNS and refontify."
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 250d37b45e..2496e092a6 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1940,15 +1940,7 @@ isearch-highlight-regexp
 			   (isearch-no-upper-case-p
 			    isearch-string isearch-regexp)
 			 isearch-case-fold-search)
-		       ;; 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 ""))
+			isearch-string)
 		      (t (regexp-quote isearch-string)))))
     (hi-lock-face-buffer regexp (hi-lock-read-face-name)
                          (if (and (eq isearch-case-fold-search t)
-- 
2.11.0

From 6f6cdbfe8e825ed1906194fd32542c1c93d94e47 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@HIDDEN>
Date: Thu, 25 May 2017 20:51:55 +0900
Subject: [PATCH 3/3] Honor case-fold-search in all kind of matches

Perform the matches of REGEXP in `hi-lock-line-face-buffer',
`hi-lock-face-phrase-buffer' and `hi-lock-face-symbol-at-point'
as in `hi-lock-face-buffer'.
* lisp/hi-lock.el (hi-lock--deduce-case-fold-from-regexp): New defun.
(hi-lock-line-face-buffer, hi-lock-face-phrase-buffer)
(hi-lock-face-symbol-at-point): Perform the matches of REGEXP
as `hi-lock-face-buffer'.
(hi-lock--regexps-in-pattern-p): New defun.
(hi-lock-unface-buffer): Use it.
---
 lisp/hi-lock.el | 162 ++++++++++++++++++++++++++++++++------------------------
 1 file changed, 94 insertions(+), 68 deletions(-)

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 5862974844..21a170f4db 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -88,6 +88,7 @@
 ;;; Code:
 
 (require 'font-lock)
+(eval-when-compile (require 'cl-lib))
 
 (defgroup hi-lock nil
   "Interactively add and remove font-lock patterns for highlighting text."
@@ -405,11 +406,17 @@ turn-on-hi-lock-if-enabled
   (unless (memq major-mode hi-lock-exclude-modes)
     (hi-lock-mode 1)))
 
+(defun hi-lock--deduce-case-fold-from-regexp (regexp)
+  (if search-upper-case
+      (isearch-no-upper-case-p regexp t)
+    case-fold-search))
+
 ;;;###autoload
 (defalias 'highlight-lines-matching-regexp 'hi-lock-line-face-buffer)
 ;;;###autoload
-(defun hi-lock-line-face-buffer (regexp &optional face)
+(defun hi-lock-line-face-buffer (regexp &optional face case-fold)
   "Set face of all lines containing a match of REGEXP to FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
 
@@ -417,16 +424,19 @@ hi-lock-line-face-buffer
 use overlays for highlighting.  If overlays are used, the
 highlighting will not update as you type."
   (interactive
-   (list
-    (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight line" 'regexp-history-last))
-    (hi-lock-read-face-name)))
+   (let* ((regexp
+           (hi-lock-regexp-okay
+            (read-regexp "Regexp to highlight line" 'regexp-history-last)))
+          (face (hi-lock-read-face-name))
+          (case-fold
+           (hi-lock--deduce-case-fold-from-regexp regexp)))
+     (list regexp face case-fold)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
   (hi-lock-set-pattern
    ;; The \\(?:...\\) grouping construct ensures that a leading ^, +, * or ?
    ;; or a trailing $ in REGEXP will be interpreted correctly.
-   (concat "^.*\\(?:" regexp "\\).*$") face))
+   (concat "^.*\\(?:" regexp "\\).*$") face case-fold))
 
 
 ;;;###autoload
@@ -447,9 +457,7 @@ hi-lock-face-buffer
             (read-regexp "Regexp to highlight" 'regexp-history-last)))
           (face (hi-lock-read-face-name))
           (case-fold
-           (if search-upper-case
-               (isearch-no-upper-case-p regexp t)
-             case-fold-search)))
+           (hi-lock--deduce-case-fold-from-regexp regexp)))
      (list regexp face case-fold)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
@@ -458,8 +466,9 @@ hi-lock-face-buffer
 ;;;###autoload
 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
 ;;;###autoload
-(defun hi-lock-face-phrase-buffer (regexp &optional face)
+(defun hi-lock-face-phrase-buffer (regexp &optional face case-fold)
   "Set face of each match of phrase REGEXP to FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
 
@@ -471,14 +480,19 @@ hi-lock-face-phrase-buffer
 use overlays for highlighting.  If overlays are used, the
 highlighting will not update as you type."
   (interactive
-   (list
-    (hi-lock-regexp-okay
-     (hi-lock-process-phrase
-      (read-regexp "Phrase to highlight" 'regexp-history-last)))
-    (hi-lock-read-face-name)))
+   (let* ((regexp
+           (hi-lock-regexp-okay
+            (read-regexp "Phrase to highlight" 'regexp-history-last)))
+          (face (hi-lock-read-face-name))
+          (case-fold
+           (hi-lock--deduce-case-fold-from-regexp regexp)))
+     (setq regexp
+           (hi-lock-regexp-okay
+            (hi-lock-process-phrase regexp case-fold)))
+     (list regexp face case-fold)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
-  (hi-lock-set-pattern regexp face))
+  (hi-lock-set-pattern regexp face case-fold))
 
 ;;;###autoload
 (defalias 'highlight-symbol-at-point 'hi-lock-face-symbol-at-point)
@@ -495,10 +509,12 @@ hi-lock-face-symbol-at-point
   (let* ((regexp (hi-lock-regexp-okay
 		  (find-tag-default-as-symbol-regexp)))
 	 (hi-lock-auto-select-face t)
-	 (face (hi-lock-read-face-name)))
+	 (face (hi-lock-read-face-name))
+         (case-fold
+          (hi-lock--deduce-case-fold-from-regexp regexp)))
     (or (facep face) (setq face 'hi-yellow))
     (unless hi-lock-mode (hi-lock-mode 1))
-    (hi-lock-set-pattern regexp face)))
+    (hi-lock-set-pattern regexp face case-fold)))
 
 (defun hi-lock-keyword->face (keyword)
   (cadr (cadr (cadr keyword))))    ; Keyword looks like (REGEXP (0 'FACE) ...).
@@ -552,6 +568,12 @@ hi-lock--unused-faces
   "List of faces that is not used and is available for highlighting new text.
 Face names from this list come from `hi-lock-face-defaults'.")
 
+(defun hi-lock--regexps-in-pattern-p (pattern &rest regexps)
+  (cl-some (lambda (reg)
+             (or (assoc reg pattern)
+                 (assoc (assoc reg (mapcar #'car pattern)) pattern)))
+           regexps))
+
 ;;;###autoload
 (defalias 'unhighlight-regexp 'hi-lock-unface-buffer)
 ;;;###autoload
@@ -574,15 +596,15 @@ hi-lock-unface-buffer
          (cons
           `keymap
           (cons "Select Pattern to Unhighlight"
-                 (mapcar (lambda (pattern)
-                           (let ((regexp (or (car-safe (car pattern))
-                                             (car pattern))))
-                             (list regexp
-                                   (format
-                                    "%s (%s)" regexp
-                                    (hi-lock-keyword->face pattern))
-                                   (cons nil nil)
-                                   regexp)))
+                (mapcar (lambda (pattern)
+                          (let ((regexp (or (car-safe (car pattern))
+                                            (car pattern))))
+                            (list regexp
+                                  (format
+                                   "%s (%s)" regexp
+                                   (hi-lock-keyword->face pattern))
+                                  (cons nil nil)
+                                  regexp)))
                         hi-lock-interactive-patterns))))
         ;; If the user clicks outside the menu, meaning that they
         ;; change their mind, x-popup-menu returns nil, and
@@ -599,45 +621,53 @@ hi-lock-unface-buffer
                           (mapcar (lambda (x)
                                     (or (car-safe (car x))
                                         (car x)))
-                                    hi-lock-interactive-patterns)))
+                                  hi-lock-interactive-patterns)))
             (regexp (completing-read (if (null defaults)
                                          "Regexp to unhighlight: "
                                        (format "Regexp to unhighlight (default %s): "
                                                (car defaults)))
                                      hi-lock-interactive-patterns
 			             nil nil nil nil defaults)))
-               (when (and (or (not search-upper-case)
-                              (isearch-no-upper-case-p regexp t))
-                          case-fold-search
-                          (not (hi-lock--case-insensitive-regexp-p regexp)))
-         (setq regexp (hi-lock--case-insensitive-regexp regexp)))
        (list regexp)))))
   (let* ((patterns hi-lock-interactive-patterns)
-         (keys (or (assoc regexp patterns)
-                   (assoc
-                    (assoc regexp (mapcar #'car patterns))
-                    patterns))))
+         (keys (or (eq regexp t)
+                   (let* ((case-fold (hi-lock--deduce-case-fold-from-regexp regexp))
+                          (case-in-regexp
+                           (and (or (not search-upper-case)
+                                    (isearch-no-upper-case-p regexp t))
+                                case-fold-search
+                                (not (hi-lock--case-insensitive-regexp-p regexp))
+                                (hi-lock--case-insensitive-regexp regexp)))
+                          (xregexp (or case-in-regexp regexp)))
+                     ;; Match a regexp.
+                     (or (hi-lock--regexps-in-pattern-p patterns regexp xregexp)
+                         ;; Match a line.
+                         (let ((line-re (format "^.*\\(?:%s\\).*$" xregexp)))
+                           (hi-lock--regexps-in-pattern-p patterns line-re))
+                         ;; Match a phrase.
+                         (let ((phrase-re (hi-lock-process-phrase regexp case-fold)))
+                           (hi-lock--regexps-in-pattern-p patterns phrase-re)))))))
     (dolist (keyword (if (eq regexp t)
                          patterns
                        (list keys)))
-    (when keyword
-      (let ((face (hi-lock-keyword->face keyword)))
-        ;; Make `face' the next one to use by default.
-        (when (symbolp face)          ;Don't add it if it's a list (bug#13297).
-          (add-to-list 'hi-lock--unused-faces (face-name face))))
-      ;; FIXME: Calling `font-lock-remove-keywords' causes
-      ;; `font-lock-specified-p' to go from nil to non-nil (because it
-      ;; 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)))
-      (setq hi-lock-interactive-patterns
-            (delq keyword hi-lock-interactive-patterns))
-      (remove-overlays
-       nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons
-                                        (or (car-safe (car keyword))
-                                            (car keyword))))
-      (font-lock-flush)))))
+      (when keyword
+        (let ((face (hi-lock-keyword->face keyword)))
+          ;; Make `face' the next one to use by default.
+          (when (symbolp face)          ;Don't add it if it's a list (bug#13297).
+            (add-to-list 'hi-lock--unused-faces (face-name face))))
+        ;; FIXME: Calling `font-lock-remove-keywords' causes
+        ;; `font-lock-specified-p' to go from nil to non-nil (because it
+        ;; 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)))
+        (setq hi-lock-interactive-patterns
+              (delq keyword hi-lock-interactive-patterns))
+        (remove-overlays
+         nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons
+                                          (or (car-safe (car keyword))
+                                              (car keyword))))
+        (font-lock-flush)))))
 
 ;;;###autoload
 (defun hi-lock-write-interactive-patterns ()
@@ -662,20 +692,16 @@ hi-lock-write-interactive-patterns
 
 ;; Implementation Functions
 
-(defun hi-lock-process-phrase (phrase)
+(defun hi-lock-process-phrase (phrase &optional case-fold)
   "Convert regexp PHRASE to a regexp that matches phrases.
 
-Blanks in PHRASE replaced by regexp that matches arbitrary whitespace
-and initial lower-case letters made case insensitive."
-  (let ((mod-phrase nil))
-    ;; 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))
+If optional arg CASE-FOLD is non-nil, then transform PHRASE into a case
+insensitive pattern.
+Blanks in PHRASE replaced by regexp that matches arbitrary whitespace."
+  ;; FIXME fragile; better to just bind case-fold-search?  (Bug#7161)
+  (let ((mod-phrase (if case-fold
+                        (hi-lock--case-insensitive-regexp phrase)
+                      phrase)))
     ;; FIXME fragile; better to use search-spaces-regexp?
     (setq mod-phrase
           (replace-regexp-in-string
@@ -750,7 +776,7 @@ hi-lock--case-insensitive-regexp
                          (setq count 0)
                          (if (string-match "[[:alpha:]]" s)
 	                     (format "[%s%s]" (upcase s) (downcase s))
-	                   (regexp-quote s))))))
+	                   s)))))
               regexp ""))))))
 
 (defun hi-lock-set-pattern (regexp face &optional case-fold)
-- 
2.11.0

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-05-25
Repository revision: b2ec91db89739153b39d10c15701b57aae7e251c




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 24 May 2017 13:35:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed May 24 09:35:58 2017
Received: from localhost ([127.0.0.1]:35687 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1dDWSE-0000Tg-CA
	for submit <at> debbugs.gnu.org; Wed, 24 May 2017 09:35:58 -0400
Received: from mail-pf0-f181.google.com ([209.85.192.181]:32949)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tino.calancha@HIDDEN>) id 1dDWSC-0000TT-FW
 for 22541 <at> debbugs.gnu.org; Wed, 24 May 2017 09:35:56 -0400
Received: by mail-pf0-f181.google.com with SMTP id e193so139646377pfh.0
 for <22541 <at> debbugs.gnu.org>; Wed, 24 May 2017 06:35:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=HSTeJ4MhIsldzxtoXhBXdrtaM8FdFAPw3ezxMYfJcmA=;
 b=k64jVQ9Vj51mPeT9TsULPHcOJUt1Q9yYwMjYZxlJojEkAv7VFbqYOag5hkTQpccQ1f
 ijgEw0b3wOWavsMEhh5P7+NrxLW4Tbp8nA3DmS1Saqf4Td6M9BfIusRSjXP7FBfj/x5u
 tL91v8lixOIJ8thdsdmf9iwnJb6XGlIT35QrNrIpA5q0vTx9u0YfpQCCZOwsmAiJevrK
 iOh9ZX/iYERymGzZsWQKHqZKg13fslFSl5mZkbJtd/tPaLll4Z3EmnAVqQn0/bDDh9b5
 qJ9CwPpOXNX6JXF81RZWn4dH0bot+fFhTngRyVB+xfxgZbPjJKnheET2UfXEF0mA22hB
 8qzg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version;
 bh=HSTeJ4MhIsldzxtoXhBXdrtaM8FdFAPw3ezxMYfJcmA=;
 b=VzwRqA6sAZQe0eZfc3kEvpB1didFblBkF0EQnJ2FnZTCdByHzzpKVWXXKMW/56XFcP
 LRdVLRBdLhsoW0Fh7DexCs/O79NSHo0IYQqwHv2orqlqjognMzPFRjKvlDOCXoxyNCkI
 YZ49/ehf1V8b8sMWsLQDfr/xK4mMnNbeRqJYzddfyNHBZ8yHl6swhRkKBbfWjnYb7lzn
 DQro9ZB/PIraEl90M+g3GGyzlgSaKUbOJ2JNPBjaE3M1YuDwNcIzZG5h3cizwk62wdA3
 EhDUG44FjPPf5lyjbk30xNVHK2BN64y692Sh8I1I1X93BSDEfenSQMPW0cuJjUmQkjnA
 Qjog==
X-Gm-Message-State: AODbwcBgI8ONCiQxfWWVVJ9QTnAUd6xza4mP+OQNvKExvmFriHvTMuXg
 bRCcjdGKCU157A==
X-Received: by 10.98.23.74 with SMTP id 71mr38136098pfx.30.1495632950436;
 Wed, 24 May 2017 06:35:50 -0700 (PDT)
Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222])
 by smtp.gmail.com with ESMTPSA id
 h21sm6658457pgn.18.2017.05.24.06.35.47
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Wed, 24 May 2017 06:35:49 -0700 (PDT)
From: Tino Calancha <tino.calancha@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
 <87vapwipy4.fsf@calancha-pc> <87shkyems1.fsf@localhost>
 <87pog112pp.fsf@calancha-pc> <87mvb4yzux.fsf@localhost>
 <87bmrilylu.fsf@calancha-pc> <87fugdfzoq.fsf@localhost>
Date: Wed, 24 May 2017 22:35:41 +0900
In-Reply-To: <87fugdfzoq.fsf@localhost> (Juri Linkov's message of "Wed, 10 May
 2017 01:10:03 +0300")
Message-ID: <8737bugyxe.fsf@calancha-pc>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.8 (--)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org, Dima Kogan <dima@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.8 (--)

Juri Linkov <juri@HIDDEN> writes:

>> The new patch, in addition to fix this bug report, it also
>> helps with the 5. in bug#22520, that is:
>> emacs -Q
>> M-s hr t RET RET ; Highlight with regexp "[Tt]"
>> M-s hu t RET ; Unhighlight the buffer.
>
> Thanks, could you find more test cases that still don't work?
Yes i did.  We need to fold according with `search-upper-case' and
`case-fold-search' for `hi-lock-face-phrase-buffer' and
`hi-lock-line-face-buffer' as well.
I am posting the updated patch in a few days after after test it.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 9 May 2017 22:13:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue May 09 18:13:01 2017
Received: from localhost ([127.0.0.1]:34719 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1d8DNM-000166-PV
	for submit <at> debbugs.gnu.org; Tue, 09 May 2017 18:13:00 -0400
Received: from sub3.mail.dreamhost.com ([69.163.253.7]:43461
 helo=homiemail-a15.g.dreamhost.com)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1d8DNK-00015y-SD
 for 22541 <at> debbugs.gnu.org; Tue, 09 May 2017 18:12:59 -0400
Received: from homiemail-a15.g.dreamhost.com (localhost [127.0.0.1])
 by homiemail-a15.g.dreamhost.com (Postfix) with ESMTP id 14F4176C069;
 Tue,  9 May 2017 15:12:57 -0700 (PDT)
Received: from localhost.linkov.net (m90-133-229-48.cust.tele2.ee
 [90.133.229.48]) (Authenticated sender: jurta@HIDDEN)
 by homiemail-a15.g.dreamhost.com (Postfix) with ESMTPA id 099CE76C065;
 Tue,  9 May 2017 15:12:55 -0700 (PDT)
From: Juri Linkov <juri@HIDDEN>
To: Tino Calancha <tino.calancha@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
Organization: LINKOV.NET
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
 <87vapwipy4.fsf@calancha-pc> <87shkyems1.fsf@localhost>
 <87pog112pp.fsf@calancha-pc> <87mvb4yzux.fsf@localhost>
 <87bmrilylu.fsf@calancha-pc>
Date: Wed, 10 May 2017 01:10:03 +0300
In-Reply-To: <87bmrilylu.fsf@calancha-pc> (Tino Calancha's message of "Thu, 27
 Apr 2017 23:22:05 +0900")
Message-ID: <87fugdfzoq.fsf@localhost>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.8 (--)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org, Dima Kogan <dima@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.8 (--)

>>> @@ -1950,7 +1950,12 @@ isearch-highlight-regexp
>>>  			      (regexp-quote s))))
>>>  			isearch-string ""))
>>>  		      (t (regexp-quote isearch-string)))))
>>> -    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
>>> +    (hi-lock-face-buffer regexp (hi-lock-read-face-name)
>>> +                         (if (and (eq isearch-case-fold-search t)
>>> +                                  search-upper-case)
>>> +                             (isearch-no-upper-case-p
>>> +                              isearch-string isearch-regexp)
>>> +                           isearch-case-fold-search)))
>>>    (and isearch-recursive-edit (exit-recursive-edit)))
>>
>> If this works reliably, then we could remove that ugly hack
>> from =E2=80=98isearch-highlight-regexp=E2=80=99, I mean the one with t=
he comment
>> =E2=80=9CTurn isearch-string into a case-insensitive regexp=E2=80=9D.
> That's right.  We don't need such trick here anymore.  But this hack
> turned ut to be useful in hi-lock.el.
>
> The new patch, in addition to fix this bug report, it also
> helps with the 5. in bug#22520, that is:
> emacs -Q
> M-s hr t RET RET ; Highlight with regexp "[Tt]"
> M-s hu t RET ; Unhighlight the buffer.

Thanks, could you find more test cases that still don't work?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 27 Apr 2017 14:22:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 27 10:22:22 2017
Received: from localhost ([127.0.0.1]:42956 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1d3kJJ-0000Fz-7i
	for submit <at> debbugs.gnu.org; Thu, 27 Apr 2017 10:22:21 -0400
Received: from mail-pf0-f178.google.com ([209.85.192.178]:33705)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tino.calancha@HIDDEN>) id 1d3kJG-0000Fi-Sx
 for 22541 <at> debbugs.gnu.org; Thu, 27 Apr 2017 10:22:19 -0400
Received: by mail-pf0-f178.google.com with SMTP id a188so28420953pfa.0
 for <22541 <at> debbugs.gnu.org>; Thu, 27 Apr 2017 07:22:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version:content-transfer-encoding;
 bh=OGChUWXguxGzdR41X5H0EHyMtuAKb5AEQg/ugJIeI/I=;
 b=WiNhByH65458QOj7HLg2iAvKZeZRHZugnVW2UMxJoDCKus9pHDTwlh8fWkaqqtkqI0
 usWLEHiURYsefvjZmeVwUZtw1Kk0EJcEdCP6GoW1/Hwbfc7Lpl7aYZUGE2y16TEbL54I
 Qxm09u3oFr+Bt4RwFscDuldFsThjPvTursY9a1DvPkpbJhZoE66gvud+HyKc/r+ssG/s
 ILkgJx6ZPkt1d61jIChnZF1BdY9TfA7PkMG8G7LxlxVVGcMp044d0Ct3VjGcKtqnJcLT
 xLHRN52UWdFHtgJno9MX/7IgsNxdNBGbPH2PsafhlglI7V37YTUyM6OrWlqgRLws2xVA
 Ingg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version:content-transfer-encoding;
 bh=OGChUWXguxGzdR41X5H0EHyMtuAKb5AEQg/ugJIeI/I=;
 b=PgxjILkWraQQSKYFz1RIcQpuPRsP4XFGAXVxwUZcNmM5G8JzR+qDPVjKIG8V2hYaqb
 NbiDIazg4AVO7OG7OB24FG6WkrNSqYlgwGIN6BoPLLJUJ3vRsNo+YkdLbnid4s3VNoEr
 k9Yo5AdQmlcIkQqzh/sFvBr2+q+AGDVAA3rcvqOL1KFNAs4f6xKp1MQ++jmopgljgdiv
 7h+Hf0sLrWUKRnlsViFA50lpSihdAcLhQcG5CTMtWvDltUPewTRfJYJKr5g/dshBacoe
 Xzw/zNby4NMTKBSDfnUj4GM17KYvG9hQ3wGz8s09GhgZq/5b1N6NSU8jProzzqwvNqn6
 voqQ==
X-Gm-Message-State: AN3rC/5y2RVXvOAhPEO1uFtjuRPQzLEThBeCg+XomyQdfhQkGCuHe8mA
 x3GY+Mw69KL0EQ==
X-Received: by 10.98.193.65 with SMTP id i62mr6085212pfg.149.1493302932306;
 Thu, 27 Apr 2017 07:22:12 -0700 (PDT)
Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222])
 by smtp.gmail.com with ESMTPSA id
 g5sm7128981pgn.38.2017.04.27.07.22.08
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Thu, 27 Apr 2017 07:22:10 -0700 (PDT)
From: Tino Calancha <tino.calancha@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
 <87vapwipy4.fsf@calancha-pc> <87shkyems1.fsf@localhost>
 <87pog112pp.fsf@calancha-pc> <87mvb4yzux.fsf@localhost>
Date: Thu, 27 Apr 2017 23:22:05 +0900
In-Reply-To: <87mvb4yzux.fsf@localhost> (Juri Linkov's message of "Tue, 25 Apr
 2017 23:52:06 +0300")
Message-ID: <87bmrilylu.fsf@calancha-pc>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.8 (--)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org, Dima Kogan <dima@HIDDEN>,
 tino.calancha@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.8 (--)

Juri Linkov <juri@HIDDEN> writes:

Thanks for the feedback!

>> -(defun hi-lock-set-pattern (regexp face)
>> -  "Highlight REGEXP with face FACE."
>> +(defun hi-lock-set-pattern (regexp face &optional case-fold)
>> +  "Highlight REGEXP with face FACE.
>> +If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to i=
t."
>>    ;; Hashcons the regexp, so it can be passed to remove-overlays later.
>>    (setq regexp (hi-lock--hashcons regexp))
>> -  (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
>> +  (let ((pattern (list (if (eq case-fold 'undefined)
>> +                           regexp
>> +                         (cons regexp
>> +                               (byte-compile
>> +                          `(lambda (limit)
>> +                             (let ((case-fold-search ,case-fold))
>> +                               (re-search-forward ,regexp limit t))))))
>> +                       (list 0 (list 'quote face) 'prepend))))
>
> Do you need to remember also the value of =E2=80=98case-fold-search=E2=80=
=99
> (together with =E2=80=98regexp=E2=80=99)?
AFAICT i don't need it.

>> @@ -1950,7 +1950,12 @@ isearch-highlight-regexp
>>  			      (regexp-quote s))))
>>  			isearch-string ""))
>>  		      (t (regexp-quote isearch-string)))))
>> -    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
>> +    (hi-lock-face-buffer regexp (hi-lock-read-face-name)
>> +                         (if (and (eq isearch-case-fold-search t)
>> +                                  search-upper-case)
>> +                             (isearch-no-upper-case-p
>> +                              isearch-string isearch-regexp)
>> +                           isearch-case-fold-search)))
>>    (and isearch-recursive-edit (exit-recursive-edit)))
>
> If this works reliably, then we could remove that ugly hack
> from =E2=80=98isearch-highlight-regexp=E2=80=99, I mean the one with the =
comment
> =E2=80=9CTurn isearch-string into a case-insensitive regexp=E2=80=9D.
That's right.  We don't need such trick here anymore.  But this hack
turned ut to be useful in hi-lock.el.

The new patch, in addition to fix this bug report, it also
helps with the 5. in bug#22520, that is:
emacs -Q
M-s hr t RET RET ; Highlight with regexp "[Tt]"
M-s hu t RET ; Unhighlight the buffer.

--8<-----------------------------cut here---------------start------------->=
8---
From 5183897b88b93060ce391f166cdeebf605785362 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@HIDDEN>
Date: Thu, 27 Apr 2017 23:02:41 +0900
Subject: [PATCH] highlight-regexp: Honor case-fold-search

* lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern):
Add optional arg CASE-FOLD.  All callers updated.
* lisp/isearch.el (isearch-highlight-regexp): Call hi-lock-face-buffer
with 3 arguments.
---
 lisp/hi-lock.el | 30 +++++++++++++++++++-----------
 lisp/isearch.el |  7 ++++++-
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 5139e01fa8..55ad3ccb58 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -432,7 +432,7 @@ hi-lock-line-face-buffer
 ;;;###autoload
 (defalias 'highlight-regexp 'hi-lock-face-buffer)
 ;;;###autoload
-(defun hi-lock-face-buffer (regexp &optional face)
+(defun hi-lock-face-buffer (regexp &optional face case-fold)
   "Set face of each match of REGEXP to FACE.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
@@ -444,10 +444,11 @@ hi-lock-face-buffer
    (list
     (hi-lock-regexp-okay
      (read-regexp "Regexp to highlight" 'regexp-history-last))
-    (hi-lock-read-face-name)))
+    (hi-lock-read-face-name)
+    case-fold-search))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
-  (hi-lock-set-pattern regexp face))
+  (hi-lock-set-pattern regexp face case-fold))
=20
 ;;;###autoload
 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
@@ -689,11 +690,17 @@ hi-lock-read-face-name
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))
=20
-(defun hi-lock-set-pattern (regexp face)
+(defun hi-lock-set-pattern (regexp face &optional case-fold)
   "Highlight REGEXP with face FACE."
   ;; Hashcons the regexp, so it can be passed to remove-overlays later.
   (setq regexp (hi-lock--hashcons regexp))
-  (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
+  (let ((pattern (list (if (eq case-fold 'undefined)
+                           regexp
+                         (byte-compile
+                          `(lambda (limit)
+                             (let ((case-fold-search ,case-fold))
+                               (re-search-forward ,regexp limit t)))))
+                       (list 0 (list 'quote face) 'prepend))))
     ;; Refuse to highlight a text that is already highlighted.
     (if (assoc regexp hi-lock-interactive-patterns)
         (add-to-list 'hi-lock--unused-faces (face-name face))
@@ -712,12 +719,13 @@ hi-lock-set-pattern
                      (+ range-max (max 0 (- (point-min) range-min))))))
           (save-excursion
             (goto-char search-start)
-            (while (re-search-forward regexp search-end t)
-              (let ((overlay (make-overlay (match-beginning 0) (match-end =
0))))
-                (overlay-put overlay 'hi-lock-overlay t)
-                (overlay-put overlay 'hi-lock-overlay-regexp regexp)
-                (overlay-put overlay 'face face))
-              (goto-char (match-end 0)))))))))
+            (let ((case-fold-search case-fold))
+              (while (re-search-forward regexp search-end t)
+                (let ((overlay (make-overlay (match-beginning 0) (match-en=
d 0))))
+                  (overlay-put overlay 'hi-lock-overlay t)
+                  (overlay-put overlay 'hi-lock-overlay-regexp regexp)
+                  (overlay-put overlay 'face face))
+                (goto-char (match-end 0))))))))))
=20
 (defun hi-lock-set-file-patterns (patterns)
   "Replace file patterns list with PATTERNS and refontify."
diff --git a/lisp/isearch.el b/lisp/isearch.el
index c34739d638..250d37b45e 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1950,7 +1950,12 @@ isearch-highlight-regexp
 			      (regexp-quote s))))
 			isearch-string ""))
 		      (t (regexp-quote isearch-string)))))
-    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
+    (hi-lock-face-buffer regexp (hi-lock-read-face-name)
+                         (if (and (eq isearch-case-fold-search t)
+                                  search-upper-case)
+                             (isearch-no-upper-case-p
+                              isearch-string isearch-regexp)
+                           isearch-case-fold-search)))
   (and isearch-recursive-edit (exit-recursive-edit)))
=20
 
--=20
2.11.0

From 32ec762b9459cf2a1b50217fa061c70541c0a241 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@HIDDEN>
Date: Thu, 27 Apr 2017 23:05:01 +0900
Subject: [PATCH] Fix hi-lock-unface-buffer from last commit

Perform the matches of REGEXP as `isearch-forward' i.e., in interactive
calls determine the case fold with `search-upper-case' and
`case-fold-search' (Bug#22541).
* lisp/hi-lock.el (hi-lock-face-buffer): Update docstring.
Determine the case fold with `search-upper-case' and
`case-fold-search'.
(hi-lock--regexps-at-point, hi-lock-unface-buffer):
Handle when pattern is a cons (REGEXP . FUNCTION).
(hi-lock-read-face-name): Update docstring.
(hi-lock--case-insensitive-regexp,
hi-lock--case-insensitive-regexp-p): New defuns.
(hi-lock-set-pattern, hi-lock-unface-buffer): Use them.
* lisp/isearch.el (isearch-highlight-regexp): Delete hack for
case-insensitive search; this is now handled in
hi-lock-face-buffer.
* test/lisp/hi-lock-tests.el (hi-lock-face-buffer-test, hi-lock-bug22520):
Add tests.
---
 lisp/hi-lock.el            | 153 +++++++++++++++++++++++++++++++++--------=
----
 lisp/isearch.el            |  10 +--
 test/lisp/hi-lock-tests.el |  91 ++++++++++++++++++++++++++-
 3 files changed, 204 insertions(+), 50 deletions(-)

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index 55ad3ccb58..5862974844 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -434,6 +434,7 @@ 'highlight-regexp
 ;;;###autoload
 (defun hi-lock-face-buffer (regexp &optional face case-fold)
   "Set face of each match of REGEXP to FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
=20
@@ -441,11 +442,15 @@ hi-lock-face-buffer
 use overlays for highlighting.  If overlays are used, the
 highlighting will not update as you type."
   (interactive
-   (list
-    (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight" 'regexp-history-last))
-    (hi-lock-read-face-name)
-    case-fold-search))
+   (let* ((regexp
+           (hi-lock-regexp-okay
+            (read-regexp "Regexp to highlight" 'regexp-history-last)))
+          (face (hi-lock-read-face-name))
+          (case-fold
+           (if search-upper-case
+               (isearch-no-upper-case-p regexp t)
+             case-fold-search)))
+     (list regexp face case-fold)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
   (hi-lock-set-pattern regexp face case-fold))
@@ -531,10 +536,17 @@ hi-lock--regexps-at-point
           ;; highlighted text at point.  Use this later in
           ;; during completing-read.
           (dolist (hi-lock-pattern hi-lock-interactive-patterns)
-            (let ((regexp (car hi-lock-pattern)))
-              (if (string-match regexp hi-text)
-                  (push regexp regexps)))))))
-    regexps))
+            (let ((regexp-or-fn (car hi-lock-pattern)))
+              (cond ((stringp regexp-or-fn)
+                     (when (string-match regexp-or-fn hi-text)
+                       (push regexp-or-fn regexps)))
+                    (t
+                     (with-temp-buffer
+                       (insert hi-text)
+                       (goto-char 1)
+                       (when (funcall regexp-or-fn nil)
+                         (push regexp-or-fn regexps)))))))
+    ))) regexps))
=20
 (defvar-local hi-lock--unused-faces nil
   "List of faces that is not used and is available for highlighting new te=
xt.
@@ -562,13 +574,15 @@ hi-lock-unface-buffer
          (cons
           `keymap
           (cons "Select Pattern to Unhighlight"
-                (mapcar (lambda (pattern)
-                          (list (car pattern)
-                                (format
-                                 "%s (%s)" (car pattern)
-                                 (hi-lock-keyword->face pattern))
-                                (cons nil nil)
-                                (car pattern)))
+                 (mapcar (lambda (pattern)
+                           (let ((regexp (or (car-safe (car pattern))
+                                             (car pattern))))
+                             (list regexp
+                                   (format
+                                    "%s (%s)" regexp
+                                    (hi-lock-keyword->face pattern))
+                                   (cons nil nil)
+                                   regexp)))
                         hi-lock-interactive-patterns))))
         ;; If the user clicks outside the menu, meaning that they
         ;; change their mind, x-popup-menu returns nil, and
@@ -582,16 +596,30 @@ hi-lock-unface-buffer
        (error "No highlighting to remove"))
      ;; Infer the regexp to un-highlight based on cursor position.
      (let* ((defaults (or (hi-lock--regexps-at-point)
-                          (mapcar #'car hi-lock-interactive-patterns))))
-       (list
-        (completing-read (if (null defaults)
-                             "Regexp to unhighlight: "
-                           (format "Regexp to unhighlight (default %s): "
-                                   (car defaults)))
-                         hi-lock-interactive-patterns
-			 nil t nil nil defaults))))))
-  (dolist (keyword (if (eq regexp t) hi-lock-interactive-patterns
-                     (list (assoc regexp hi-lock-interactive-patterns))))
+                          (mapcar (lambda (x)
+                                    (or (car-safe (car x))
+                                        (car x)))
+                                    hi-lock-interactive-patterns)))
+            (regexp (completing-read (if (null defaults)
+                                         "Regexp to unhighlight: "
+                                       (format "Regexp to unhighlight (def=
ault %s): "
+                                               (car defaults)))
+                                     hi-lock-interactive-patterns
+			             nil nil nil nil defaults)))
+               (when (and (or (not search-upper-case)
+                              (isearch-no-upper-case-p regexp t))
+                          case-fold-search
+                          (not (hi-lock--case-insensitive-regexp-p regexp)=
))
+         (setq regexp (hi-lock--case-insensitive-regexp regexp)))
+       (list regexp)))))
+  (let* ((patterns hi-lock-interactive-patterns)
+         (keys (or (assoc regexp patterns)
+                   (assoc
+                    (assoc regexp (mapcar #'car patterns))
+                    patterns))))
+    (dolist (keyword (if (eq regexp t)
+                         patterns
+                       (list keys)))
     (when keyword
       (let ((face (hi-lock-keyword->face keyword)))
         ;; Make `face' the next one to use by default.
@@ -606,8 +634,10 @@ hi-lock-unface-buffer
       (setq hi-lock-interactive-patterns
             (delq keyword hi-lock-interactive-patterns))
       (remove-overlays
-       nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons (car keyword)))
-      (font-lock-flush))))
+       nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons
+                                        (or (car-safe (car keyword))
+                                            (car keyword))))
+      (font-lock-flush)))))
=20
 ;;;###autoload
 (defun hi-lock-write-interactive-patterns ()
@@ -690,23 +720,67 @@ hi-lock-read-face-name
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))
=20
+(defun hi-lock--case-insensitive-regexp-p (regexp)
+  (let (case-fold-search)
+    (and (string-match-p regexp (downcase regexp))
+         (string-match-p regexp (upcase regexp)))))
+
+(defun hi-lock--case-insensitive-regexp (regexp)
+  "Turn regexp into a case-insensitive regexp."
+  (let ((count 0)
+        (upper-re "[[:upper:]]")
+        (slash-upper-re "\\(\\\\\\)\\([[:upper:]]\\)")
+        case-fold-search)
+    (cond ((or (hi-lock--case-insensitive-regexp-p regexp)
+               (and (string-match upper-re regexp)
+                    (not (string-match slash-upper-re regexp))))
+           regexp)
+          (t
+           (let ((string regexp))
+             (while (string-match slash-upper-re string)
+               (setq string (replace-match "" t t string 1)))
+             (setq regexp string)
+             (mapconcat
+              (lambda (c)
+                (let ((s (string c)))
+                  (cond ((or (eq c ?\\)
+                             (and (=3D count 1) (string=3D s (upcase s))))
+                         (setq count (1+ count)) s)
+                        (t
+                         (setq count 0)
+                         (if (string-match "[[:alpha:]]" s)
+	                     (format "[%s%s]" (upcase s) (downcase s))
+	                   (regexp-quote s))))))
+              regexp ""))))))
+
 (defun hi-lock-set-pattern (regexp face &optional case-fold)
-  "Highlight REGEXP with face FACE."
+  "Highlight REGEXP with face FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it."
   ;; Hashcons the regexp, so it can be passed to remove-overlays later.
   (setq regexp (hi-lock--hashcons regexp))
-  (let ((pattern (list (if (eq case-fold 'undefined)
+  (let* ((pattern (list (if (eq case-fold 'undefined)
                            regexp
-                         (byte-compile
-                          `(lambda (limit)
-                             (let ((case-fold-search ,case-fold))
-                               (re-search-forward ,regexp limit t)))))
-                       (list 0 (list 'quote face) 'prepend))))
+                         (cons regexp
+                               (byte-compile
+                                `(lambda (limit)
+                                   (let ((case-fold-search ,case-fold))
+                                     (re-search-forward ,regexp limit t)))=
)))
+                       (list 0 (list 'quote face) 'prepend)))
+         (regexp-fold
+          (cond ((not (consp (car pattern)))
+                 (car pattern))
+                (t
+                 (if (not case-fold)
+                     (caar pattern)
+		   (hi-lock--case-insensitive-regexp (caar pattern)))))))
     ;; Refuse to highlight a text that is already highlighted.
-    (if (assoc regexp hi-lock-interactive-patterns)
+    (if (or (assoc regexp hi-lock-interactive-patterns)
+            (assoc regexp-fold hi-lock-interactive-patterns)
+            (assoc regexp-fold (mapcar #'car hi-lock-interactive-patterns)=
))
         (add-to-list 'hi-lock--unused-faces (face-name face))
-      (push pattern hi-lock-interactive-patterns)
       (if (and font-lock-mode (font-lock-specified-p major-mode))
-	  (progn
+          (progn
+            (setq pattern (list regexp-fold (list 0 (list 'quote face) 'pr=
epend)))
 	    (font-lock-add-keywords nil (list pattern) t)
 	    (font-lock-flush))
         (let* ((range-min (- (point) (/ hi-lock-highlight-range 2)))
@@ -725,7 +799,8 @@ hi-lock-set-pattern
                   (overlay-put overlay 'hi-lock-overlay t)
                   (overlay-put overlay 'hi-lock-overlay-regexp regexp)
                   (overlay-put overlay 'face face))
-                (goto-char (match-end 0))))))))))
+                (goto-char (match-end 0)))))))
+      (push pattern hi-lock-interactive-patterns))))
=20
 (defun hi-lock-set-file-patterns (patterns)
   "Replace file patterns list with PATTERNS and refontify."
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 250d37b45e..2496e092a6 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1940,15 +1940,7 @@ isearch-highlight-regexp
 			   (isearch-no-upper-case-p
 			    isearch-string isearch-regexp)
 			 isearch-case-fold-search)
-		       ;; 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 ""))
+			isearch-string)
 		      (t (regexp-quote isearch-string)))))
     (hi-lock-face-buffer regexp (hi-lock-read-face-name)
                          (if (and (eq isearch-case-fold-search t)
diff --git a/test/lisp/hi-lock-tests.el b/test/lisp/hi-lock-tests.el
index 2cb662cfac..1d97e1f054 100644
--- a/test/lisp/hi-lock-tests.el
+++ b/test/lisp/hi-lock-tests.el
@@ -22,6 +22,7 @@
=20
 (require 'ert)
 (require 'hi-lock)
+(eval-when-compile (require 'cl-lib))
=20
 (ert-deftest hi-lock-bug26666 ()
   "Test for http://debbugs.gnu.org/26666 ."
@@ -29,12 +30,98 @@
     (with-temp-buffer
       (insert "a A b B\n")
       (cl-letf (((symbol-function 'completing-read)
-                   (lambda (prompt coll x y z hist defaults)
-                     (car defaults))))
+                 (lambda (prompt coll x y z hist defaults)
+                   (car defaults))))
         (dotimes (_ 2)
           (let ((face (hi-lock-read-face-name)))
             (hi-lock-set-pattern "a" face))))
       (should (equal hi-lock--unused-faces (cdr faces))))))
=20
+(defun hi-lock--count (face)
+  (let ((count 0))
+    (save-excursion
+      (goto-char (point-min))
+      (cond ((and font-lock-mode (font-lock-specified-p major-mode))
+             (when (and (consp (get-text-property (point) 'face))
+                        (memq 'hi-yellow (get-text-property (point) 'face)=
))
+               (cl-incf count))
+             (while (next-property-change (point))
+               (goto-char (next-property-change (point)))
+               (when (and (consp (get-text-property (point) 'face))
+                          (memq 'hi-yellow (get-text-property (point) 'fac=
e)))
+                 (cl-incf count))))
+            (t
+             (dolist (ov (car (overlay-lists)))
+               (let ((props (memq 'face (overlay-properties ov))))
+                 (when (eq (cadr props) face)
+                   (cl-incf count)))))))
+    count))
+
+(defun hi-lock--highlight-and-count (regexp face case-fold)
+  "Highlight REGEXP with FACE with case fold CASE-FOLD.
+Return number of matches."
+  (hi-lock-unface-buffer t)
+  (should (eq 0 (hi-lock--count face)))
+  (hi-lock-face-buffer regexp face case-fold)
+  (hi-lock--count face))
+
+(defun hi-lock--interactive-test-1 (regexp face res ucase cfold)
+  (hi-lock-unface-buffer t)
+  (should (eq 0 (hi-lock--count face)))
+  (cl-letf (((symbol-function 'read-regexp)
+             (lambda (x y) (ignore x y) regexp))
+            ((symbol-function 'hi-lock-read-face-name)
+             (lambda () face)))
+    (setq search-upper-case ucase
+          case-fold-search cfold)
+    (call-interactively 'hi-lock-face-buffer)
+    (should (=3D res (hi-lock--count face)))))
+
+;; Interactive test should not depend on the major mode.
+(defun hi-lock--interactive-test (regexp face res ucase cfold)
+  (lisp-interaction-mode)
+  (hi-lock--interactive-test-1 regexp face res ucase cfold)
+  (fundamental-mode)
+  (hi-lock--interactive-test-1 regexp face res ucase cfold))
+
+;; In batch calls to `hi-lock-face-buffer', case is given by
+;; its third argument.  In interactive calls, case depends
+;; on `search-upper-case' and `case-fold-search'.
+(ert-deftest hi-lock-face-buffer-test ()
+  "Test for http://debbugs.gnu.org/22541 ."
+  (let ((face 'hi-yellow)
+        (regexp "a")
+        case-fold-search search-upper-case)
+    (with-temp-buffer
+      (insert "a A\n")
+      (should (=3D 1 (hi-lock--highlight-and-count regexp face nil)))
+      (should (=3D 2 (hi-lock--highlight-and-count regexp face t)))
+      ;; Case depends on the regexp.
+      (hi-lock--interactive-test regexp face 2 t nil)
+      (hi-lock--interactive-test "A" face 1 t nil)
+      (hi-lock--interactive-test "\\A" face 2 t nil)
+      ;; Case depends on `case-fold-search'.
+      (hi-lock--interactive-test "a" face 1 nil nil)
+      (hi-lock--interactive-test "A" face 1 nil nil)
+      (hi-lock--interactive-test "\\A" face 1 nil nil)
+      ;;
+      (hi-lock--interactive-test "a" face 2 nil t)
+      (hi-lock--interactive-test "A" face 2 nil t)
+      (hi-lock--interactive-test "\\A" face 2 nil t))))
+
+(ert-deftest hi-lock-bug22520 ()
+  "Test for http://debbugs.gnu.org/22520 ."
+  (with-temp-buffer
+    (erase-buffer)
+    (insert "foo and Foo")
+    (dolist (ucase '(nil t))
+      (dolist (cfold '(nil t))
+        (let ((res (cond ((null ucase)
+                          (if cfold 2 1))
+                         (t 2))))
+        (hi-lock--interactive-test "f" 'hi-yellow res ucase cfold)
+        (hi-lock-unface-buffer "f")
+        (should (=3D 0 (hi-lock--count 'hi-yellow))))))))
+
 (provide 'hi-lock-tests)
 ;;; hi-lock-tests.el ends here
--=20
2.11.0

--8<-----------------------------cut here---------------end--------------->=
8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-04-27
Repository revision: 79c5ea9911a9aba7db0ba0e367e06507cee2fc02




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 25 Apr 2017 20:58:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 25 16:58:35 2017
Received: from localhost ([127.0.0.1]:40173 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1d37Xf-00047y-1L
	for submit <at> debbugs.gnu.org; Tue, 25 Apr 2017 16:58:35 -0400
Received: from sub3.mail.dreamhost.com ([69.163.253.7]:47685
 helo=homiemail-a17.g.dreamhost.com)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1d37Xc-00047j-La
 for 22541 <at> debbugs.gnu.org; Tue, 25 Apr 2017 16:58:33 -0400
Received: from homiemail-a17.g.dreamhost.com (localhost [127.0.0.1])
 by homiemail-a17.g.dreamhost.com (Postfix) with ESMTP id 9CD892B207F;
 Tue, 25 Apr 2017 13:58:30 -0700 (PDT)
Received: from localhost.linkov.net (m83-179-141-227.cust.tele2.ee
 [83.179.141.227]) (Authenticated sender: jurta@HIDDEN)
 by homiemail-a17.g.dreamhost.com (Postfix) with ESMTPA id 8BEB92B207D;
 Tue, 25 Apr 2017 13:58:29 -0700 (PDT)
From: Juri Linkov <juri@HIDDEN>
To: Tino Calancha <tino.calancha@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
Organization: LINKOV.NET
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
 <87vapwipy4.fsf@calancha-pc> <87shkyems1.fsf@localhost>
 <87pog112pp.fsf@calancha-pc>
Date: Tue, 25 Apr 2017 23:52:06 +0300
In-Reply-To: <87pog112pp.fsf@calancha-pc> (Tino Calancha's message of "Tue, 25
 Apr 2017 14:22:10 +0900")
Message-ID: <87mvb4yzux.fsf@localhost>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org, Dima Kogan <dima@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

> I updated the patch to make work `hi-lock-unface-buffer'.  I added test=
s
> as well.
>
> Note that in interactive calls the case fold is determined with the
> variables `search-upper-case' and `case-fold-search'.  This way it beha=
ves
> as `isearch-forward-regexp'.
> Before this bug case fold was determined _just_ with `case-fold-search'=
.
> Do you prefer avoid `search-upper-case' in this case?

Since =E2=80=98search-upper-case=E2=80=99 is used by other commands such =
as =E2=80=98occur=E2=80=99 and
=E2=80=98perform-replace=E2=80=99, I think =E2=80=98hi-lock=E2=80=99 shou=
ld use it as well.

>>From 7cad27c0fcc39add8679d0893010c4fdb3ed507a Mon Sep 17 00:00:00 2001
> From: Juri Linkov <juri@HIDDEN>
> Date: Tue, 25 Apr 2017 14:17:23 +0900
> Subject: [PATCH] highlight-regexp: Honor case-fold-search
> ...
> Co-authored-by: Tino Calancha <tino.calancha@HIDDEN>

I recommend to commit first my old patch, and then later your changes ove=
r it.

> -(defun hi-lock-face-buffer (regexp &optional face)
> +(defun hi-lock-face-buffer (regexp &optional face case-fold)
> ...
> +   (let* ((reg
> +           (hi-lock-regexp-okay
> +            (read-regexp "Regexp to highlight" 'regexp-history-last)))
> +          (face (hi-lock-read-face-name))
> +          (fold
> +           (if search-upper-case
> +               (isearch-no-upper-case-p reg t)
> +             case-fold-search)))
> +     (list reg face fold)))

Small thing, but for readability in the interactive spec better to use
the same variable names as argument names:

        (list regexp face case-fold)

> -(defun hi-lock-set-pattern (regexp face)
> -  "Highlight REGEXP with face FACE."
> +(defun hi-lock-set-pattern (regexp face &optional case-fold)
> +  "Highlight REGEXP with face FACE.
> +If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to =
it."
>    ;; Hashcons the regexp, so it can be passed to remove-overlays later=
.
>    (setq regexp (hi-lock--hashcons regexp))
> -  (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
> +  (let ((pattern (list (if (eq case-fold 'undefined)
> +                           regexp
> +                         (cons regexp
> +                               (byte-compile
> +                          `(lambda (limit)
> +                             (let ((case-fold-search ,case-fold))
> +                               (re-search-forward ,regexp limit t)))))=
)
> +                       (list 0 (list 'quote face) 'prepend))))

Do you need to remember also the value of =E2=80=98case-fold-search=E2=80=
=99
(together with =E2=80=98regexp=E2=80=99)?

> @@ -1950,7 +1950,12 @@ isearch-highlight-regexp
>  			      (regexp-quote s))))
>  			isearch-string ""))
>  		      (t (regexp-quote isearch-string)))))
> -    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
> +    (hi-lock-face-buffer regexp (hi-lock-read-face-name)
> +                         (if (and (eq isearch-case-fold-search t)
> +                                  search-upper-case)
> +                             (isearch-no-upper-case-p
> +                              isearch-string isearch-regexp)
> +                           isearch-case-fold-search)))
>    (and isearch-recursive-edit (exit-recursive-edit)))

If this works reliably, then we could remove that ugly hack
from =E2=80=98isearch-highlight-regexp=E2=80=99, I mean the one with the =
comment
=E2=80=9CTurn isearch-string into a case-insensitive regexp=E2=80=9D.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 25 Apr 2017 05:22:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 25 01:22:26 2017
Received: from localhost ([127.0.0.1]:38733 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1d2svi-0007kJ-03
	for submit <at> debbugs.gnu.org; Tue, 25 Apr 2017 01:22:26 -0400
Received: from mail-pg0-f52.google.com ([74.125.83.52]:33725)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tino.calancha@HIDDEN>) id 1d2svf-0007k3-NG
 for 22541 <at> debbugs.gnu.org; Tue, 25 Apr 2017 01:22:24 -0400
Received: by mail-pg0-f52.google.com with SMTP id 63so22821751pgh.0
 for <22541 <at> debbugs.gnu.org>; Mon, 24 Apr 2017 22:22:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:in-reply-to:references:user-agent:date
 :message-id:mime-version;
 bh=SI7xKN1V/mud17lXGX1iZ3qzKmY9h0URP63F43SK9Os=;
 b=BhmG2Ob9bQN97OUhuTvVSWBGo0GVDWzodNi48iduJO7T4pxtQc836qP9C0vusMPwtW
 H0JcRxDDYPmVFRFNEfXMkb4JAxVV7cAh8HE1koKVueV9Pvl+soWVUn5b4pV3IhVY/HSj
 GR3HEWJyL4/m0w7cLisHTBmB69R1TOuHFY8FZzVixusuqvrLll7pAhF/uuTcetSJiKYM
 JaPZ60qNq+qT2hNFY0AwyhVGQIfxzUviCcEz/A5juneIeOFotUUbJjXfqtDZX97qzB55
 apoPAU+sGcbS2V7/LrqmMn5NA1jCvTJx7dqpx9N6aQ/yzWdWWs1GyW6cCSywkEqEksJu
 ziTQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:in-reply-to:references
 :user-agent:date:message-id:mime-version;
 bh=SI7xKN1V/mud17lXGX1iZ3qzKmY9h0URP63F43SK9Os=;
 b=DuOlTZ7SniGQxtI2LfGankpXoAr2MboEuCn4T0xcte4/VbjpXB04cNtXFcO35buvn8
 QiSAXrwaBzI0uxcGkcHUBLKpqxoAeQOYu1IdCl/KH+WtWp1lmh26AeBgN2IcKiY86yl5
 cEn0AVxosFtyCc4xT2353CKx8EraW2saYDvdH5gVRTw8IEDvTdCtG/XsVGrPCcCOCuRK
 5m+2N+xeCxRmSY+zxKo/ZLVvaB9mAvlwksPphK14H+Ul5wWJ1wFynzTTo5BujHwtHLXi
 R8KgTCZz7QgKvtJE2RREkrZHcI6/WnQZooeMxqSuSC+rRTGtJ7rHjBhiUTqP2y4u3uJ0
 n4JQ==
X-Gm-Message-State: AN3rC/5MWFDQGWjDfl3gtIayr3cPI2wKrbJsD0RuSvgKtPB2h5NNAGCf
 Qo1BDzUwiPjcLw==
X-Received: by 10.99.157.138 with SMTP id i132mr27105663pgd.87.1493097736831; 
 Mon, 24 Apr 2017 22:22:16 -0700 (PDT)
Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222])
 by smtp.gmail.com with ESMTPSA id
 202sm33693380pgh.21.2017.04.24.22.22.13
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Mon, 24 Apr 2017 22:22:15 -0700 (PDT)
From: Tino Calancha <tino.calancha@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
In-Reply-To: <87shkyems1.fsf@localhost> (Juri Linkov's message of "Mon, 24 Apr
 2017 02:18:06 +0300")
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
 <87vapwipy4.fsf@calancha-pc> <87shkyems1.fsf@localhost>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)
Date: Tue, 25 Apr 2017 14:22:10 +0900
Message-ID: <87pog112pp.fsf@calancha-pc>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.5 (/)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org, Dima Kogan <dima@HIDDEN>,
 tino.calancha@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.5 (/)

Juri Linkov <juri@HIDDEN> writes:

>> I think is a good moment to comeback to this issue once we have already
>> released Emacs 25.2.
>> I have updated your patch so that hi-lock-face-buffer checks search-upper-case
>> in interactive calls.  It works OK.
>> Since there isn't recent activity in the implementation of the pcre-style
>> embedded modifiers, we might use your patch in the meantime.
>
> Thank you for taking care of this issue.  If in your tests it works
> as expected, then I suppose this is the way to go.

I updated the patch to make work `hi-lock-unface-buffer'.  I added tests
as well.

Note that in interactive calls the case fold is determined with the
variables `search-upper-case' and `case-fold-search'.  This way it behaves
as `isearch-forward-regexp'.
Before this bug case fold was determined _just_ with `case-fold-search'.
Do you prefer avoid `search-upper-case' in this case?

--8<-----------------------------cut here---------------start------------->8---
From 7cad27c0fcc39add8679d0893010c4fdb3ed507a Mon Sep 17 00:00:00 2001
From: Juri Linkov <juri@HIDDEN>
Date: Tue, 25 Apr 2017 14:17:23 +0900
Subject: [PATCH] highlight-regexp: Honor case-fold-search

Perform the matches of REGEXP as `isearch-forward' i.e., in interactive
calls determine the case fold with `search-upper-case' and
`case-fold-search' (Bug#22541).
* lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern):
Add optional arg CASE-FOLD.  All callers updated.
(hi-lock--regexps-at-point, hi-lock-unface-buffer):
Handle when pattern is a cons (REGEXP . FUNCTION).
* lisp/isearch.el (isearch-highlight-regexp): Call hi-lock-face-buffer
with 3 arguments.

Co-authored-by: Tino Calancha <tino.calancha@HIDDEN>
---
 lisp/hi-lock.el | 99 ++++++++++++++++++++++++++++++++++++++-------------------
 lisp/isearch.el |  7 +++-
 2 files changed, 73 insertions(+), 33 deletions(-)

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index ebd18621ef..c9e0428f01 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -432,8 +432,9 @@ hi-lock-line-face-buffer
 ;;;###autoload
 (defalias 'highlight-regexp 'hi-lock-face-buffer)
 ;;;###autoload
-(defun hi-lock-face-buffer (regexp &optional face)
+(defun hi-lock-face-buffer (regexp &optional face case-fold)
   "Set face of each match of REGEXP to FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
 
@@ -441,13 +442,18 @@ hi-lock-face-buffer
 use overlays for highlighting.  If overlays are used, the
 highlighting will not update as you type."
   (interactive
-   (list
-    (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight" 'regexp-history-last))
-    (hi-lock-read-face-name)))
+   (let* ((reg
+           (hi-lock-regexp-okay
+            (read-regexp "Regexp to highlight" 'regexp-history-last)))
+          (face (hi-lock-read-face-name))
+          (fold
+           (if search-upper-case
+               (isearch-no-upper-case-p reg t)
+             case-fold-search)))
+     (list reg face fold)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
-  (hi-lock-set-pattern regexp face))
+  (hi-lock-set-pattern regexp face case-fold))
 
 ;;;###autoload
 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
@@ -530,10 +536,17 @@ hi-lock--regexps-at-point
           ;; highlighted text at point.  Use this later in
           ;; during completing-read.
           (dolist (hi-lock-pattern hi-lock-interactive-patterns)
-            (let ((regexp (car hi-lock-pattern)))
-              (if (string-match regexp hi-text)
-                  (push regexp regexps)))))))
-    regexps))
+            (let ((regexp-or-fn (car hi-lock-pattern)))
+              (cond ((stringp regexp-or-fn)
+                     (when (string-match regexp-or-fn hi-text)
+                       (push regexp-or-fn regexps)))
+                    (t
+                     (with-temp-buffer
+                       (insert hi-text)
+                       (goto-char 1)
+                       (when (funcall regexp-or-fn nil)
+                         (push regexp-or-fn regexps)))))))
+    ))) regexps))
 
 (defvar-local hi-lock--unused-faces nil
   "List of faces that is not used and is available for highlighting new text.
@@ -561,13 +574,16 @@ hi-lock-unface-buffer
          (cons
           `keymap
           (cons "Select Pattern to Unhighlight"
-                (mapcar (lambda (pattern)
-                          (list (car pattern)
-                                (format
-                                 "%s (%s)" (car pattern)
-                                 (hi-lock-keyword->face pattern))
-                                (cons nil nil)
-                                (car pattern)))
+                 (mapcar (lambda (pattern)
+                           (let ((regexp (if (consp (car pattern))
+                                             (caar pattern)
+                                           (car pattern))))
+                             (list regexp
+                                   (format
+                                    "%s (%s)" regexp
+                                    (hi-lock-keyword->face pattern))
+                                   (cons nil nil)
+                                   regexp)))
                         hi-lock-interactive-patterns))))
         ;; If the user clicks outside the menu, meaning that they
         ;; change their mind, x-popup-menu returns nil, and
@@ -581,16 +597,24 @@ hi-lock-unface-buffer
        (error "No highlighting to remove"))
      ;; Infer the regexp to un-highlight based on cursor position.
      (let* ((defaults (or (hi-lock--regexps-at-point)
-                          (mapcar #'car hi-lock-interactive-patterns))))
+                          (mapcar (lambda (x)
+                                    (if (consp (car x)) (caar x) (car x)))
+                                    hi-lock-interactive-patterns))))
        (list
         (completing-read (if (null defaults)
                              "Regexp to unhighlight: "
                            (format "Regexp to unhighlight (default %s): "
                                    (car defaults)))
                          hi-lock-interactive-patterns
-			 nil t nil nil defaults))))))
-  (dolist (keyword (if (eq regexp t) hi-lock-interactive-patterns
-                     (list (assoc regexp hi-lock-interactive-patterns))))
+			 nil nil nil nil defaults))))))
+  (let ((keys
+         (mapcar (lambda (x)
+                   (if (consp (car x))
+                       (cons (caar x) (cdr x))
+                     x))
+                 hi-lock-interactive-patterns)))
+    (dolist (keyword (if (eq regexp t) keys
+                       (list (assoc regexp keys))))
     (when keyword
       (let ((face (hi-lock-keyword->face keyword)))
         ;; Make `face' the next one to use by default.
@@ -606,7 +630,7 @@ hi-lock-unface-buffer
             (delq keyword hi-lock-interactive-patterns))
       (remove-overlays
        nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons (car keyword)))
-      (font-lock-flush))))
+      (font-lock-flush)))))
 
 ;;;###autoload
 (defun hi-lock-write-interactive-patterns ()
@@ -689,15 +713,25 @@ hi-lock-read-face-name
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))
 
-(defun hi-lock-set-pattern (regexp face)
-  "Highlight REGEXP with face FACE."
+(defun hi-lock-set-pattern (regexp face &optional case-fold)
+  "Highlight REGEXP with face FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it."
   ;; Hashcons the regexp, so it can be passed to remove-overlays later.
   (setq regexp (hi-lock--hashcons regexp))
-  (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
+  (let ((pattern (list (if (eq case-fold 'undefined)
+                           regexp
+                         (cons regexp
+                               (byte-compile
+                          `(lambda (limit)
+                             (let ((case-fold-search ,case-fold))
+                               (re-search-forward ,regexp limit t))))))
+                       (list 0 (list 'quote face) 'prepend))))
     ;; Refuse to highlight a text that is already highlighted.
     (unless (assoc regexp hi-lock-interactive-patterns)
       (push pattern hi-lock-interactive-patterns)
-      (if (and font-lock-mode (font-lock-specified-p major-mode))
+      (if (and font-lock-mode
+               (font-lock-specified-p major-mode)
+               (not (consp pattern)))
 	  (progn
 	    (font-lock-add-keywords nil (list pattern) t)
 	    (font-lock-flush))
@@ -711,12 +745,13 @@ hi-lock-set-pattern
                      (+ range-max (max 0 (- (point-min) range-min))))))
           (save-excursion
             (goto-char search-start)
-            (while (re-search-forward regexp search-end t)
-              (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
-                (overlay-put overlay 'hi-lock-overlay t)
-                (overlay-put overlay 'hi-lock-overlay-regexp regexp)
-                (overlay-put overlay 'face face))
-              (goto-char (match-end 0)))))))))
+            (let ((case-fold-search case-fold))
+              (while (re-search-forward regexp search-end t)
+                (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
+                  (overlay-put overlay 'hi-lock-overlay t)
+                  (overlay-put overlay 'hi-lock-overlay-regexp regexp)
+                  (overlay-put overlay 'face face))
+                (goto-char (match-end 0))))))))))
 
 (defun hi-lock-set-file-patterns (patterns)
   "Replace file patterns list with PATTERNS and refontify."
diff --git a/lisp/isearch.el b/lisp/isearch.el
index c34739d638..250d37b45e 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1950,7 +1950,12 @@ isearch-highlight-regexp
 			      (regexp-quote s))))
 			isearch-string ""))
 		      (t (regexp-quote isearch-string)))))
-    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
+    (hi-lock-face-buffer regexp (hi-lock-read-face-name)
+                         (if (and (eq isearch-case-fold-search t)
+                                  search-upper-case)
+                             (isearch-no-upper-case-p
+                              isearch-string isearch-regexp)
+                           isearch-case-fold-search)))
   (and isearch-recursive-edit (exit-recursive-edit)))
 
 
-- 
2.11.0

From f0f68d2a2049b549a6690f411dd746cb4333f99b Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@HIDDEN>
Date: Tue, 25 Apr 2017 14:18:00 +0900
Subject: [PATCH] * test/lisp/hi-lock-tests.el: Add test.

---
 test/lisp/hi-lock-tests.el | 90 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
 create mode 100644 test/lisp/hi-lock-tests.el

diff --git a/test/lisp/hi-lock-tests.el b/test/lisp/hi-lock-tests.el
new file mode 100644
index 0000000000..836fbe9a89
--- /dev/null
+++ b/test/lisp/hi-lock-tests.el
@@ -0,0 +1,90 @@
+;;; hi-lock-tests.el --- Tests for hi-lock.el  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Tino Calancha <tino.calancha@HIDDEN>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'hi-lock)
+(eval-when-compile (require 'cl-lib))
+
+(defun hi-lock--count (face)
+  (let ((count 0))
+    (save-excursion
+      (goto-char (point-min))
+      (dolist (ov (car (overlay-lists)))
+        (let ((props (memq 'face (overlay-properties ov))))
+          (when (eq (cadr props) face)
+            (cl-incf count)))))
+    count))
+
+(defun hi-lock--highlight-and-count (regexp face case-fold)
+  "Highlight REGEXP with FACE with case fold CASE-FOLD.
+Return number of matches."
+       (hi-lock-unface-buffer t)
+       (should (eq 0 (hi-lock--count face)))
+       (hi-lock-face-buffer regexp face case-fold)
+       (hi-lock--count face))
+
+(defun hi-lock--interactive-test-1 (regexp face res ucase cfold)
+  (hi-lock-unface-buffer t)
+  (should (eq 0 (hi-lock--count face)))
+  (cl-letf (((symbol-function 'read-regexp)
+             (lambda (x y) (ignore x y) regexp))
+            ((symbol-function 'hi-lock-read-face-name)
+             (lambda () face)))
+    (setq search-upper-case ucase
+          case-fold-search cfold)
+    (call-interactively 'hi-lock-face-buffer)
+    (should (= res (hi-lock--count face)))))
+
+;; Interactive test should not depend on the major mode.
+(defun hi-lock--interactive-test (regexp face res ucase cfold)
+  (lisp-interaction-mode)
+  (hi-lock--interactive-test-1 regexp face res ucase cfold)
+  (fundamental-mode)
+  (hi-lock--interactive-test-1 regexp face res ucase cfold))
+
+;; In batch calls to `hi-lock-face-buffer', case is given by
+;; its third argument.  In interactive calls, case depends
+;; on `search-upper-case' and `case-fold-search'.
+(ert-deftest hi-lock-face-buffer-test ()
+  "Test for http://debbugs.gnu.org/22541 ."
+  (let ((face 'hi-yellow)
+        (regexp "a")
+        case-fold-search search-upper-case)
+    (with-temp-buffer
+      (insert "a A\n")
+      (should (= 1 (hi-lock--highlight-and-count regexp face nil)))
+      (should (= 2 (hi-lock--highlight-and-count regexp face t)))
+      ;; Case depends on the regexp.
+      (hi-lock--interactive-test regexp face 2 t nil)
+      (hi-lock--interactive-test "A" face 1 t nil)
+      (hi-lock--interactive-test "\\A" face 2 t nil)
+      ;; Case depends on `case-fold-search'.
+      (hi-lock--interactive-test "a" face 1 nil nil)
+      (hi-lock--interactive-test "A" face 1 nil nil)
+      (hi-lock--interactive-test "\\A" face 1 nil nil)
+      ;;
+      (hi-lock--interactive-test "a" face 2 nil t)
+      (hi-lock--interactive-test "A" face 2 nil t)
+      (hi-lock--interactive-test "\\A" face 2 nil t))))
+
+(provide 'hi-lock-tests)
+;;; hi-lock-tests.el ends here
-- 
2.11.0

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-04-25
Repository revision: 622c24a2b75a564b9861fc3ca7a7878741e8568d




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 23 Apr 2017 23:21:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 23 19:21:12 2017
Received: from localhost ([127.0.0.1]:36913 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1d2Qoa-0001uB-Le
	for submit <at> debbugs.gnu.org; Sun, 23 Apr 2017 19:21:12 -0400
Received: from sub3.mail.dreamhost.com ([69.163.253.7]:36885
 helo=homiemail-a100.g.dreamhost.com)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1d2QoZ-0001u0-62
 for 22541 <at> debbugs.gnu.org; Sun, 23 Apr 2017 19:21:11 -0400
Received: from homiemail-a100.g.dreamhost.com (localhost [127.0.0.1])
 by homiemail-a100.g.dreamhost.com (Postfix) with ESMTP id 21A2331A070;
 Sun, 23 Apr 2017 16:21:10 -0700 (PDT)
Received: from localhost.linkov.net (m83-179-141-227.cust.tele2.ee
 [83.179.141.227]) (Authenticated sender: jurta@HIDDEN)
 by homiemail-a100.g.dreamhost.com (Postfix) with ESMTPA id 0B9AA31A061;
 Sun, 23 Apr 2017 16:21:08 -0700 (PDT)
From: Juri Linkov <juri@HIDDEN>
To: Tino Calancha <tino.calancha@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
Organization: LINKOV.NET
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
 <87vapwipy4.fsf@calancha-pc>
Date: Mon, 24 Apr 2017 02:18:06 +0300
In-Reply-To: <87vapwipy4.fsf@calancha-pc> (Tino Calancha's message of "Sat, 22
 Apr 2017 21:31:31 +0900")
Message-ID: <87shkyems1.fsf@localhost>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.5 (/)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org, Dima Kogan <dima@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.5 (/)

> I think is a good moment to comeback to this issue once we have already
> released Emacs 25.2.
> I have updated your patch so that hi-lock-face-buffer checks search-upper-case
> in interactive calls.  It works OK.
> Since there isn't recent activity in the implementation of the pcre-style
> embedded modifiers, we might use your patch in the meantime.

Thank you for taking care of this issue.  If in your tests it works
as expected, then I suppose this is the way to go.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 22 Apr 2017 12:31:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Apr 22 08:31:46 2017
Received: from localhost ([127.0.0.1]:33259 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1d1uCY-0000XP-Jb
	for submit <at> debbugs.gnu.org; Sat, 22 Apr 2017 08:31:46 -0400
Received: from mail-io0-f179.google.com ([209.85.223.179]:35855)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tino.calancha@HIDDEN>) id 1d1uCW-0000X8-VF
 for 22541 <at> debbugs.gnu.org; Sat, 22 Apr 2017 08:31:45 -0400
Received: by mail-io0-f179.google.com with SMTP id p80so26249458iop.3
 for <22541 <at> debbugs.gnu.org>; Sat, 22 Apr 2017 05:31:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=WY9AMrc4movKFcsBaAu8f26SyGOwUiY9xTcahI40lsE=;
 b=NYwErRaK4errW8UH4xHKT3/4irlbAvnSmLTbPbgT7mn/2YXe7CvxZwi/BWqt/FyWwa
 QYGqldqPBEQUNhcYSP3oJRnw5pb6I41VkyCePrJMusFkGzMispyxJ7/TnSq/fX5uS/Ov
 DU3eCBykOBK4KonHCJcczqgflygsggOMnoUf4X/3tBOjRaJ6gPoulsgfAKFe5asizSlI
 Fy5GjXfOeTBcfjMblwqNdj7wefHsBIywRNVqCA3d7c20f5DJ4Grt2qaQEug4TkmJSQzl
 V/WDx01bjRzsJ9IHoevYw2m1f2s7ddxpc4uam4aq2XCCmOKOZPGhhOMTs+0bSJboPHtC
 fSZQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version;
 bh=WY9AMrc4movKFcsBaAu8f26SyGOwUiY9xTcahI40lsE=;
 b=BVX/Ul+o0wdXJ3KfU62LSSUoAJkMQkAIHa7vRO8gPFuen92hEsyi/oZnljXs/rzEAd
 DgqWvt7B9xBswD+FbBW2fhQQcFskxUuK2R9MXuRi1v7DvhGG1MU7Y7Rge78nv++8NsuW
 j87aSnhfqw6o5gVC+LVtGGa8ubvUp65rjYh5y3LZyGBmUmOXoCPTXSlkDajhmsrG/Nyl
 RDkhpSldgoUsG+/6H/Mb9bWcNwfiqP+XYfTMjS2TZO+yiTtwv3N6Lk2JZpHk7WFev/jG
 mInSKh++U8vYrfbcjzyjnrelvfFGTyVqAqRkwjNdS99cuuCRSOcUb1Dzoiu426x526j4
 oKoA==
X-Gm-Message-State: AN3rC/5A09vdUFzCVIsCJ0HA7meGSLpUXjVDIV7dd6li07MqXxSSBlOz
 7kthn3dCoGanxg==
X-Received: by 10.98.219.197 with SMTP id f188mr16656817pfg.109.1492864298096; 
 Sat, 22 Apr 2017 05:31:38 -0700 (PDT)
Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222])
 by smtp.gmail.com with ESMTPSA id
 c63sm21392767pfb.13.2017.04.22.05.31.34
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Sat, 22 Apr 2017 05:31:36 -0700 (PDT)
From: Tino Calancha <tino.calancha@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
Date: Sat, 22 Apr 2017 21:31:31 +0900
In-Reply-To: <8760x7vyui.fsf@HIDDEN> (Juri Linkov's message of "Tue, 
 01 Mar 2016 02:14:15 +0200")
Message-ID: <87vapwipy4.fsf@calancha-pc>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org, Dima Kogan <dima@HIDDEN>,
 tino.calancha@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

Juri Linkov <juri@HIDDEN> writes:

> The problem is that with introduction of char-folding, a hack responsible
> for case-folding in isearch-highlight-regexp that turns isearch-string
> into a case-insensitive regexp is not used anymore, i.e. it's overridden by
> isearch-regexp-function.  (Also note a FIXME comment in hi-lock-process-phrase)
>
> Since we can't change the value of font-lock-keywords-case-fold-search
> for font-lock based highlighting in hi-lock for individual regexps,
> the best solution is to rely on the feature allowing MATCHER in
> font-lock-keywords to be a function.  So we can let-bind case-fold-search
> in its lambda.
>
> Now the remaining problem is how to transfer case-fold from
> isearch-highlight-regexp down to hi-lock-set-pattern.
>
> Implementing pcre-style embedded modifiers is a good long-term goal,
> but we need to fix this for the next release.  What options do we have now?
> I see no other way than adding new argument to the chain of calls:

Hi Juri,

I think is a good moment to comeback to this issue once we have already
released Emacs 25.2.
I have updated your patch so that hi-lock-face-buffer checks search-upper-case
in interactive calls.  It works OK.
Since there isn't recent activity in the implementation of the pcre-style
embedded modifiers, we might use your patch in the meantime.

--8<-----------------------------cut here---------------start------------->8---
commit 7c3a515ec92f4bd9e82393dff1fcc4a3c2bb03b4
Author: Juri Linkov <juri@HIDDEN>
Date:   Sat Apr 22 21:11:41 2017 +0900

    highlight-regexp: Honor case-fold-search
    
    Perform the matches of REGEXP as `isearch-forward' (Bug#22541).
    * lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern):
    Add optional arg CASE-FOLD.  All callers updated.
    * lisp/isearch.el (isearch-highlight-regexp): Call hi-lock-face-buffer
    with 3 arguments.

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index ebd18621ef..845b52c6b6 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -432,8 +432,9 @@ hi-lock-line-face-buffer
 ;;;###autoload
 (defalias 'highlight-regexp 'hi-lock-face-buffer)
 ;;;###autoload
-(defun hi-lock-face-buffer (regexp &optional face)
+(defun hi-lock-face-buffer (regexp &optional face case-fold)
   "Set face of each match of REGEXP to FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
 
@@ -441,13 +442,18 @@ hi-lock-face-buffer
 use overlays for highlighting.  If overlays are used, the
 highlighting will not update as you type."
   (interactive
-   (list
-    (hi-lock-regexp-okay
-     (read-regexp "Regexp to highlight" 'regexp-history-last))
-    (hi-lock-read-face-name)))
+   (let* ((reg
+           (hi-lock-regexp-okay
+            (read-regexp "Regexp to highlight" 'regexp-history-last)))
+          (face (hi-lock-read-face-name))
+          (fold
+           (if search-upper-case
+               (isearch-no-upper-case-p reg t)
+             case-fold-search)))
+     (list reg face fold)))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
-  (hi-lock-set-pattern regexp face))
+  (hi-lock-set-pattern regexp face case-fold))
 
 ;;;###autoload
 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
@@ -689,11 +695,18 @@ hi-lock-read-face-name
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))
 
-(defun hi-lock-set-pattern (regexp face)
-  "Highlight REGEXP with face FACE."
+(defun hi-lock-set-pattern (regexp face &optional case-fold)
+  "Highlight REGEXP with face FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it."
   ;; Hashcons the regexp, so it can be passed to remove-overlays later.
   (setq regexp (hi-lock--hashcons regexp))
-  (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
+  (let ((pattern (list (if (eq case-fold 'undefined)
+                           regexp
+                         (byte-compile
+                          `(lambda (limit)
+                             (let ((case-fold-search ,case-fold))
+                               (re-search-forward ,regexp limit t)))))
+                       (list 0 (list 'quote face) 'prepend))))
     ;; Refuse to highlight a text that is already highlighted.
     (unless (assoc regexp hi-lock-interactive-patterns)
       (push pattern hi-lock-interactive-patterns)
@@ -711,12 +724,13 @@ hi-lock-set-pattern
                      (+ range-max (max 0 (- (point-min) range-min))))))
           (save-excursion
             (goto-char search-start)
-            (while (re-search-forward regexp search-end t)
-              (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
-                (overlay-put overlay 'hi-lock-overlay t)
-                (overlay-put overlay 'hi-lock-overlay-regexp regexp)
-                (overlay-put overlay 'face face))
-              (goto-char (match-end 0)))))))))
+            (let ((case-fold-search case-fold))
+              (while (re-search-forward regexp search-end t)
+                (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
+                  (overlay-put overlay 'hi-lock-overlay t)
+                  (overlay-put overlay 'hi-lock-overlay-regexp regexp)
+                  (overlay-put overlay 'face face))
+                (goto-char (match-end 0))))))))))
 
 (defun hi-lock-set-file-patterns (patterns)
   "Replace file patterns list with PATTERNS and refontify."
diff --git a/lisp/isearch.el b/lisp/isearch.el
index c34739d638..250d37b45e 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1950,7 +1950,12 @@ isearch-highlight-regexp
 			      (regexp-quote s))))
 			isearch-string ""))
 		      (t (regexp-quote isearch-string)))))
-    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
+    (hi-lock-face-buffer regexp (hi-lock-read-face-name)
+                         (if (and (eq isearch-case-fold-search t)
+                                  search-upper-case)
+                             (isearch-no-upper-case-p
+                              isearch-string isearch-regexp)
+                           isearch-case-fold-search)))
   (and isearch-recursive-edit (exit-recursive-edit)))
 
 
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-04-22
Repository revision: eb52828a439f674733ba70844b795c6673733572





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 30 Apr 2016 20:10:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Apr 30 16:10:43 2016
Received: from localhost ([127.0.0.1]:58521 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1awbDv-0003nx-2L
	for submit <at> debbugs.gnu.org; Sat, 30 Apr 2016 16:10:43 -0400
Received: from sub3.mail.dreamhost.com ([69.163.253.7]:37888
 helo=homiemail-a22.g.dreamhost.com)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1awbDu-0003no-5f
 for 22541 <at> debbugs.gnu.org; Sat, 30 Apr 2016 16:10:42 -0400
Received: from homiemail-a22.g.dreamhost.com (localhost [127.0.0.1])
 by homiemail-a22.g.dreamhost.com (Postfix) with ESMTP id 8F168114066;
 Sat, 30 Apr 2016 13:10:40 -0700 (PDT)
Received: from localhost.linkov.net (m83-191-208-165.cust.tele2.ee
 [83.191.208.165]) (Authenticated sender: jurta@HIDDEN)
 by homiemail-a22.g.dreamhost.com (Postfix) with ESMTPA id 7E744114065;
 Sat, 30 Apr 2016 13:10:39 -0700 (PDT)
From: Juri Linkov <juri@HIDDEN>
To: Dima Kogan <dima@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
Organization: LINKOV.NET
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
 <87zisfhcf4.fsf@HIDDEN>
Date: Sat, 30 Apr 2016 23:07:40 +0300
In-Reply-To: <87zisfhcf4.fsf@HIDDEN> (Dima Kogan's message of "Tue,
 26 Apr 2016 22:02:23 -0700")
Message-ID: <87bn4s8d7b.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.92 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

>>>> > Another possible side effect of this is that highlighting
>>>> >
>>>> >   Database directory:
>>>> >
>>>> > doesn't work: hi-lock goes through the motions but nothing ends up=
 being
>>>> > highlighted. Turning off char-folding fixes that.
>>>>
>>>> Actually =E2=80=9CDatabase directory:=E2=80=9D is not highlighted du=
e to case-folding.
>>>> After toggling case-folding with =E2=80=98M-s c=E2=80=99 and preserv=
ing the capital D,
>>>> it's highlighted correctly.
>>>>
>>>> ......
>>
>> The problem is that with introduction of char-folding, a hack responsi=
ble
>> for case-folding in isearch-highlight-regexp that turns isearch-string
>> into a case-insensitive regexp is not used anymore, i.e. it's overridd=
en by
>> isearch-regexp-function.  (Also note a FIXME comment in hi-lock-proces=
s-phrase)
>>
>> Since we can't change the value of font-lock-keywords-case-fold-search
>> for font-lock based highlighting in hi-lock for individual regexps,
>> the best solution is to rely on the feature allowing MATCHER in
>> font-lock-keywords to be a function.  So we can let-bind case-fold-sea=
rch
>> in its lambda.
>>
>> Now the remaining problem is how to transfer case-fold from
>> isearch-highlight-regexp down to hi-lock-set-pattern.
>
> Hi. Sorry it took me so long to reply to this. I haven't looked at
> isearch specifically in enough detail to comment on this, but if it
> makes this better, then I'm all for it :)

Fortunately, I'll have more time in May to help in fixing this.

>> Implementing pcre-style embedded modifiers is a good long-term goal,
>> but we need to fix this for the next release.  What options do we have=
 now?
>> I see no other way than adding new argument to the chain of calls:
>> ...
>
> I've been looking long-term, and emacs-devel now has a thread about an
> initial implementation of one of the embedded modifiers. Since char-fol=
d
> isn't the default anymore, maybe this issue isn't pressing and isn't
> critical to fix by emacs-25?

Better to release emacs-25 with less bugs :)




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 27 Apr 2016 05:02:28 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Apr 27 01:02:28 2016
Received: from localhost ([127.0.0.1]:49314 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1avHcK-0001Uc-5P
	for submit <at> debbugs.gnu.org; Wed, 27 Apr 2016 01:02:28 -0400
Received: from out2-smtp.messagingengine.com ([66.111.4.26]:44788)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dima@HIDDEN>) id 1avHcI-0001UU-Ay
 for 22541 <at> debbugs.gnu.org; Wed, 27 Apr 2016 01:02:26 -0400
Received: from compute5.internal (compute5.nyi.internal [10.202.2.45])
 by mailout.nyi.internal (Postfix) with ESMTP id E183220AA1
 for <22541 <at> debbugs.gnu.org>; Wed, 27 Apr 2016 01:02:25 -0400 (EDT)
Received: from frontend2 ([10.202.2.161])
 by compute5.internal (MEProxy); Wed, 27 Apr 2016 01:02:25 -0400
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=secretsauce.net;
 h=cc:content-transfer-encoding:content-type:date:from
 :in-reply-to:message-id:mime-version:references:subject:to
 :x-sasl-enc:x-sasl-enc; s=mesmtp; bh=ALnVnVbJV86Dm4ezxV98Lh8Vg3c
 =; b=JdHSrj5KAv2+ZwnXghMkpNKXDSAqoDQ//qQEudby/hm4bAcsVf7MTpJvLy1
 TMRyOc8GdelNB6rXmJx0y88PsDHsyXgo2r6gBYjWwsq4nb3OYudOu51cMO+/L1F4
 8bsUfctYcBQH6jXg5lzn447fJmfIKxHpT36UnpfRARZZS6xE=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-transfer-encoding:content-type
 :date:from:in-reply-to:message-id:mime-version:references
 :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=ALnVnVbJV86Dm4e
 zxV98Lh8Vg3c=; b=jM2oFsp0COGr+MQNTZLVr5p09RwzrQzwpT15J6eRkffKPik
 Ej2Ysk9lLkln2+PcxsV5+wLYVCoIdG6MFhikNteUkOcX7pKJgrHSkAN46Xt613Ah
 9M4L9AIuprC6oGQ4dLNozJPKn6sI1cct921IE64lRzvLIp2lpL97kFqunM7c=
X-Sasl-enc: 0ZCKG3W9tZpfXNdfxo0x3IPgjnHn+y6ODhn7jnEtAxrj 1461733345
Received: from shorty.local (50-1-153-216.dsl.dynamic.fusionbroadband.com
 [50.1.153.216])
 by mail.messagingengine.com (Postfix) with ESMTPA id 93BA56800F3;
 Wed, 27 Apr 2016 01:02:25 -0400 (EDT)
Received: from ip6-localhost ([::1] helo=shorty)
 by shorty.local with esmtp (Exim 4.84)
 (envelope-from <dima@HIDDEN>)
 id 1avHcF-0002Fx-6J; Tue, 26 Apr 2016 22:02:23 -0700
References: <87si1a2tod.fsf@HIDDEN> <8760x7vyui.fsf@HIDDEN>
User-agent: mu4e 0.9.17; emacs 25.0.92.1
From: Dima Kogan <dima@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
In-reply-to: <8760x7vyui.fsf@HIDDEN>
Date: Tue, 26 Apr 2016 22:02:23 -0700
Message-ID: <87zisfhcf4.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

Juri Linkov <juri@HIDDEN> writes:

>> This is an offshoot of #22520:
>>
>> Juri Linkov wrote:
>>
>>> > Another possible side effect of this is that highlighting
>>> >
>>> >   Database directory:
>>> >
>>> > doesn't work: hi-lock goes through the motions but nothing ends up being
>>> > highlighted. Turning off char-folding fixes that.
>>>
>>> Actually “Database directory:” is not highlighted due to case-folding.
>>> After toggling case-folding with ‘M-s c’ and preserving the capital D,
>>> it's highlighted correctly.
>>>
>>> ......
>
> The problem is that with introduction of char-folding, a hack responsible
> for case-folding in isearch-highlight-regexp that turns isearch-string
> into a case-insensitive regexp is not used anymore, i.e. it's overridden by
> isearch-regexp-function.  (Also note a FIXME comment in hi-lock-process-phrase)
>
> Since we can't change the value of font-lock-keywords-case-fold-search
> for font-lock based highlighting in hi-lock for individual regexps,
> the best solution is to rely on the feature allowing MATCHER in
> font-lock-keywords to be a function.  So we can let-bind case-fold-search
> in its lambda.
>
> Now the remaining problem is how to transfer case-fold from
> isearch-highlight-regexp down to hi-lock-set-pattern.

Hi. Sorry it took me so long to reply to this. I haven't looked at
isearch specifically in enough detail to comment on this, but if it
makes this better, then I'm all for it :)


> Implementing pcre-style embedded modifiers is a good long-term goal,
> but we need to fix this for the next release.  What options do we have now?
> I see no other way than adding new argument to the chain of calls:
> ...

I've been looking long-term, and emacs-devel now has a thread about an
initial implementation of one of the embedded modifiers. Since char-fold
isn't the default anymore, maybe this issue isn't pressing and isn't
critical to fix by emacs-25?

Thanks
dima




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.

Message received at 22541 <at> debbugs.gnu.org:


Received: (at 22541) by debbugs.gnu.org; 1 Mar 2016 00:21:44 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Feb 29 19:21:44 2016
Received: from localhost ([127.0.0.1]:54337 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1aaY4O-0006de-B0
	for submit <at> debbugs.gnu.org; Mon, 29 Feb 2016 19:21:44 -0500
Received: from sub3.mail.dreamhost.com ([69.163.253.7]:43997
 helo=homiemail-a22.g.dreamhost.com)
 by debbugs.gnu.org with esmtp (Exim 4.84)
 (envelope-from <juri@HIDDEN>) id 1aaY4L-0006dI-M2
 for 22541 <at> debbugs.gnu.org; Mon, 29 Feb 2016 19:21:42 -0500
Received: from homiemail-a22.g.dreamhost.com (localhost [127.0.0.1])
 by homiemail-a22.g.dreamhost.com (Postfix) with ESMTP id EB809114066;
 Mon, 29 Feb 2016 16:21:40 -0800 (PST)
Received: from localhost.linkov.net (62.65.219.72.cable.starman.ee
 [62.65.219.72]) (Authenticated sender: jurta@HIDDEN)
 by homiemail-a22.g.dreamhost.com (Postfix) with ESMTPA id 20E83114060;
 Mon, 29 Feb 2016 16:21:39 -0800 (PST)
From: Juri Linkov <juri@HIDDEN>
To: Dima Kogan <dima@HIDDEN>
Subject: Re: bug#22541: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
Organization: LINKOV.NET
References: <87si1a2tod.fsf@HIDDEN>
Date: Tue, 01 Mar 2016 02:14:15 +0200
In-Reply-To: <87si1a2tod.fsf@HIDDEN> (Dima Kogan's message of "Tue,
 02 Feb 2016 22:29:22 -0800")
Message-ID: <8760x7vyui.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 22541
Cc: 22541 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

> This is an offshoot of #22520:
>
> Juri Linkov wrote:
>
>> > Another possible side effect of this is that highlighting
>> >
>> >   Database directory:
>> >
>> > doesn't work: hi-lock goes through the motions but nothing ends up b=
eing
>> > highlighted. Turning off char-folding fixes that.
>>
>> Actually =E2=80=9CDatabase directory:=E2=80=9D is not highlighted due =
to case-folding.
>> After toggling case-folding with =E2=80=98M-s c=E2=80=99 and preservin=
g the capital D,
>> it's highlighted correctly.
>
> This is true! And it's really weird... The user expectation is that if
> we highlight something (M-s h r) directly from isearch, then at least
> the thing isearch was finding would be highlighted, and here this
> doesn't happen. So a slightly simpler example is:
>
> 0: Let the buffer have the string Ab
> 1: put the point on A
> 2: C-s
> 3: C-w (to isearch the whole thing)
> 4: M-s h r enter
>
> Then Ab isn't found because we defaulted to char-folding, and the regex=
 was
>
>   \(?:a[=CC=80-=CC=84=CC=86-=CC=8A=CC=8C=CC=8F=CC=91=CC=A3=CC=A5=CC=A8]=
\|[a=C2=AA=C3=A0-=C3=A5=C4=81=C4=83=C4=85=C7=8E=C8=81=C8=83=C8=A7=E1=B5=83=
=E1=B8=81=E1=BA=A1=E1=BA=A3=E2=82=90=E2=93=90=EF=BD=81=F0=9D=90=9A=F0=9D=91=
=8E=F0=9D=92=82=F0=9D=92=B6=F0=9D=93=AA=F0=9D=94=9E=F0=9D=95=92=F0=9D=96=86=
=F0=9D=96=BA=F0=9D=97=AE=F0=9D=98=A2=F0=9D=99=96=F0=9D=9A=8A]\)\(?:b[=CC=87=
=CC=A3=CC=B1]\|[b=E1=B5=87=E1=B8=83=E1=B8=85=E1=B8=87=E2=93=91=EF=BD=82=F0=
=9D=90=9B=F0=9D=91=8F=F0=9D=92=83=F0=9D=92=B7=F0=9D=93=AB=F0=9D=94=9F=F0=9D=
=95=93=F0=9D=96=87=F0=9D=96=BB=F0=9D=97=AF=F0=9D=98=A3=F0=9D=99=97=F0=9D=9A=
=8B]\)
>
> This clearly has no case-folding active on top of the char-folding. But
> the isearch had both, so the regex should get both. This would make the
> regex twice as long, but it would be right, at least.
>
> If we turn off char-folding (but leave case-folding alone; on) by addin=
g
> a step
>
> 2.5: M-s '
>
> then the regex we get is
>
>   [Aa][Bb]
>
> which clearly has the case-folding, and works the way we expect.

The problem is that with introduction of char-folding, a hack responsible
for case-folding in isearch-highlight-regexp that turns isearch-string
into a case-insensitive regexp is not used anymore, i.e. it's overridden =
by
isearch-regexp-function.  (Also note a FIXME comment in hi-lock-process-p=
hrase)

Since we can't change the value of font-lock-keywords-case-fold-search
for font-lock based highlighting in hi-lock for individual regexps,
the best solution is to rely on the feature allowing MATCHER in
font-lock-keywords to be a function.  So we can let-bind case-fold-search
in its lambda.

Now the remaining problem is how to transfer case-fold from
isearch-highlight-regexp down to hi-lock-set-pattern.

Implementing pcre-style embedded modifiers is a good long-term goal,
but we need to fix this for the next release.  What options do we have no=
w?
I see no other way than adding new argument to the chain of calls:

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 2efa4c7..f77ef19 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1906,7 +1906,12 @@ isearch-highlight-regexp
 			      (regexp-quote s))))
 			isearch-string ""))
 		      (t (regexp-quote isearch-string)))))
-    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
+    (hi-lock-face-buffer regexp (hi-lock-read-face-name)
+                         (if (and (eq isearch-case-fold-search t)
+                                  search-upper-case)
+                             (isearch-no-upper-case-p
+                              isearch-string isearch-regexp)
+                           isearch-case-fold-search)))
   (and isearch-recursive-edit (exit-recursive-edit)))
=20
 =0C
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index ec14e0b..27a2ae6 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -432,7 +432,7 @@ hi-lock-line-face-buffer
 ;;;###autoload
 (defalias 'highlight-regexp 'hi-lock-face-buffer)
 ;;;###autoload
-(defun hi-lock-face-buffer (regexp &optional face)
+(defun hi-lock-face-buffer (regexp &optional face case-fold)
   "Set face of each match of REGEXP to FACE.
 Interactively, prompt for REGEXP using `read-regexp', then FACE.
 Use the global history list for FACE.
@@ -444,10 +444,11 @@ hi-lock-face-buffer
    (list
     (hi-lock-regexp-okay
      (read-regexp "Regexp to highlight" 'regexp-history-last))
-    (hi-lock-read-face-name)))
+    (hi-lock-read-face-name)
+    case-fold-search))
   (or (facep face) (setq face 'hi-yellow))
   (unless hi-lock-mode (hi-lock-mode 1))
-  (hi-lock-set-pattern regexp face))
+  (hi-lock-set-pattern regexp face case-fold))
=20
 ;;;###autoload
 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
@@ -689,11 +690,17 @@ hi-lock-read-face-name
       (add-to-list 'hi-lock-face-defaults face t))
     (intern face)))
=20
-(defun hi-lock-set-pattern (regexp face)
+(defun hi-lock-set-pattern (regexp face &optional case-fold)
   "Highlight REGEXP with face FACE."
   ;; Hashcons the regexp, so it can be passed to remove-overlays later.
   (setq regexp (hi-lock--hashcons regexp))
-  (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
+  (let ((pattern (list (if (eq case-fold 'undefined)
+                           regexp
+                         (byte-compile
+                          `(lambda (limit)
+                             (let ((case-fold-search ,case-fold))
+                               (re-search-forward ,regexp limit t)))))
+                       (list 0 (list 'quote face) 'prepend))))
     ;; Refuse to highlight a text that is already highlighted.
     (unless (assoc regexp hi-lock-interactive-patterns)
       (push pattern hi-lock-interactive-patterns)
@@ -711,12 +718,13 @@ hi-lock-set-pattern
                      (+ range-max (max 0 (- (point-min) range-min))))))
           (save-excursion
             (goto-char search-start)
-            (while (re-search-forward regexp search-end t)
-              (let ((overlay (make-overlay (match-beginning 0) (match-en=
d 0))))
-                (overlay-put overlay 'hi-lock-overlay t)
-                (overlay-put overlay 'hi-lock-overlay-regexp regexp)
-                (overlay-put overlay 'face face))
-              (goto-char (match-end 0)))))))))
+            (let ((case-fold-search case-fold))
+              (while (re-search-forward regexp search-end t)
+                (let ((overlay (make-overlay (match-beginning 0) (match-=
end 0))))
+                  (overlay-put overlay 'hi-lock-overlay t)
+                  (overlay-put overlay 'hi-lock-overlay-regexp regexp)
+                  (overlay-put overlay 'face face))
+                (goto-char (match-end 0))))))))))
=20
 (defun hi-lock-set-file-patterns (patterns)
   "Replace file patterns list with PATTERNS and refontify."




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.
Changed bug title to '25.0.50; highlight-regexp from isearch is case-sensitive even if case-fold is active' from '25.0.50; highlight-regexp from isearch has is case-sensitive even if case-fold is active' Request was from Dima Kogan <dima@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 3 Feb 2016 06:29:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 03 01:29:54 2016
Received: from localhost ([127.0.0.1]:57362 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1aQqws-0004gH-It
	for submit <at> debbugs.gnu.org; Wed, 03 Feb 2016 01:29:54 -0500
Received: from eggs.gnu.org ([208.118.235.92]:50145)
 by debbugs.gnu.org with esmtp (Exim 4.84)
 (envelope-from <dima@HIDDEN>) id 1aQqwp-0004g4-Oz
 for submit <at> debbugs.gnu.org; Wed, 03 Feb 2016 01:29:52 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <dima@HIDDEN>) id 1aQqwj-00013q-Js
 for submit <at> debbugs.gnu.org; Wed, 03 Feb 2016 01:29:46 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_DKIM_INVALID
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:53489)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <dima@HIDDEN>) id 1aQqwj-00013m-GN
 for submit <at> debbugs.gnu.org; Wed, 03 Feb 2016 01:29:45 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41105)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <dima@HIDDEN>) id 1aQqwi-0003DP-LX
 for bug-gnu-emacs@HIDDEN; Wed, 03 Feb 2016 01:29:45 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <dima@HIDDEN>) id 1aQqwf-00013a-Fl
 for bug-gnu-emacs@HIDDEN; Wed, 03 Feb 2016 01:29:44 -0500
Received: from out1-smtp.messagingengine.com ([66.111.4.25]:39309)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <dima@HIDDEN>) id 1aQqwf-00013T-7E
 for bug-gnu-emacs@HIDDEN; Wed, 03 Feb 2016 01:29:41 -0500
Received: from compute2.internal (compute2.nyi.internal [10.202.2.42])
 by mailout.nyi.internal (Postfix) with ESMTP id A0B322098B
 for <bug-gnu-emacs@HIDDEN>; Wed,  3 Feb 2016 01:29:36 -0500 (EST)
Received: from frontend2 ([10.202.2.161])
 by compute2.internal (MEProxy); Wed, 03 Feb 2016 01:29:36 -0500
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=secretsauce.net;
 h=content-transfer-encoding:content-type:date:from:message-id
 :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=lDg
 X5oEQZENwsiKx3+o13CJnlR4=; b=MwkP+Qt1ZCvX68HE8dLQyuBEtiB9nbMxHIf
 6M7e5nIBmjvTqDH9vTVeGYT5Of9pdBUJsdGNApj6KCcTi8fy1oi/ahcv5kPxD1sj
 FE8OTxTS6Tl7QcUFE1RS8wbiBE3bB3WgBbYqBAAuxN9lQ2Jyvbx6hKRX+grm6Mdc
 Puj8zNZ4=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=
 messagingengine.com; h=content-transfer-encoding:content-type
 :date:from:message-id:mime-version:subject:to:x-sasl-enc
 :x-sasl-enc; s=smtpout; bh=lDgX5oEQZENwsiKx3+o13CJnlR4=; b=J1qxy
 zN9n+LOlnu4UNhzEFe1K9Uu/L18ZKtser9sZQ/LP/Y0qfaOBtHYyYbuJkfwtA3en
 E8AqF1Ion6HkY9XxM8SmZFln6ld1jH3hjvf5HOSiIyZxLNuNrH+3j9AxpaCEJV6y
 bQLUniv0CDMrwqBnDUVpK7GZq3WYzNpQYrfTHY=
X-Sasl-enc: Yh9k/Hf1cNRIJoeJuLeLlWSb64ZxGgMAsYu2pA/gKaIc 1454480975
Received: from shorty.local (174-28-85-47.albq.qwest.net [174.28.85.47])
 by mail.messagingengine.com (Postfix) with ESMTPA id 56E4968010A
 for <bug-gnu-emacs@HIDDEN>; Wed,  3 Feb 2016 01:29:35 -0500 (EST)
Received: from localhost ([::1] helo=shorty)
 by shorty.local with esmtp (Exim 4.84)
 (envelope-from <dima@HIDDEN>) id 1aQqwN-0007b4-TQ
 for bug-gnu-emacs@HIDDEN; Tue, 02 Feb 2016 22:29:23 -0800
From: Dima Kogan <dima@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 25.0.50;
 highlight-regexp from isearch has is case-sensitive even if case-fold
 is active
Date: Tue, 02 Feb 2016 22:29:22 -0800
Message-ID: <87si1a2tod.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

This is an offshoot of #22520:


Juri Linkov wrote:

> > Another possible side effect of this is that highlighting
> >
> >   Database directory:
> >
> > doesn't work: hi-lock goes through the motions but nothing ends up being
> > highlighted. Turning off char-folding fixes that.
>
> Actually =E2=80=9CDatabase directory:=E2=80=9D is not highlighted due to =
case-folding.
> After toggling case-folding with =E2=80=98M-s c=E2=80=99 and preserving t=
he capital D,
> it's highlighted correctly.

This is true! And it's really weird... The user expectation is that if
we highlight something (M-s h r) directly from isearch, then at least
the thing isearch was finding would be highlighted, and here this
doesn't happen. So a slightly simpler example is:

0: Let the buffer have the string Ab
1: put the point on A
2: C-s
3: C-w (to isearch the whole thing)
4: M-s h r enter

Then Ab isn't found because we defaulted to char-folding, and the regex was

  \(?:a[=CC=80-=CC=84=CC=86-=CC=8A=CC=8C=CC=8F=CC=91=CC=A3=CC=A5=CC=A8]\|[a=
=C2=AA=C3=A0-=C3=A5=C4=81=C4=83=C4=85=C7=8E=C8=81=C8=83=C8=A7=E1=B5=83=E1=
=B8=81=E1=BA=A1=E1=BA=A3=E2=82=90=E2=93=90=EF=BD=81=F0=9D=90=9A=F0=9D=91=8E=
=F0=9D=92=82=F0=9D=92=B6=F0=9D=93=AA=F0=9D=94=9E=F0=9D=95=92=F0=9D=96=86=F0=
=9D=96=BA=F0=9D=97=AE=F0=9D=98=A2=F0=9D=99=96=F0=9D=9A=8A]\)\(?:b[=CC=87=CC=
=A3=CC=B1]\|[b=E1=B5=87=E1=B8=83=E1=B8=85=E1=B8=87=E2=93=91=EF=BD=82=F0=9D=
=90=9B=F0=9D=91=8F=F0=9D=92=83=F0=9D=92=B7=F0=9D=93=AB=F0=9D=94=9F=F0=9D=95=
=93=F0=9D=96=87=F0=9D=96=BB=F0=9D=97=AF=F0=9D=98=A3=F0=9D=99=97=F0=9D=9A=8B=
]\)

This clearly has no case-folding active on top of the char-folding. But
the isearch had both, so the regex should get both. This would make the
regex twice as long, but it would be right, at least.

If we turn off char-folding (but leave case-folding alone; on) by adding
a step

2.5: M-s '

then the regex we get is

  [Aa][Bb]

which clearly has the case-folding, and works the way we expect.




Acknowledgement sent to Dima Kogan <dima@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#22541; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 25 May 2017 12:15:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.