From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: [PATCH] sort TODO entries more usefully Date: Sun, 25 May 2014 13:33:15 +0800 Message-ID: <8738fyctic.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoR1q-00038t-Dc for emacs-orgmode@gnu.org; Sun, 25 May 2014 01:31:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WoR1k-00085I-2F for emacs-orgmode@gnu.org; Sun, 25 May 2014 01:31:26 -0400 Received: from plane.gmane.org ([80.91.229.3]:51879) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoR1j-00084s-RR for emacs-orgmode@gnu.org; Sun, 25 May 2014 01:31:19 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WoR1i-00087X-Vl for emacs-orgmode@gnu.org; Sun, 25 May 2014 07:31:18 +0200 Received: from 50.56.99.223 ([50.56.99.223]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 25 May 2014 07:31:18 +0200 Received: from eric by 50.56.99.223 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 25 May 2014 07:31:18 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain For some reason I've been sorting lots of TODOs recently, and found the default behavior of org-sort-entries a little odd. It sorts according to the order found in org-todo-keywords-1, which apparently just comes from the order the keywords were scanned during setup. I don't think that's all that useful, so the attached patch sorts first by org-not-done-keywords vs org-done-keywords, then alphabetically. Headings with no keywords sort "big". I'm not very experienced at logical tricks like sorting strategies, and I'd be very curious to see if anyone had a more concise way of expressing the comp function. Eric --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Sort-TODO-entries-more-usefully.patch >From d19c86e720feb65e0aef7a1fff9bf19bd75dbcf4 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sun, 25 May 2014 12:18:52 +0800 Subject: [PATCH] Sort TODO entries more usefully lisp/org.el (org-sort-entries, org-compare-todos-subr): Change the sort routine for TODO entries so that they are first sorted by keyword time (done or not done) and then alphabetically. Entries with no TODO keyword at all are sorted "big". --- lisp/org.el | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 9f14c44..2400ddf 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8703,6 +8703,15 @@ Optional argument WITH-CASE means sort case-sensitively." (setq s (substring st 1 -1))) s) +(defun org-compare-todos-subr (a b) + (if (or (and (member a org-not-done-keywords) + (member b org-not-done-keywords)) + (and (member a org-done-keywords) + (member b org-done-keywords))) + (string< a b) + (or (member a org-done-keywords) + (consp a)))) + (defvar org-priority-regexp) ; defined later in the file (defvar org-after-sorting-entries-or-items-hook nil @@ -8904,8 +8913,8 @@ When sorting is done, call `org-after-sorting-entries-or-items-hook'." (or (org-entry-get nil property) "")) ((= dcst ?o) (if (looking-at org-complex-heading-regexp) - (- 9999 (length (member (match-string 2) - org-todo-keywords-1))))) + (car (member (match-string 2) + org-todo-keywords-1)))) ((= dcst ?f) (if getkey-func (progn @@ -8918,6 +8927,7 @@ When sorting is done, call `org-after-sorting-entries-or-items-hook'." (cond ((= dcst ?a) 'string<) ((= dcst ?f) compare-func) + ((= dcst ?o) 'org-compare-todos-subr) ((member dcst '(?p ?t ?s ?d ?c ?k)) '<))))) (run-hooks 'org-after-sorting-entries-or-items-hook) ;; Reset the clock marker if needed -- 1.9.3 --=-=-=--