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: Sun, 20 Mar 2022 20:59:40 +0100 Message-ID: <87o820iedv.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> <86sfrjia5u.fsf@mail.linkov.net> <87ilseyks7.fsf@gmail.com> <868rt9wwji.fsf@mail.linkov.net> <871qz11w82.fsf@gmail.com> <86ilsc7e31.fsf@mail.linkov.net> <87tubwz9dd.fsf@gmail.com> <86sfrc2zr8.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9660"; 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 Sun Mar 20 21:00:20 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 1nW1io-000228-RB for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Mar 2022 21:00:14 +0100 Original-Received: from localhost ([::1]:41988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nW1in-0000re-Ce for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Mar 2022 16:00:13 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nW1ic-0000rR-VY for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2022 16:00:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41269) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nW1ic-00053p-Lp for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2022 16:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nW1ic-0003VH-IW for bug-gnu-emacs@gnu.org; Sun, 20 Mar 2022 16:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Mar 2022 20:00: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.164780639213427 (code B ref 53126); Sun, 20 Mar 2022 20:00:02 +0000 Original-Received: (at 53126) by debbugs.gnu.org; 20 Mar 2022 19:59:52 +0000 Original-Received: from localhost ([127.0.0.1]:35166 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nW1iR-0003UU-AK for submit@debbugs.gnu.org; Sun, 20 Mar 2022 15:59:51 -0400 Original-Received: from mail-ej1-f43.google.com ([209.85.218.43]:33708) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nW1iP-0003UG-AA for 53126@debbugs.gnu.org; Sun, 20 Mar 2022 15:59:50 -0400 Original-Received: by mail-ej1-f43.google.com with SMTP id pv16so26323168ejb.0 for <53126@debbugs.gnu.org>; Sun, 20 Mar 2022 12:59:49 -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=dYLo2jfmA/TFq28VFEowTW/DA93z7suGP6Bh7sTxZxI=; b=fJGiE8LT3LWEVCKQ04Ux2MRv80Vt4L6uXH+DMD5IAo5Xq+iSKVqMVQ5VhMJr6ewmlz X/gMMXK205z4lFdOTdsiZtAE0okIRqH8oJfnPbz4XdKRq5CxOG86zEhYC6vBW/EcjINN GhzOLQi+F1yiY+16SjOdpy0msbY97CYQGF1DFa4QhVe1W58cCApGWQLr3lzzzLT0u062 4bCvaaz+UotGFnTtkyapCYr3jgFrZ3iEWdgOwJTXyjaGzhxeWS9C8J+1ZRcYP6yMgHWD 3bhWzDbO4gSd3YzlRqJfAPjZHc9AF6ceTJBex7v/2FLdXKWwO3Z6kYfOS66ALqt3f92d yfOg== 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=dYLo2jfmA/TFq28VFEowTW/DA93z7suGP6Bh7sTxZxI=; b=DbO6FF3/w2KwvfYSfGNJPeN10Qdw34NZaM5YF4TyxQkSURhhE69tfMbAjImXChdB8b 7KEvd5JM5CcpQ74yjtJ0+NztSc61SaMr6JfvtIDnEtiAV33MKrGIXvmYL5us167tsBCM OmxrBabv3XGG+VQlwMnIm2jBvspdVt1Wa2XxFlRhSITaLj/Iq+piwwSMQqW79mQoHt/+ S8xR6nRbdX7tknUPeJHqDKGGeGJFu6fUMcIxn9o+a3yKqDb5hThUsxvcYRuV7hc/C6yw Y4OkhkLwCryVxnzET1hSrb13fXURkjH3wXclgmjIz3OOYNfz3ztbuUmF3ooTN2R6g3zb xU3g== X-Gm-Message-State: AOAM5305V8NyXrfNHBwYov21QayiDjzLAS4d3HxsJHT3ldb30xH6Jfpv slhQgAUB0iV+Jfu3BabJqYBtrYLnanGnLg== X-Google-Smtp-Source: ABdhPJyXvzDy9JSXqvJ3Sev12a5eZLcVoNmBOC2BNKdedYSIe7ywd4dmPW+UsgJaGgu3DtkaGr6L0g== X-Received: by 2002:a17:906:7746:b0:6ce:a12e:489f with SMTP id o6-20020a170906774600b006cea12e489fmr17287531ejn.551.1647806382898; Sun, 20 Mar 2022 12:59:42 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::758e]) by smtp.gmail.com with ESMTPSA id p14-20020a05640210ce00b00413211746d4sm7083919edu.51.2022.03.20.12.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Mar 2022 12:59:42 -0700 (PDT) In-Reply-To: <86sfrc2zr8.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 20 Mar 2022 21:24:43 +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:228636 Archived-At: --=-=-= Content-Type: text/plain On Sun, 20 Mar 2022 at 21:24, Juri Linkov wrote: > Could you please split it to more logically separate patches? > > 1. a patch that removes checks for 'isearch-mode (null isearch-message-function)' > and adds '(setq-local isearch-lazy-count nil)'. > It could also contain more changes in comint.el etc > from your earlier patch from 14 May 2021. > > 2. a patch that adds and runs 'lazy-count-update-hook'. > > 3. a patch with minibuffer-lazy-highlight feature in isearch.el. > > Then what will remain to do is to decide how it would be better to activate > the minibuffer-lazy-highlight feature. Okay. Points 1 and 2 are hard to disentangle, and 1 strictly is only necessary because of 2. Also, separating things further risks introducing bugs in code that has been tested quite a bit by now. So my patch 00001 is for your points 1 and 2, patch 0002 is for point 3, and patch 0003 adds lazy highlight to isearch-edit-string, where I guess there is no controversy about what the configuration variables should be. Feel free to copy-edit my patches before merging if desired. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-Add-lazy-highlight-to-isearch-edit-string.patch >From e5b00cd015043eb7c3eca564994babfa2c2f8e0e Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Sun, 20 Mar 2022 20:49:32 +0100 Subject: [PATCH 3/3] Add lazy highlight to 'isearch-edit-string' * lisp/isearch.el (isearch-edit-string): Activate lazy highlight and lazy count, provided 'isearch-lazy-highlight' respectively 'isearch-lazy-count' are non-nil. --- lisp/isearch.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/isearch.el b/lisp/isearch.el index 1ee5f2e9a8..1a83586ef8 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -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)) (setq isearch-new-string (read-from-minibuffer (isearch-message-prefix nil isearch-nonincremental) -- 2.35.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Allow-lazy-highlight-and-match-count-while-reading-f.patch >From 10290ac4e7f816ab33edad896448ac7d26951225 Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Sun, 20 Mar 2022 20:46:31 +0100 Subject: [PATCH 2/3] Allow lazy highlight and match count while reading from minibuffer * lisp/isearch.el (minibuffer-lazy-highlight-setup): New function, can be added to 'minibuffer-setup-hook' to enable lazy highlight and count while reading from minibuffer. (minibuffer-lazy-count-format, minibuffer-lazy-highlight-transform, minibuffer-lazy-highlight--overlay, minibuffer-lazy-highlight--count, minibuffer-lazy-highlight--after-change, minibuffer-lazy-highlight--exit): Auxiliary variables and functions implementing the lazy highlight functionality while reading from minibuffer. --- lisp/isearch.el | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/lisp/isearch.el b/lisp/isearch.el index b1951a8659..1ee5f2e9a8 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -4346,6 +4346,69 @@ isearch-lazy-highlight-buffer-update (run-at-time lazy-highlight-interval nil 'isearch-lazy-highlight-buffer-update))))))))) + +;; Reading from minibuffer with lazy highlight and match count + +(defcustom minibuffer-lazy-count-format "%s " + "Format of the total number of matches for the prompt prefix." + :type '(choice (const :tag "Don't display a count" nil) + (string :tag "Display match count" "%s ")) + :group 'lazy-count + :version "29.1") + +(defvar minibuffer-lazy-highlight-transform #'identity + "Function to transform minibuffer text into a `isearch-string' for highlighting.") + +(defvar minibuffer-lazy-highlight--overlay nil + "Overlay for minibuffer prompt updates.") + +(defun minibuffer-lazy-highlight--count () + "Display total match count in the minibuffer prompt." + (when minibuffer-lazy-highlight--overlay + (overlay-put minibuffer-lazy-highlight--overlay + 'before-string + (and isearch-lazy-count-total + (not isearch-error) + (format minibuffer-lazy-count-format + isearch-lazy-count-total))))) + +(defun minibuffer-lazy-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 minibuffer-lazy-highlight-transform string)) + (isearch-lazy-highlight-new-loop))))) + +(defun minibuffer-lazy-highlight--exit () + "Unwind changes from `minibuffer-lazy-highlight-setup'." + (remove-hook 'after-change-functions + #'minibuffer-lazy-highlight--after-change) + (remove-hook 'lazy-count-update-hook #'minibuffer-lazy-highlight--count) + (remove-hook 'minibuffer-exit-hook #'minibuffer-lazy-highlight--exit) + (setq minibuffer-lazy-highlight--overlay nil) + (when lazy-highlight-cleanup + (lazy-highlight-cleanup))) + +(defun minibuffer-lazy-highlight-setup () + "Set up minibuffer for lazy highlight of matches in the original window. + +This function is intended to be added to `minibuffer-setup-hook'. +Note that several other isearch variables influence the lazy +highlighting, including `isearch-regexp', +`isearch-lazy-highlight' and `isearch-lazy-count'." + (remove-hook 'minibuffer-setup-hook #'minibuffer-lazy-highlight-setup) + (add-hook 'after-change-functions + #'minibuffer-lazy-highlight--after-change) + (add-hook 'lazy-count-update-hook #'minibuffer-lazy-highlight--count) + (add-hook 'minibuffer-exit-hook #'minibuffer-lazy-highlight--exit) + (setq minibuffer-lazy-highlight--overlay + (and minibuffer-lazy-count-format + (make-overlay (point-min) (point-min) (current-buffer) t))) + (minibuffer-lazy-highlight--after-change nil nil nil)) + + (defun isearch-resume (string regexp word forward message case-fold) "Resume an incremental search. STRING is the string or regexp searched for. -- 2.35.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-hook-lazy-count-update-hook.patch >From 3eb2ec884310fc86bde1d9a897a266e5011fe9ec Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Sun, 20 Mar 2022 20:43:10 +0100 Subject: [PATCH 1/3] New hook, lazy-count-update-hook * lisp/isearch.el (lazy-count-update-hook): New hook allowing to display the lazy count in special ways. (isearch-lazy-highlight-new-loop, isearch-lazy-highlight-buffer-update): Run `lazy-count-update-hook' at appropriate times. * lisp/comint.el (comint-history-isearch-setup, comint-history-isearch-end): Make sure no lazy count is displayed. * lisp/simple.el (minibuffer-history-isearch-setup): Make sure no lazy count is displayed. --- lisp/comint.el | 2 ++ lisp/isearch.el | 21 +++++++++++++++------ lisp/simple.el | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index 4c82e74e4b..56082f622a 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 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) + (kill-local-variable 'isearch-lazy-count) (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 8970216398..b1951a8659 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -3990,6 +3990,8 @@ isearch-lazy-highlight-error (defvar isearch-lazy-count-current nil) (defvar isearch-lazy-count-total nil) (defvar isearch-lazy-count-hash (make-hash-table)) +(defvar lazy-count-update-hook nil + "Hook run after new lazy count results are computed.") (defun lazy-highlight-cleanup (&optional force procrastinate) "Stop lazy highlighting and remove extra highlighting from current buffer. @@ -4048,7 +4050,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 @@ -4067,7 +4069,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)) + (run-hooks 'lazy-count-update-hook)))) (setq isearch-lazy-highlight-window-start-changed nil) (setq isearch-lazy-highlight-window-end-changed nil) (setq isearch-lazy-highlight-error isearch-error) @@ -4120,13 +4125,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 ;; 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)) + (run-hooks 'lazy-count-update-hook)))) (defun isearch-lazy-highlight-search (string bound) "Search ahead for the next or previous match, for lazy highlighting. @@ -4327,12 +4334,14 @@ 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)) + (run-hooks 'lazy-count-update-hook)) (setq isearch-lazy-highlight-timer (run-at-time lazy-highlight-interval nil 'isearch-lazy-highlight-buffer-update))))))))) diff --git a/lisp/simple.el b/lisp/simple.el index accc119e2b..61319b6060 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2840,6 +2840,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 nil) (add-hook 'isearch-mode-end-hook 'minibuffer-history-isearch-end nil t)) (defun minibuffer-history-isearch-end () -- 2.35.1 --=-=-=--