Skip to content

Commit

Permalink
Merge: Keep sort order
Browse files Browse the repository at this point in the history
Closes #166.  Closes #167.

Thanks to Alexander-Miller (@Alexander-Miller).
  • Loading branch information
alphapapa committed Sep 28, 2021
2 parents fd08d0b + 6c23eb4 commit 6fc1208
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ As explained in the usage instructions and shown in the example, items are colle
+ Selector ~:property~, which groups items with a property, optionally also matching a value or predicate. (Thanks to [[https://github.com/weipe][Per Weijnitz]].)
+ Special selector ~:take~, which limits the number of items displayed in a group. (Thanks to [[https://github.com/pkazmier][Pete Kazmier]].)
+ Option ~org-super-agenda-hide-empty-groups~, which hides empty groups. (Thanks to [[https://github.com/cslux][Christian Schwarzgruber]].)
+ Optioin ~org-super-agenda-keep-order~, which re-sorts items after grouping to preserve their original sort order. (Thanks to [[https://github.com/Alexander-Miller][Alexander-Miller]].)

** 1.2

Expand Down
11 changes: 11 additions & 0 deletions org-super-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ Note that `org-super-agenda-mode' must be toggled for this option
to take effect."
:type 'boolean)

(defcustom org-super-agenda-keep-order nil
"Keep items' original sort order.
When multiple selectors are used, items' sort order may be
changed by the grouping process. This option re-sorts items
after grouping. The cost of this may range from negligible to
considerable, depending on the number of items."
:type 'boolean)

;;;; Faces

(defface org-super-agenda-header '((t (:inherit org-agenda-structure)))
Expand Down Expand Up @@ -821,6 +829,9 @@ The string should be the priority cookie letter, e.g. \"A\".")
for order = (or (plist-get filter :order) 0) ; Lowest number first, 0 by default
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)))

;; Transformer
for transformer = (plist-get filter :transformer)
when transformer
Expand Down
25 changes: 14 additions & 11 deletions org-super-agenda.info
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ File: README.info, Node: 13-pre, Next: 12, Up: Changelog
• Option ‘org-super-agenda-hide-empty-groups’, which hides empty
groups. (Thanks to Christian Schwarzgruber
(https://github.com/cslux).)
• Optioin ‘org-super-agenda-keep-order’, which re-sorts items after
grouping to preserve their original sort order. (Thanks to
Alexander-Miller (https://github.com/Alexander-Miller).)


File: README.info, Node: 12, Next: 111, Prev: 13-pre, Up: Changelog
Expand Down Expand Up @@ -801,17 +804,17 @@ Node: Why are some items not displayed even though I used group selectors for th
Node: Why did a group disappear when I moved it to the end of the list?20725
Node: Changelog21300
Node: 13-pre21535
Node: 1222128
Node: 11124712
Node: 1124881
Node: 10326453
Node: 10226664
Node: 10126798
Node: 10027136
Node: Development27241
Node: Bugs27643
Node: Tests28296
Node: Credits28615
Node: 1222332
Node: 11124916
Node: 1125085
Node: 10326657
Node: 10226868
Node: 10127002
Node: 10027340
Node: Development27445
Node: Bugs27847
Node: Tests28500
Node: Credits28819

End Tag Table

Expand Down
20 changes: 20 additions & 0 deletions test/results.el
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,26 @@ Wednesday 5 July 2017
WAITING items
ambition: In 53 d.: WAITING Visit the moon :universe:ambition::space:travel:
" "903c57072a094bf52612ecccf3535ae7" "Day-agenda (W27):
Wednesday 5 July 2017
Ambitions vs Bills with retained sorting
ambition: Sched. 1x: TODO [#A] Skype with president of Antarctica :universe:ambition:world::meetings:
ambition: In 2 d.: TODO [#A] Take over the world :universe:ambition::world:
ambition: In 10 d.: TODO [#A] Take over the universe :universe:ambition:
test: In 27 d.: TODO [#A] Spaceship lease :bills:spaceship:
ambition: In 5 d.: TODO [#B] Renew membership in supervillain club :universe:ambition::
test: In 16 d.: TODO [#B] Internet :bills:
" "8e99e160e61a0555288f7a1b45bda03d" "Day-agenda (W27):
Wednesday 5 July 2017
Ambitions vs Bills without retained sorting
ambition: Sched. 1x: TODO [#A] Skype with president of Antarctica :universe:ambition:world::meetings:
ambition: In 2 d.: TODO [#A] Take over the world :universe:ambition::world:
ambition: In 10 d.: TODO [#A] Take over the universe :universe:ambition:
ambition: In 5 d.: TODO [#B] Renew membership in supervillain club :universe:ambition::
test: In 27 d.: TODO [#A] Spaceship lease :bills:spaceship:
test: In 16 d.: TODO [#B] Internet :bills:
" "21c447791e388f4c16ebc74eba214a1a" "Day-agenda (W27):
Wednesday 5 July 2017
Expand Down
18 changes: 18 additions & 0 deletions test/test.el
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,24 @@ already loaded."
(should (org-super-agenda-test--run
:groups '((:not (:todo t))))))

(ert-deftest org-super-agenda-test--with-retained-sorting ()
(should (org-super-agenda-test--run
:groups '((:name "Ambitions vs Bills with retained sorting"
:and (:todo "TODO" :priority>= "B" :tag "ambition")
:and (:todo "TODO" :priority>= "B" :tag "bills")
:discard (:anything)))
:let* ((org-agenda-sorting-strategy '(priority-down tag-down))
(org-super-agenda-retain-sorting t)))))

(ert-deftest org-super-agenda-test--without-retained-sorting ()
(should (org-super-agenda-test--run
:groups '((:name "Ambitions vs Bills without retained sorting"
:and (:todo "TODO" :priority>= "B" :tag "ambition")
:and (:todo "TODO" :priority>= "B" :tag "bills")
:discard (:anything)))
:let* ((org-agenda-sorting-strategy '(priority-down tag-down))
(org-super-agenda-retain-sorting nil)))))

(ert-deftest org-super-agenda-test--:order ()
;; DONE: Works.
(should (org-super-agenda-test--run
Expand Down

0 comments on commit 6fc1208

Please sign in to comment.