Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sublists when sorting for original order. #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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