emacs-devel
[Top][All Lists]
Advanced

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

Re: Is it valid to call isearch-filter-predicate outside isearch?


From: Ihor Radchenko
Subject: Re: Is it valid to call isearch-filter-predicate outside isearch?
Date: Thu, 01 Jun 2023 11:42:25 +0000

Michael Heerdegen <michael_heerdegen@web.de> writes:

>> I am now investigating an Org mode issue related to interaction between
>> Org mode folding and isearch.
>> https://list.orgmode.org/orgmode/CAP7OBx+L11ck3Ni6rv94HGU3otdj6C4rG-rMDzkwR1LTj=BWiw@mail.gmail.com/
>
> The answer to the subject is probably: query-replace is also ok, else
> "no".

AFAIK, at least evil does it:
https://github.com/emacs-evil/evil/blob/be736b8dbc468d53e6cb3e76db66c1141330b030/evil-search.el#L183

I asked them to respect `isearch-mode-end-hook' in
https://github.com/emacs-evil/evil/issues/1630, but after seeing
`query-replace' I started to doubt my confidence.

>> Org mode overrides the default value of isearch-filter-predicate with
>>
>> (defun org-fold-core--isearch-filter-predicate-overlays (beg end)
>>   "Return non-nil if text between BEG and END is deemed visible by isearch.
>> This function is intended to be used as `isearch-filter-predicate'."
>>   (org-fold-core--create-isearch-overlays beg end) ;; trick isearch by 
>> creating overlays in place of invisible text
>>   (isearch-filter-visible beg end))
>>
>> As you can see, Org produces side effects when the predicate is
>> called.
>
>                 (if (org-fold-core-get-folding-spec-property spec 
> :isearch-open)
>                   (overlay-put o 'isearch-open-invisible #'delete-overlay)
>                   (overlay-put o 'isearch-open-invisible #'ignore)
>                   (overlay-put o 'isearch-open-invisible-temporary #'ignore))
>                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Can't you bind this to a function that does what you want?  AFAIU it is
> called with two arguments - the overlay itself and a bool saying "open"
> (nil) or "re-hide" (non-nil).  That should allow to not rely on any
> hooks to remove your helper overlays.  Unless, maybe, not all of them
> are opened.  Can that happen?

I tried... But it is prohibited to remove overlays when isearch is
tracking them: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60399
Also, closing an overlay does not necessarily mean that isearch is over
- Org cannot yet convert it back to text properties.

That said, the idea is good for other reasons.

> If it does, maybe using `post-command-hook' would be a better choice
> than `isearch-end-hook' (which is, obviously, not a good choice)?

Surely not. `post-command-hook' is triggered after each
`self-insert-command' during isearch/query-replace.

I had to advice `isearch-clean-overlays', which appears to be called by
all the users of `isearch-filter-predicate' (replace-regexp, evil-mode,
and swipet). Still a workaround. Ugly.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=7dee2c07f

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

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