Emacs Org: Display a subset of tasks by context
| emacs, orgI wanted to get a quick preview of my top three tasks by context. Since org-tags-view didn’t seem to have a built-in way to limit the
number of displayed items, I used defadvice to add my own. Here’s the relevant code from my Emacs configuration:
(defvar sacha/org-agenda-limit-items nil "Number of items to show in agenda to-do views; nil if unlimited.") (defadvice org-agenda-finalize-entries (around sacha activate) (if sacha/org-agenda-limit-items (progn (setq list (mapcar 'org-agenda-highlight-todo list)) (if nosort (setq ad-return-value (subseq list 0 sacha/org-agenda-limit-items)) (when org-agenda-before-sorting-filter-function (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list)))) (setq ad-return-value (mapconcat 'identity (subseq (sort list 'org-entries-lessp) 0 sacha/org-agenda-limit-items) "\n")))) ad-do-it))
and the snippet from my org-agenda-custom-commands:
(setq org-agenda-custom-commands
'(
;; ... other commands go here
("0" "Block agenda"
((tags-todo "+@phone")
(tags-todo "+@work")
(tags-todo "+@drawing")
(tags-todo "+@coding")
(tags-todo "+@writing")
(tags-todo "+@computer")
(tags-todo "+@home"))
((org-agenda-sorting-strategy '(priority-up effort-down))
(sacha/org-agenda-limit-items 3)))
(")" "Block agenda"
((tags-todo "+@phone")
(tags-todo "+@work")
(tags-todo "+@drawing")
(tags-todo "+@coding")
(tags-todo "+@writing")
(tags-todo "+@computer")
(tags-todo "+@home"))
((org-agenda-sorting-strategy '(priority-down effort-down))
(sacha/org-agenda-limit-items nil)))
("9" "Unscheduled by context"
((tags-todo "+@phone")
(tags-todo "+@work")
(tags-todo "+@drawing")
(tags-todo "+@coding")
(tags-todo "+@writing")
(tags-todo "+@computer")
(tags-todo "+@home"))
((org-agenda-skip-function
(lambda nil
(org-agenda-skip-entry-if (quote scheduled) (quote deadline)
(quote regexp) "\n]+>")))
(org-agenda-sorting-strategy '(priority-down effort-down))
(sacha/org-agenda-limit-items 3)))
;; ... more after this
))
This way, I can see all of my common contexts on one screen, and I can decide what I want to work on first.
You can e-mail me at sacha@sachachua.com.