diff options
author | Bastien Guerry <bzg@altern.org> | 2014-04-16 18:23:47 +0200 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2014-04-16 18:23:47 +0200 |
commit | 132da2db35a2f1ca027152ec4212c3da646ec691 (patch) | |
tree | 6ec0351a199b894f369be5ad1e683f6410bdebde | |
parent | 6ff38b1f6dccec14b236ec2d40a011f36ca9fd2f (diff) | |
download | org-mode-132da2db35a2f1ca027152ec4212c3da646ec691.tar.gz |
Let sort-by-time handle [H]H:MM strings and add a :sort parameter for clocktables
* org-clock.el (org-clocktable-write-default): New parameter
":sort" to sort a column by a sorting type. E.g., a value of
:sort (1 . ?a) will sort the first column alphabetically. The
sorting line is the third one, table-wise, which is usually
the first line that contains user data.
* org.texi (The clock table): Document the new :sort
parameter.
* org.el (org-do-sort): Recognize [H]H:MM strings as time
values and allow sort-by-time to process them.
* org-table.el (org-table-sort-lines): Mention that sorting by
time also recognize [H]H:MM time values.
-rw-r--r-- | doc/org.texi | 2 | ||||
-rw-r--r-- | lisp/org-clock.el | 6 | ||||
-rw-r--r-- | lisp/org-table.el | 3 | ||||
-rw-r--r-- | lisp/org.el | 19 |
4 files changed, 21 insertions, 9 deletions
diff --git a/doc/org.texi b/doc/org.texi index b02d2b6..9f46056 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -6533,6 +6533,8 @@ but you can specify your own function using the @code{:formatter} parameter. :tcolumns @r{Number of columns to be used for times. If this is smaller} @r{than @code{:maxlevel}, lower levels will be lumped into one column.} :level @r{Should a level number column be included?} +:sort @r{A cons cell like containing the column to sort and a sorting type.} + @r{E.g., @code{:sort (1 . ?a)} sorts the first column alphabetically.} :compact @r{Abbreviation for @code{:level nil :indent t :narrow 40! :tcolumns 1}} @r{All are overwritten except if there is an explicit @code{:narrow}} :timestamp @r{A timestamp for the entry, when available. Look for SCHEDULED,} diff --git a/lisp/org-clock.el b/lisp/org-clock.el index d47bf59..8aefe80 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2339,6 +2339,7 @@ from the dynamic block definition." org-clock-clocktable-language-setup)) (multifile (plist-get params :multifile)) (block (plist-get params :block)) + (sort (plist-get params :sort)) (ts (plist-get params :tstart)) (te (plist-get params :tend)) (header (plist-get params :header)) @@ -2545,6 +2546,11 @@ from the dynamic block definition." (when org-hide-emphasis-markers ;; we need to align a second time (org-table-align)) + (when sort + (save-excursion + (org-table-goto-line 3) + (org-table-goto-column (car sort)) + (org-table-sort-lines nil (cdr sort)))) (when recalc (if (eq formula '%) (save-excursion diff --git a/lisp/org-table.el b/lisp/org-table.el index c996b7c..c7bf789 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -1642,7 +1642,8 @@ should be in the last line to be included into the sorting. The command then prompts for the sorting type which can be alphabetically, numerically, or by time (as given in a time stamp -in the field). Sorting in reverse order is also possible. +in the field, or as a HH:MM value). Sorting in reverse order is +also possible. With prefix argument WITH-CASE, alphabetic sorting will be case-sensitive. diff --git a/lisp/org.el b/lisp/org.el index b40c25d..56bdb7e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8885,9 +8885,10 @@ When sorting is done, call `org-after-sorting-entries-or-items-hook'." (defun org-do-sort (table what &optional with-case sorting-type) "Sort TABLE of WHAT according to SORTING-TYPE. The user will be prompted for the SORTING-TYPE if the call to this -function does not specify it. WHAT is only for the prompt, to indicate -what is being sorted. The sorting key will be extracted from -the car of the elements of the table. +function does not specify it. +WHAT is only for the prompt, to indicate what is being sorted. +The sorting key will be extracted from the car of the elements of +the table. If WITH-CASE is non-nil, the sorting will be case-sensitive." (unless sorting-type (message @@ -8911,11 +8912,13 @@ If WITH-CASE is non-nil, the sorting will be case-sensitive." ((= dcst ?t) (setq extractfun (lambda (x) - (if (or (string-match org-ts-regexp x) - (string-match org-ts-regexp-both x)) - (org-float-time - (org-time-string-to-time (match-string 0 x))) - 0)) + (cond ((or (string-match org-ts-regexp x) + (string-match org-ts-regexp-both x)) + (org-float-time + (org-time-string-to-time (match-string 0 x)))) + ((string-match "[0-9]\\{1,2\\}:[0-9]\\{2\\}" x) + (org-hh:mm-string-to-minutes x)) + (t 0))) comparefun (if (= dcst sorting-type) '< '>))) (t (error "Invalid sorting type `%c'" sorting-type))) |