(I don't know lisp, so I suspect this is really simple.)
I want to write a function to simplify my org-mode and GTD setup.
I've based my org-mode setup on the write up here: http://doc.norang.ca/org-mode.html#CustomAgendaViewSetup
I want to use the "NEXT" setup (see below) for multiple tags - I can just simply cut and paste the same code over and over, but it would be so much cleaner to write a function, so rather than having this:
(tags-todo "-WAITING-CANCELLED/!NEXT"
((org-agenda-overriding-header "Next Tasks")
(org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
(org-agenda-todo-ignore-scheduled 'future)
(org-agenda-todo-ignore-deadlines 'future)
(org-tags-match-list-sublevels t)
(org-agenda-sorting-strategy
'(todo-state-down effort-up category-keep))))
I'd prefer something like:
(MyFunction "@work")
(MyFunction "@computer")
Where the argument to the function changes the filtering in the above code block to something like:
(tags-todo "-WAITING-CANCELLED+<XXX>/!NEXT"
i.e.
(tags-todo "-WAITING-CANCELLED+@work/!NEXT"
Can someone help by pointing me in the right direction?
The following should do the trick (it also includes a variable to test for whether to use +
or -
before the tag, defaulting to -
).
(defun zin/agenda-test (tag &optional signp)
"Simplify agenda coding, only require TAG to create new block.
SIGNP determines whether to use `+' or `-' when adding the tag.
Defaulting to `-'."
(let ((sign (if signp "+" "-")))
`(tags-todo ,(format "-WAITING-CANCELLED%s%s/!NEXT" sign tag)
((org-agenda-overriding-header "Next Tasks")
(org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
(org-agenda-todo-ignore-scheduled 'future)
(org-agenda-todo-ignore-deadlines 'future)
(org-tags-match-list-sublevels t)
(org-agenda-sorting-strategy
'(todo-state-down effort-up category-keep))))))
(setq org-agenda-custom-commands `(("t" "Test"
(,(zin/agenda-test "@tag")
,(zin/agenda-test "@test" '+)))))
You have to make sure that org-agenda-custom-commands
uses the backquote syntax (`
) instead of (quote ...)
, otherwise the commands will not expand properly.