unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Make isearch show number of invisible matches
@ 2022-06-24 20:19 Joost Kremers
  2022-06-27 19:45 ` Juri Linkov
  0 siblings, 1 reply; 10+ messages in thread
From: Joost Kremers @ 2022-06-24 20:19 UTC (permalink / raw)
  To: emacs-devel

Hi,

The consult package has a command `consult-focus-lines` which is a bit like
`keep-lines`, except that it doesn't actually delete non-matching lines from the
buffer, it just hides them using overlays with an `invisible` property.

Running `isearch` in such a buffer does the Right Thing, in that it doesn't try
to move point to invisible matches. There's a slight hiccup, though, in the fact
that the pre- or suffix shows the total number of matches in the buffer,
including the ones that are not visible, so there is no way to see how many
*visible* matches there are.

Is it possible to add this information to the isearch pre/suffix? What would be
most useful to me, would in fact be if both the total number of matches and the
number of visible matches would be shown.

I assume this is currently not possible, so I would like to submit this as a
feature request.

Thanks,

Joost


-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  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:05   ` Joost Kremers
  0 siblings, 2 replies; 10+ messages in thread
From: Juri Linkov @ 2022-06-27 19:45 UTC (permalink / raw)
  To: Joost Kremers; +Cc: emacs-devel

> The consult package has a command `consult-focus-lines` which is a bit like
> `keep-lines`, except that it doesn't actually delete non-matching lines from the
> buffer, it just hides them using overlays with an `invisible` property.
>
> Running `isearch` in such a buffer does the Right Thing, in that it doesn't try
> to move point to invisible matches. There's a slight hiccup, though, in the fact
> that the pre- or suffix shows the total number of matches in the buffer,
> including the ones that are not visible, so there is no way to see how many
> *visible* matches there are.
>
> Is it possible to add this information to the isearch pre/suffix? What would be
> most useful to me, would in fact be if both the total number of matches and the
> number of visible matches would be shown.
>
> I assume this is currently not possible, so I would like to submit this as a
> feature request.

Thanks for the feature request, actually it's bug#40808
that's still not closed due to problems in Org mode.

And now I'm not sure if this should be implemented at all,
because displaying the number of all matches helped me
many times.  For example, it helped greatly when searching
for a text that is part of the link in Org mode, so it
provided very useful information about the real number
of matches even when these matches can't be visited.
But when isearch show that they exists, it's possible
to edit these matches using Org commands such as a link edit
with `C-c C-l'.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  2022-06-27 19:45 ` Juri Linkov
@ 2022-06-27 19:53   ` T.V Raman
  2022-06-27 21:29     ` Rudolf Schlatte
  2022-06-27 21:05   ` Joost Kremers
  1 sibling, 1 reply; 10+ messages in thread
From: T.V Raman @ 2022-06-27 19:53 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Joost Kremers, emacs-devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=gb18030, Size: 233 bytes --]

Another idea --- not mutually exclusive -- would be to provide an easy
way of turning the present isearch into an occur result 
-- 

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
7©4 Id: kg:/m/0285kf1  •0Ü8



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  2022-06-27 19:45 ` Juri Linkov
  2022-06-27 19:53   ` T.V Raman
@ 2022-06-27 21:05   ` Joost Kremers
  2022-06-28 17:05     ` Juri Linkov
  1 sibling, 1 reply; 10+ messages in thread
From: Joost Kremers @ 2022-06-27 21:05 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel


On Mon, Jun 27 2022, Juri Linkov wrote:
> 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.

-- 
Joost Kremers
Life has its moments




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  2022-06-27 19:53   ` T.V Raman
@ 2022-06-27 21:29     ` Rudolf Schlatte
  2022-06-28  0:14       ` T.V Raman
  0 siblings, 1 reply; 10+ messages in thread
From: Rudolf Schlatte @ 2022-06-27 21:29 UTC (permalink / raw)
  To: emacs-devel

"T.V Raman" <raman@google.com> writes:

> Another idea --- not mutually exclusive -- would be to provide an easy
> way of turning the present isearch into an occur result 

Isn't that what `M-s o' does?




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  2022-06-27 21:29     ` Rudolf Schlatte
@ 2022-06-28  0:14       ` T.V Raman
  2022-06-28  0:17         ` T.V Raman
  0 siblings, 1 reply; 10+ messages in thread
From: T.V Raman @ 2022-06-28  0:14 UTC (permalink / raw)
  To: Rudolf Schlatte; +Cc: emacs-devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=gb18030, Size: 568 bytes --]

Rudolf Schlatte <rudi@constantly.at> writes:

yes, but it's a mental switch to do something other than
isearch. Personally I'd be happy with a binding in isearch-map that
invokes occur with the current isearch pattern for my use case.
> "T.V Raman" <raman@google.com> writes:
>
>> Another idea --- not mutually exclusive -- would be to provide an easy
>> way of turning the present isearch into an occur result 
>
> Isn't that what `M-s o' does?
>
>

-- 

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
7©4 Id: kg:/m/0285kf1  •0Ü8



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  2022-06-28  0:14       ` T.V Raman
@ 2022-06-28  0:17         ` T.V Raman
  0 siblings, 0 replies; 10+ messages in thread
From: T.V Raman @ 2022-06-28  0:17 UTC (permalink / raw)
  To: Rudolf Schlatte; +Cc: emacs-devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=gb18030, Size: 734 bytes --]

"T.V Raman" <raman@google.com> writes:

Following up to myself ---- Yes, M-s o does exactly what I want -- I
learnt something I had forgotten!

> Rudolf Schlatte <rudi@constantly.at> writes:
>
> yes, but it's a mental switch to do something other than
> isearch. Personally I'd be happy with a binding in isearch-map that
> invokes occur with the current isearch pattern for my use case.
>> "T.V Raman" <raman@google.com> writes:
>>
>>> Another idea --- not mutually exclusive -- would be to provide an easy
>>> way of turning the present isearch into an occur result 
>>
>> Isn't that what `M-s o' does?
>>
>>

-- 

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
7©4 Id: kg:/m/0285kf1  •0Ü8



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  2022-06-27 21:05   ` Joost Kremers
@ 2022-06-28 17:05     ` Juri Linkov
  2022-06-28 17:18       ` Eli Zaretskii
  2022-07-08 17:47       ` Juri Linkov
  0 siblings, 2 replies; 10+ messages in thread
From: Juri Linkov @ 2022-06-28 17:05 UTC (permalink / raw)
  To: Joost Kremers; +Cc: emacs-devel

[-- 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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  2022-06-28 17:05     ` Juri Linkov
@ 2022-06-28 17:18       ` Eli Zaretskii
  2022-07-08 17:47       ` Juri Linkov
  1 sibling, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2022-06-28 17:18 UTC (permalink / raw)
  To: Juri Linkov; +Cc: joostkremers, emacs-devel

> From: Juri Linkov <juri@linkov.net>
> Cc: emacs-devel@gnu.org
> Date: Tue, 28 Jun 2022 20:05:24 +0300
> 
> Good idea.  Something like query-replace says when skipping invisible matches:
> 
>   Replaced 3 occurrences (skipped 10 invisible)
> 
> Here is a complete implementation.

Don't forget to update the :version tag of the defcustoms you are
modifying.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Make isearch show number of invisible matches
  2022-06-28 17:05     ` Juri Linkov
  2022-06-28 17:18       ` Eli Zaretskii
@ 2022-07-08 17:47       ` Juri Linkov
  1 sibling, 0 replies; 10+ messages in thread
From: Juri Linkov @ 2022-07-08 17:47 UTC (permalink / raw)
  To: Joost Kremers; +Cc: emacs-devel

>> It could also say "[3/15] (5 invisible)" for all I care. Just that the
>> information is there.
>
> 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.

Now pushed a version where it's not hard-coded but defined by a variable.
Thanks for the suggestion!



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-07-08 17:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2022-06-28 17:18       ` Eli Zaretskii
2022-07-08 17:47       ` Juri Linkov

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).