5

I add custom org-agenda commands to the org-agenda-custom-commands like so

  (setq w-view
           `("W" "Work"
             (
              (agenda ""
                      (
                       (org-agenda-span 'day)
                       (org-deadline-warning-days 365)
                       ))
              (tags-todo "work"
                         ((org-agenda-overriding-header "All Work")
                          (org-agenda-files '("~/Dropbox/org/inbox.org"))
                          (org-agenda-sorting-strategy '(deadline-up priority-down tag-up))
                          ))
              (tags-todo "work"
                         ((org-agenda-overriding-header "Work Projects")
                          (org-agenda-files '("~/Dropbox/org/projects.org"))
                          (org-agenda-sorting-strategy '(deadline-up priority-down tag-up))
                          ))
              nil
              )
             )
           )
  (add-to-list 'org-agenda-custom-commands `,w-view)

I understand that items can start with "agenda," "tags-todo," or "tags," and possibly other things, though I'm not clear on what exactly as the documentation doesn't say.

I do know that an agenda item shows my TODO items that have deadlines or are scheduled, in order and with their timestamps. I also know that I can create custom headers, i.e. like I do for "All Work" or "Work Projects." I know that I can determine what TODO items are displayed under those custom headers because I start those sections with tags-todo.

What I don't understand is how I can make a custom section that starts with agenda only show TODO items of a certain tag.

I've tried the following:

          (agenda ""
                  ((tags-todo "work")
                   (org-agenda-span 'day)
                   (org-deadline-warning-days 365)
                   ))

Which didn't throw any errors but also shows all TODO items regardless of tags, i.e., didn't change anything.

When making a custom org-agenda-custom-commands view, and using the "agenda" custom header identifier, how can I make that custom agenda view only display certain tags?

I'm not sure what to call the "agenda" or "tags-todo" or "tags" custom header identifier, help in the vocabulary sense so I can edit and clarify this question would be appreciated.

2
  • 1
    Here is a link to the advanced searching section of the org-mode manual: orgmode.org/worg/org-tutorials/advanced-searching.html In addition to that, Sacha Chua has a nice section for the org-agenda-custom-commands you might like to take a look at: pages.sachachua.com/.emacs.d/Sacha.html When you get to Sacha's webpage linked in the previous sentence, just word-search for the term org-agenda-custom-commands and you can jump to her configuration and take a look
    – lawlist
    Commented Mar 9, 2020 at 23:19
  • You can only use matching with todo, tags and tags-todo; you cannot use matching with agenda. Do C-h v org-agenda-custom-commands to see its doc string. OTOH, the org-agenda-tag-filter-preset setting in the Sacha Chua document that @lawlist pointed you to might be just the ticket.
    – NickD
    Commented Mar 10, 2020 at 0:58

1 Answer 1

6

This can be done using built in tools using org-agenda-skip-function (I've used this answer on Stack Overflow in the past).

If you don't mind external packages, org-super-agenda makes this easy:

(add-to-list 'org-agenda-custom-commands
             '("w" "Work agenda" agenda ""
              ((org-super-agenda-groups
                '((:discard (:not (:tag ("work"))))
                 ))
               )
        ))

This will remove any item that doesn't match the selector (:tag ("work")), that is will show only :work: items. This is also significantly faster than using org-agenda-skip-function.

You can give multiple tags and combine them using :and and :or. For example,

(:or 
  (:not (:tag ("work"))) 
  (:and 
    (:tag ("home")) 
    (:tag ("urgent"))))

will match work items, but also :urgent: items at home. For even more advanced matching, check out org-ql, which is very powerful and fast

1
  • By the way, I eventually did just make a custom org-agenda-skip-function, here's one that rejects anything not of todo type PROJECT : ``` (defun my/org-agenda-skip-entry-if-not-project () "Skip entries that are not PROJECT type todos." (let ((todo (org-get-todo-state))) (if (and todo (string= todo "PROJECT")) nil (or (outline-next-heading) (goto-char (point-max)))))) ```
    – Caleb Jay
    Commented Mar 17, 2023 at 5:59

Your Answer

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

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