From 4c2e8c359b863a85f3add6692305cfbe9939333b Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Fri, 30 Apr 2010 07:31:43 +0200 Subject: [PATCH] New agenda sorting strategy alphabetically Requested by John Wiegley --- lisp/ChangeLog | 5 +++++ lisp/org-agenda.el | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 743995f49..1ee199233 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2010-04-30 Carsten Dominik + + * org-agenda.el (org-sorting-choice): New sorting type alpha. + (org-cmp-alpha): New defsubst. + 2010-04-29 Carsten Dominik * org-html.el (org-format-org-table-html): Test all columns diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 279d682ba..984752935 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -211,6 +211,7 @@ you can \"misuse\" it to also add other text to the header. However, (const todo-state-up) (const todo-state-down) (const effort-up) (const effort-down) (const habit-up) (const habit-down) + (const alpha-up) (const alpha-down) (const user-defined-up) (const user-defined-down)) "Sorting choices.") @@ -1120,6 +1121,8 @@ 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. habit-up Put entries that are habits first habit-down Put entries that are habits last +alpha-up Sort headlines alphabetically +alpha-down Sort headlines alphabetically, reversed The different possibilities will be tried in sequence, and testing stops if one comparison returns a \"not-equal\". For example, the default @@ -5208,6 +5211,28 @@ HH:MM." ((< lb la) +1) (t nil)))) +(defsubst org-cmp-alpha (a b) + "Compare the headlines, alphabetically." + (let* ((pla (get-text-property 0 'prefix-length a)) + (plb (get-text-property 0 'prefix-length b)) + (ta (and pla (substring a pla))) + (tb (and plb (substring b plb)))) + (when pla + (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "") + "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta) + (setq ta (substring ta (match-end 0)))) + (setq ta (downcase ta))) + (when plb + (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "") + "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb) + (setq tb (substring tb (match-end 0)))) + (setq tb (downcase tb))) + (cond ((not ta) +1) + ((not tb) -1) + ((string-lessp ta tb) -1) + ((string-lessp tb ta) +1) + (t nil)))) + (defsubst org-cmp-tag (a b) "Compare the string values of the first tags of A and B." (let ((ta (car (last (get-text-property 1 'tags a)))) @@ -5254,6 +5279,8 @@ HH:MM." (todo-state-down (if todo-state-up (- todo-state-up) nil)) (habit-up (org-cmp-habit-p a b)) (habit-down (if habit-up (- habit-up) nil)) + (alpha-up (org-cmp-alpha a b)) + (alpha-down (if alpha-up (- alpha-up) nil)) user-defined-up user-defined-down) (if (and org-agenda-cmp-user-defined (functionp org-agenda-cmp-user-defined)) -- 2.11.4.GIT