Search code examples
emacselisporg-mode

Calling an org-mode custom command in elisp


Org-mode allow to define custom commands by customizing org-agenda-custom-commands. Doing something like this:

(setq org-agenda-custom-commands
  '(("pb" "Bugs "
      (
       (todo "KNOWNCAUSE")
       (todo "BUG")
       (todo "REPORT")
      )
    ((org-agenda-files (list projects-dir))))

will allow me to press C-c a to call the agenda dispatcher and then if i press pb it will filter my todos by folder (project-dirs) and by states.

Is there an elisp function that calls that (a specific) custom command defined in org-agenda-custom-commands directly?

Rephrasing: I would like an elisp function that if called shows my filtered todos, just like pressing C-c a p b now does.


Solution

  • I think you are asking for a way to call through the dispatcher from a function so you can reuse your configured dispatcher. Try:

    (org-agenda nil "pb")
    

    If you are looking for function to add to a hook or initialize you can wrap this up using a lambda expression. So for example you might have your inital-buffer as this view:

    (setq initial-buffer-choice (lambda ()
      (org-agenda nil "pb")
      (get-buffer "*Org Agenda*")))