GNU bug report logs - #53126
29.0.50; [PATCH] Lazy highlight/count when reading query-replace string, etc.

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: Augusto Stoffel <arstoffel@HIDDEN>; Keywords: patch; merged with #53341; dated Sat, 8 Jan 2022 13:25:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Forcibly Merged 53126 53341. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

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


Received: (at 53126) by debbugs.gnu.org; 10 Jan 2022 19:11:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 10 14:11:23 2022
Received: from localhost ([127.0.0.1]:53318 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n704h-0006wO-6x
	for submit <at> debbugs.gnu.org; Mon, 10 Jan 2022 14:11:23 -0500
Received: from relay9-d.mail.gandi.net ([217.70.183.199]:40987)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n704f-0006w9-0x
 for 53126 <at> debbugs.gnu.org; Mon, 10 Jan 2022 14:11:22 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 98B38FF803;
 Mon, 10 Jan 2022 19:11:12 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Augusto Stoffel <arstoffel@HIDDEN>
Subject: Re: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading
 query-replace string, etc.
Organization: LINKOV.NET
References: <87sftyweb2.fsf@HIDDEN> <861r1iyrvw.fsf@HIDDEN>
 <87zgo6owaf.fsf@HIDDEN> <86k0f9xnrn.fsf@HIDDEN>
 <87tuedp6pl.fsf@HIDDEN> <861r1g7n3b.fsf@HIDDEN>
 <87o84jcx5x.fsf@HIDDEN>
Date: Mon, 10 Jan 2022 21:09:40 +0200
In-Reply-To: <87o84jcx5x.fsf@HIDDEN> (Augusto Stoffel's message of "Mon, 10
 Jan 2022 18:34:18 +0100")
Message-ID: <8635lvif0r.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 53126
Cc: 53126 <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: -1.7 (-)

> I attached a new patch (still a sketch) that requires no changes in
> comint.el and simple.el.  Perhaps you will find this approach more
> acceptable.

Thanks, no changes in other files is certainly a big plus.

>> It would be great to use your new variable with a function
>> to show replacement counts in perform-replace.  IIUC,
>> let-binding isearch-lazy-count-display-function to
>> isearch-read-with-highlight-count will suppress isearch-message?
>
> I tried this and it's relatively simple to do, but there is a problem.
> Suppose you want to replace all "a" with "z", and your buffer has 20
> "a"s initially.  Then, as you keep hitting "y" to confirm a replacement
> the count will be
>
>    1/20, 1/19, ..., 1/1

This is an interesting question.  I tried in other editors,
and e.g. in the editor xed that is installed by default,
this is exactly what is displayed: 1/20, 1/19, ..., 1/1.

> since the number of "a"s decrease, and the point is always at the first
> of the still-existing ones.  But probably one should count the number of
> prompts, so
>
>    1/20, 2/20, ..., 20/20
>
> I think this means `perform-replace' has to implement its own way to
> display a count.

Maybe this makes more sense, when the users will learn
what do these numbers mean.

>> I meant using simply
>>
>>   (add-hook 'minibuffer-setup-hook 'isearch-read-with-highlight-setup)
>>
>> But it seems isearch-read-with-highlight-setup doesn't set
>> isearch-lazy-count-display-function.
>
> I guess this could be done.

Maybe two separate hooks could be defined?  One highlights like
lazy-highlight, and another counts like lazy-count does:

  (add-hook 'minibuffer-setup-hook 'isearch-read-with-highlight-setup)
  (add-hook 'minibuffer-setup-hook 'isearch-read-with-count-setup)

> But note that there are two possible types
> of counts: a "current/total" counter or just a "total" counter.  Each
> use case calls for a different count style.

The format of the total counter needs to be defined in a separate variable.

> By the way, I'm debating a bit whether
> `isearch-lazy-count-display-function' should be:
>
> 1. Either nil or function, as it is right now,
> 2. #'ignore by default, so similar to 1) but a bit easier to use with
>    `add-function'
> 3. a hook, the main inconvenience being that it can't be easily let-bound.

This can be answered only by testing with all possible cases ;-)




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

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


Received: (at 53126) by debbugs.gnu.org; 10 Jan 2022 17:34:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 10 12:34:32 2022
Received: from localhost ([127.0.0.1]:53235 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6yYx-0004O4-LX
	for submit <at> debbugs.gnu.org; Mon, 10 Jan 2022 12:34:32 -0500
Received: from mail-wr1-f42.google.com ([209.85.221.42]:37665)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <arstoffel@HIDDEN>) id 1n6yYt-0004Nj-54
 for 53126 <at> debbugs.gnu.org; Mon, 10 Jan 2022 12:34:30 -0500
Received: by mail-wr1-f42.google.com with SMTP id t28so21418912wrb.4
 for <53126 <at> debbugs.gnu.org>; Mon, 10 Jan 2022 09:34:27 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=pKlFXI4hqbg5bUzdL9GYEL60wd8IM9vJU2PTZzc6Rrs=;
 b=f5aDXswxJy5RT1FyZL5Y9TKwKBs7VIQTU2tc7WEkgMjTkRYPA26bqZxke4d9fBYefP
 gyLUT9T5TELLj9h8N/jtmMgsqwdG6wG78sroBY7Z5DlDM1JUl2Sl19jb0qinghUPYtmq
 WJ3VYLumHYAAfTp/cQZuy7rBLKxLuxdMnI14/8eMY6DyapjXiDkAcEjnqbX/qhXywgt/
 /Hh3L8j6/K98bBaGZhk4pfkTwW04LpOMW3vmhdrXOufOsWxc42cepRh3AZO8nEgJFmHR
 46YSgiEUbPNr1mP7f5a+osKyIH/ZULCUqzMvUma+QGYQhG2oFj2SArQM9Ks8F0mKU9DU
 n53A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version;
 bh=pKlFXI4hqbg5bUzdL9GYEL60wd8IM9vJU2PTZzc6Rrs=;
 b=KiDJIxjwTUuuKmAtmfI7aYVhnzI3pKfx+hHoI0NeMFf8FfFO0fbxA8HaCYLr0aioUc
 6w3dZxp8YubG6t3QBYLalmc+adtOBt0Wv67keaijwwum7zETN7+PQl5eW+L5HHZow3+M
 IoXrZpDx2CofWudWkd/+u2SSL8jWAZJ9AjeiF6mf53H0FBS3INxB7xXGSZQVGlAKyFQj
 EhDaLoII78ghi8lik8PXXRUqdnZBa3IM7+x6MXJr1dI9Bhy561n4RSXi5r07Cs4uT/P/
 3aTDIA+G9vLBg2Rn6U/A+mihu1cH9IWmhUJeLmBZpN5dBK2hIFzjthGIlfxbBtuaMkA7
 0Vmw==
X-Gm-Message-State: AOAM532EzN+C/SuxRsVvEKjjToMMuAVDIX8WLVsc1eEXtE61qkwXccZb
 lOsYBfnjxSFByFAw21dusSF9tf2c1gQ=
X-Google-Smtp-Source: ABdhPJy1ZLRKpsF1pBvJE9ACrwl1sjUBu4muypnSj12jEsMMTx8HfqZkbmtc2FHA/ks9N2pyTJEpJA==
X-Received: by 2002:adf:d226:: with SMTP id k6mr530173wrh.243.1641836061002;
 Mon, 10 Jan 2022 09:34:21 -0800 (PST)
Received: from ars3 ([2a02:8109:8ac0:56d0::23a0])
 by smtp.gmail.com with ESMTPSA id l6sm9933140wry.18.2022.01.10.09.34.19
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 10 Jan 2022 09:34:20 -0800 (PST)
From: Augusto Stoffel <arstoffel@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading
 query-replace string, etc.
References: <87sftyweb2.fsf@HIDDEN> <861r1iyrvw.fsf@HIDDEN>
 <87zgo6owaf.fsf@HIDDEN> <86k0f9xnrn.fsf@HIDDEN>
 <87tuedp6pl.fsf@HIDDEN> <861r1g7n3b.fsf@HIDDEN>
Date: Mon, 10 Jan 2022 18:34:18 +0100
In-Reply-To: <861r1g7n3b.fsf@HIDDEN> (Juri Linkov's message of "Sun, 
 09 Jan 2022 20:58:32 +0200")
Message-ID: <87o84jcx5x.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 53126
Cc: 53126 <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: -1.0 (-)

--=-=-=
Content-Type: text/plain


Hi Juri,

I attached a new patch (still a sketch) that requires no changes in
comint.el and simple.el.  Perhaps you will find this approach more
acceptable.

More comments below.

On Sun,  9 Jan 2022 at 20:58, Juri Linkov <juri@HIDDEN> wrote:

> It would be great to use your new variable with a function
> to show replacement counts in perform-replace.  IIUC,
> let-binding isearch-lazy-count-display-function to
> isearch-read-with-highlight-count will suppress isearch-message?
>

I tried this and it's relatively simple to do, but there is a problem.
Suppose you want to replace all "a" with "z", and your buffer has 20
"a"s initially.  Then, as you keep hitting "y" to confirm a replacement
the count will be

   1/20, 1/19, ..., 1/1

since the number of "a"s decrease, and the point is always at the first
of the still-existing ones.  But probably one should count the number of
prompts, so

   1/20, 2/20, ..., 20/20

I think this means `perform-replace' has to implement its own way to
display a count.

> I meant using simply
>
>   (add-hook 'minibuffer-setup-hook 'isearch-read-with-highlight-setup)
>
> But it seems isearch-read-with-highlight-setup doesn't set
> isearch-lazy-count-display-function.
>

I guess this could be done.  But note that there are two possible types
of counts: a "current/total" counter or just a "total" counter.  Each
use case calls for a different count style.

>>> Then maybe a new feature could be named e.g. "lazy-minibuffer"?
>
> This feature has little to do with isearch.  This is why there are
> efforts to move away from the prefix isearch- for lazy-related
> functions and variables, so we have now:
>
>   lazy-count-prefix-format
>   lazy-count-suffix-format
>   lazy-highlight-buffer
>   lazy-highlight-buffer-max-at-a-time
>   lazy-highlight-cleanup
>   lazy-highlight-initial-delay
>   lazy-highlight-interval
>   lazy-highlight-max-at-a-time
>   ...
>
> There are still isearch-specific names like isearch-lazy-count
> that enables lazy-count in isearch-mode.  What would be a similar
> name for the minibuffer?  Maybe minibuffer-lazy-count?

I see, the lazy-* names are the new ones!

>
> Then the prefix isearch- needs to be removed from other names too,
> e.g. isearch-lazy-count-display-function -> lazy-count-display-function
> isearch-read-with-highlight-setup maybe to minibuffer-lazy-highlight-setup,
> etc.

Yes, I agree.  The names I came up with are horrible and
`lazy-minibuffer' is weird, but your current suggestion is nice.

By the way, I'm debating a bit whether
`isearch-lazy-count-display-function' should be:

1. Either nil or function, as it is right now,
2. #'ignore by default, so similar to 1) but a bit easier to use with
   `add-function'
3. a hook, the main inconvenience being that it can't be easily let-bound.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-Allow-reading-from-minibuffer-with-lazy-highlight-an.patch

From 471c37844f0baba925bd948e13005d2227d43f65 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@HIDDEN>
Date: Sat, 8 Jan 2022 11:08:46 +0100
Subject: [PATCH 1/2] Allow reading from minibuffer with lazy highlight and
 match count

* lisp/isearch.el (isearch-lazy-count-display-function): New variable
allowing to display the lazy count in special ways.
(isearch-edit-string): Add lazy highlight and count of matching text.
(isearch-lazy-highlight-new-loop,
isearch-lazy-highlight-buffer-update): Use
`isearch-lazy-count-display-function' instead of hardcoded call to
`isearch-message'.
(isearch-read-with-highlight--overlay,
isearch-read-with-highlight--after-change,
isearch-read-with-highlight--exit, isearch-read-with-highlight-setup,
isearch-read-with-highlight-count): Variable and functions
implementing the lazy highlight functionality while reading from
minibuffer.
* lisp/simple.el (minibuffer-history-isearch-setup): Set
`isearch-lazy-count-display-function' appropriately.
* lisp/comint.el (comint-history-isearch-setup,
comint-history-isearch-end): Set `isearch-lazy-count-display-function'
appropriately.
---
 lisp/isearch.el | 100 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 82 insertions(+), 18 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 7593a0ec98..c10f365ee5 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -465,6 +465,9 @@ lazy-count-suffix-format
   :group 'lazy-count
   :version "27.1")
 
+(defvar isearch-lazy-count-display-function nil
+  "Function called when new lazy count results are available.")
+
 
 ;; Define isearch help map.
 
@@ -1808,19 +1811,21 @@ isearch-edit-string
 	  ;; for some incompatibility with gmhist.
 	  (minibuffer-history-symbol)
 	  ;; Search string might have meta information on text properties.
-	  (minibuffer-allow-text-properties t))
+	  (minibuffer-allow-text-properties t)
+          (isearch-lazy-count-display-function #'isearch-read-with-highlight-count))
      (setq isearch-new-string
-	   (read-from-minibuffer
-	    (isearch-message-prefix nil isearch-nonincremental)
-	    (cons isearch-string (1+ (or (isearch-fail-pos)
-					 (length isearch-string))))
-	    minibuffer-local-isearch-map nil
-	    (if isearch-regexp
-		(cons 'regexp-search-ring
-		      (1+ (or regexp-search-ring-yank-pointer -1)))
-	      (cons 'search-ring
-		    (1+ (or search-ring-yank-pointer -1))))
-	    nil t)
+	   (minibuffer-with-setup-hook #'isearch-read-with-highlight-setup
+             (read-from-minibuffer
+	      (isearch-message-prefix nil isearch-nonincremental)
+	      (cons isearch-string (1+ (or (isearch-fail-pos)
+					   (length isearch-string))))
+	      minibuffer-local-isearch-map nil
+	      (if isearch-regexp
+		  (cons 'regexp-search-ring
+		        (1+ (or regexp-search-ring-yank-pointer -1)))
+	        (cons 'search-ring
+		      (1+ (or search-ring-yank-pointer -1))))
+	      nil t))
 	   isearch-new-message
 	   (mapconcat 'isearch-text-char-description
 		      isearch-new-string "")))))
@@ -4023,7 +4028,7 @@ isearch-lazy-highlight-new-loop
 			         isearch-lazy-highlight-window-end))))))
     ;; something important did indeed change
     (lazy-highlight-cleanup t (not (equal isearch-string ""))) ;stop old timer
-    (when (and isearch-lazy-count isearch-mode (null isearch-message-function))
+    (when isearch-lazy-count
       (when (or (equal isearch-string "")
                 ;; Check if this place was reached by a condition above
                 ;; other than changed window boundaries (that shouldn't
@@ -4042,7 +4047,11 @@ isearch-lazy-highlight-new-loop
         (setq isearch-lazy-count-current nil
               isearch-lazy-count-total nil)
         ;; Delay updating the message if possible, to avoid flicker
-        (when (string-equal isearch-string "") (isearch-message))))
+        (when (string-equal isearch-string "")
+          (when (and isearch-mode (null isearch-message-function))
+            (isearch-message))
+          (when isearch-lazy-count-display-function
+            (funcall isearch-lazy-count-display-function)))))
     (setq isearch-lazy-highlight-window-start-changed nil)
     (setq isearch-lazy-highlight-window-end-changed nil)
     (setq isearch-lazy-highlight-error isearch-error)
@@ -4095,13 +4104,16 @@ isearch-lazy-highlight-new-loop
                                  'isearch-lazy-highlight-start))))
   ;; Update the current match number only in isearch-mode and
   ;; unless isearch-mode is used specially with isearch-message-function
-  (when (and isearch-lazy-count isearch-mode (null isearch-message-function))
+  (when isearch-lazy-count
     ;; Update isearch-lazy-count-current only when it was already set
     ;; at the end of isearch-lazy-highlight-buffer-update
     (when isearch-lazy-count-current
       (setq isearch-lazy-count-current
             (gethash (point) isearch-lazy-count-hash 0))
-      (isearch-message))))
+      (when (and isearch-mode (null isearch-message-function))
+        (isearch-message))
+      (when isearch-lazy-count-display-function
+        (funcall isearch-lazy-count-display-function)))))
 
 (defun isearch-lazy-highlight-search (string bound)
   "Search ahead for the next or previous match, for lazy highlighting.
@@ -4302,16 +4314,68 @@ isearch-lazy-highlight-buffer-update
 		    (setq looping nil
 			  nomore  t))))
 	    (if nomore
-		(when (and isearch-lazy-count isearch-mode (null isearch-message-function))
+		(when isearch-lazy-count
 		  (unless isearch-lazy-count-total
 		    (setq isearch-lazy-count-total 0))
 		  (setq isearch-lazy-count-current
 			(gethash opoint isearch-lazy-count-hash 0))
-		  (isearch-message))
+                  (when (and isearch-mode (null isearch-message-function))
+                    (isearch-message))
+		  (when isearch-lazy-count-display-function
+                    (funcall isearch-lazy-count-display-function)))
 	      (setq isearch-lazy-highlight-timer
 		    (run-at-time lazy-highlight-interval nil
 				 'isearch-lazy-highlight-buffer-update)))))))))
 
+;; Reading from minibuffer with lazy highlight and match count
+
+(defvar isearch-read-with-highlight--overlay nil
+  "Overlay for minibuffer prompt updates.")
+
+(defvar isearch-read-with-highlight-transform #'identity
+  "Function to transform minibuffer text into a `isearch-string' for highlighting.")
+
+(defun isearch-read-with-highlight--after-change (_beg _end _len)
+  "Update lazy highlight state in minibuffer selected window."
+  (when isearch-lazy-highlight
+    (let ((inhibit-redisplay t) ;; Avoid cursor flickering
+          (string (minibuffer-contents)))
+      (with-minibuffer-selected-window
+        (setq isearch-string (funcall isearch-read-with-highlight-transform string))
+        (isearch-lazy-highlight-new-loop)))))
+
+(defun isearch-read-with-highlight--exit ()
+  "Unwind changes from `isearch-read-with-highlight-setup'."
+  (remove-hook 'after-change-functions
+               #'isearch-read-with-highlight--after-change)
+  (remove-hook 'minibuffer-exit-hook #'isearch-read-with-highlight--exit)
+  (setq isearch-read-with-highlight--overlay nil)
+  (lazy-highlight-cleanup))
+
+(defun isearch-read-with-highlight-setup ()
+  "Set up minibuffer for lazy highlight of matches in the original window.
+
+This is intended to be called via `minibuffer-with-setup-hook'.
+Note that several other isearch variables influence the lazy
+highlighting, including `isearch-regexp' and
+`isearch-lazy-count-display-function'."
+  (add-hook 'after-change-functions
+            #'isearch-read-with-highlight--after-change)
+  (add-hook 'minibuffer-exit-hook #'isearch-read-with-highlight--exit)
+  (setq isearch-read-with-highlight--overlay
+        (make-overlay (point-min) (point-min) (current-buffer) t t))
+  (isearch-read-with-highlight--after-change nil nil nil))
+
+(defun isearch-read-with-highlight-count ()
+  "Display total match count in the minibuffer prompt."
+  (when isearch-read-with-highlight--overlay
+    (overlay-put isearch-read-with-highlight--overlay
+                 'before-string
+                 (and isearch-lazy-count-total
+                      (not isearch-error)
+                      (format "%s " isearch-lazy-count-total)))))
+
+
 (defun isearch-resume (string regexp word forward message case-fold)
   "Resume an incremental search.
 STRING is the string or regexp searched for.
-- 
2.34.1


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0002-Lazy-highlight-when-reading-query-replace-text.patch

From 8a24c1cc976e003494c3526304a02de8f37b5896 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@HIDDEN>
Date: Sat, 8 Jan 2022 13:15:40 +0100
Subject: [PATCH 2/2] Lazy highlight when reading query-replace text

* lisp/replace.el (query-replace-read-from): Add lazy highlighting.
---
 lisp/replace.el | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lisp/replace.el b/lisp/replace.el
index 60e507c642..31478ee4a9 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -244,6 +244,19 @@ query-replace-read-from
                                    (query-replace-descr
                                     (cdar query-replace-defaults)))))
                   (t (format-prompt prompt nil))))
+           ;; Set up lazy highlighting while reading FROM regexp.
+           ;; TODO: Treat the `region-noncontiguous-p' case by setting
+           ;; `isearch-filter-predicate'.
+           (isearch-lazy-highlight query-replace-highlight)
+           (isearch-regexp regexp-flag)
+           (isearch-regexp-function nil)
+           (isearch-case-fold-search case-fold-search) ;; TODO: the case-folding rule here is complicated...
+           (isearch-read-with-highlight-transform
+            (lambda (string)
+              (let ((from (query-replace--split-string string)))
+                (if (consp from) (car from) from))))
+           (isearch-lazy-count-display-function
+            #'isearch-read-with-highlight-count)
 	   (from
 	    ;; The save-excursion here is in case the user marks and copies
 	    ;; a region in order to specify the minibuffer input.
@@ -251,6 +264,7 @@ query-replace-read-from
 	    (save-excursion
               (minibuffer-with-setup-hook
                   (lambda ()
+                    (isearch-read-with-highlight-setup)
                     (setq-local text-property-default-nonsticky
                                 (append '((separator . t) (face . t))
                                         text-property-default-nonsticky)))
-- 
2.34.1


--=-=-=--




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

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


Received: (at 53126) by debbugs.gnu.org; 9 Jan 2022 19:04:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jan 09 14:04:24 2022
Received: from localhost ([127.0.0.1]:51270 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6dUJ-0007ZS-Jx
	for submit <at> debbugs.gnu.org; Sun, 09 Jan 2022 14:04:24 -0500
Received: from relay12.mail.gandi.net ([217.70.178.232]:47495)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n6dUD-0007Z8-O6
 for 53126 <at> debbugs.gnu.org; Sun, 09 Jan 2022 14:04:18 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay12.mail.gandi.net (Postfix) with ESMTPSA id 63FEC20000A;
 Sun,  9 Jan 2022 19:04:05 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Augusto Stoffel <arstoffel@HIDDEN>
Subject: Re: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading
 query-replace string, etc.
Organization: LINKOV.NET
References: <87sftyweb2.fsf@HIDDEN> <861r1iyrvw.fsf@HIDDEN>
 <87zgo6owaf.fsf@HIDDEN> <86k0f9xnrn.fsf@HIDDEN>
 <87tuedp6pl.fsf@HIDDEN>
Date: Sun, 09 Jan 2022 20:58:32 +0200
In-Reply-To: <87tuedp6pl.fsf@HIDDEN> (Augusto Stoffel's message of "Sun, 09
 Jan 2022 11:02:46 +0100")
Message-ID: <861r1g7n3b.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 53126
Cc: 53126 <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: -1.7 (-)

>> Or for asynchronous lazy-count a new hook needs to be run at the end
>> of isearch-lazy-highlight-buffer-update in addition to the call of
>> isearch-message.
>
> That's what the patch does (but with a variable pointing to a function
> instead of a hook, although this can be changed).  But note that it's
> not enough to do something “in addition to the call of isearch-message”;
> it's necessary to _suppress_ the call to isearch-message.

It would be great to use your new variable with a function
to show replacement counts in perform-replace.  IIUC,
let-binding isearch-lazy-count-display-function to
isearch-read-with-highlight-count will suppress isearch-message?

>> Maybe then this feature could be added to read-regexp or even
>> to read-from-minibuffer?  And activated by adding a setup function
>> to minibuffer-setup-hook like other minibuffer's features do, such as
>> icomplete-minibuffer-setup, minibuffer-depth-setup, rfn-eshadow-setup-minibuffer.
>
> This is what the patch does, with code of this kind:
>
> ```
> (let ((isearch-regexp t)
>       ;; Whatever else isearch / lazy-highlight settings might be needed
>       (isearch-lazy-count-display-function #'isearch-read-with-highlight-count))
>   (minibuffer-with-setup-hook #'isearch-read-with-highlight-setup
>     (read-from-minibuffer "Type a regexp with preview: ")))
> ```
>
> There could be a convenience wrapper for this code, but I'm not sure
> that makes much sense, because isearch and lazy-highlight have too many
> parameters one might need to set so it's better to be explicit/flexible.

I meant using simply

  (add-hook 'minibuffer-setup-hook 'isearch-read-with-highlight-setup)

But it seems isearch-read-with-highlight-setup doesn't set
isearch-lazy-count-display-function.

>> Then maybe a new feature could be named e.g. "lazy-minibuffer"?

This feature has little to do with isearch.  This is why there are
efforts to move away from the prefix isearch- for lazy-related
functions and variables, so we have now:

  lazy-count-prefix-format
  lazy-count-suffix-format
  lazy-highlight-buffer
  lazy-highlight-buffer-max-at-a-time
  lazy-highlight-cleanup
  lazy-highlight-initial-delay
  lazy-highlight-interval
  lazy-highlight-max-at-a-time
  ...

There are still isearch-specific names like isearch-lazy-count
that enables lazy-count in isearch-mode.  What would be a similar
name for the minibuffer?  Maybe minibuffer-lazy-count?

Then the prefix isearch- needs to be removed from other names too,
e.g. isearch-lazy-count-display-function -> lazy-count-display-function
isearch-read-with-highlight-setup maybe to minibuffer-lazy-highlight-setup,
etc.




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

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


Received: (at 53126) by debbugs.gnu.org; 9 Jan 2022 10:30:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jan 09 05:30:40 2022
Received: from localhost ([127.0.0.1]:49266 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6VTE-0002rF-Es
	for submit <at> debbugs.gnu.org; Sun, 09 Jan 2022 05:30:40 -0500
Received: from mail-wr1-f45.google.com ([209.85.221.45]:34578)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <arstoffel@HIDDEN>) id 1n6VTC-0002r1-Uq
 for 53126 <at> debbugs.gnu.org; Sun, 09 Jan 2022 05:30:39 -0500
Received: by mail-wr1-f45.google.com with SMTP id h10so10851981wrb.1
 for <53126 <at> debbugs.gnu.org>; Sun, 09 Jan 2022 02:30:38 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=gvjzta1aPfQKabc+93ZfUQHb0zwtIo8ursBiO7Did0E=;
 b=Ee6+J2YPd2WT5/V0p+lmgUYec1xGCU6wk8F+iLBL+DaYOSNVAiI2z3C2nnf2aiWZBP
 HycVgAlK23e+Kn2sLPEEFXqsdJzUO7U4o53fJ+CiXxhL3hjvKZriKkrp7dYpM/OmSYdq
 ruYVR0yfOIxl165t+7Ownz9jhGYtPT7MEG7zGlsn7P221XrMpEoIzvp+CdfMzaKaVwHq
 0VyPq5gDrCOncIjDwoTOijSksWjFTjzOBUk/93Iaspg0JURJt3MvcPjeWThLcjVEjEKy
 fpAO6hm3h8Wn26/dNGqyNDbtwx11cZVuNTiiJKjbsUTyIykfH1ytDu3Jx61OAUtk1PJd
 9arg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version;
 bh=gvjzta1aPfQKabc+93ZfUQHb0zwtIo8ursBiO7Did0E=;
 b=C38UPQiWtVcEx5xrYWTQBSzNgiOsfQMaCF9oQEA8ny/ukG43sUL9XDf8OLaZMCWoeM
 BWeDfgVKZkAg1u/+MrtsZcaneVEEWsgzn5VEBkVM/ud0cVT/YznAtttJKjmhnQYcYoF8
 HF8vO5EOH3vndBi2NEKLRffRatt3Bi0kn4DXasBPjS6V4tn4yGtqqYCokv/GIujtVqPB
 /wHUhP1HLSB8gNjrbh943CzYEXbvfYp+yVOBZOSX++1F+TYQz2lzkD4rWaj+5/wTJr7I
 nfCdVzYyKD0aM2Y9/lyYBO2NVJ6lJUd3i0PNvgT0Dv4OLzETVSUyvQobPCkBegLLls2p
 qU7A==
X-Gm-Message-State: AOAM531Se1F4t2NTJz6HgHWyfwjsVn0FMjtSoJHR022OpxfP9H0tNnKF
 va+J7agXbRNoqVU8QdxQyZdnzqypEGk=
X-Google-Smtp-Source: ABdhPJyioj92klZIxSpayFv7pQy5NQPZrccXEP1kj0srgFzTmpaTG2zPV/BcF5Rlk93ZoT0X2/5ViA==
X-Received: by 2002:adf:f985:: with SMTP id f5mr61342148wrr.14.1641724232891; 
 Sun, 09 Jan 2022 02:30:32 -0800 (PST)
Received: from ars3 ([2a02:8109:8ac0:56d0::15a6])
 by smtp.gmail.com with ESMTPSA id p11sm4507171wru.99.2022.01.09.02.30.32
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 09 Jan 2022 02:30:32 -0800 (PST)
From: Augusto Stoffel <arstoffel@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading
 query-replace string, etc.
References: <87sftyweb2.fsf@HIDDEN> <861r1iyrvw.fsf@HIDDEN>
 <87zgo6owaf.fsf@HIDDEN> <86k0f9xnrn.fsf@HIDDEN>
 <87tuedp6pl.fsf@HIDDEN>
Date: Sun, 09 Jan 2022 11:30:31 +0100
In-Reply-To: <87tuedp6pl.fsf@HIDDEN> (Augusto Stoffel's message of "Sun, 09
 Jan 2022 11:02:46 +0100")
Message-ID: <871r1hmcag.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.90 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 53126
Cc: 53126 <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: -1.0 (-)

On Sun,  9 Jan 2022 at 11:02, Augusto Stoffel <arstoffel@HIDDEN> wrote:

> OTOH, you can't do a replace-in-region that way.

Or rather -- you can, but it's tricky to keep the desired region
unchanged.




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

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


Received: (at 53126) by debbugs.gnu.org; 9 Jan 2022 10:03:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jan 09 05:03:00 2022
Received: from localhost ([127.0.0.1]:49246 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6V2S-0008NZ-HC
	for submit <at> debbugs.gnu.org; Sun, 09 Jan 2022 05:03:00 -0500
Received: from mail-wm1-f51.google.com ([209.85.128.51]:51962)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <arstoffel@HIDDEN>) id 1n6V2N-0008NF-Fh
 for 53126 <at> debbugs.gnu.org; Sun, 09 Jan 2022 05:02:59 -0500
Received: by mail-wm1-f51.google.com with SMTP id e5so6883737wmq.1
 for <53126 <at> debbugs.gnu.org>; Sun, 09 Jan 2022 02:02:55 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version:content-transfer-encoding;
 bh=NR3hJ1pJzoUao3ou56k+2G1jNK69h6AnXUqpzG1VZS4=;
 b=CZ2/eKk2TFa9nW4pVqGl7vIOmcBPoJL+K36VfKIvvBwvntNkDJuT/CE4zzSmR1pvPH
 Pa+5QvHkKT0xiIwV47Q+hZ8Iv8zOEiOZ9hCZbNIYDjQtBPJa6eV+gKPAsbFFCo+LI99a
 X/+8AEXegm2D/fQqlK3wnOIDe+QqdowylbuZ+FWAMqB+/bWfyGFWNZjYYrlbu8ur8cDZ
 i4mpabTZuvaxZIGaIm7zb6FJVvfyFnT1Oj2bLu4eKnJFjsVQCHcRQDClQK+6y9MKOzQQ
 FPlKR2VeDvpLRfmD53OMXA7GRwpFUCyEHLSWPCRchi/6RDg1CC5rNRgt81bocFFVnqSE
 COPQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version:content-transfer-encoding;
 bh=NR3hJ1pJzoUao3ou56k+2G1jNK69h6AnXUqpzG1VZS4=;
 b=6cCKJEzvHCC2141CyheIzGuDKZPCkYF64HeVUOxTm5SK3o5CowcaDqNE5PLpQw5s4Y
 iZt5SLHft1bGF8ctqex5hAYU4qRpPaCbLPPcTGcsia4AbqVIaDIpnWiBaFzxoOU5FVLz
 tnTtPjE49Xgns/oKDTq2ARr9aU+or7b+nB+QC9QeYKzTswSRn+7TvNoG7jv3hWRtPzYh
 NXbth95bFCbZhK4lwIgqZuDPgxH7VfA/yKKBPnPg1c+h0Rud84gR84kA8n1EENdQO5SQ
 EMsGvSyGuAQMIYO2Qrq+K5On0cqh6gl9ZfFZEU0GjvIWPrKqCJYtJVSHaEWHjMAcArWU
 ykAA==
X-Gm-Message-State: AOAM532hbRDOv/8NB1A/keyBUjrqSDMERn7szdMFxp0NEbTuXQ6mElpN
 2/+QcddSFxkwFsfNikevld50yRMtuFI=
X-Google-Smtp-Source: ABdhPJw802vdoShSRUq0cUhQhuQ2I1HTYo5Ugd8qd4ipoDWu2zuESRH9Gb3hKe3p5WvTRGPsraMCMw==
X-Received: by 2002:a05:600c:1e24:: with SMTP id
 ay36mr18065529wmb.84.1641722568968; 
 Sun, 09 Jan 2022 02:02:48 -0800 (PST)
Received: from ars3 ([2a02:8109:8ac0:56d0::15a6])
 by smtp.gmail.com with ESMTPSA id f8sm4134376wry.16.2022.01.09.02.02.47
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 09 Jan 2022 02:02:48 -0800 (PST)
From: Augusto Stoffel <arstoffel@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading
 query-replace string, etc.
References: <87sftyweb2.fsf@HIDDEN> <861r1iyrvw.fsf@HIDDEN>
 <87zgo6owaf.fsf@HIDDEN> <86k0f9xnrn.fsf@HIDDEN>
Date: Sun, 09 Jan 2022 11:02:46 +0100
In-Reply-To: <86k0f9xnrn.fsf@HIDDEN> (Juri Linkov's message of "Sun, 
 09 Jan 2022 11:10:13 +0200")
Message-ID: <87tuedp6pl.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.90 (gnu/linux)
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: 53126
Cc: 53126 <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: -1.0 (-)

On Sun,  9 Jan 2022 at 11:10, Juri Linkov <juri@HIDDEN> wrote:

> It seems the "Query replacing" prompt in perform-replace could just
> display the values of isearch-lazy-count-current and
> isearch-lazy-count-total.

Yes, I guess you are right.

> Or for asynchronous lazy-count a new hook needs to be run at the end
> of isearch-lazy-highlight-buffer-update in addition to the call of
> isearch-message.
>

That's what the patch does (but with a variable pointing to a function
instead of a hook, although this can be changed).  But note that it's
not enough to do something =E2=80=9Cin addition to the call of isearch-mess=
age=E2=80=9D;
it's necessary to _suppress_ the call to isearch-message.

>>> But your patches are intended for a different feature - highlighting
>>> of matches in the buffer while entering an input string in the minibuff=
er.
>>>
>>> I wonder how many users need this feature, when it's easy to construct
>>> a query-replace string using highlighting/counting in isearch-mode,
>>> then type M-%
>>> (isearch-query-replace) that invokes query-replace with the
>>> query-replace string.
>>
>> Sure, this alternative method works.  But somehow it's not the way I
>> usually start a replace, and I think there's nothing wrong with that
>> preference :-)
>
> But this method is more limiting - no keys to pull text from the buffer
> like 'C-w' (isearch-yank-word-or-char) does in isearch-mode, no way
> to navigate to the first match like it's possible in isearch-mode, etc.
>

OTOH, you can't do a replace-in-region that way.

> Maybe then this feature could be added to read-regexp or even
> to read-from-minibuffer?  And activated by adding a setup function
> to minibuffer-setup-hook like other minibuffer's features do, such as
> icomplete-minibuffer-setup, minibuffer-depth-setup, rfn-eshadow-setup-min=
ibuffer.
>
> Then maybe a new feature could be named e.g. "lazy-minibuffer"?

This is what the patch does, with code of this kind:

```
(let ((isearch-regexp t)
      ;; Whatever else isearch / lazy-highlight settings might be needed
      (isearch-lazy-count-display-function #'isearch-read-with-highlight-co=
unt))
  (minibuffer-with-setup-hook #'isearch-read-with-highlight-setup
    (read-from-minibuffer "Type a regexp with preview: ")))
```

There could be a convenience wrapper for this code, but I'm not sure
that makes much sense, because isearch and lazy-highlight have too many
parameters one might need to set so it's better to be explicit/flexible.




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

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


Received: (at 53126) by debbugs.gnu.org; 9 Jan 2022 09:29:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jan 09 04:29:09 2022
Received: from localhost ([127.0.0.1]:49195 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6UVh-0007V9-Ec
	for submit <at> debbugs.gnu.org; Sun, 09 Jan 2022 04:29:09 -0500
Received: from relay8-d.mail.gandi.net ([217.70.183.201]:54913)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n6UVf-0007Ul-Qy
 for 53126 <at> debbugs.gnu.org; Sun, 09 Jan 2022 04:29:08 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 7864E1BF207;
 Sun,  9 Jan 2022 09:28:59 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Augusto Stoffel <arstoffel@HIDDEN>
Subject: Re: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading
 query-replace string, etc.
Organization: LINKOV.NET
References: <87sftyweb2.fsf@HIDDEN> <861r1iyrvw.fsf@HIDDEN>
 <87zgo6owaf.fsf@HIDDEN>
Date: Sun, 09 Jan 2022 11:10:13 +0200
In-Reply-To: <87zgo6owaf.fsf@HIDDEN> (Augusto Stoffel's message of "Sat, 08
 Jan 2022 20:35:36 +0100")
Message-ID: <86k0f9xnrn.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 53126
Cc: 53126 <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: -1.7 (-)

>> Strange, I expected that the lazy-count feature applied to query-replace
>> should do a different thing - when querying about replacing the current match,
>> it should show the number of current match and the number of total matches.
>> The latter number should be updated after every replacement.
>
> That would be handy too.  I haven't checked how the `perform-replace'
> loop works, but wouldn't this require a hook into the lazy count
> procedure --- precisely what my patch introduces through the new
> variable `isearch-lazy-count-display-function'?

It seems the "Query replacing" prompt in perform-replace could just
display the values of isearch-lazy-count-current and
isearch-lazy-count-total.  Or for asynchronous lazy-count a new hook
needs to be run at the end of isearch-lazy-highlight-buffer-update
in addition to the call of isearch-message.

>> But your patches are intended for a different feature - highlighting
>> of matches in the buffer while entering an input string in the minibuffer.
>>
>> I wonder how many users need this feature, when it's easy to construct
>> a query-replace string using highlighting/counting in isearch-mode,
>> then type M-%
>> (isearch-query-replace) that invokes query-replace with the
>> query-replace string.
>
> Sure, this alternative method works.  But somehow it's not the way I
> usually start a replace, and I think there's nothing wrong with that
> preference :-)

But this method is more limiting - no keys to pull text from the buffer
like 'C-w' (isearch-yank-word-or-char) does in isearch-mode, no way
to navigate to the first match like it's possible in isearch-mode, etc.

>> Perhaps better to ask on emacs-devel if anyone needs this feature.
>
> We can ask.  But note that the bulk of the patch has a fairly general
> purpose, namely to read a regexp with live preview of the matches.
> There's probably a couple extra uses for this.

Maybe then this feature could be added to read-regexp or even
to read-from-minibuffer?  And activated by adding a setup function
to minibuffer-setup-hook like other minibuffer's features do, such as
icomplete-minibuffer-setup, minibuffer-depth-setup, rfn-eshadow-setup-minibuffer.

Then maybe a new feature could be named e.g. "lazy-minibuffer"?




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

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


Received: (at 53126) by debbugs.gnu.org; 8 Jan 2022 19:35:48 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 08 14:35:47 2022
Received: from localhost ([127.0.0.1]:48738 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6HVD-0003QG-K9
	for submit <at> debbugs.gnu.org; Sat, 08 Jan 2022 14:35:47 -0500
Received: from mail-wm1-f41.google.com ([209.85.128.41]:54937)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <arstoffel@HIDDEN>) id 1n6HVB-0003Q2-4f
 for 53126 <at> debbugs.gnu.org; Sat, 08 Jan 2022 14:35:46 -0500
Received: by mail-wm1-f41.google.com with SMTP id o30so6159363wms.4
 for <53126 <at> debbugs.gnu.org>; Sat, 08 Jan 2022 11:35:45 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=uaFdM9GK9mFThXF458EmwUwxMBv5A1iBXXFs/RMmQGI=;
 b=JjEV2dJsDq9LCRftjphE2m1bwrOpzB4f+n7Z14f35n4xgDIHH4gSMSfJq/KoT6WyjL
 Rdgwe0k1mFZX8h04v+S1ndQxDSyQoyiTRcoTfUgHTByQWpoZPHFfeRMBOlrET0r2QjTV
 ju/pN4/5P8jVAPHfi5Eajgsnuh8ndnULHG0uXSI6k7ziZGOawj3rzbGTpxWyTcMeS/AS
 siLUhS9Sq/GAxCNOpK8i/FXIgVj7UPuihzPncgR70xdup/tujvFD3r+qBlJcGLavOZ53
 OqSdKKG5fJArat/N0N5jTsCBlewgGgcTsbNE/OnJcnKpXRdcpSB0MNBHanINAQ+aJyEU
 yJwg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version;
 bh=uaFdM9GK9mFThXF458EmwUwxMBv5A1iBXXFs/RMmQGI=;
 b=Y5LXePkCz/W7nGd3WuL05wS5cmFQ+mS/wrcG5AEi9LSmXQUxTT/5GTtp7X5tMRL/3Q
 oQz3UXcEkhavP/pMFoqHKNMl9GX+/uG350ZWu/9uSLFP8Ir2Ty/qL3u4A9AXy0r94Hjn
 xLvH7dsrXH+2mRt4slwYfyGVP2ZB+8BM7PselCfegt4lx7mOtoJnfVW9jmvE1OlBkEuq
 TDXB5Ws9xPYmcLhqVgQ7urDSLTsuT1pH8A9E8jIckb7YjG4/GwJTDjly1dUTdzg9565g
 IFjOTrB/FkA0tGWvpWxJ6K3QYuuNRXh+3e4CqBl8ZNI9gSd+F58Mg3k6ilD9KoRHEO+O
 aQUw==
X-Gm-Message-State: AOAM533gscDtbMf+5ZDlpdaA+3UfVI8uFMRHKQ9JTfWVTxekzSMzw4pk
 OXdoVe3SfjrjyfQrwz9etAn2vL6rN+o=
X-Google-Smtp-Source: ABdhPJwSp0nqUfLyX1/18IEtB5/hB0Nmz+AbulT0dk4wEo1PL0b7zruH0D71BaIElfpU2uKHXCh+XA==
X-Received: by 2002:a1c:e909:: with SMTP id q9mr15344151wmc.184.1641670538936; 
 Sat, 08 Jan 2022 11:35:38 -0800 (PST)
Received: from ars3 ([2a02:8109:8ac0:56d0::b4b9])
 by smtp.gmail.com with ESMTPSA id m39sm2021535wms.33.2022.01.08.11.35.37
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 08 Jan 2022 11:35:38 -0800 (PST)
From: Augusto Stoffel <arstoffel@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading
 query-replace string, etc.
References: <87sftyweb2.fsf@HIDDEN> <861r1iyrvw.fsf@HIDDEN>
Date: Sat, 08 Jan 2022 20:35:36 +0100
In-Reply-To: <861r1iyrvw.fsf@HIDDEN> (Juri Linkov's message of "Sat, 
 08 Jan 2022 20:59:45 +0200")
Message-ID: <87zgo6owaf.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.90 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 53126
Cc: 53126 <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: -1.0 (-)

On Sat,  8 Jan 2022 at 20:59, Juri Linkov <juri@HIDDEN> wrote:

> Strange, I expected that the lazy-count feature applied to query-replace
> should do a different thing - when querying about replacing the current match,
> it should show the number of current match and the number of total matches.
> The latter number should be updated after every replacement.
>

That would be handy too.  I haven't checked how the `perform-replace'
loop works, but wouldn't this require a hook into the lazy count
procedure --- precisely what my patch introduces through the new
variable `isearch-lazy-count-display-function'?

> But your patches are intended for a different feature - highlighting
> of matches in the buffer while entering an input string in the minibuffer.
>
> I wonder how many users need this feature, when it's easy to construct
> a query-replace string using highlighting/counting in isearch-mode,
> then type M-%
> (isearch-query-replace) that invokes query-replace with the
> query-replace string.
>

Sure, this alternative method works.  But somehow it's not the way I
usually start a replace, and I think there's nothing wrong with that
preference :-)

> Perhaps better to ask on emacs-devel if anyone needs this feature.

We can ask.  But note that the bulk of the patch has a fairly general
purpose, namely to read a regexp with live preview of the matches.
There's probably a couple extra uses for this.




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

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


Received: (at 53126) by debbugs.gnu.org; 8 Jan 2022 19:10:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 08 14:10:32 2022
Received: from localhost ([127.0.0.1]:48722 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6H6m-0002ik-Ew
	for submit <at> debbugs.gnu.org; Sat, 08 Jan 2022 14:10:32 -0500
Received: from relay5-d.mail.gandi.net ([217.70.183.197]:41207)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n6H6k-0002iU-CB
 for 53126 <at> debbugs.gnu.org; Sat, 08 Jan 2022 14:10:31 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 3E97D1C0002;
 Sat,  8 Jan 2022 19:10:22 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Augusto Stoffel <arstoffel@HIDDEN>
Subject: Re: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading
 query-replace string, etc.
Organization: LINKOV.NET
References: <87sftyweb2.fsf@HIDDEN>
Date: Sat, 08 Jan 2022 20:59:45 +0200
In-Reply-To: <87sftyweb2.fsf@HIDDEN> (Augusto Stoffel's message of "Sat, 08
 Jan 2022 14:24:33 +0100")
Message-ID: <861r1iyrvw.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 53126
Cc: 53126 <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: -1.7 (-)

> The anzu package was mentioned recently in the mailing list.  Emacs now
> includes the lazy-count feature, which is the main purpose of anzu, but
> it's still missing one nice feature from that package, namely the
> highlighting and count of matches as one types a regexp or string to
> replace in `query-replace{-regexp}'.  See the below patch for a
> (probably not yet mature) stab at this.

Strange, I expected that the lazy-count feature applied to query-replace
should do a different thing - when querying about replacing the current match,
it should show the number of current match and the number of total matches.
The latter number should be updated after every replacement.

But your patches are intended for a different feature - highlighting
of matches in the buffer while entering an input string in the minibuffer.

I wonder how many users need this feature, when it's easy to construct
a query-replace string using highlighting/counting in isearch-mode, then type M-%
(isearch-query-replace) that invokes query-replace with the query-replace string.

Perhaps better to ask on emacs-devel if anyone needs this feature.




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

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


Received: (at submit) by debbugs.gnu.org; 8 Jan 2022 13:24:45 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 08 08:24:45 2022
Received: from localhost ([127.0.0.1]:46587 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n6Bi8-0004yY-Dz
	for submit <at> debbugs.gnu.org; Sat, 08 Jan 2022 08:24:45 -0500
Received: from lists.gnu.org ([209.51.188.17]:46044)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <arstoffel@HIDDEN>) id 1n6Bi4-0004yN-Ov
 for submit <at> debbugs.gnu.org; Sat, 08 Jan 2022 08:24:43 -0500
Received: from eggs.gnu.org ([209.51.188.92]:58020)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arstoffel@HIDDEN>)
 id 1n6Bi4-0007js-K3
 for bug-gnu-emacs@HIDDEN; Sat, 08 Jan 2022 08:24:40 -0500
Received: from [2a00:1450:4864:20::334] (port=51722
 helo=mail-wm1-x334.google.com)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <arstoffel@HIDDEN>)
 id 1n6Bi2-0002sV-Ah
 for bug-gnu-emacs@HIDDEN; Sat, 08 Jan 2022 08:24:40 -0500
Received: by mail-wm1-x334.google.com with SMTP id e5so5728044wmq.1
 for <bug-gnu-emacs@HIDDEN>; Sat, 08 Jan 2022 05:24:36 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:subject:date:message-id:user-agent:mime-version;
 bh=SgV5AddMxwLgFwrCpf68eS9aqAcUfGRMfInRKJRQ35g=;
 b=XFKlAWhHxo1vg4rIA6TQ3+gA6EOvf99uTYo06EY4vu2Aoi+IWqtktYZtCdxhA2ZNae
 AWq3N5iG6HxjkErhVuZFF+FXX5Wbv3gUy79tql1Fry7oNOOl7XgGg07f69+Mf2Jieuja
 HkE2m0Fa0uX7B1wBelWMD+O3Y/5fsXrgnzbx2rHHnuGRzZE3r9MF67gLN3bcwJyHeY9w
 z9HB8Ab1WFkkusIXAP4rtdnwedT5ZZnvtjZ1+/w133B6i0EndohqsCntDe3ReyJ1yj0h
 1hGXDMJTJUwqlnIR2XBAIbAARdgX08tPV4y+ohb8soMf9WJYA5OLxgIeZ5F9Vlc5nwqQ
 Tagg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:subject:date:message-id:user-agent
 :mime-version;
 bh=SgV5AddMxwLgFwrCpf68eS9aqAcUfGRMfInRKJRQ35g=;
 b=xkNaid8TjdjCLOJlPOLR2ZjUl7bXXqdh/YOnSicxQFCorC9Ho19qOtdFm/71Mj84ZJ
 scbv4EZ7ABM1+y7yhUN0AWBPFNDyBFABR30ebu5sNJgWQgLTwLDQATeOPXclk0zvsyob
 94PQNAvisthd68Z/h8XjdFusd1/z9Cig4mZvf3nn+o4nsPRl6W9JEyQfMzGistrEdoQH
 liB4YJPTgQgx2BpWsVUYb4bcuP4hL90z9/dv60CUG2bEMgRmQ/7349sPTiYt5FH7xQDS
 m4bWmyO0LREJ/vHcXU9wFCwFoTI/vOGjo1P12QVmIDbPSQIB27MO2xRu8JCH+/O85E8T
 bHcw==
X-Gm-Message-State: AOAM533A7HjEfRRM1V9N1sjIC/JiYt+xOsUx3JI7GK/uxdgPmpor7XRf
 b1WLY3IFwjja0gZojc2P9ducA0JGRS8=
X-Google-Smtp-Source: ABdhPJyRswlDYINO1Gc7brHFbkCAi6yJHCIAh0kJa5Pvl3ypSVLGG5bEEeALM7c9a5xjJIdR/OmCSg==
X-Received: by 2002:a1c:740c:: with SMTP id p12mr14642787wmc.140.1641648275461; 
 Sat, 08 Jan 2022 05:24:35 -0800 (PST)
Received: from ars3 ([2a02:8109:8ac0:56d0::b4b9])
 by smtp.gmail.com with ESMTPSA id r19sm730999wmh.42.2022.01.08.05.24.34
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 08 Jan 2022 05:24:34 -0800 (PST)
From: Augusto Stoffel <arstoffel@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 29.0.50; [PATCH] Lazy highlight/count when reading query-replace
 string, etc.
Date: Sat, 08 Jan 2022 14:24:33 +0100
Message-ID: <87sftyweb2.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::334
 (failed)
Received-SPF: pass client-ip=2a00:1450:4864:20::334;
 envelope-from=arstoffel@HIDDEN; helo=mail-wm1-x334.google.com
X-Spam_score_int: -12
X-Spam_score: -1.3
X-Spam_bar: -
X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.4 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview: The anzu package was mentioned recently in the mailing list.
 Emacs now includes the lazy-count feature, which is the main purpose of anzu, 
 but it's still missing one nice feature from that package, na [...] 
 Content analysis details:   (1.4 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record
 1.0 SPF_SOFTFAIL           SPF: sender does not match SPF record (softfail)
 0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
 provider (arstoffel[at]gmail.com)
 0.0 RCVD_IN_MSPIKE_H3      RBL: Good reputation (+3)
 [209.51.188.17 listed in wl.mailspike.net]
 -2.3 RCVD_IN_DNSWL_MED      RBL: Sender listed at https://www.dnswl.org/,
 medium trust [209.51.188.17 listed in list.dnswl.org]
 0.0 RCVD_IN_MSPIKE_WL      Mailspike good senders
 1.3 SPOOFED_FREEMAIL       No description available.
 1.5 SPOOF_GMAIL_MID        From Gmail but it doesn't seem to be...
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: -2.3 (--)

--=-=-=
Content-Type: text/plain

The anzu package was mentioned recently in the mailing list.  Emacs now
includes the lazy-count feature, which is the main purpose of anzu, but
it's still missing one nice feature from that package, namely the
highlighting and count of matches as one types a regexp or string to
replace in `query-replace{-regexp}'.  See the below patch for a
(probably not yet mature) stab at this.

I've also added lazy highlighting to the `isearch-edit-string' command.

I didn't introduce any new customization variables.  Lazy highlighting
in both `query-replace{-regexp}' and `isearch-edit-string' is controlled
by `isearch-lazy-highlight' (therefore is on by default) and lazy count
next to the minibuffer prompt is controlled by `isearch-lazy-count'
(therefore off by default).

I believe the problems pointed out in a previous iteration of this in
https://lists.gnu.org/archive/html/emacs-devel/2021-05/msg01196.html are
now solved.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-Allow-reading-from-minibuffer-with-lazy-highlight-an.patch

From 11e52a1bf1adb2a15dda3097d6c6016034ae4487 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@HIDDEN>
Date: Sat, 8 Jan 2022 11:08:46 +0100
Subject: [PATCH 1/2] Allow reading from minibuffer with lazy highlight and
 match count

* lisp/isearch.el (isearch-lazy-count-display-function): New variable
allowing to display the lazy count in special ways.
(isearch-edit-string): Add lazy highlight and count of matching text.
(isearch-lazy-highlight-new-loop,
isearch-lazy-highlight-buffer-update): Use
`isearch-lazy-count-display-function' instead of hardcoded call to
`isearch-message'.
(isearch-read-with-highlight--overlay,
isearch-read-with-highlight--after-change,
isearch-read-with-highlight--exit, isearch-read-with-highlight-setup,
isearch-read-with-highlight-count): Variable and functions
implementing the lazy highlight functionality while reading from
minibuffer.
* lisp/simple.el (minibuffer-history-isearch-setup): Set
`isearch-lazy-count-display-function' appropriately.
* lisp/comint.el (comint-history-isearch-setup,
comint-history-isearch-end): Set `isearch-lazy-count-display-function'
appropriately.
---
 lisp/comint.el  |  2 ++
 lisp/isearch.el | 91 +++++++++++++++++++++++++++++++++++++++----------
 lisp/simple.el  |  1 +
 3 files changed, 76 insertions(+), 18 deletions(-)

diff --git a/lisp/comint.el b/lisp/comint.el
index fdea3e33bb..c1695bbbdf 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -1515,6 +1515,7 @@ comint-history-isearch-setup
                 #'comint-history-isearch-wrap)
     (setq-local isearch-push-state-function
                 #'comint-history-isearch-push-state)
+    (setq-local isearch-lazy-count-display-function nil)
     (add-hook 'isearch-mode-end-hook 'comint-history-isearch-end nil t)))
 
 (defun comint-history-isearch-end ()
@@ -1526,6 +1527,7 @@ comint-history-isearch-end
   (setq isearch-message-function nil)
   (setq isearch-wrap-function nil)
   (setq isearch-push-state-function nil)
+  (setq-local isearch-lazy-count-display-function #'isearch-message)
   (remove-hook 'isearch-mode-end-hook 'comint-history-isearch-end t)
   (unless isearch-suspended
     (custom-reevaluate-setting 'comint-history-isearch)))
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 7593a0ec98..ccb06d534e 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -465,6 +465,9 @@ lazy-count-suffix-format
   :group 'lazy-count
   :version "27.1")
 
+(defvar isearch-lazy-count-display-function #'isearch-message
+  "Function called when new lazy count results are available.")
+
 
 ;; Define isearch help map.
 
@@ -1808,19 +1811,21 @@ isearch-edit-string
 	  ;; for some incompatibility with gmhist.
 	  (minibuffer-history-symbol)
 	  ;; Search string might have meta information on text properties.
-	  (minibuffer-allow-text-properties t))
+	  (minibuffer-allow-text-properties t)
+          (isearch-lazy-count-display-function #'isearch-read-with-highlight-count))
      (setq isearch-new-string
-	   (read-from-minibuffer
-	    (isearch-message-prefix nil isearch-nonincremental)
-	    (cons isearch-string (1+ (or (isearch-fail-pos)
-					 (length isearch-string))))
-	    minibuffer-local-isearch-map nil
-	    (if isearch-regexp
-		(cons 'regexp-search-ring
-		      (1+ (or regexp-search-ring-yank-pointer -1)))
-	      (cons 'search-ring
-		    (1+ (or search-ring-yank-pointer -1))))
-	    nil t)
+	   (minibuffer-with-setup-hook #'isearch-read-with-highlight-setup
+             (read-from-minibuffer
+	      (isearch-message-prefix nil isearch-nonincremental)
+	      (cons isearch-string (1+ (or (isearch-fail-pos)
+					   (length isearch-string))))
+	      minibuffer-local-isearch-map nil
+	      (if isearch-regexp
+		  (cons 'regexp-search-ring
+		        (1+ (or regexp-search-ring-yank-pointer -1)))
+	        (cons 'search-ring
+		      (1+ (or search-ring-yank-pointer -1))))
+	      nil t))
 	   isearch-new-message
 	   (mapconcat 'isearch-text-char-description
 		      isearch-new-string "")))))
@@ -4023,7 +4028,7 @@ isearch-lazy-highlight-new-loop
 			         isearch-lazy-highlight-window-end))))))
     ;; something important did indeed change
     (lazy-highlight-cleanup t (not (equal isearch-string ""))) ;stop old timer
-    (when (and isearch-lazy-count isearch-mode (null isearch-message-function))
+    (when (and isearch-lazy-count isearch-lazy-count-display-function)
       (when (or (equal isearch-string "")
                 ;; Check if this place was reached by a condition above
                 ;; other than changed window boundaries (that shouldn't
@@ -4042,7 +4047,8 @@ isearch-lazy-highlight-new-loop
         (setq isearch-lazy-count-current nil
               isearch-lazy-count-total nil)
         ;; Delay updating the message if possible, to avoid flicker
-        (when (string-equal isearch-string "") (isearch-message))))
+        (when (string-equal isearch-string "")
+          (funcall isearch-lazy-count-display-function))))
     (setq isearch-lazy-highlight-window-start-changed nil)
     (setq isearch-lazy-highlight-window-end-changed nil)
     (setq isearch-lazy-highlight-error isearch-error)
@@ -4095,13 +4101,13 @@ isearch-lazy-highlight-new-loop
                                  'isearch-lazy-highlight-start))))
   ;; Update the current match number only in isearch-mode and
   ;; unless isearch-mode is used specially with isearch-message-function
-  (when (and isearch-lazy-count isearch-mode (null isearch-message-function))
+  (when (and isearch-lazy-count isearch-lazy-count-display-function)
     ;; Update isearch-lazy-count-current only when it was already set
     ;; at the end of isearch-lazy-highlight-buffer-update
     (when isearch-lazy-count-current
       (setq isearch-lazy-count-current
             (gethash (point) isearch-lazy-count-hash 0))
-      (isearch-message))))
+      (funcall isearch-lazy-count-display-function))))
 
 (defun isearch-lazy-highlight-search (string bound)
   "Search ahead for the next or previous match, for lazy highlighting.
@@ -4302,16 +4308,65 @@ isearch-lazy-highlight-buffer-update
 		    (setq looping nil
 			  nomore  t))))
 	    (if nomore
-		(when (and isearch-lazy-count isearch-mode (null isearch-message-function))
+		(when (and isearch-lazy-count isearch-lazy-count-display-function)
 		  (unless isearch-lazy-count-total
 		    (setq isearch-lazy-count-total 0))
 		  (setq isearch-lazy-count-current
 			(gethash opoint isearch-lazy-count-hash 0))
-		  (isearch-message))
+		  (funcall isearch-lazy-count-display-function))
 	      (setq isearch-lazy-highlight-timer
 		    (run-at-time lazy-highlight-interval nil
 				 'isearch-lazy-highlight-buffer-update)))))))))
 
+;; Reading from minibuffer with lazy highlight and match count
+
+(defvar isearch-read-with-highlight--overlay nil
+  "Overlay for minibuffer prompt updates.")
+
+(defvar isearch-read-with-highlight-transform #'identity
+  "Function to transform minibuffer text into a `isearch-string' for highlighting.")
+
+(defun isearch-read-with-highlight--after-change (_beg _end _len)
+  "Update lazy highlight state in minibuffer selected window."
+  (when isearch-lazy-highlight
+    (let ((inhibit-redisplay t) ;; Avoid cursor flickering
+          (string (minibuffer-contents)))
+      (with-minibuffer-selected-window
+        (setq isearch-string (funcall isearch-read-with-highlight-transform string))
+        (isearch-lazy-highlight-new-loop)))))
+
+(defun isearch-read-with-highlight--exit ()
+  "Unwind changes from `isearch-read-with-highlight-setup'."
+  (remove-hook 'after-change-functions
+               #'isearch-read-with-highlight--after-change)
+  (remove-hook 'minibuffer-exit-hook #'isearch-read-with-highlight--exit)
+  (setq isearch-read-with-highlight--overlay nil)
+  (lazy-highlight-cleanup))
+
+(defun isearch-read-with-highlight-setup ()
+  "Set up minibuffer for lazy highlight of matches in the original window.
+
+This is intended to be called via `minibuffer-with-setup-hook'.
+Note that several other isearch variables influence the lazy
+highlighting, including `isearch-regexp' and
+`isearch-lazy-count-display-function'."
+  (add-hook 'after-change-functions
+            #'isearch-read-with-highlight--after-change)
+  (add-hook 'minibuffer-exit-hook #'isearch-read-with-highlight--exit)
+  (setq isearch-read-with-highlight--overlay
+        (make-overlay (point-min) (point-min) (current-buffer) t t))
+  (isearch-read-with-highlight--after-change nil nil nil))
+
+(defun isearch-read-with-highlight-count ()
+  "Display total match count in the minibuffer prompt."
+  (when isearch-read-with-highlight--overlay
+    (overlay-put isearch-read-with-highlight--overlay
+                 'before-string
+                 (and isearch-lazy-count-total
+                      (not isearch-error)
+                      (format "%s " isearch-lazy-count-total)))))
+
+
 (defun isearch-resume (string regexp word forward message case-fold)
   "Resume an incremental search.
 STRING is the string or regexp searched for.
diff --git a/lisp/simple.el b/lisp/simple.el
index 070d2764fe..ecf07b912d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2787,6 +2787,7 @@ minibuffer-history-isearch-setup
               #'minibuffer-history-isearch-wrap)
   (setq-local isearch-push-state-function
               #'minibuffer-history-isearch-push-state)
+  (setq-local isearch-lazy-count-display-function nil)
   (add-hook 'isearch-mode-end-hook 'minibuffer-history-isearch-end nil t))
 
 (defun minibuffer-history-isearch-end ()
-- 
2.33.1


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0002-Lazy-highlight-when-reading-query-replace-text.patch

From 6d9ec412addfc450f63487de0d90a1076cab47a0 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@HIDDEN>
Date: Sat, 8 Jan 2022 13:15:40 +0100
Subject: [PATCH 2/2] Lazy highlight when reading query-replace text

* lisp/replace.el (query-replace-read-from): Add lazy highlighting.
---
 lisp/replace.el | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lisp/replace.el b/lisp/replace.el
index 60e507c642..241a97a3a2 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -244,6 +244,17 @@ query-replace-read-from
                                    (query-replace-descr
                                     (cdar query-replace-defaults)))))
                   (t (format-prompt prompt nil))))
+           ;; Set up lazy highlighting while reading FROM regexp
+           (isearch-lazy-highlight query-replace-highlight)
+           (isearch-regexp regexp-flag)
+           (isearch-regexp-function nil)
+           (isearch-case-fold-search case-fold-search) ;; TODO: the case-folding rule here is complicated...
+           (isearch-read-with-highlight-transform
+            (lambda (string)
+              (let ((from (query-replace--split-string string)))
+                (if (consp from) (car from) from))))
+           (isearch-lazy-count-display-function
+            #'isearch-read-with-highlight-count)
 	   (from
 	    ;; The save-excursion here is in case the user marks and copies
 	    ;; a region in order to specify the minibuffer input.
@@ -251,6 +262,7 @@ query-replace-read-from
 	    (save-excursion
               (minibuffer-with-setup-hook
                   (lambda ()
+                    (isearch-read-with-highlight-setup)
                     (setq-local text-property-default-nonsticky
                                 (append '((separator . t) (face . t))
                                         text-property-default-nonsticky)))
-- 
2.33.1


--=-=-=--




Acknowledgement sent to Augusto Stoffel <arstoffel@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#53126; 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: Fri, 21 Jan 2022 11:30:02 UTC

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