5

In org-mode, M-x org-agenda a will display a built-in agenda view labeled "Agenda for current week or day". How can I exclude a tag from this view?

Parenthetical clarification

I know how to filter a tag out of this view after it is displayed, but I would like to add something to my configuration to exclude the tag by default.

I know how to exclude a tag from a custom agenda view, but I would like to exclude a tag from the built-in agenda view labeled "Agenda for current week or day".

2

I you don't want to see :foo:, this should exclude it:

(setq org-agenda-tag-filter-preset '("-foo"))

However, the doc string says:

This variable should not be set directly, but agenda custom commands can bind it in the options section.

So, let bind the variable before calling org-agenda by defining your own wrapper function:

(defun yashi/org-agenda (&optional arg)
  (interactive "P")
  (let ((org-agenda-tag-filter-preset '("-foo")))
   (org-agenda arg "a")))

And bind it to, say, F1

(bind-key "<f1>" 'yashi/org-agenda)
2

As Yasushi Shoji mentioned, the correct approach is to let-bind org-agenda-tag-filter-preset. To advise just the one pre-built agenda view, you'll want to use advice around the function org-agenda-list, which builds just that particular view. Try this:

(defun my/org-agenda-list-exclude-tags-advice (orig-fn &rest args)
  "Exclude selected tags from `org-agenda-list'.
Intended as :around advice for `org-agenda-list'."
  (let ((org-agenda-tag-filter-preset '("-foo")))
    (funcall orig-fn args)))

(advice-add #'org-agenda-list :around #'my/org-agenda-list-exclude-tags-advice)

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.