Might as well brag about this, since I’m inordinately proud (I become an #elisp hacker about once every two or three years). I love #emacs #org-mode, but I don’t love what it does with todo entries (highest-priority, longest-scheduled first). For me, if something’s been at priority A for 280 days, it’s not that high-priority (but still higher than anything at priority B). I want highest-priority, most-recently-scheduled first, in the time-honored tradition of ignoring things in the hope they’ll go away.
Here it is.
(defun my-org-agenda-todo-sort (a b)
"Function should only sort TODO items; since I can't return ``unsortable'' for things that don't compare, I just
return 0 and hope for the best. Seems to be working so far. Higher-priority and more-recently-scheduled items
have higher urgency."
(if (string-match "\\(Sched\\.\\s-*\\([0-9]+\\)x\\|Scheduled\\):\\s-+\\S-+ \\[#\\([ABC]\\)\\]" a)
(let ((a-sched-days (string-to-number (if (null (match-string 2 a)) "0" (match-string 2 a))))
(a-priority (match-string 3 a)))
(if (string-match "\\(Sched\\.\\s-*\\([0-9]+\\)x\\|Scheduled\\):\\s-+\\S-+ \\[#\\([ABC]\\)\\]" b)
(let ((b-sched-days (string-to-number (if (null (match-string 2 b)) "0" (match-string 2 b))))
(b-priority (match-string 3 b)))
;(message "Agenda item a of type %s: %s" (type-of a) a)
;(message "Agenda item b of type %s: %s" (type-of b) b)
;(message "a-priority: %s; b-priority: %s; a-sched-days: %s; b-sched-days: %s"
; a-priority b-priority a-sched-days b-sched-days)
(cond ((string< a-priority b-priority) 1)
((string> a-priority b-priority) -1)
(t (cond ((< a-sched-days b-sched-days) 1)
((> a-sched-days b-sched-days) -1)
(t 0)))))
0
)
)
0
)
)
(setq org-agenda-cmp-user-defined 'my-org-agenda-todo-sort)
(setq org-agenda-sorting-strategy '((agenda habit-down time-up user-defined-down category-keep)
(todo urgency-down category-keep)
(tags urgency-down category-keep)
(search category-keep)))
Update: Ok, that was stupid. Here’s a more readable version:
https://gist.github.com/JohnL4/4ddd2ec185b8a9b948db6d62edb9d32d