Browse Source

org.el (org-sort-entries): Allow to sort by clocking time

* org.el (org-sort-entries): Allow to sort by clocking time.

Thanks to Noah Slater for this idea.
Bastien Guerry 11 years ago
parent
commit
5ec31814f9
1 changed files with 14 additions and 10 deletions
  1. 14 10
      lisp/org.el

+ 14 - 10
lisp/org.el

@@ -8683,20 +8683,21 @@ a time stamp, by a property, by priority order, or by a custom function.
 
 
 The command prompts for the sorting type unless it has been given to the
 The command prompts for the sorting type unless it has been given to the
 function through the SORTING-TYPE argument, which needs to be a character,
 function through the SORTING-TYPE argument, which needs to be a character,
-\(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?o ?O ?r ?R ?f ?F).  Here is the
-precise meaning of each character:
+\(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?o ?O ?r ?R ?f ?F ?k ?K).  Here is
+the precise meaning of each character:
 
 
-n   Numerically, by converting the beginning of the entry/item to a number.
 a   Alphabetically, ignoring the TODO keyword and the priority, if any.
 a   Alphabetically, ignoring the TODO keyword and the priority, if any.
-o   By order of TODO keywords.
-t   By date/time, either the first active time stamp in the entry, or, if
-    none exist, by the first inactive one.
-s   By the scheduled date/time.
-d   By deadline date/time.
 c   By creation time, which is assumed to be the first inactive time stamp
 c   By creation time, which is assumed to be the first inactive time stamp
     at the beginning of a line.
     at the beginning of a line.
+d   By deadline date/time.
+k   By clocking time.
+n   Numerically, by converting the beginning of the entry/item to a number.
+o   By order of TODO keywords.
 p   By priority according to the cookie.
 p   By priority according to the cookie.
 r   By the value of a property.
 r   By the value of a property.
+s   By scheduled date/time.
+t   By date/time, either the first active time stamp in the entry, or, if
+    none exist, by the first inactive one.
 
 
 Capital letters will reverse the sort order.
 Capital letters will reverse the sort order.
 
 
@@ -8775,8 +8776,8 @@ When sorting is done, call `org-after-sorting-entries-or-items-hook'."
     (unless sorting-type
     (unless sorting-type
       (message
       (message
        "Sort %s: [a]lpha  [n]umeric  [p]riority  p[r]operty  todo[o]rder  [f]unc
        "Sort %s: [a]lpha  [n]umeric  [p]riority  p[r]operty  todo[o]rder  [f]unc
-               [t]ime [s]cheduled  [d]eadline  [c]reated
-               A/N/P/R/O/F/T/S/D/C means reversed:"
+               [t]ime [s]cheduled  [d]eadline  [c]reated  cloc[k]ing
+               A/N/P/R/O/F/T/S/D/C/K means reversed:"
        what)
        what)
       (setq sorting-type (read-char-exclusive))
       (setq sorting-type (read-char-exclusive))
 
 
@@ -8794,6 +8795,7 @@ When sorting is done, call `org-after-sorting-entries-or-items-hook'."
 				       (mapcar 'list (org-buffer-property-keys t))
 				       (mapcar 'list (org-buffer-property-keys t))
 				       nil t))))
 				       nil t))))
 
 
+    (when (member sorting-type '(?k ?K)) (org-clock-sum))
     (message "Sorting entries...")
     (message "Sorting entries...")
 
 
     (save-restriction
     (save-restriction
@@ -8828,6 +8830,8 @@ When sorting is done, call `org-after-sorting-entries-or-items-hook'."
 	     (if (looking-at org-complex-heading-regexp)
 	     (if (looking-at org-complex-heading-regexp)
 		 (funcall case-func (org-sort-remove-invisible (match-string 4)))
 		 (funcall case-func (org-sort-remove-invisible (match-string 4)))
 	       nil))
 	       nil))
+	    ((= dcst ?k)
+	     (get-text-property (point) :org-clock-minutes))
 	    ((= dcst ?t)
 	    ((= dcst ?t)
 	     (let ((end (save-excursion (outline-next-heading) (point))))
 	     (let ((end (save-excursion (outline-next-heading) (point))))
 	       (if (or (re-search-forward org-ts-regexp end t)
 	       (if (or (re-search-forward org-ts-regexp end t)