Dunno anything about Org or org-sparse-tree
. But if it makes only some text visible by making the rest of the text invisible, then Isearch should automatically do the right thing: search only the visible text.
However, you might need to set (or bind, in, e.g., a command you write), option search-invisible
to nil
. The default value is open
, which means that certain invisible text can be matched (opened) by Isearch. C-h v search-invisible
tells you:
search-invisible
is a variable defined in isearch.el
.
Its value is open
Documentation:
If t
incremental search/query-replace can match hidden text.
A nil
value means don't match invisible text.
When the value is open
, if the text matched is made invisible by
an overlay having an invisible
property and that overlay has a property
isearch-open-invisible
, then incremental search will show the contents.
(This applies when using outline.el
and hideshow.el
.)
To temporarily change the value for an active incremental search,
use M-s i
.
See also the related option isearch-hide-immediately
.
See also reveal-mode
if you want overlays to automatically be opened
whenever point is in one of them.
You can customize this variable.
As that doc also says, you can use M-s i
to toggle the value temporarily.
But of course, this variable has an effect only on overlays with property invisible
and property isearch-open-invisible
.