I have no idea how useful this would be to others, but in case it is, I thought I would share it. And I’m also interested in hearing how others would have accomplished the same result with a better method.
My org-roam files have a “YYMMDD_” prefix. When I used to run org-todo-list
, the todos were showing up in a pretty random order as far as I could tell. I decided I wanted to have them in descending order of the date prefix of the file they appear in. When I googled for this, I found one person’s approach (under my/org-agenda-sort-longterm-tags
). I modified that slightly to arrive at:
;; this function sorts todos by the yymmdd timestamp in the roam filename
;; so the todos in the most recently created files are at the top.
(defun <=> (a b)
"Compare A and B, returning 1, 0, or -1"
(cond ((= a b) 0)
((> a b) 1)
((< a b) -1)))
(defun gpc/org-agenda-cmp-user-defined (a b)
"Compare two org-agenda-events by their org-roam file prefix datestamp"
(let* ((regex "\\(2[0-9][0-9][0-9][0-9][0-9]\\)")
(date-a (if (string-match regex a)
(string-to-number (or (match-string 1 a) "0"))
0))
(date-b (if (string-match regex b)
(string-to-number (or (match-string 1 b) "0"))
0)))
(<=> date-a date-b)))
(setq org-agenda-cmp-user-defined 'gpc/org-agenda-cmp-user-defined)
What do people think of this a) desired outcome b) approach for achieving it? I personally assume the code above could be more elegant, but I’m not sure how I would do that.