From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.bugs Subject: bug#53126: 29.0.50; [PATCH] Lazy highlight/count when reading query-replace string, etc. Date: Tue, 05 Apr 2022 18:38:52 +0200 Message-ID: <87bkxfeb8j.fsf@gmail.com> References: <87sftyweb2.fsf@gmail.com> <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> <86ils2mmbe.fsf@mail.linkov.net> <87v8w2qsee.fsf@gmail.com> <86y20vu9c6.fsf@mail.linkov.net> <875ynt41g9.fsf@gmail.com> <86pmm1azkd.fsf@mail.linkov.net> <87a6d43c6n.fsf@gmail.com> <86r16fz6bw.fsf@mail.linkov.net> <87o81i5zzn.fsf@gmail.com> <86v8vo6c2k.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9569"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1.50 (gnu/linux) Cc: 53126@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 05 18:40:11 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 1nbmDz-0002Jw-1u for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Apr 2022 18:40:11 +0200 Original-Received: from localhost ([::1]:45164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nbmDx-0001Xq-Tw for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Apr 2022 12:40:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nbmDq-0001Ww-1K for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2022 12:40:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nbmDp-0008Nt-Os for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2022 12:40:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nbmDp-0000En-KN for bug-gnu-emacs@gnu.org; Tue, 05 Apr 2022 12:40:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Apr 2022 16:40: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.1649176743831 (code B ref 53126); Tue, 05 Apr 2022 16:40:01 +0000 Original-Received: (at 53126) by debbugs.gnu.org; 5 Apr 2022 16:39:03 +0000 Original-Received: from localhost ([127.0.0.1]:55980 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nbmCt-0000DL-AH for submit@debbugs.gnu.org; Tue, 05 Apr 2022 12:39:03 -0400 Original-Received: from mail-ej1-f50.google.com ([209.85.218.50]:40610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nbmCr-0000Cp-Gq for 53126@debbugs.gnu.org; Tue, 05 Apr 2022 12:39:02 -0400 Original-Received: by mail-ej1-f50.google.com with SMTP id p15so27864567ejc.7 for <53126@debbugs.gnu.org>; Tue, 05 Apr 2022 09:39:01 -0700 (PDT) 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=nXULJH5dhHA76l/gf7B9fQ7Vi0srhYHRM2DC95uH0ds=; b=Qb1+Zd26faTnvkvPiUI71zE1fg0KJfcDpWmYrjZooCGjCqfFOCMcv43P8jwNAWSKzi QeToa5KRfku1wawjbZLD5hzs/AY/k0PLV/qZo4yIHEr5UytI+viNzLJthI84mqJXYkkv Q4iNQLk5tEgELd29TeKXfMphbKqyvALbM83cUq/CE6dyuA/NgNcsQA0oBM2cW61ocfkk ka8dj5KWEE776JR/rrlRqAJOvnD4Npny6xmbaa6yVb6zxyKq1sr7M0h3BN5aPsry5gz1 S/eDQRoRuDBfba4XCF4J4sp8PnPkQx9E3vfVXnB3PBSvls+nS9WB/s04Pf4j4BzZUyxb bPeQ== 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=nXULJH5dhHA76l/gf7B9fQ7Vi0srhYHRM2DC95uH0ds=; b=b4dLbo090WAxbm5C5ydQqaGUlDcq9/R+uBlRKVneyAgE71yE/eV6QVDKnasFBCYyl8 /mqMQDQt6bc7ZRnO0q7kc2YSDgE2gbVzkBiL3laNCyCJPfl6FJMSk14HApydBlkLL+LD z/6t4bksVO2S4UdFIpE4IU+MNXeRzdlqcp5qRv1SUqIusCvGu5dq6AzbTsu5PZGt/zvn f69vPE/6SEhIi/XdnFYjgifYa3JEHimPo/0WE82XY8N9TyxUttfyF9+hKPzDiOxyHhlv qLFGpE1dKf+BT/LXrTAhnELoLJPxxgKjcNOllMCaAPDCI2piNYvahgHdAcJtVEtdqddC UfVA== X-Gm-Message-State: AOAM533FIXgTB/Kk/Wuhh3eUfxpv+BETscEybyyTp7isAZiY0ts5nR+S 7A3Kv7IBJwzfAz7I4Yn6krTCwaiIyKI= X-Google-Smtp-Source: ABdhPJx+2AR+01whGEQZKU+nPB+zVWqLBkligNljGAuKPMX7IbNK/vxYaIRKFAMtS7kLVVjVJtwARg== X-Received: by 2002:a17:907:1b10:b0:6e4:dae9:b8e5 with SMTP id mp16-20020a1709071b1000b006e4dae9b8e5mr4437949ejc.470.1649176735210; Tue, 05 Apr 2022 09:38:55 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::7039]) by smtp.gmail.com with ESMTPSA id v8-20020a50d848000000b0041cb912717asm4722058edj.91.2022.04.05.09.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 09:38:54 -0700 (PDT) In-Reply-To: <86v8vo6c2k.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 04 Apr 2022 19:37:10 +0300") 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:229446 Archived-At: On Mon, 4 Apr 2022 at 19:37, Juri Linkov wrote: >> I've attached a sketch of a macro to help activating the minibuffer lazy >> highlight. It doesn't make query-replace-read-args exactly short, but >> if you like this, I can prepare the patch. > > I realized we already have the macro minibuffer-with-setup-hook, > so we don't need more macros. > > The purpose of minibuffer-with-setup-hook is to set up the minibuffer > to the initial state with buffer-local variables. In case of > lazy-highlighting, we can't set isearch variables directly, > but all isearch variables can be replaced by one variable > that contains a set of lazy-highlight parameters. For example: > > (minibuffer-with-setup-hook > (lambda () > (setq-local lazy-highlight-params > `((case-fold ,case-fold-search) > (regexp ,regexp-flag) > (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))))) > (minibuffer-lazy-highlight-init)) > (query-replace-read-from prompt regexp-flag)) With this code, case-fold-search and all following lazy highlight params are evaluated with the minibuffer as current buffer, which is not the intended behavior. But that's a good point, we don't need a macro. Among several variations, we could make the setup code look like this: (minibuffer-with-setup-hook (minibuffer-lazy-highlight-init :case-fold case-fold-search :regexp regexp-flag ...) (query-replace-read-from prompt regexp-flag)) where now `minibuffer-lazy-highlight-init' is not the function that initializes stuff, but rather a function that returns a closure that initializes stuff. > where minibuffer-lazy-highlight-init does a little more than > minibuffer-lazy-highlight-setup. Or maybe it's not needed, > and minibuffer-lazy-highlight-setup should be enough. > Or maybe instead of setq-local is can let-bind variables. > > Please also note that condition-case can be replaced by > a hook in minibuffer-exit-hook that can remove highlighting > after exiting the minibuffer. If it was a `unwind-protect', I would agree. But I don't know how to simulate a `condition-case'. Specifically, how can we determine if some hook (the minibuffer-exit-hook in this case) is being run "normally" or as part of the recovery from a signaled error? > Alternatively, the same lambda above could be added to > > (add-hook 'minibuffer-setup-hook (lambda () ...)) Why was it again that we want to avoid saying something like this? (let ((case-fold-search whatever) (isearch-regexp regexp-flag)) (minibuffer-with-setup-hook #'minibuffer-lazy-highlight-init (query-replace-read-from prompt regexp-flag)))