* [PATCH] Add :sort option to clocktable report
@ 2011-08-04 14:45 Max Mikhanosha
2011-08-17 10:16 ` Bastien
0 siblings, 1 reply; 2+ messages in thread
From: Max Mikhanosha @ 2011-08-04 14:45 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 414 bytes --]
Attached patch adds new options :sort to the clocktable report
options. Valid values:
time-up or T - highest time on top
time-down - lowest time on top
For multi-file clock reports, entries in each file are sorted
separately and then the files are also sorted based on file total.
Perhaps this should be made a default? It seems clocktable report is
something that user would naturally expect to be sorted.
[-- Attachment #2: 0016-Add-sort-option-to-clocktable-report.patch --]
[-- Type: application/octet-stream, Size: 2978 bytes --]
From 8982d1e9c551b7c027483cc6984f27a234a0c167 Mon Sep 17 00:00:00 2001
From: Max Mikhanosha <max@openchat.com>
Date: Thu, 4 Aug 2011 10:26:47 -0400
Subject: [PATCH 16/16] Add :sort option to clocktable report
---
lisp/org-clock.el | 42 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 491f047..436e745 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2037,6 +2037,44 @@ the currently selected interval size."
(org-update-dblock)
t)))))
+(defun org-clocktable-sort-clock-data (tables params)
+ "TABLES is a list of tables with clocking data as produced by
+`org-clock-get-table-data'. PARAMS is the parameter property
+list obtained from the dynamic block defintion.
+
+When PARAMS contains a :SORT entry, sort the tables and the entries
+inside them accordnly:
+
+:SORT time-up or T, sorts by most time spent on top
+:SORT time-down, sorts by least time spent on top
+
+Returns the sorted table list"
+ (let ((sort (plist-get params :sort)))
+ (if (not sort) tables
+ (sort (mapcar
+ (lambda (table)
+ (list (nth 0 table)
+ (nth 1 table)
+ (sort
+ (third table)
+ (lambda (elem1 elem2)
+ (let ((d1 (nth 3 elem1))
+ (d2 (nth 3 elem2)))
+ (cond ((memq sort '(t time-up))
+ (> d1 d2))
+ ((eq sort 'time-down)
+ (< d1 d2))
+ (t (error "Invalid :sort parameter %s" sort))))))))
+ tables)
+ (lambda (table1 table2)
+ (let ((d1 (nth 1 table1))
+ (d2 (nth 1 table2)))
+ (cond ((memq sort '(t time-up))
+ (> d1 d2))
+ ((eq sort 'time-down)
+ (< d1 d2))
+ (t (error "Invalid :sort parameter %s" sort)))))))))
+
(defun org-dblock-write:clocktable (params)
"Write the standard clocktable."
(setq params (org-combine-plists org-clocktable-defaults params))
@@ -2054,7 +2092,6 @@ the currently selected interval size."
'org-clocktable-write-default))
cc range-text ipos pos one-file-with-archives
scope-is-list tbls level)
-
;; Check if we need to do steps
(when block
;; Get the range text for the header
@@ -2123,7 +2160,8 @@ the currently selected interval size."
(setq params (plist-put params :one-file-with-archives
one-file-with-archives))
- (funcall formatter ipos tbls params))))
+ (funcall formatter ipos
+ (org-clocktable-sort-clock-data tbls params) params))))
(defun org-clocktable-write-default (ipos tables params)
"Write out a clock table at position IPOS in the current buffer.
--
1.7.3.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Add :sort option to clocktable report
2011-08-04 14:45 [PATCH] Add :sort option to clocktable report Max Mikhanosha
@ 2011-08-17 10:16 ` Bastien
0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2011-08-17 10:16 UTC (permalink / raw)
To: Max Mikhanosha; +Cc: emacs-orgmode
Hi Max,
Max Mikhanosha <max@openchat.com> writes:
> Attached patch adds new options :sort to the clocktable report
> options. Valid values:
>
> time-up or T - highest time on top
> time-down - lowest time on top
>
> For multi-file clock reports, entries in each file are sorted
> separately and then the files are also sorted based on file total.
That's a *great* addition. I've tested the patch and it works well.
As the patch is more than 15 lines, you would need to sign the FSF
copyright assignment before I can apply the patch. I'll send you the
relevant papers in private.
> Perhaps this should be made a default? It seems clocktable report is
> something that user would naturally expect to be sorted.
Yes, I think :sort time-up should be the default.
Best,
--
Bastien
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-17 10:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-04 14:45 [PATCH] Add :sort option to clocktable report Max Mikhanosha
2011-08-17 10:16 ` Bastien
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.