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: Thu, 17 Mar 2022 20:06:54 +0100 Message-ID: <87tubwz9dd.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> 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="15326"; 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 Thu Mar 17 20:08:21 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 1nUvTx-0003n3-Nk for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Mar 2022 20:08:21 +0100 Original-Received: from localhost ([::1]:33394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nUvTw-00008N-6b for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Mar 2022 15:08:20 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:40294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUvTe-000070-Pl for bug-gnu-emacs@gnu.org; Thu, 17 Mar 2022 15:08:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33076) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nUvTe-0004Oo-Gc for bug-gnu-emacs@gnu.org; Thu, 17 Mar 2022 15:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nUvTe-0002m0-B8 for bug-gnu-emacs@gnu.org; Thu, 17 Mar 2022 15:08: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: Thu, 17 Mar 2022 19:08: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.164754402510595 (code B ref 53126); Thu, 17 Mar 2022 19:08:02 +0000 Original-Received: (at 53126) by debbugs.gnu.org; 17 Mar 2022 19:07:05 +0000 Original-Received: from localhost ([127.0.0.1]:55206 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nUvSi-0002ko-Nd for submit@debbugs.gnu.org; Thu, 17 Mar 2022 15:07:05 -0400 Original-Received: from mail-ej1-f45.google.com ([209.85.218.45]:33382) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nUvSh-0002kK-CB for 53126@debbugs.gnu.org; Thu, 17 Mar 2022 15:07:04 -0400 Original-Received: by mail-ej1-f45.google.com with SMTP id pv16so12829765ejb.0 for <53126@debbugs.gnu.org>; Thu, 17 Mar 2022 12:07:03 -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=2U2i5qeBUBOQo5r52AMVeGb0t5xWDgoH97eOxdhgWJI=; b=XyjR5/XH42cmgsMjEQ+d2U2MvhYKb8F8F544MdOTWBa9heYvllbrDwbwcbOHNz9/xn zLmSg/QklqTEXZp6pTG6I0bm0r0HvRRU48tqlOk2o6bX5lKLixzvIN4ytQm+el2Yo3kp tU0TIA7yfbUUGDAf9Tjp6VZj71mWDtdga55zL3fPq1f77/Gu37PhE6gbKbJ+k++1jB5z FmyfjubRcbWBRQEgDYxKiL+1+WBAS03Brko7IxIqMycl2uccKsrDY9k5D+fPXOaGHXFN AMzfc2NVWlSqNSDCvzII2pUhC67lc2g2vhpJHoSj/d4npzoY8MUTrPc90EVJuX85hTP0 9lrg== 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=2U2i5qeBUBOQo5r52AMVeGb0t5xWDgoH97eOxdhgWJI=; b=bNlUr7g7p1gP6hz2r0cFNaJ3Y+k4NPEuvvtj6yTylewEK4bMe2K80ajrpvaJ5XdhmI d2jrM8+dRi/QYMiYlF+dcccgTmJ/tCrmS2F4iZFC26EwjzuvOGIzNoUZ4YvhlVpvslQc sGtf+ZCaO3+GVOoM1Mk/1Y+wFG9a36y7YwDJr2th3Q9qsLPKIEw6kZO1FVYNq6W7l9vi B9vUMQ/LUXhBV0m8oTNmICyYuaPEtrOlp9J7OFkbZbSenqKFwDwb7FkkuK/i34XL1urS J8mdIfapEhmrfcZje3FPJsB/W5F6w9o8vqixpsC87qgJmAm439RTBboh5WiwPdvziNZe r0rQ== X-Gm-Message-State: AOAM530DGWCOADxCMRGnNABg/ghtxcKxL6camXSXaDh+tSeHd1xhboRK DY/4Q5vdnW4ztA3gxOlYSRyP/DFwfqo= X-Google-Smtp-Source: ABdhPJzbiTFJNvrpi0BQkj2a/HWOANkxb5P86XnECUoop+dxL3Mi5s/Uie/88LwN0KN0oZ4BAmvNYg== X-Received: by 2002:a17:906:2991:b0:6cc:fc18:f10c with SMTP id x17-20020a170906299100b006ccfc18f10cmr5737529eje.744.1647544017193; Thu, 17 Mar 2022 12:06:57 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::758e]) by smtp.gmail.com with ESMTPSA id si13-20020a170906cecd00b006cded0c5ee2sm2840370ejb.61.2022.03.17.12.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 12:06:56 -0700 (PDT) In-Reply-To: <86ilsc7e31.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 17 Mar 2022 19:05:34 +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:228504 Archived-At: --=-=-= Content-Type: text/plain On Thu, 17 Mar 2022 at 19:05, Juri Linkov wrote: > OTOH, your changes that add lazy-count-update-hook and remove > '(null isearch-message-function)' can be already pushed. > Could you please send a separate patch for pushing with these changes only? > > Then the patch with minibuffer-lazy-count feature will be shorter. There it is: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Allow-lazy-highlight-and-match-count-while-reading-f.patch >From 3de37cfec647cedd69032df072a1176970224ecb Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Thu, 17 Mar 2022 20:02:13 +0100 Subject: [PATCH] Allow lazy highlight and match count while reading from minibuffer * lisp/isearch.el (lazy-count-update-hook): New hook allowing to display the lazy count in special ways. (isearch-edit-string): Add lazy highlight and count of matching text. (isearch-lazy-highlight-new-loop, isearch-lazy-highlight-buffer-update): Use `isearch-lazy-count-display-function' instead of hardcoded call to `isearch-message'. (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, minibuffer-lazy-highlight-setup): Variables and functions implementing the lazy highlight functionality while reading from minibuffer. * 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 | 86 +++++++++++++++++++++++++++++++++++++++++++++---- lisp/simple.el | 1 + 3 files changed, 83 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..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) @@ -3990,6 +3992,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 +4052,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 +4071,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 +4127,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,16 +4336,81 @@ 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))))))))) + +;; 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. 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 --=-=-=--