From mboxrd@z Thu Jan 1 00:00:00 1970 From: James TD Smith Subject: [PATCH 2/2] Make org-agenda-columns-summarize work properly with the new summary types. Date: Wed, 11 Nov 2009 18:17:20 +0000 Message-ID: <1257963440-8651-2-git-send-email-ahktenzero@mohorovi.cc> References: <1257963440-8651-1-git-send-email-ahktenzero@mohorovi.cc> Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N8Hl1-0000Z1-Kt for emacs-orgmode@gnu.org; Wed, 11 Nov 2009 13:17:27 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N8Hky-0000TP-0F for emacs-orgmode@gnu.org; Wed, 11 Nov 2009 13:17:27 -0500 Received: from [199.232.76.173] (port=52854 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8Hkx-0000Sz-KC for emacs-orgmode@gnu.org; Wed, 11 Nov 2009 13:17:23 -0500 Received: from 81-86-40-42.dsl.pipex.com ([81.86.40.42]:52497 helo=yog-sothoth.mohorovi.cc) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N8Hkx-0001Pw-09 for emacs-orgmode@gnu.org; Wed, 11 Nov 2009 13:17:23 -0500 In-Reply-To: <1257963440-8651-1-git-send-email-ahktenzero@mohorovi.cc> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org It was assuming the values should be summarised by adding them together. It's now updated to use the summary functions in org-columns-compile-map, and also handles summary types with calculated values properly. --- lisp/org-colview.el | 62 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 43 insertions(+), 19 deletions(-) diff --git a/lisp/org-colview.el b/lisp/org-colview.el index d0784f5..0fc843f 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1044,9 +1044,16 @@ Don't set this, this is meant for dynamic scoping.") (if s (cond ((memq fmt '(min_age max_age mean_age)) - (if (string= s "") - org-columns-time - (time-to-number-of-days (apply 'encode-time (org-parse-time-string s t))))) + (cond ((string= s "") org-columns-time) + ((string-match + "\\([0-9]+\\)d \\([0-9]+\\)h \\([0-9]+\\)m \\([0-9]+\\)s" + s) + (+ (* 60 (+ (* 60 (+ (* 24 (string-to-number (match-string 1 s))) + (string-to-number (match-string 2 s)))) + (string-to-number (match-string 3 s)))) + (string-to-number (match-string 4 s)))) + (t (time-to-number-of-days (apply 'encode-time + (org-parse-time-string s t)))))) ((string-match ":" s) (let ((l (nreverse (org-split-string s ":"))) (sum 0.0)) (while l @@ -1363,10 +1370,11 @@ and tailing newline characters." "Summarize the summarizable columns in column view in the agenda. This will add overlays to the date lines, to show the summary for each day." (let* ((fmt (mapcar (lambda (x) - (list (car x) (if (equal (car x) "CLOCKSUM") - 'add_times (nth 4 x)))) + (if (equal (car x) "CLOCKSUM") + (list "CLOCKSUM" (nth 2 x) add_times + identity) + (cdr x))) org-columns-current-fmt-compiled)) - line c c1 stype props lsum entries prop v) + line c c1 stype calc sumfunc props lsum entries prop v) (catch 'exit (when (delq nil (mapcar 'cadr fmt)) ;; OK, at least one summation column, it makes sense to try this @@ -1389,24 +1397,40 @@ This will add overlays to the date lines, to show the summary for each day." (setq props (mapcar (lambda (f) - (setq prop (car f) stype (nth 1 f)) + (setq prop (car f) + stype (nth 3 f) + sumfunc (nth 5 f) + calc (or (nth 6 f) 'identity)) (cond ((equal prop "ITEM") (cons prop (buffer-substring (point-at-bol) (point-at-eol)))) ((not stype) (cons prop "")) - (t - ;; do the summary - (setq lsum 0) - (mapc (lambda (x) - (setq v (cdr (assoc prop x))) - (if v (setq lsum (+ lsum - (org-columns-string-to-number - v stype))))) - entries) - (setq lsum (org-columns-number-to-string lsum stype)) - (put-text-property - 0 (length lsum) 'face 'bold lsum) + (t ;; do the summary + (setq lsum nil) + (dolist (x entries) + (setq v (cdr (assoc prop x))) + (if v + (push + (funcall + (if (not (get-text-property 0 'org-computed v)) + calc + 'identity) + (org-columns-string-to-number + v stype)) + lsum))) + (setq lsum (remove nil lsum)) + (setq lsum + (cond ((> (length lsum) 1) + (org-columns-number-to-string + (apply sumfunc lsum) stype)) + ((eq (length lsum) 1) + (org-columns-number-to-string + (car lsum) stype)) + (t ""))) + (put-text-property 0 (length lsum) 'face 'bold lsum) + (if (neq calc 'identity) + (put-text-property 0 (length lsum) 'org-computed t lsum)) (cons prop lsum)))) fmt)) (org-columns-display-here props 'dateline) -- 1.6.5