UP | HOME

Working with Agenda in Org-Mode

Table of Contents

1 Setting up agenda files

First, you need to setup where will we collect the agenda informations, I prefer to have Emacs scanning every working folder I have, so I set something like this:

(setq org-agenda-files '("~/notes/2019/"))

2 Setup a custom agenda view

By using org-agenda-custom-commands, we can setup a customized agenda view with our custom headers, for example, in the code below, we added a new section called "High-priority unfinished tasks", to list all of the tasks that we already started but not finished, and are high priority.

(setq org-agenda-custom-commands
      '(("c" "Custom agenda view"
         ((tags "PRIORITY=\"A\""
                ((org-agenda-skip-function '(org-agenda-skip-if nil '(todo done)))
                 (org-agenda-overriding-header "High-priority unfinished tasks:")))
          (agenda "")
          (alltodo "")))))

With a more complex modifications, we have this:

(defun filter-org-skip-subtree-if-priority (priority)
  "Skip an agenda subtree if it has a priority of PRIORITY.
   PRIORITY may be one of the characters ?A, ?B, or ?C."
  (let ((subtree-end (save-excursion (org-end-of-subtree t)))
        (pri-value (* 1000 (- org-lowest-priority priority)))
        (pri-current (org-get-priority (thing-at-point 'line t))))
    (if (= pri-value pri-current)
        subtree-end
      nil)))
(setq org-agenda-custom-commands
      '(("c" "Custom agenda view"
         ((tags "PRIORITY=\"A\""
                ((org-agenda-skip-function '(org-agenda-skip-if nil '(todo done)))
                 (org-agenda-overriding-header "High-priority unfinished tasks:")))
          (agenda "")
          (alltodo ""
                   ((org-agenda-skip-function '(or (filter-org-skip-subtree-if-priority ?A)
                                                   (org-agenda-skip-if nil '(scheduled deadline))))))
                   ))))

3 Calling custom command agenda in elisp

We can call the custom agenda view by the following code, with "c" is the custom key binding defined in the previous section.

(org-agenda nil "c")

Date: 2019-01-02 Wed 00:00

Author: Huy Tran

Created: 2019-04-22 Mon 14:41