From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Malakhovski Subject: [PATCH 4/4] org-clock: make clock table respect `org-effort-durations' Date: Sun, 27 Dec 2015 15:13:49 +0000 Message-ID: <1451229229-18973-5-git-send-email-oxij@oxij.org> References: <1451229229-18973-1-git-send-email-oxij@oxij.org> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aDD1Y-0005JD-94 for emacs-orgmode@gnu.org; Sun, 27 Dec 2015 10:14:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aDD1V-0004HD-0R for emacs-orgmode@gnu.org; Sun, 27 Dec 2015 10:14:20 -0500 Received: from tricoro.koumakan.jp ([195.154.188.176]:16880) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aDD1U-0004H9-RE for emacs-orgmode@gnu.org; Sun, 27 Dec 2015 10:14:16 -0500 In-Reply-To: <1451229229-18973-1-git-send-email-oxij@oxij.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: Jan Malakhovski * lisp/org-clock.el (org-clock-time%): Rewrite using (org-clocksum-string-to-minutes), document pitfalls. (org-clock-time%-with-effort): New function. (org-clocktable-write-default): Fix effort-duration parameter. * doc/org.texi (The clock table): Update documentation. --- doc/org.texi | 6 ++++++ lisp/org-clock.el | 49 ++++++++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 92ec29a..c526057 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -6687,6 +6687,7 @@ but you can specify your own function using the @code{:formatter} parameter. @r{As a special case, @samp{:formula %} adds a column with % time.} @r{If you do not specify a formula here, any existing formula} @r{below the clock table will survive updates and be evaluated.} +:effort-durations @r{Name of a symbol to use as @code{org-effort-durations} when preparing the table.} :formatter @r{A function to format clock data and insert it into the buffer.} @end example To get a clock summary of the current level 1 tree, for the current @@ -6714,6 +6715,11 @@ A summary of the current subtree with % times would be #+BEGIN: clocktable :scope subtree :link t :formula % #+END: clocktable @end example +The same thing measured in 8-hour work days would be +@example +#+BEGIN: clocktable :scope subtree :link t :formula % :effort-durations org-effort-durations-8h +#+END: clocktable +@end example A horizontally compact representation of everything clocked during last week would be @example diff --git a/lisp/org-clock.el b/lisp/org-clock.el index df993b0..53292ae 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2468,9 +2468,10 @@ from the dynamic block definition." (maxlevel (or (plist-get params :maxlevel) 3)) (emph (plist-get params :emphasize)) (level-p (plist-get params :level)) - ;; FIXME: setting this will break `org-clock-time%' - (org-time-clocksum-use-effort-durations - (plist-get params :effort-durations)) + (effort-durations (plist-get params :effort-durations)) + (org-effort-durations (if (null effort-durations) + org-effort-durations + (eval effort-durations))) (timestamp (plist-get params :timestamp)) (properties (plist-get params :properties)) (ntcol (max 1 (or (plist-get params :tcolumns) 100))) @@ -2641,8 +2642,11 @@ from the dynamic block definition." (if timestamp 1 0))) (insert (format - "\n#+TBLFM: $%d='(org-clock-time%% @%d$%d $%d..$%d);%%.1f" + "\n#+TBLFM: $%d='(%s @%d$%d $%d..$%d);%%.1f" pcol ; the column where the % numbers should go + (if (null effort-durations) + "org-clock-time%" + (format "org-clock-time%%-with-effort %s" (symbol-name effort-durations))) (if (and narrow (not narrow-cut-p)) 3 2) ; row of the total time tcol ; column of the total time tcol (1- pcol) ; range of columns where times can be found @@ -2858,25 +2862,28 @@ TIME: The sum of all time spend in this tree, in minutes. This time "Compute a time fraction in percent. TOTAL s a time string like 10:21 specifying the total times. STRINGS is a list of strings that should be checked for a time. +Strings are parsed using `org-clocksum-string-to-minutes'. The first string that does have a time will be used. -This function is made for clock tables." - (let ((re "\\([0-9]+\\):\\([0-9]+\\)") - tot s) - (save-match-data + +This function is made for clock tables. + +This function can be broken by setting `org-time-clocksum-format' +to something that `org-clocksum-string-to-minutes' can not +parse." + (save-match-data + (let ((tot (org-clocksum-string-to-minutes total)) + s cur) (catch 'exit - (if (not (string-match re total)) - (throw 'exit 0.) - (setq tot (+ (string-to-number (match-string 2 total)) - (* 60 (string-to-number (match-string 1 total))))) - (if (= tot 0.) (throw 'exit 0.))) - (while (setq s (pop strings)) - (if (string-match "\\([0-9]+\\):\\([0-9]+\\)" s) - (throw 'exit - (/ (* 100.0 (+ (string-to-number (match-string 2 s)) - (* 60 (string-to-number - (match-string 1 s))))) - tot)))) - 0)))) + (if (= tot 0.) (throw 'exit 0.)) + (dolist (s strings) + (setq cur (org-clocksum-string-to-minutes s)) + (when cur (throw 'exit (/ (* 100.0 cur) tot)))) + nil)))) + +(defun org-clock-time%-with-effort (effort-durations total &rest strings) + "A version of `org-clock-time%' that temporary sets `org-effort-durations'." + (let ((org-effort-durations effort-durations)) + (apply 'org-clock-time% total strings))) ;; Saving and loading the clock -- 2.6.4