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.devel Subject: Re: [ELPA?] Controlling Isearch from the minibuffer Date: Sun, 16 May 2021 13:00:48 +0200 Message-ID: <877djzymcf.fsf@gmail.com> References: <87zgx5cz33.fsf@gmail.com> <87o8djohqf.fsf@mail.linkov.net> <87eeeenxqq.fsf@gmail.com> <87h7jath3m.fsf@mail.linkov.net> <87mtt0wj37.fsf@gmail.com> <87cztvx4dc.fsf@mail.linkov.net> <87bl9fr7xh.fsf@gmail.com> <87tun6n12v.fsf@mail.linkov.net> <87lf8i8kba.fsf_-_@gmail.com> <878s4hxly0.fsf@gmail.com> <87im3l5g9y.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="5033"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cc: emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 16 13:02:44 2021 Return-path: Envelope-to: ged-emacs-devel@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 1liEXj-0001AZ-R0 for ged-emacs-devel@m.gmane-mx.org; Sun, 16 May 2021 13:02:43 +0200 Original-Received: from localhost ([::1]:40394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1liEXi-0000t3-Qt for ged-emacs-devel@m.gmane-mx.org; Sun, 16 May 2021 07:02:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1liEW2-0008D7-BK for emacs-devel@gnu.org; Sun, 16 May 2021 07:00:58 -0400 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:41854) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1liEVy-00018t-A4 for emacs-devel@gnu.org; Sun, 16 May 2021 07:00:57 -0400 Original-Received: by mail-ej1-x62b.google.com with SMTP id k10so4908020ejj.8 for ; Sun, 16 May 2021 04:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=dAI9VU4pHqhIeP+RrrMjJlSUdFZCEO1i0eWgdq6nb0o=; b=s9tk412TjD8WYELy2MbqEyWMovI0xA7yON+3mMpMMu85Ss8btW0ncP+rqsw04qjtem Fj9U0lKuRNHmITSfp9xLOiXs8ZofdD/flJF2ZG/gXp3OkAZEI6IiQGJ/vHPsLHVUjsqa T0ZRsBrXtWbg2J+H0Mi9DwS/PiJ/NoJ2wcofYiAon/m93hruDZSOjWxsoAN4p7MnyoH/ sgSwGlGcYGFQ/Q5IFYfGCz9lYTQa5YKqphYFhYqbJVSIL4wJKLzpPiFR7EgS2C1HQ1+v 51uLxfhZeM8ZDH/llEDFMlHBBLyiZlF8cwNZt5P+hAVutjalnGugEXLlNev14DtWRSGs /iuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=dAI9VU4pHqhIeP+RrrMjJlSUdFZCEO1i0eWgdq6nb0o=; b=E4XxVUUTt86YELilsL0mfkZNfRvG4TmaqOlKQPkFftyk8eE1EQ75zi2ZO8B/Dczhx5 vJpgWizoam/DlX4ZWnga45e5qlwdcOkhqCBbqr9/OorcsQ+vYdizaK/ufCQYBs3SPo8Y scWmhxg38KCW1/tZKjjx/0DGVOqHeB0W+24MJb09O1FwIkpI2UGuLNPm3AaSbfa0BnRC H0k7w4847XCcUtd5JgG2+lrioWnHgeAfE08iUhkquRQLAXU/Cng151MB9crMeuYvvQdW 7HcRhFIzZs44kL5FxISgjW70zSxWTQ15zPe/QHKbbQX4mrhn6UMl1K8aL1FKC3GRdAH9 e9og== X-Gm-Message-State: AOAM532J71W/xGLknfW86wMo1MqlxbACjvkraxSUBF+sP5HwKDIB/DA8 X+ZfPkWdjOCBOeWga1khpqdgfpGVjZM= X-Google-Smtp-Source: ABdhPJwPfZvPwwDs2cPJ0x57DiQF6PWBkCe+WeUPYx/fU9D5wo4lCGEVXorahSFvn7FdUUHNuFZ2ag== X-Received: by 2002:a17:906:c352:: with SMTP id ci18mr10050366ejb.149.1621162850456; Sun, 16 May 2021 04:00:50 -0700 (PDT) Original-Received: from ars3 ([2a02:908:2211:8540::66]) by smtp.gmail.com with ESMTPSA id dn4sm1327406edb.88.2021.05.16.04.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 May 2021 04:00:49 -0700 (PDT) In-Reply-To: <87im3l5g9y.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 14 May 2021 21:20:09 +0300") Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=arstoffel@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:269350 Archived-At: --=-=-= Content-Type: text/plain On Fri, 14 May 2021 at 21:20, Juri Linkov wrote: > Do you see the correct lazy-count values in the minibuffer and comint > after removing `(null isearch-message-function)'? > >> - (funcall (or isearch-message-function #'isearch-message))) >> + (isearch-message)) I would see the number of matches in the current line, which is only logical. But the relevant information here would be number of candidates in the minibuffer/comint history that match the string, as opposed to the total number of matches among those candidates. So I believe these modes should implement their own lazy count. I just disabled the count in the new patch below. > > What do you think about adding `isearch-message' as the default value > of isearch-message-function? E.g. > > #+begin_src diff > -(defvar isearch-message-function nil > +(defvar isearch-message-function #'isearch-message > #+end_src Yes, this is nicer, assuming no one relies on this variable usually being nil up to now. Now, I took a closer look at the history of changes around lazy highlight and the interactions with other features seems very tricky. I'm not super confident about the patch I'm attaching, but if you are willing to review it and test a bit, I hope it helps. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Don-t-give-special-treatment-to-the-isearch-message-.patch >From 98226106351e2edba99ea647abf1fcd059e2e79d Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Fri, 14 May 2021 11:58:35 +0200 Subject: [PATCH] Don't give special treatment to the isearch-message function * lisp/isearch.el (isearch-message-function): new default value. (isearch-message): just defer to isearch-message-function, if non-nil. (isearch-standard-message): new function, corresponds to the old `isearch-message'. (isearch-mode-end-hook-quit, isearch-update, with-isearch-suspended, isearch-del-char, isearch-search-and-update, isearch-ring-adjust, isearch-lazy-highlight-new-loop, isearch-lazy-highlight-buffer-update): just call `isearch-message', no need to check isearch-message-function anymore. * lisp/comint.el (comint-history-isearch-setup): disable lazy count, since this only counts matches in the current line. (comint-history-isearch-end): kill local variables instead of setting them to the presumed previous value. (comint-history-isearch-message): call isearch-standard-message explicitly where needed. * lisp/simple.el (minibuffer-history-isearch-setup): disable lazy count, since this only counts matches in the current line. (minibuffer-history-isearch-message): call `isearch-standard-message' explicitly where needed. --- lisp/comint.el | 18 ++++++++++-------- lisp/isearch.el | 30 +++++++++++++++++------------- lisp/simple.el | 5 +++-- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index ef34174305..cc062e3e5a 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1487,7 +1487,7 @@ comint-history-isearch-setup (and (eq comint-history-isearch 'dwim) ;; Point is at command line. (comint-after-pmark-p)))) - (setq isearch-message-prefix-add "history ") + (setq-local isearch-message-prefix-add "history ") (setq-local isearch-search-fun-function #'comint-history-isearch-search) (setq-local isearch-message-function @@ -1496,17 +1496,19 @@ 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 () "Clean up the comint after terminating Isearch in comint." (if comint-history-isearch-message-overlay (delete-overlay comint-history-isearch-message-overlay)) - (setq isearch-message-prefix-add nil) - (setq isearch-search-fun-function 'isearch-search-fun-default) - (setq isearch-message-function nil) - (setq isearch-wrap-function nil) - (setq isearch-push-state-function nil) + (kill-local-variable 'isearch-message-prefix-add) + (kill-local-variable 'isearch-search-fun-function) + (kill-local-variable 'isearch-message-function) + (kill-local-variable 'isearch-wrap-function) + (kill-local-variable 'isearch-push-state-function) + (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))) @@ -1588,11 +1590,11 @@ comint-history-isearch-message Otherwise, it displays the standard Isearch message returned from the function `isearch-message'." (if (not (and isearch-success (not isearch-error))) - ;; Use standard function `isearch-message' when not in comint prompt, + ;; Use `isearch-standard-message' when not in comint prompt, ;; or search fails, or has an error (like incomplete regexp). ;; This function displays isearch message in the echo area, ;; so it's possible to see what is wrong in the search string. - (isearch-message c-q-hack ellipsis) + (isearch-standard-message c-q-hack ellipsis) ;; Otherwise, put the overlay with the standard isearch prompt over ;; the initial comint prompt. (if (overlayp comint-history-isearch-message-overlay) diff --git a/lisp/isearch.el b/lisp/isearch.el index 536c76ea5d..f545bf5558 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -209,9 +209,10 @@ isearch-mode-end-hook (defvar isearch-mode-end-hook-quit nil "Non-nil while running `isearch-mode-end-hook' if the user quits the search.") -(defvar isearch-message-function nil - "Function to call to display the search prompt. -If nil, use function `isearch-message'.") +(defvar isearch-message-function #'isearch-standard-message + "Function called by `isearch-message' to display the search prompt. +This should be nil to supress printing messages, or a function +taking the same arguments as `isearch-standard-message'.") (defvar isearch-wrap-function nil "Function to call to wrap the search when search is failed. @@ -1343,7 +1344,7 @@ isearch-update (null executing-kbd-macro)) (progn (if (not (input-pending-p)) - (funcall (or isearch-message-function #'isearch-message))) + (isearch-message)) (if (and isearch-slow-terminal-mode (not (or isearch-small-window (pos-visible-in-window-group-p)))) @@ -1731,7 +1732,7 @@ with-isearch-suspended (isearch-update-from-string-properties isearch-string) ;; Restore the minibuffer message before moving point. - (funcall (or isearch-message-function #'isearch-message) nil t) + (isearch-message nil t) ;; Set point at the start (end) of old match if forward (backward), ;; so after exiting minibuffer isearch resumes at the start (end) @@ -2504,7 +2505,7 @@ isearch-del-char isearch-message (mapconcat 'isearch-text-char-description isearch-string ""))) ;; Do the following before moving point. - (funcall (or isearch-message-function #'isearch-message) nil t) + (isearch-message nil t) ;; Use the isearch-other-end as new starting point to be able ;; to find the remaining part of the search string again. ;; This is like what `isearch-search-and-update' does, @@ -2765,7 +2766,7 @@ isearch-search-and-update (isearch-no-upper-case-p isearch-string isearch-regexp)))) ;; Not regexp, not reverse, or no match at point. ;; Do the following before moving point. - (funcall (or isearch-message-function #'isearch-message) nil t) + (isearch-message nil t) (if (and isearch-other-end (not isearch-adjusted)) (goto-char (if isearch-forward isearch-other-end (min isearch-opoint @@ -3187,7 +3188,7 @@ isearch-ring-adjust (isearch-ring-adjust1 advance) (if search-ring-update (progn - (funcall (or isearch-message-function #'isearch-message) nil t) + (isearch-message nil t) (isearch-search) (isearch-push-state) (isearch-update)) @@ -3260,6 +3261,11 @@ isearch-complete-edit (defun isearch-message (&optional c-q-hack ellipsis) "Generate and print the message string." + (when isearch-message-function + (funcall isearch-message-function c-q-hack ellipsis))) + +(defun isearch-standard-message (&optional c-q-hack ellipsis) + "Generate and print the standard Isearch message string." ;; N.B.: This function should always be called with point at the ;; search point, because in certain (rare) circumstances, undesired @@ -3940,7 +3946,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 @@ -4010,9 +4016,7 @@ isearch-lazy-highlight-new-loop lazy-highlight-initial-delay) nil '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 @@ -4220,7 +4224,7 @@ 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 diff --git a/lisp/simple.el b/lisp/simple.el index 0255f69e42..8deb07b31a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2733,6 +2733,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 () @@ -2794,11 +2795,11 @@ minibuffer-history-isearch-message Otherwise, it displays the standard isearch message returned from the function `isearch-message'." (if (not (and (minibufferp) isearch-success (not isearch-error))) - ;; Use standard function `isearch-message' when not in the minibuffer, + ;; Use `isearch-standard-message' when not in the minibuffer, ;; or search fails, or has an error (like incomplete regexp). ;; This function overwrites minibuffer text with isearch message, ;; so it's possible to see what is wrong in the search string. - (isearch-message c-q-hack ellipsis) + (isearch-standard-message c-q-hack ellipsis) ;; Otherwise, put the overlay with the standard isearch prompt over ;; the initial minibuffer prompt. (if (overlayp minibuffer-history-isearch-message-overlay) -- 2.31.1 --=-=-=--