emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] sort TODO entries more usefully
@ 2014-05-25  5:33 Eric Abrahamsen
  2014-05-25  6:32 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2014-05-25  5:33 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 618 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Sort-TODO-entries-more-usefully.patch --]
[-- Type: text/x-diff, Size: 1978 bytes --]

From d19c86e720feb65e0aef7a1fff9bf19bd75dbcf4 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sort TODO entries more usefully
  2014-05-25  5:33 [PATCH] sort TODO entries more usefully Eric Abrahamsen
@ 2014-05-25  6:32 ` Bastien
  2014-05-25 11:51   ` Eric Abrahamsen
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2014-05-25  6:32 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

Hi Eric,

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> 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 don't think the alphabetical order is very useful here, and putting
headlines without TODO keywords first when sorting by TODO order is
counter-intuitive at least.

Let me suggest the attached patch instead: it puts TODO entries, then
entries without a TODO keyword, then DONE entries.

Would it be an improvement?

For specific needs, there is always C-c ^ f

Thanks,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-todo-sort-done-at-the-end.patch --]
[-- Type: text/x-diff, Size: 592 bytes --]

diff --git a/lisp/org.el b/lisp/org.el
index dc223b4..f2963b2 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8904,8 +8904,9 @@ 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)))))
+		 (let* ((m (match-string 2))
+			(s (if (member m org-done-keywords) '- '+)))
+		   (- 99 (funcall s (length (member m org-todo-keywords-1)))))))
 	    ((= dcst ?f)
 	     (if getkey-func
 		 (progn

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sort TODO entries more usefully
  2014-05-25  6:32 ` Bastien
@ 2014-05-25 11:51   ` Eric Abrahamsen
  2014-05-26  5:10     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2014-05-25 11:51 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg@gnu.org> writes:

> Hi Eric,
>
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> 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 don't think the alphabetical order is very useful here, and putting
> headlines without TODO keywords first when sorting by TODO order is
> counter-intuitive at least.
>
> Let me suggest the attached patch instead: it puts TODO entries, then
> entries without a TODO keyword, then DONE entries.
>
> Would it be an improvement?

Sure! The actual ordering of stuff was an arbitrary choice on my part --
the only thing I cared about was getting done and not-done separated.
This looks like a tidier solution, to boot...

E

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sort TODO entries more usefully
  2014-05-25 11:51   ` Eric Abrahamsen
@ 2014-05-26  5:10     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2014-05-26  5:10 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Hi Eric,

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Sure! The actual ordering of stuff was an arbitrary choice on my part --
> the only thing I cared about was getting done and not-done separated.
> This looks like a tidier solution, to boot...

Applied, thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-26  5:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-25  5:33 [PATCH] sort TODO entries more usefully Eric Abrahamsen
2014-05-25  6:32 ` Bastien
2014-05-25 11:51   ` Eric Abrahamsen
2014-05-26  5:10     ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).