all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Joost Kremers <joostkremers@fastmail.fm>
Cc: emacs-devel@gnu.org
Subject: Re: Make isearch show number of invisible matches
Date: Tue, 28 Jun 2022 20:05:24 +0300	[thread overview]
Message-ID: <867d50oh0r.fsf@mail.linkov.net> (raw)
In-Reply-To: <87czetolui.fsf@fastmail.fm> (Joost Kremers's message of "Mon, 27 Jun 2022 23:05:21 +0200")

[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]

>> 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: <some search string> [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"?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: isearch-lazy-count-invisible.patch --]
[-- Type: text/x-diff, Size: 3541 bytes --]

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)
+                  ""))
       "")))
 
 \f
@@ -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

  reply	other threads:[~2022-06-28 17:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24 20:19 Make isearch show number of invisible matches Joost Kremers
2022-06-27 19:45 ` Juri Linkov
2022-06-27 19:53   ` T.V Raman
2022-06-27 21:29     ` Rudolf Schlatte
2022-06-28  0:14       ` T.V Raman
2022-06-28  0:17         ` T.V Raman
2022-06-27 21:05   ` Joost Kremers
2022-06-28 17:05     ` Juri Linkov [this message]
2022-06-28 17:18       ` Eli Zaretskii
2022-07-08 17:47       ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=867d50oh0r.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=emacs-devel@gnu.org \
    --cc=joostkremers@fastmail.fm \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.