emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Mikhanosha <max@openchat.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Add :sort option to clocktable report
Date: Thu, 04 Aug 2011 10:45:56 -0400	[thread overview]
Message-ID: <877h6txmjf.wl%max@openchat.com> (raw)

[-- 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


             reply	other threads:[~2011-08-04 14:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-04 14:45 Max Mikhanosha [this message]
2011-08-17 10:16 ` [PATCH] Add :sort option to clocktable report Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877h6txmjf.wl%max@openchat.com \
    --to=max@openchat.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).