1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-28 10:56:57 +00:00

Agenda: Introduce user-defined sorting operators.

The new variable `org-agenda-cmp-user-defined' can contain a function
to test how two entries should be compared during sorting.
user-defined-up and user-defined-down can then be part of any sorting
strategy.
This commit is contained in:
Carsten Dominik 2009-03-27 17:50:21 +01:00
parent a26aa3777e
commit 68e6c08c17
3 changed files with 43 additions and 17 deletions

View File

@ -6570,7 +6570,9 @@ overdue scheduled or deadline items.
@item
For the TODO list, items remain in the order of categories, but within
each category, sorting takes place according to priority
(@pxref{Priorities}).
(@pxref{Priorities}). The priority used for sorting derives from the
priority cookie, with additions depending on how close an item is to its due
or scheduled date.
@item
For tags matches, items are not sorted at all, but just appear in the
sequence in which they are found in the agenda files.

View File

@ -1,5 +1,10 @@
2009-03-27 Carsten Dominik <carsten.dominik@gmail.com>
* org-agenda.el (org-agenda-cmp-user-defined): New option.
(org-sorting-choice, org-agenda-sorting-strategy): Add the new
sorting options.
(org-entries-lessp): Apply the new sorting option.
* org.el (org-block-todo-from-children-or-siblings): Fix bug in
blocker code, when an older sibling has children.

View File

@ -188,7 +188,8 @@ you can \"misuse\" it to also add other text to the header. However,
(const tag-down) (const tag-up)
(const priority-up) (const priority-down)
(const todo-state-up) (const todo-state-down)
(const effort-up) (const effort-down))
(const effort-up) (const effort-down)
(const user-defined-up) (const user-defined-down))
"Sorting choices.")
(defconst org-agenda-custom-commands-local-options
@ -861,20 +862,22 @@ This is a list of symbols which will be used in sequence to determine
if an entry should be listed before another entry. The following
symbols are recognized:
time-up Put entries with time-of-day indications first, early first
time-down Put entries with time-of-day indications first, late first
category-keep Keep the default order of categories, corresponding to the
sequence in `org-agenda-files'.
category-up Sort alphabetically by category, A-Z.
category-down Sort alphabetically by category, Z-A.
tag-up Sort alphabetically by last tag, A-Z.
tag-down Sort alphabetically by last tag, Z-A.
priority-up Sort numerically by priority, high priority last.
priority-down Sort numerically by priority, high priority first.
todo-state-up Sort by todo state, tasks that are done last.
todo-state-down Sort by todo state, tasks that are done first.
effort-up Sort numerically by estimated effort, high effort last.
effort-down Sort numerically by estimated effort, high effort first.
time-up Put entries with time-of-day indications first, early first
time-down Put entries with time-of-day indications first, late first
category-keep Keep the default order of categories, corresponding to the
sequence in `org-agenda-files'.
category-up Sort alphabetically by category, A-Z.
category-down Sort alphabetically by category, Z-A.
tag-up Sort alphabetically by last tag, A-Z.
tag-down Sort alphabetically by last tag, Z-A.
priority-up Sort numerically by priority, high priority last.
priority-down Sort numerically by priority, high priority first.
todo-state-up Sort by todo state, tasks that are done last.
todo-state-down Sort by todo state, tasks that are done first.
effort-up Sort numerically by estimated effort, high effort last.
effort-down Sort numerically by estimated effort, high effort first.
user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
The different possibilities will be tried in sequence, and testing stops
if one comparison returns a \"not-equal\". For example, the default
@ -905,6 +908,16 @@ Custom commands can bind this variable in the options section."
(cons (const :tag "Strategy for Tags matches" tags)
(repeat ,org-sorting-choice)))))
(defcustom org-agenda-cmp-user-defined nil
"A function to define the comparison `user-defined'.
This function must receive two arguments, agenda entry a and b.
If a>b, return +1. If a<b, return -1. If they are equal as seen by
the user comparison, return nil.
When this is defined, you can make `user-defined-up' and `user-defined-down'
part of an agenda sorting strategy."
:group 'org-agenda-sorting
:type 'symbol)
(defcustom org-sort-agenda-notime-is-late t
"Non-nil means, items without time are considered late.
This is only relevant for sorting. When t, items which have no explicit
@ -4458,7 +4471,13 @@ HH:MM."
(tag-up (org-cmp-tag a b))
(tag-down (if tag-up (- tag-up) nil))
(todo-state-up (org-cmp-todo-state a b))
(todo-state-down (if todo-state-up (- todo-state-up) nil)))
(todo-state-down (if todo-state-up (- todo-state-up) nil))
user-defined-up user-defined-down)
(if (and org-agenda-cmp-user-defined
(functionp org-agenda-cmp-user-defined))
(setq user-defined-up
(funcall org-agenda-cmp-user-defined a b)
user-defined-down (if user-defined-up (- user-defined-up) nil)))
(cdr (assoc
(eval (cons 'or org-agenda-sorting-strategy-selected))
'((-1 . t) (1 . nil) (nil . nil))))))