emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make isearch show number of invisible matches


From: Juri Linkov
Subject: Re: Make isearch show number of invisible matches
Date: Tue, 28 Jun 2022 20:05:24 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>> 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"?

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]