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: Fri, 25 Mar 2022 10:39:12 +0200 Organization: LINKOV.NET Message-ID: <86ils2mmbe.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> <86zglrl4gq.fsf@mail.linkov.net> <87ee32yk7v.fsf@gmail.com> <861qz1zqfb.fsf@mail.linkov.net> <875yod1wyb.fsf@gmail.com> <86mtho5y56.fsf@mail.linkov.net> <87sfrgz979.fsf@gmail.com> <861qz0475w.fsf@mail.linkov.net> <87sfrd2cbb.fsf@gmail.com> <86fsnc4fvm.fsf@mail.linkov.net> <878rsz6um2.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="17501"; 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 Fri Mar 25 10:14:45 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 1nXg1t-0004T7-JM for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 25 Mar 2022 10:14:45 +0100 Original-Received: from localhost ([::1]:47304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXg1s-0000oa-DG for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 25 Mar 2022 05:14:44 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:41882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXfyK-0006Jw-2S for bug-gnu-emacs@gnu.org; Fri, 25 Mar 2022 05:11:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56210) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nXfyH-0001ze-Ui for bug-gnu-emacs@gnu.org; Fri, 25 Mar 2022 05:11:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nXfyH-0000t4-Nw for bug-gnu-emacs@gnu.org; Fri, 25 Mar 2022 05:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 25 Mar 2022 09:11:01 +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.16481994233363 (code B ref 53126); Fri, 25 Mar 2022 09:11:01 +0000 Original-Received: (at 53126) by debbugs.gnu.org; 25 Mar 2022 09:10:23 +0000 Original-Received: from localhost ([127.0.0.1]:50107 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nXfxf-0000sB-62 for submit@debbugs.gnu.org; Fri, 25 Mar 2022 05:10:23 -0400 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:48029) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nXfxd-0000rr-2L for 53126@debbugs.gnu.org; Fri, 25 Mar 2022 05:10:22 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id B350FC000F; Fri, 25 Mar 2022 09:10:12 +0000 (UTC) In-Reply-To: <878rsz6um2.fsf@gmail.com> (Augusto Stoffel's message of "Thu, 24 Mar 2022 20:03:33 +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:228919 Archived-At: > @@ -365,14 +372,49 @@ query-replace-read-args > - (let* ((from (query-replace-read-from prompt regexp-flag)) > - (to (if (consp from) (prog1 (cdr from) (setq from (car from))) > - (query-replace-read-to from prompt regexp-flag)))) > - (list from to > - (or (and current-prefix-arg (not (eq current-prefix-arg '-))) > - (and (plist-member (text-properties-at 0 from) 'isearch-regexp-function) > - (get-text-property 0 'isearch-regexp-function from))) > - (and current-prefix-arg (eq current-prefix-arg '-)))))) The name of the function is `query-replace-read-args'. And now most of the function is dealing with highlighting: > + (condition-case error > + (let (;; Variables controlling lazy highlighting while reading > + ;; FROM and TO. > + (isearch-case-fold-search case-fold-search) > + (isearch-lazy-highlight query-replace-lazy-highlight) > + (isearch-regexp regexp-flag) > + (isearch-regexp-function (or replace-regexp-function > + (and current-prefix-arg > + (not (eq current-prefix-arg '-))) > + (and replace-char-fold > + (not regexp-flag) > + #'char-fold-to-regexp))) > + (lazy-highlight-cleanup nil) > + (minibuffer-lazy-highlight-transform > + (lambda (string) > + (let* ((split (query-replace--split-string string)) > + (from-string (if (consp split) (car split) split))) > + (when (and case-fold-search search-upper-case) > + (setq isearch-case-fold-search > + (isearch-no-upper-case-p from-string regexp-flag))) > + from-string))) > + from to) > + (when query-replace-lazy-highlight > + (add-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup) > + (when (use-region-p) > + (letrec ((region-filter (replace--region-filter > + (funcall region-extract-function 'bounds))) > + (cleanup (lambda () > + (remove-function isearch-filter-predicate region-filter) > + (remove-hook 'minibuffer-exit-hook cleanup)))) > + (add-function :after-while isearch-filter-predicate region-filter) > + (add-hook 'minibuffer-exit-hook cleanup)))) > + (setq from (query-replace-read-from prompt regexp-flag)) > + (setq to (if (consp from) > + (prog1 (cdr from) (setq from (car from))) > + (query-replace-read-to from prompt regexp-flag))) > + (list from to > + (or (and current-prefix-arg (not (eq current-prefix-arg '-))) > + (and (plist-member (text-properties-at 0 from) 'isearch-regexp-function) > + (get-text-property 0 'isearch-regexp-function from))) > + (and current-prefix-arg (eq current-prefix-arg '-)))) > + (t (lazy-highlight-cleanup) > + (signal (car error) (cdr error)))))) This highlighting needs to be refactored from `query-replace-read-args' into a separate highlighting function.