emacs-devel
[Top][All Lists]
Advanced

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

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


From: Ihor Radchenko
Subject: Is it valid to call isearch-filter-predicate outside isearch?
Date: Sat, 20 May 2023 14:10:38 +0000

Hi,

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/

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.

I thought that side effects are acceptable since
`isearch-filter-visible' itself also manipulates buffer visibility in
`isearch-range-invisible' - it calls
`isearch-close-unnecessary-overlays' and
`isearch-open-overlay-temporary' for side effects.
However, we have found that `query-replace' calls
`isearch-filter-predicate' outside isearch, and it may not be safe to
assume that isearch hooks will be executed.

The documentation for `isearch-filter-visible' sounds like no side
effects are expected:

    Predicate to filter hits of Isearch and replace commands.
    
    Isearch hits that don't satisfy the predicate will be skipped.
    The value should be a function of two arguments; it will be
    called with the positions of the start and the end of the text
    matched by Isearch and replace commands.  If this function
    returns nil, Isearch and replace commands will continue searching
    without stopping at resp. replacing this match.
    This function is expected to be careful not to clobber the match data.
    
Either the docstring is not accurate or the implementation of
`isearch-range-invisible' is not safe.

Am I missing something?

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