1

Background information to motivate my question:

With the agenda open, I can press "\" then "+" to show only results containing a certain tag, say A. I can then press "\" and "+" again to show results with both A and another tag, say B. These combinations are boolean expressions of the tags AND'ed together: A AND B for the former and A AND NOT B for the latter.

My question:

I would like to filter my agenda in the same way but with the union of tags A and B, so that any entries with either tag A OR tag B are shown (A OR B). How can I do this?

org-agenda-custom-commands can define tag searches using the full boolean expression syntax described in the manual (as described in the answer to this question), so that defining a custom command like
(setq org-agenda-custom-commands '(("z" "test" tags "A|B")))
but these searches do not produce a weekly agenda. For example, they are not sectioned by date, they do not only show scheduled and deadline items, and they do not show upcoming deadlines.

How can I filter the weekly agenda using a query for tag A OR B?

0

You have to use a skip-function. For details see this page. Adjusted to your needs the function there would be:

(defun my-skip-tags ()
  (let ((subtree-end (save-excursion (org-end-of-subtree t))))
    (if (not (or (re-search-forward ":A:" subtree-end t)
                 (re-search-forward ":B:" subtree-end t)))
        nil          ; tag found, do not skip
      subtree-end))) ; tag not found, continue after end of subtree

This solution does not work, though, if you want to filter by inherited tags. For this case I use the following function:

(defun my-skip-inherited-tags ()
  (let (beg end m)
    (org-back-to-heading t)
    (setq beg (point)
          end (progn (outline-next-heading) (1- (point))))
    (goto-char beg)
    (setq alltags (prin1-to-string (org-get-tags-at)))
    (goto-char beg)
    (if (not (or (string-match "A" alltags)
                 (string-match "B" alltags)))
        end)))

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.