5

I want to search my diary folder for all items with the tag :meeting:

Here's an example of one such file:

2021-01-01.org

* meeting with boss :meeting:
** regarding project
  we're running late
** regarding my employment
  i'm fired

When I do M-x org-tags-view and match for meeting, I see a buffer that looks like:

Headlines with TAGS match: meeting
Press ‘C-u r’ to search again
  2021-01-01:        meeting with boss :meeting:
  2021-01-01:        regarding project :meeting:
  2021-01-01:        regarding my employment :meeting:

I'd like to make it so I only see the headline that has the meeting tag applied, not child headlines that inherit the meeting. I want my view to look like:

Headlines with TAGS match: meeting
Press ‘C-u r’ to search again
  2021-01-01:        meeting with boss :meeting:

I've read through the org-mode tags documentation, as well as matching tags and properties and the agenda dispatcher. I've also search Stackoverflow and the internet, and haven't found anyway to do this. Is this possible?

EDIT: I've discovered the tag inheritance docs page, and it says I can try setting org-agenda-use-tag-inheritance. It gives me three options for "agenda type" if I do this: "todo," "agenda," and "search." I'm not sure what an "agenda type" is, but I know I want tag inheritance for agenda views, and I'm pretty sure I want them for "TODO" views. I tried removing it for "search" views but that didn't change anything about the output of my tags search, so I don't know if this is what will help me.

EDIT: I can customize org-tags-exclude-from-inheritance to exclude the meeting tag from being inherited. It does accomplish what I want, but only from this tag, and will force me to for example use combined tags to allow for inheritance when I want it vs not, so for example I'll probably now include a meeting-inherited or similar type tag on all things tagged with meeting in case I need to display an agenda view with a TODO that matches for meeting (in this case meeting-inherited. It's not ideal.

2 Answers 2

2

Try this:

(setq org-tags-match-list-sublevels nil)

The doc string for the variable (C-h v org-tags-match-list-sublevels) says:

Non-nil means list also sublevels of headlines matching a search.
This variable applies to tags/property searches, and also to stuck
projects because this search is based on a tags match as well.

When set to the symbol ‘indented’, sublevels are indented with
leading dots.

Because of tag inheritance (see variable ‘org-use-tag-inheritance’),
the sublevels of a headline matching a tag search often also match
the same search.  Listing all of them can create very long lists.
Setting this variable to nil causes subtrees of a match to be skipped.

This variable is semi-obsolete and probably should always be true.  It
is better to limit inheritance to certain tags using the variables
‘org-use-tag-inheritance’ and ‘org-tags-exclude-from-inheritance’.

Even though the variable is declared semi-obsolete, the suggested replacements are the ones that you have investigated and found wanting, so setting this variable might be exactly what you need.

0
1

You could define your own org-tags-view function that turns off inheritance for its duration, but does not otherwise change anything else:

(defun my/org-tags-view (&optional todo-only watch)
  (let ((org-use-tag-inheritance nil))
    (org-tags-view todo-only watch)))

If you always want to use this function instead of the standard org-tags-view, you can advise org-tags-view:

(advice-add 'org-tags-view :around
              (lambda (orig-fun &rest args)
                (let ((org-use-tag-inheritance nil))
                  (apply orig-fun args))))

Do C-h i g(elisp)Advising Functions to read more about the advice mechanism.

Untested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.