Skip to content

Commit

Permalink
Handle sublists when sorting for original order.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Miller committed Mar 1, 2023
1 parent f4f5289 commit f524347
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion org-super-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ The string should be the priority cookie letter, e.g. \"A\".")
for (auto-section-name non-matching matching) = (org-super-agenda--group-dispatch all-items filter)

do (when org-super-agenda-keep-order
(setf matching (sort matching #'org-entries-lessp)))
(setf matching (org-super-agenda--sort-matches-for-original-order matching)))

;; Transformer
for transformer = (plist-get filter :transformer)
Expand Down Expand Up @@ -900,6 +900,31 @@ The string should be the priority cookie letter, e.g. \"A\".")
;; No super-filters; return list unmodified
all-items))

(defun org-super-agenda--sort-matches-for-original-order (matching)
"Sort MATCHING items back into their original ordering based on `org-entries-lessp'.
Only used when `org-super-agenda-keep-order' is non-nil."
(--sort
;; Sorting has a shallow element of recursion because not all of the given items
;; are matched org headlines that can just be sorted using `org-entries-lessp'.
;; Some super-agenda matchers, like `:auto-category', will introduce sublists
;; whose contents need sorting of their own. In that case the lists' `:items'
;; properties need to be sorted instead.
(let ((first-is-list (listp it))
(second-is-list (listp other)))
(when first-is-list
(plist-put
it :items
(sort (plist-get it :items) #'org-entries-lessp)))
(when second-is-list
(plist-put
other :items
(sort (plist-get other :items) #'org-entries-lessp)))
(cond
(second-is-list t)
(first-is-list nil)
(t (org-entries-lessp it other))))
matching))

;;;;; Auto-grouping

(cl-defmacro org-super-agenda--def-auto-group (name docstring-ending
Expand Down

0 comments on commit f524347

Please sign in to comment.