I would like to filter the buffer in Org-mode to only those headings that match certain tags.
I tried C-c /
followed by tag1&tag2
. But instead of narrowing the buffer, Emacs just highlights the asterisk next to each heading that has those tags...
How can I change this so that Emacs actually narrows the buffer to those matched headlines?
Thanks!
The search regexp used by the original poster is probably incorrect. The sub-function used by
org-occur
to set the boundaries for the highlighted result is rather simple --(while (re-search-forward regexp nil t) . . .)
The beginning and ending of the matched pattern determine the boundaries of the highlighted area -- i.e.,(match-beginning 0)
, and(match-end 0)
.To search for headlines containing either or both tags, the regexp
:tag1:\|:tag2:
is used whenorg-occur
is called interactively -- i.e., just one backslash and pipe. Whenorg-occur
is used NON-interactively, two (2) backslashes and a pipe are required -- e.g.,(org-occur ":tag1:\\|:tag2:")
When looking for two tags that are together in a specific order, the regexp looks like this:
:tag1:tag2:
The default behavior of
org-occur
is to fold everything and then unfold only matched results -- with an exception for previously matched results remaining visible, unless the argumentkeep-previous
is non-nil. If the buffer looks completely unfolded (after a search usingorg-occur
), then the regexp that was used probably matched everything.It is also prudent to check and verify that a current version of
org-mode
is being used --M-x org-version RET
.Example of a search using
org-occur
for the tag:lasc:
(source: lawlist.com)