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

Here's an example of one such file:


* 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.


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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