Carsten Dominik <carsten.domi...@gmail.com> writes:

> Dear Niels,
>
> I am confused by the three patch pieces applied to the same file.

Hi Carsten. Sorry for the confusion; I thought atomic commits were the
proper thing to do, but apparently they are not.

> Can you please resubmit, with a single patch, and a proper
> changelog-like entry?

I hope my current attachment is in the appropriate form.

>From 9065d22f5e41d73a47c72e6ee3f70bd974bee9ff Mon Sep 17 00:00:00 2001
From: niels giesen <niels.gie...@gmail.com>
Date: Fri, 13 May 2011 09:43:15 +0200
Subject: [PATCH] org-clock: Implement columns of arbitrary properties for clocktables.

* org-mode/lisp/org-clock.el (org-clocktable-write-default): List
  properties in their own columns.
  (org-clock-get-table-data): Return alist of properties specified in
  a clocktable's `BEGIN' line under :properties, inherited when
  :inherit-props is non-nil.

Each property specified in :properties parameter of a clocktable's
`BEGIN' line will get a column in the clocktable, at the left side of
that table. When :inherit-props is specified, such properties will be
inherited.
---
 lisp/org-clock.el |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index efeb72f..127f041 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1,6 +1,6 @@
 ;;; org-clock.el --- The time clocking code for Org-mode
 
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
+;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 ;;   Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
@@ -2059,6 +2059,7 @@ from the dynamic block defintion."
 	 (emph (plist-get params :emphasize))
 	 (level-p (plist-get params :level))
 	 (timestamp (plist-get params :timestamp))
+	 (properties (plist-get params :properties))
 	 (ntcol (max 1 (or (plist-get params :tcolumns) 100)))
 	 (rm-file-column (plist-get params :one-file-with-archives))
 	 (indent (plist-get params :indent))
@@ -2122,6 +2123,7 @@ from the dynamic block defintion."
 	 (if multifile "|" "")          ; file column, maybe
 	 (if level-p   "|" "")          ; level column, maybe
 	 (if timestamp "|" "")          ; timestamp column, maybe
+	 (if properties (make-string (length properties) ?|) "")  ;properties columns, maybe
 	 (format "<%d>| |\n" narrow)))  ; headline and time columns
 
       ;; Insert the table header line
@@ -2130,6 +2132,7 @@ from the dynamic block defintion."
        (if multifile (concat (nth 1 lwords) "|") "")  ; file column, maybe
        (if level-p   (concat (nth 2 lwords) "|") "")  ; level column, maybe
        (if timestamp (concat (nth 3 lwords) "|") "")  ; timestamp column, maybe
+       (if properties (concat (mapconcat 'identity properties "|") "|") "") ;properties columns, maybe
        (concat (nth 4 lwords) "|" 
 	       (nth 5 lwords) "|\n"))                 ; headline and time columns
 
@@ -2141,6 +2144,7 @@ from the dynamic block defintion."
 				         ; file column, maybe
        (if level-p   "|"      "")        ; level column, maybe
        (if timestamp "|"      "")        ; timestamp column, maybe
+       (if properties (make-string (length properties) ?|) "")  ;properties columns, maybe
        (concat "*" (nth 7 lwords) "*| ") ; instead of a headline
        "*"
        (org-minutes-to-hh:mm-string (or total-time 0)) ; the time
@@ -2164,6 +2168,7 @@ from the dynamic block defintion."
 		       (file-name-nondirectory (car tbl))
 		       (if level-p   "| " "") ; level column, maybe
 		       (if timestamp "| " "") ; timestamp column, maybe
+		       (if properties (make-string (length properties) ?|) "")  ;properties columns, maybe
 		       (org-minutes-to-hh:mm-string (nth 1 tbl))))) ; the time
 
 	    ;; Get the list of node entries and iterate over it
@@ -2188,6 +2193,11 @@ from the dynamic block defintion."
 	       (if multifile "|" "")    ; free space for file name column?
 	       (if level-p (format "%d|" (car entry)) "")   ; level, maybe
 	       (if timestamp (concat (nth 2 entry) "|") "") ; timestamp, maybe
+	       (if properties
+		   (concat
+		    (mapconcat
+		     (lambda (p) (or (cdr (assoc p (nth 4 entry))) ""))
+		     properties "|") "|") "")  ;properties columns, maybe
 	       (if indent (org-clocktable-indent-string level) "") ; indentation
 	       hlc headline hlc "|"                                ; headline
 	       (make-string (min (1- ntcol) (or (- level 1))) ?|)
@@ -2342,6 +2352,8 @@ TIME:      The sum of all time spend in this tree, in minutes.  This time
 	 (block (plist-get params :block))
 	 (link (plist-get params :link))
 	 (tags (plist-get params :tags))
+	 (properties (plist-get params :properties))
+	 (inherit-property-p (plist-get params :inherit-props))
 	 (matcher (if tags (cdr (org-make-tags-matcher tags))))
 	 cc range-text st p time level hdl props tsp tbl)
 
@@ -2395,8 +2407,15 @@ TIME:      The sum of all time spend in this tree, in minutes.  This time
 			  (or (cdr (assoc "SCHEDULED" props))
 			      (cdr (assoc "DEADLINE" props))
 			      (cdr (assoc "TIMESTAMP" props))
-			      (cdr (assoc "TIMESTAMP_IA" props)))))
-	      (when (> time 0) (push (list level hdl tsp time) tbl))))))
+			      (cdr (assoc "TIMESTAMP_IA" props))))
+	    props (when properties
+		    (remove nil
+			    (mapcar
+			     (lambda (p)
+			       (when (org-entry-get (point) p inherit-property-p)
+				 (cons p (org-entry-get (point) p inherit-property-p))))
+			     properties))))
+	      (when (> time 0) (push (list level hdl tsp time props) tbl))))))
       (setq tbl (nreverse tbl))
       (list file org-clock-file-total-minutes tbl))))
 
-- 
1.6.0.4

> Thanks.
>
> - Carsten
>
> On Mar 26, 2011, at 9:29 PM, Niels Giesen wrote:
>
>> 
>> Here are a few patches to add property columns in clocktables. These
>> allow me e.g. to freely set different cost centers which is wanted @
>> my work, and also possibly small descriptions. It is generically set
>> up so I reckon other people may find use in this too.
>> 
>> The patches together add two parameters to the dynamic block line:
>> 
>> : :properties ("prop-this" "prop-other") :inherit-props t
>> 
>> The property columns will be added at the left side of the existing
>> columns; I did experiment with adding them to the right, but because
>> of the variable number of levels (being defined both by :maxlevel and
>> the actual number of found levels), that did not work out well.
>> 
>> I used the parameter =:inherit-props= to set inheritance for
>> properties, as I have learned in the past that
>> =org-use-property-inheritance= should be used very sparingly.
>> 
>> #+begin_src diff
>> From 20346cf661e2b9ba0b4a66b705809e6100d9e8e0 Mon Sep 17 00:00:00 2001
>> From: Niels Giesen <niels.gie...@gmail.com>
>> Date: Sat, 26 Mar 2011 10:19:08 +0100
>> Subject: [PATCH 1/3] org-clock: Add properties param handling to 
>> `org-clock-get-table-data'
>> 
>> This param should be a list of strings referring to properties. Those
>> properties will be returned in an alist when found in an entry.
>> ---
>> lisp/org-clock.el |   14 +++++++++++---
>> 1 files changed, 11 insertions(+), 3 deletions(-)
>> 
>> diff --git a/lisp/org-clock.el b/lisp/org-clock.el
>> index c567a26..df096d1 100644
>> --- a/lisp/org-clock.el
>> +++ b/lisp/org-clock.el
>> @@ -1,6 +1,6 @@
>> ;;; org-clock.el --- The time clocking code for Org-mode
>> 
>> -;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
>> +;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
>> ;;   Free Software Foundation, Inc.
>> 
>> ;; Author: Carsten Dominik <carsten at orgmode dot org>
>> @@ -2335,6 +2335,7 @@ TIME:      The sum of all time spend in this tree, in 
>> minutes.  This time
>>       (block (plist-get params :block))
>>       (link (plist-get params :link))
>>       (tags (plist-get params :tags))
>> +     (properties (plist-get params :properties))
>>       (matcher (if tags (cdr (org-make-tags-matcher tags))))
>>       cc range-text st p time level hdl props tsp tbl)
>> 
>> @@ -2388,8 +2389,15 @@ TIME:      The sum of all time spend in this tree, in 
>> minutes.  This time
>>                        (or (cdr (assoc "SCHEDULED" props))
>>                            (cdr (assoc "DEADLINE" props))
>>                            (cdr (assoc "TIMESTAMP" props))
>> -                          (cdr (assoc "TIMESTAMP_IA" props)))))
>> -          (when (> time 0) (push (list level hdl tsp time) tbl))))))
>> +                          (cdr (assoc "TIMESTAMP_IA" props))))
>> +        props (when properties
>> +                (remove nil
>> +                        (mapcar
>> +                         (lambda (p)
>> +                           (when (org-entry-get (point) p)
>> +                             (cons p (org-entry-get (point) p))))
>> +                         properties))))
>> +          (when (> time 0) (push (list level hdl tsp time props) tbl))))))
>>       (setq tbl (nreverse tbl))
>>       (list file org-clock-file-total-minutes tbl))))
>> 
>> -- 
>> 1.7.1
>> #+end_src
>> 
>> #+begin_src diff
>> From a5da80e0b42256e1a1ea07e213bcae3685786589 Mon Sep 17 00:00:00 2001
>> From: Niels Giesen <niels.gie...@gmail.com>
>> Date: Sat, 26 Mar 2011 11:05:33 +0100
>> Subject: [PATCH 2/3] org-clock: Add properties param handling to 
>> `org-clocktable-write-default'
>> 
>> Each property specified in properties will get a column in the clocktable.
>> ---
>> lisp/org-clock.el |   10 ++++++++++
>> 1 files changed, 10 insertions(+), 0 deletions(-)
>> 
>> diff --git a/lisp/org-clock.el b/lisp/org-clock.el
>> index df096d1..a330db0 100644
>> --- a/lisp/org-clock.el
>> +++ b/lisp/org-clock.el
>> @@ -2052,6 +2052,7 @@ from the dynamic block defintion."
>>       (emph (plist-get params :emphasize))
>>       (level-p (plist-get params :level))
>>       (timestamp (plist-get params :timestamp))
>> +     (properties (plist-get params :properties))
>>       (ntcol (max 1 (or (plist-get params :tcolumns) 100)))
>>       (rm-file-column (plist-get params :one-file-with-archives))
>>       (indent (plist-get params :indent))
>> @@ -2115,6 +2116,7 @@ from the dynamic block defintion."
>>       (if multifile "|" "")          ; file column, maybe
>>       (if level-p   "|" "")          ; level column, maybe
>>       (if timestamp "|" "")          ; timestamp column, maybe
>> +     (if properties (make-string (length properties) ?|) "")  ;properties 
>> columns, maybe
>>       (format "<%d>| |\n" narrow)))  ; headline and time columns
>> 
>>       ;; Insert the table header line
>> @@ -2123,6 +2125,7 @@ from the dynamic block defintion."
>>        (if multifile (concat (nth 1 lwords) "|") "")  ; file column, maybe
>>        (if level-p   (concat (nth 2 lwords) "|") "")  ; level column, maybe
>>        (if timestamp (concat (nth 3 lwords) "|") "")  ; timestamp column, 
>> maybe
>> +       (if properties (concat (mapconcat 'identity properties "|") "|") "") 
>> ;properties columns, maybe
>>        (concat (nth 4 lwords) "|" 
>>             (nth 5 lwords) "|\n"))                 ; headline and time 
>> columns
>> 
>> @@ -2134,6 +2137,7 @@ from the dynamic block defintion."
>>                                       ; file column, maybe
>>        (if level-p   "|"      "")        ; level column, maybe
>>        (if timestamp "|"      "")        ; timestamp column, maybe
>> +       (if properties (make-string (length properties) ?|) "")  ;properties 
>> columns, maybe
>>        (concat "*" (nth 7 lwords) "*| ") ; instead of a headline
>>        "*"
>>        (org-minutes-to-hh:mm-string (or total-time 0)) ; the time
>> @@ -2157,6 +2161,7 @@ from the dynamic block defintion."
>>                     (file-name-nondirectory (car tbl))
>>                     (if level-p   "| " "") ; level column, maybe
>>                     (if timestamp "| " "") ; timestamp column, maybe
>> +                   (if properties (make-string (length properties) ?|) "")  
>> ;properties columns, maybe
>>                     (org-minutes-to-hh:mm-string (nth 1 tbl))))) ; the time
>> 
>>          ;; Get the list of node entries and iterate over it
>> @@ -2181,6 +2186,11 @@ from the dynamic block defintion."
>>             (if multifile "|" "")    ; free space for file name column?
>>             (if level-p (format "%d|" (car entry)) "")   ; level, maybe
>>             (if timestamp (concat (nth 2 entry) "|") "") ; timestamp, maybe
>> +           (if properties
>> +               (concat
>> +                (mapconcat
>> +                 (lambda (p) (or (cdr (assoc p (nth 4 entry))) ""))
>> +                 properties "|") "|") "")  ;properties columns, maybe
>>             (if indent (org-clocktable-indent-string level) "") ; indentation
>>             hlc headline hlc "|"                                ; headline
>>             (make-string (min (1- ntcol) (or (- level 1))) ?|)
>> -- 
>> 1.7.1
>> #+end_src
>> 
>> #+begin_src diff
>> From e7b95ec4b61ada44d501e1212d3a3cb80e663911 Mon Sep 17 00:00:00 2001
>> From: Niels Giesen <niels.gie...@gmail.com>
>> Date: Sat, 26 Mar 2011 14:48:21 +0100
>> Subject: [PATCH 3/3] org-clock: Add param :inherit-props
>> 
>> When non-nil, properties are computed with inheritance.
>> ---
>> lisp/org-clock.el |    5 +++--
>> 1 files changed, 3 insertions(+), 2 deletions(-)
>> 
>> diff --git a/lisp/org-clock.el b/lisp/org-clock.el
>> index a330db0..1eecb68 100644
>> --- a/lisp/org-clock.el
>> +++ b/lisp/org-clock.el
>> @@ -2346,6 +2346,7 @@ TIME:      The sum of all time spend in this tree, in 
>> minutes.  This time
>>       (link (plist-get params :link))
>>       (tags (plist-get params :tags))
>>       (properties (plist-get params :properties))
>> +     (inherit-property-p (plist-get params :inherit-props))
>>       (matcher (if tags (cdr (org-make-tags-matcher tags))))
>>       cc range-text st p time level hdl props tsp tbl)
>> 
>> @@ -2404,8 +2405,8 @@ TIME:      The sum of all time spend in this tree, in 
>> minutes.  This time
>>                  (remove nil
>>                          (mapcar
>>                           (lambda (p)
>> -                           (when (org-entry-get (point) p)
>> -                             (cons p (org-entry-get (point) p))))
>> +                           (when (org-entry-get (point) p 
>> inherit-property-p)
>> +                             (cons p (org-entry-get (point) p 
>> inherit-property-p))))
>>                           properties))))
>>            (when (> time 0) (push (list level hdl tsp time props) tbl))))))
>>       (setq tbl (nreverse tbl))
>> -- 
>> 1.7.1
>> #+end_src
>> 
>> niels
>> --
>> http://pft.github.com
>> 
>
> - Carsten
>
>
>

-- 
http://pft.github.com/

Reply via email to