When creating a sparse-tree, what I'd like to do is show all headlines matching the search query, and their entries, but no child or sibling headlines that don't match the query.
# Example document:
* H1 :mytag:
** H1.1 :mytag:
Some text related to H1.1
** H1.2 :someothertag:
* H2 :someothertag:
** H2.1 :someothertag:
# When running sparse-tree search for "mytag" it should show:
* H1 :mytag:
** H1.1 :mytag:
Some text related to H1.1
I would guess that such a basic operation has an existing command, but after looking for it for hours, it seems like it doesn't exist, and that I have to edit code in the org repository. I'm just trying to do a sanity check before I try to figure that all out.
Things I've tried
adjusting org-fold-show-context-detail
It seems that to adjust which items after a query are shown, we have to edit the org-fold-show-context-detail
variable. The docs show that the following possibilities are available:
Allowed visibility spans are
minimal show current headline; if point is not on headline,
also show entry
local show current headline, entry and next headline
ancestors show current headline and its direct ancestors; if
point is not on headline, also show entry
ancestors-full show current subtree and its direct ancestors
lineage show current headline, its direct ancestors and all
their children; if point is not on headline, also show
entry and first child
tree show current headline, its direct ancestors and all
their children; if point is not on headline, also show
entry and all children
canonical show current headline, its direct ancestors along with
their entries and children; if point is not located on
the headline, also show current entry and all children
The only reasonable options for me are minimal
and local
.
local
: when I try local
it indeed shows the entries (as I want), but also shows the next headline, as stated. I don't want the next headline to be shown.
minimal
: when I try this, it correctly doesn't show the next headline, but now also no longer shows the entries. I don't really know what is meant by "if point is not on headline", since it also fails to show the entries when my cursor is at the top of the document before I do a sparse-tree query.
Using the org-ql package
When I use the org-ql package, and run a query using org-ql-sparse-tree
, it simply does the same thing as org-sparse-tree
, using the org-fold-show-context-detail
variable that I've set.
How do I get the desired behaviour? A sparse-tree that includes all headlines matching a query, together with their entries, but nothing else? It seems like such a simple command, there should be a default for it.
Am I going to have to adjust the org-mode code itself, and add a new entry-only
visibility span? I hope there is a simpler way.
Is there a package that does this?