Given a simple org-mode outline (i.e. consisting only of heading lines) in its OVERVIEW
global state (IOW, only the top-level nodes are visible), I want to make simultaneously visible all the nodes that mention a given substring.
From the point of view of this aim, Emacs' standard isearch-forward
(C-s
) command has two shortcomings:
- in a given search, only the "current" match is visible; I can reveal subsequent matches by repeatedly hitting
C-s
, but only one1 matching node is visible at a time. - revealing all matches requires hitting
C-s
for each match, which is tedious or impractical when the number of matches is large.
Therefore, I'm looking for a way to reveal all the matching nodes at once, and to do so in a way that minimizes the number of "open" nodes. (IOW, any node that does not contain additional matching nodes among its strict descendants should remain closed.)
How can I achieve this?
Example:
Consider this artificial example in which the "leaf-level" headings are all 27 length-3 combinations of the characters a
, b
, and c
, and the headings of intermediate nodes represent prefixes of their descendant headings. (Thus, the leaf node with heading abc
is a child of the node with heading ab
, which in turn is a child of the node with heading a
.)
In the initial (i.e. OVERVIEW
) state, this outline would look like this:
* a...
* b...
* c...
Now, if I perform the desired operation (as described above) on this outline, using the substring ab
as my search term, the outline should look like this:
* a
* aa
* aaa
* aab
* aac
* ab
* aba
* abb
* abc
* ac...
* b
* ba
* baa
* bab
* bac
* bb...
* bc...
* c
* ca
* caa
* cab
* cac
* cb...
* cc...
Note that the only "open" nodes are those that must be open in order to reveal nodes containing the substring ab
.
EDIT: Following up a suggestion in the comments, below is the result of running C-c / / ab
on the example's outline:
* a
* aa...
* aab...
* ab
* aba
* abb
* abc...
* b
* ba...
* bab...
* c
* ca...
* cab...
This does not really match the description of the desired result, as given in the example, but it is not a bad alternative.
1 Well, not precisely: in addition to the current matching node, any other matching node that happens to be an ancestor of the current one will be visible as well, but only as a "byproduct" of the current matching node's visibility.
C-c /
?C-c / /
does not produced the desired results, is specified in the original problem statement, but what it does produce is a useful enough alternative that I'd be glad to accept it if you care to post it as an answer.