Search code examples
emacsorg-mode

How to regex search heading to create custom agenda?


I'm try to get a custom agenda setup which shows top level headings starting with cookies ([/])

(setq org-agenda-custom-commands
      '(("p" "Custom daily agenda"
         ((search "\[[[:digit:]]*/[[:digit:]]*\]" ((org-agenda-overriding-header "Projects"))))
         ((org-agenda-files '("~/Dropbox/org/todo.org"))))))

todo.org contains:

* [/] Project A
* [1/2] Project B
** DONE task A
** TODO task B

The agenda buffer shows up empty. It should show

Projects
todo: [/] Project A
todo: [1/2] Project B

Solution

  • Since you're using a regular expression to search, your search string must be enclosed in curly braces (you can find details for the syntax of these strings in the help for function org-search-view). You should also use two double backslashes instead of one in your regexp string to quote the literal square brackets:

    (setq org-agenda-custom-commands
          '(("p" "Custom daily agenda"
             ((search "{\\[[[:digit:]]*/[[:digit:]]*\\]}" ((org-agenda-overriding-header "Projects"))))
             ((org-agenda-files '("~/Dropbox/org/todo.org"))))))
    

    With this change, pressing p causes the *Org Agenda* buffer to show:

    Projects
      todo:       [/] Project A
      todo:       [1/2] Project B