From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading query-replace string, etc. Date: Tue, 15 Mar 2022 19:24:01 +0200 Organization: LINKOV.NET Message-ID: <86sfrjia5u.fsf@mail.linkov.net> References: <87sftyweb2.fsf@gmail.com> <861r1iyrvw.fsf@mail.linkov.net> <87zgo6owaf.fsf@gmail.com> <86k0f9xnrn.fsf@mail.linkov.net> <87tuedp6pl.fsf@gmail.com> <861r1g7n3b.fsf@mail.linkov.net> <87o84jcx5x.fsf@gmail.com> <8635lvif0r.fsf@mail.linkov.net> <87mtidip1w.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8397"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 53126@debbugs.gnu.org To: Augusto Stoffel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 15 18:28:12 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nUAxv-00022B-Dk for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 15 Mar 2022 18:28:11 +0100 Original-Received: from localhost ([::1]:51044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nUAxu-0005mr-9N for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 15 Mar 2022 13:28:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUAxm-0005mQ-ON for bug-gnu-emacs@gnu.org; Tue, 15 Mar 2022 13:28:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55636) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nUAxm-0002VK-Ev for bug-gnu-emacs@gnu.org; Tue, 15 Mar 2022 13:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nUAxm-0005Od-BN for bug-gnu-emacs@gnu.org; Tue, 15 Mar 2022 13:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 Mar 2022 17:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53126 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 53126-submit@debbugs.gnu.org id=B53126.164736525020692 (code B ref 53126); Tue, 15 Mar 2022 17:28:02 +0000 Original-Received: (at 53126) by debbugs.gnu.org; 15 Mar 2022 17:27:30 +0000 Original-Received: from localhost ([127.0.0.1]:49532 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nUAxF-0005Ng-PU for submit@debbugs.gnu.org; Tue, 15 Mar 2022 13:27:30 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:40013) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nUAxE-0005ND-2K for 53126@debbugs.gnu.org; Tue, 15 Mar 2022 13:27:28 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 0C00840009; Tue, 15 Mar 2022 17:27:18 +0000 (UTC) In-Reply-To: <87mtidip1w.fsf@gmail.com> (Augusto Stoffel's message of "Sat, 26 Feb 2022 17:13:31 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:228414 Archived-At: > Sorry for getting back to this after such a long time. I've attached a > new patch that hopefully is good to merge, except for adding some NEWS > entry. Let me know what you think. Please see comments for your latest patch below: > @@ -1812,6 +1812,8 @@ isearch-edit-string > (minibuffer-history-symbol) > ;; Search string might have meta information on text properties. > (minibuffer-allow-text-properties t)) > + (when isearch-lazy-highlight > + (add-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup)) Since this does both highlighting and counting, shouldn't the condition be (when (and isearch-lazy-highlight isearch-lazy-count)) Or maybe new separate customizable options are needed, e.g. 'minibuffer-lazy-highlight' and 'minibuffer-lazy-count'? > @@ -2350,7 +2352,9 @@ isearch-query-replace > (isearch-recursive-edit nil) > (isearch-string-propertized > (isearch-string-propertize isearch-string))) > - (isearch-done nil t) > + (let ((lazy-highlight-cleanup (and lazy-highlight-cleanup > + (not query-replace-lazy-highlight)))) > + (isearch-done nil t)) Is this some optimization? It seems it's intended to leave some existing highlighting? Is this to avoid double highlighting? Also maybe this condition could use a new variable as well. > @@ -4048,7 +4056,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 > ... > @@ -4067,7 +4075,10 @@ 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)) > ... > @@ -4120,13 +4131,15 @@ 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 The problem is that when these conditions 'isearch-mode (null isearch-message-function)' are removed, now this shows wrong counts in the minibuffer history search (e.g. 'M-! C-r s C-r C-r ...') and the shell history search (e.g. 'M-x shell RET M-r s C-r C-r ...'). Before this change counting was disabled in the history search because it shows wrong numbers. > +(defun minibuffer-lazy-highlight--count () > + "Display total match count in the minibuffer prompt." > + (when minibuffer-lazy-highlight--overlay > + (overlay-put minibuffer-lazy-highlight--overlay > + 'after-string > + (and isearch-lazy-count-total > + (not isearch-error) > + (format minibuffer-lazy-count-format > + isearch-lazy-count-total))))) > ... > + (setq minibuffer-lazy-highlight--overlay > + (and minibuffer-lazy-count-format > + (make-overlay (point-min) (point-min) (current-buffer) t))) For some reasons the package lisp/mb-depth.el uses 'after-string' instead of 'before-string', and (make-overlay (point-min) (1+ (point-min))) instead of (make-overlay (point-min) (point-min)), so maybe better to do the same? > @@ -365,14 +372,44 @@ query-replace-read-args > + (condition-case error > + (let (;; Variables controlling lazy highlighting while reading > + ;; FROM and TO. > + (lazy-highlight-cleanup nil) > + (isearch-lazy-highlight query-replace-lazy-highlight) > + (isearch-regexp regexp-flag) > + (isearch-regexp-function nil) Highlighting is still incorrect for word replacement ('C-u M-%') and for non-nil 'replace-char-fold'. To handle these cases correctly, 'replace-highlight' uses: (isearch-regexp-function (or replace-regexp-function delimited-flag (and replace-char-fold (not regexp-flag) #'char-fold-to-regexp))) > @@ -2857,22 +2914,8 @@ perform-replace > (when region-noncontiguous-p > - (let ((region-bounds > - (mapcar (lambda (position) > - (cons (copy-marker (car position)) > - (copy-marker (cdr position)))) > - (funcall region-extract-function 'bounds)))) > - (setq region-filter > - (lambda (start end) > - (delq nil (mapcar > - (lambda (bounds) > - (and > - (>= start (car bounds)) > - (<= start (cdr bounds)) > - (>= end (car bounds)) > - (<= end (cdr bounds)))) > - region-bounds)))) > - (add-function :after-while isearch-filter-predicate region-filter))) > + (setq region-filter (replace--region-filter > + (funcall region-extract-function 'bounds)))) I wonder why (add-function :after-while isearch-filter-predicate region-filter) is removed?