From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Make isearch show number of invisible matches Date: Tue, 28 Jun 2022 20:05:24 +0300 Organization: LINKOV.NET Message-ID: <867d50oh0r.fsf@mail.linkov.net> References: <87bkuhiyr1.fsf@fastmail.fm> <86h745nb4k.fsf@mail.linkov.net> <87czetolui.fsf@fastmail.fm> 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="28943"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: emacs-devel@gnu.org To: Joost Kremers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 28 19:08:40 2022 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 1o6Ehc-0007Qc-MP for ged-emacs-devel@m.gmane-mx.org; Tue, 28 Jun 2022 19:08:40 +0200 Original-Received: from localhost ([::1]:58672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6Eha-0005ab-H8 for ged-emacs-devel@m.gmane-mx.org; Tue, 28 Jun 2022 13:08:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6Egh-0004qZ-1y for emacs-devel@gnu.org; Tue, 28 Jun 2022 13:07:43 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:33971) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6Ege-0006D3-LD for emacs-devel@gnu.org; Tue, 28 Jun 2022 13:07:42 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 1AC471C000B; Tue, 28 Jun 2022 17:07:36 +0000 (UTC) In-Reply-To: <87czetolui.fsf@fastmail.fm> (Joost Kremers's message of "Mon, 27 Jun 2022 23:05:21 +0200") Received-SPF: pass client-ip=217.70.183.197; envelope-from=juri@linkov.net; helo=relay5-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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:291691 Archived-At: --=-=-= Content-Type: text/plain >> And now I'm not sure if this should be implemented at all, >> because displaying the number of all matches helped me >> many times. > > Yeah, what I actually meant was that both the total number and the number of > invisible matches is shown. Something like (using a suffix): > > I-search: [3/15] (10 visible) > > It could also say "[3/15] (5 invisible)" for all I care. Just that the > information is there. Good idea. Something like query-replace says when skipping invisible matches: Replaced 3 occurrences (skipped 10 invisible) Here is a complete implementation. But still there are small details that are not quite nice: 1. The format for invisible matches is hard-coded to " (invisible %s)", and can't be added to lazy-count-prefix-format/lazy-count-suffix-format because it's not used when there are no invisible matches. 2. Are these matches really "invisible"? There are other types of matches that are invisible as well, but can be opened. Is there a better word for matches that are invisible but can't be opened? Maybe "unreachable" or "intangible"? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-lazy-count-invisible.patch diff --git a/lisp/isearch.el b/lisp/isearch.el index 0624858993..37f9b50724 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -452,17 +452,17 @@ lazy-count :group 'isearch :group 'matching) -(defcustom lazy-count-prefix-format "%s/%s " +(defcustom lazy-count-prefix-format "%s/%s%s " "Format of the current/total number of matches for the prompt prefix." :type '(choice (const :tag "No prefix" nil) - (string :tag "Prefix format string" "%s/%s ")) + (string :tag "Prefix format string" "%s/%s%s ")) :group 'lazy-count :version "27.1") (defcustom lazy-count-suffix-format nil "Format of the current/total number of matches for the prompt suffix." :type '(choice (const :tag "No suffix" nil) - (string :tag "Suffix format string" " [%s of %s]")) + (string :tag "Suffix format string" " [%s of %s]%s")) :group 'lazy-count :version "27.1") @@ -1277,6 +1277,7 @@ isearch-mode isearch-lazy-count-current nil isearch-lazy-count-total nil + isearch-lazy-count-invisible nil ;; Save the original value of `minibuffer-message-timeout', and ;; set it to nil so that isearch's messages don't get timed out. @@ -3528,7 +3533,11 @@ isearch-lazy-count-format (- isearch-lazy-count-total isearch-lazy-count-current -1))) - (or isearch-lazy-count-total "?")) + (or isearch-lazy-count-total "?") + (if isearch-lazy-count-invisible + ;; "invisible" means "unreachable", "intangible" + (format " (invisible %s)" isearch-lazy-count-invisible) + "")) ""))) @@ -4007,6 +4017,7 @@ isearch-lazy-highlight-forward (defvar isearch-lazy-highlight-error nil) (defvar isearch-lazy-count-current nil) (defvar isearch-lazy-count-total nil) +(defvar isearch-lazy-count-invisible nil) (defvar isearch-lazy-count-hash (make-hash-table)) (defvar lazy-count-update-hook nil "Hook run after new lazy count results are computed.") @@ -4085,7 +4096,8 @@ isearch-lazy-highlight-new-loop ;; Reset old counter before going to count new numbers (clrhash isearch-lazy-count-hash) (setq isearch-lazy-count-current nil - isearch-lazy-count-total nil) + isearch-lazy-count-total nil + isearch-lazy-count-invisible nil) ;; Delay updating the message if possible, to avoid flicker (when (string-equal isearch-string "") (when (and isearch-mode (null isearch-message-function)) @@ -4327,11 +4349,14 @@ isearch-lazy-highlight-buffer-update (setq found nil) (forward-char -1))) (when isearch-lazy-count - (setq isearch-lazy-count-total - (1+ (or isearch-lazy-count-total 0))) - (puthash (if isearch-lazy-highlight-forward me mb) - isearch-lazy-count-total - isearch-lazy-count-hash)) + (if (and search-invisible (invisible-p (get-text-property (point) 'invisible))) + (setq isearch-lazy-count-invisible + (1+ (or isearch-lazy-count-invisible 0))) + (setq isearch-lazy-count-total + (1+ (or isearch-lazy-count-total 0))) + (puthash (if isearch-lazy-highlight-forward me mb) + isearch-lazy-count-total + isearch-lazy-count-hash))) ;; Don't highlight the match when this loop is used ;; only to count matches or when matches were already ;; highlighted within the current window boundaries --=-=-=--