help-gnu-emacs
[Top][All Lists]
Advanced

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

Locating matches in isearch-open-invisible-temporary callback


From: Kévin Le Gouguec
Subject: Locating matches in isearch-open-invisible-temporary callback
Date: Sat, 26 Dec 2020 15:58:54 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hello Emacs,

Org 9.4 (to be shipped in Emacs 27.2) comes with a minor annoyance for
me: Isearch opens drawers even though they don't contain matches[1][2].

(Caveat: all my assertions about how Org and overlays work ought to be
prefixed with "IIUC, ")

Org≤9.3 used to setup invisible overlays like this:

* header 1                      
** subheader 1.1                ╮ (1)
:LOGBOOK:               ╮ (2)   │
…               ╮ (3)   │       │
:END:           ╯       │       │
notes go here           ╯       ╯
* header 2

When isearching for "sub", only overlay (1) was revealed since nothing
matched within overlays (2) and (3).

To improve performance by reducing the number of overlays, Org 9.4 no
longer bothers with overlays (2) and (3).  This means that when
isearching for "sub", the content of neighboring :LOGBOOK:s is revealed,
adding lots of distracting visual noise.

(This is only an issue *while* isearching; when exiting Isearch, the
drawers become folded)

The resolution that was suggested on emacs-orgmode is to use the
isearch-open-invisible-temporary property[3], setting it to a callback
that should do the following:

1. when Isearch asks us to reveal the span of an invisible overlay,
    1. remove the overlay (or set the 'invisible property to nil)
    2. identify the drawers within that span that do not contain
       matches,
    3. fold these drawers with temporary invisible overlays;

2. when Isearch asks us to hide a span,
    1. remove the temporary invisible overlays inside that span,
    2. restore the original overlay.

I've tried looking at isearch-open-invisible-temporary callbacks in
Emacs core (AFAICT hs-isearch-show-temporary is the only example), but I
could not find ways to perform step 1.1: how can I know whether a drawer
contains a search result?

Empirically and by looking at Isearch's code, it seems that
(match-beginning 0) and (match-end 0) give me the information I need,
but is that something I can rely on or is it an implementation detail?


Thanks for your time.


[1] bug-gnu-emacs <87wny723u0.fsf@gmail.com>
[2] emacs-orgmode <87r1nrdl5o.fsf_-_@gmail.com>
[3] emacs-orgmode <87sg7th8mh.fsf@gmail.com>



reply via email to

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