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: Wed, 16 Mar 2022 21:09:16 +0100 Message-ID: <875yod1wyb.fsf@gmail.com> 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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11168"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (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 Wed Mar 16 21:10:35 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 1nUZyd-0002fU-B3 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Mar 2022 21:10:35 +0100 Original-Received: from localhost ([::1]:48882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nUZyb-0008Ig-Pc for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Mar 2022 16:10:33 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUZy7-0008IF-Ns for bug-gnu-emacs@gnu.org; Wed, 16 Mar 2022 16:10:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nUZy7-0004Ob-DS for bug-gnu-emacs@gnu.org; Wed, 16 Mar 2022 16:10:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nUZy7-0003hb-4M for bug-gnu-emacs@gnu.org; Wed, 16 Mar 2022 16:10:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 16 Mar 2022 20:10: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.164746136914177 (code B ref 53126); Wed, 16 Mar 2022 20:10:02 +0000 Original-Received: (at 53126) by debbugs.gnu.org; 16 Mar 2022 20:09:29 +0000 Original-Received: from localhost ([127.0.0.1]:52362 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nUZxZ-0003gb-B5 for submit@debbugs.gnu.org; Wed, 16 Mar 2022 16:09:29 -0400 Original-Received: from mail-ej1-f46.google.com ([209.85.218.46]:34691) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nUZxX-0003gM-3y for 53126@debbugs.gnu.org; Wed, 16 Mar 2022 16:09:27 -0400 Original-Received: by mail-ej1-f46.google.com with SMTP id gb39so6517845ejc.1 for <53126@debbugs.gnu.org>; Wed, 16 Mar 2022 13:09:27 -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=GK1S3p0rVp4K+w7JFPVXCBFjs9GbHi8IU6IX98vfGxQ=; b=XlZm+zs2qzgvQ1J4redCSgv2ETFkAQGe6YxfqVi5w/dIBPCO1F0HFNdAnfh6pyv+Kg m9dI0Rx1wm57tkfJiDt9FogpYubRe4GVBgAwtizo/njWLYoUYw4d1QEKMdUr8m/En58x 0Bz9+8TYGvkZZnPFJXoLmw+oSHWRfqw4bQTW6e+yXOOcAvZHQyuNh6ZzkGM5oPVxGcAX yYw0YSYWfVaGWcS7qrCukfo7VWEvlA0/1HNQG1zPdaljXpwpYh0NpT1uUATXku58IwCd B49s24jtRAs6OI3IuXAmbk3KkUMflC7SZSnAss0Tc86aFkoC2Qfsd7ZNK7eIg90ht7UK w4cg== 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=GK1S3p0rVp4K+w7JFPVXCBFjs9GbHi8IU6IX98vfGxQ=; b=rUQSrleWDU2DTGKor6KMXRaXlBgv9uZw3Xv7jItWQTNvtRSEgyhMDupm3cjTRlMhbK ITqdQb5eElBovaHzrZTwaCmYTeH3zJ6j45hAvbAFMH9X3A69qYKydnqdUgMwWYvqSFpS 1P5BXr6Jlzi5a+yR6MCr6OK7TFS8tDKvfRFrIpGG9LKNFmTek7DYh7t8Y6r+gka8Eic/ zTZpfCGmPdsqlssS2LrmWy9IUQkgrl7XudqvtI0qY26Tgl9eS9+20vr5NW/VkddvD3Dq fC2wYrO8ZuQ8kRXu0eLN9BDYPFG52Q7WyEo7VwHkU2QX6exT3EKlKdUn+zKayCzasFGS nBHA== X-Gm-Message-State: AOAM530nTGJPuaJ1I7YN+1PntBXw0aAPmMotBHc9Uff2VH6IOYq72Bc9 4A6oQT4asupDx1qEEcWoVu+OWL4ZXY8= X-Google-Smtp-Source: ABdhPJyY1RZCc7POJKqYmWgXl3q77kErmTaInhFjgvsPaN5OXTD8MpozwwaEMj/a0S7KhfRuGCHOGA== X-Received: by 2002:a17:906:d205:b0:6d1:4446:d950 with SMTP id w5-20020a170906d20500b006d14446d950mr1359257ejz.702.1647461358741; Wed, 16 Mar 2022 13:09:18 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::758e]) by smtp.gmail.com with ESMTPSA id s18-20020a170906779200b006dbb2c2a847sm1319681ejm.125.2022.03.16.13.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 13:09:18 -0700 (PDT) In-Reply-To: <861qz1zqfb.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 16 Mar 2022 20:56:16 +0200") 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:228449 Archived-At: On Wed, 16 Mar 2022 at 20:56, Juri Linkov wrote: >>> So I don't see the need to have this line: >>> >>> (remove-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup) >> >> Okay, but if I remove this line, then all calls to >> minibuffer-lazy-highlight-setup will require a with-minibuffer-setup >> hook. And this will be awkward: >> >> (minibuffer-with-setup-hook (if isearch-lazy-highlight >> #'minibuffer-lazy-highlight-setup >> #'ignore) >> (read-from-minibuffer "Something: ")) > > The answer depends on another question: how do you intend the users > would enable this feature? When to enable it in all minibuffers > (like e.g. minibuffer-depth-indicate-mode does) the users will add > to their init files: > > (add-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup) > > Then removing the user's customization would not be a nice thing to do. > OTOH, minibuffer-with-setup-hook will remove only own hook, not the user's one. > So to allow enabling this feature selectively, minibuffer-with-setup-hook > is not quite awkward. My idea is: - The users of the feature are Elisp programmers / package authors. - I don't think end users can meaningfully do anything directly with this new minibuffer hook. - If package X wants to take advantage of the feature, then it will either add minibuffer-lazy-highlight-setup to the minibuffer-setup-hook unconditionally, or it will define an X-lazy-highlight customization option to control this. So I think the conclusion is that the current approach in my patch is an good way to proceed here? >>> BTW, what is the relation between the minibuffer-lazy-highlight feature >>> and another proposed feature that immediately updates the search in >>> the buffer while editing the string in the minibuffer by isearch-edit-string? >>> Can minibuffer-lazy-highlight be considered as a lightweight version of >>> the buffer search from the minibuffer? >> >> Well, there's a package for that on ELPA (isearch-mb), so extending >> isearch-edit-string to do that seems superfluous now? > > It's still possible to add this feature to isearch-edit-string, > when the change would not be too enormous. I recall squeezing > it into a small patch, but unfortunately it requires changes > in keymap priorities. I would suggest taking a look at isearch-mb. I think the code is pretty tight, and I would be unable to shorten the implementation other than by deleting comment :-) >>>> There are a few more we could add (perhaps later), >>>> such as `occur' and `keep-lines'. >>> >>> I tried (add-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup) >>> in the minibuffer of 'occur' and others, and it works nicely. >>> Maybe it could even semi-deprecate the package re-builder.el. >>> >>> Thanks for this generally usable feature. >> >> By the way, this is a byproduct of that long discussion that led to >> isearch-mb, so it was not all in vain :-). > > Are you sure these features can't be combined? One feature basically > runs isearch-search-and-update in the buffer from the minibuffer, > and this feature runs isearch-lazy-highlight-new-loop. For one thing, isearch-mode has 2 essential commands (repeat forward and backwards), a couple more necessary ones (quit, abort, scroll, beginning/end of buffer, mode toggles), and then a number of commands that end the search with a special action (query-replace, etc.). These little details add up to the 283 lines in isearch-mb.el currently has. >>>> - There's no customization variable to enable the minibuffer lazy >>>> highlight. The rationale is that each command that will use it should >>>> define its own user option (or use an existing one). For >>>> `isearch-edit-string' it's `isearch-lazy-highlight'; for >>>> `query-replace' it's `query-replace-lazy-highlight'; and so on. >>> >>> A common customizable option to enable this everywhere would be nice too. >>> Maybe disabling is already possible by customizing >>> 'minibuffer-lazy-count-format' to nil? Then the checks for >>> non-nil 'minibuffer-lazy-count-format' could be added to >>> more places, such as to wrap the whole '(condition-case error' >>> in query-replace-read-args with the 'when' condition, etc. >> >> Yes, the user can set minibuffer-lazy-count-format to nil to get rid of >> the lazy count. >> >> Concerning query-replace, why would anyone want to have lazy highlight >> during the perform-replace loop, but not earlier? I'm not a fan of >> adding a custom option here, not because it would be hard, but because >> it seems totally unnecessary. > > Maybe a new option would make sense for the same reason why there is > the option isearch-lazy-count? Okay, I'm not against this, but let's think about the names of these user options. The existing option is named query-replace-lazy-highlight, which seems to exactly describe the new feature. The existing feature would more specifically be called perform-replace-lazy highlight.