This documentation explains how to set up custom agenda views, and I understand the example code I've seen there. But there is one thing I'd like to do that might not be possible: I'd like to look over my next actions by category instead of looking through all of them at once. However, to do this I need a "miscellaneous" category to make sure I don't lose anything. This category would include all TODOs that are not tagged with OFFICE, ERRANDS, or HOME:

(setq org-agenda-custom-commands
      '(("O" tags-todo "OFFICE") 
        ("B" tags-todo "ERRANDS")       
        ("H" tags-todo "HOME") 
        ; Here comes the part where I make up pseudocode to show that
        ; I want a list of all TODOs that do not contain any of the
        ; tags specified above:
        ; ("M" tags-todo-NOT "OFFICE" "ERRANDS" "HOME")

Is this possible using Elisp?

  • 1
    By the way: Welcome to Emacs.SE! :) – itsjeyd Apr 9 '15 at 6:39

Yes, that's possible:

(setq org-agenda-custom-commands
      '(("O" tags-todo "OFFICE") 
        ("B" tags-todo "ERRANDS")   
        ("H" tags-todo "HOME") 
        ("M" tags-todo "-OFFICE-ERRANDS-HOME")))

There's two things at work here:

  1. - negates a search term. For example, -OFFICE matches headlines that are not tagged with :OFFICE:.

  2. Search terms can be concatenated with + or -. A + in front of a tag means that headlines matching a query must include that tag.

| improve this answer | |
  • Nice! Seems to be working perfectly. :) – Var87 Apr 8 '15 at 21:10
  • 1
    You can also search for or negate regular expressions with {...}. For example "-{OFFICE\\|ERRANDS\\|HOME}" will include everything except those tagged with one of OFFICE, ERRANDS or HOME. – erikstokes Apr 8 '15 at 22:26
  • Thanks! Just curious: Are these (isjeyds and eriks examples) features or a typical pattern of elisp in general or specific to orgmode? – Var87 Apr 9 '15 at 15:07
  • 2
    The "+/-" syntax for including/excluding things is an orgmode thing as is the "{}" syntax for regular expressions. The regex inside the "{}" is a standard Emacs regex. – erikstokes Apr 10 '15 at 1:40

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.