Browse Source

Introduce a new special property CLOCKSUM_T for today's clocked time.

* org.el (org-special-properties): New special property
CLOCKSUM_T.
(org-entry-properties): Handle the new special property.

* org-colview.el (org-columns): Handle a new special property
CLOCKSUM_T.
(org-agenda-colview-summarize, org-agenda-colview-compute):
Ditto.

* org-clock.el (org-clock-sum-today): New function.
(org-clock-sum): New argument PROPNAME to set a custom text
property instead of :org-clock-minutes.

* org.texi (Special properties, Column attributes)
(Agenda column view): Document the new special property
CLOCKSUM_T.

Thanks to Brian Wood who asked a question wrt this.
Bastien Guerry 12 years ago
parent
commit
de271e3751
4 changed files with 56 additions and 22 deletions
  1. 16 3
      doc/org.texi
  2. 15 7
      lisp/org-clock.el
  3. 16 9
      lisp/org-colview.el
  4. 9 3
      lisp/org.el

+ 16 - 3
doc/org.texi

@@ -4999,6 +4999,7 @@ used as keys in the properties drawer:
 @cindex property, special, TIMESTAMP
 @cindex property, special, TIMESTAMP
 @cindex property, special, TIMESTAMP_IA
 @cindex property, special, TIMESTAMP_IA
 @cindex property, special, CLOCKSUM
 @cindex property, special, CLOCKSUM
+@cindex property, special, CLOCKSUM_T
 @cindex property, special, BLOCKED
 @cindex property, special, BLOCKED
 @c guessing that ITEM is needed in this area; also, should this list be sorted?
 @c guessing that ITEM is needed in this area; also, should this list be sorted?
 @cindex property, special, ITEM
 @cindex property, special, ITEM
@@ -5018,6 +5019,9 @@ TIMESTAMP    @r{The first keyword-less timestamp in the entry.}
 TIMESTAMP_IA @r{The first inactive timestamp in the entry.}
 TIMESTAMP_IA @r{The first inactive timestamp in the entry.}
 CLOCKSUM     @r{The sum of CLOCK intervals in the subtree.  @code{org-clock-sum}}
 CLOCKSUM     @r{The sum of CLOCK intervals in the subtree.  @code{org-clock-sum}}
              @r{must be run first to compute the values in the current buffer.}
              @r{must be run first to compute the values in the current buffer.}
+CLOCKSUM_T   @r{The sum of CLOCK intervals in the subtree for today.}
+             @r{@code{org-clock-sum-today}} must be run first to compute the}
+             @r{values in the current buffer.}
 BLOCKED      @r{"t" if task is currently blocked by children or siblings}
 BLOCKED      @r{"t" if task is currently blocked by children or siblings}
 ITEM         @r{The headline of the entry.}
 ITEM         @r{The headline of the entry.}
 FILE         @r{The filename the entry is located in.}
 FILE         @r{The filename the entry is located in.}
@@ -5235,7 +5239,7 @@ values.
 
 
 @example
 @example
 :COLUMNS:  %25ITEM %9Approved(Approved?)@{X@} %Owner %11Status \@footnote{Please note that the COLUMNS definition must be on a single line---it is wrapped here only because of formatting constraints.}
 :COLUMNS:  %25ITEM %9Approved(Approved?)@{X@} %Owner %11Status \@footnote{Please note that the COLUMNS definition must be on a single line---it is wrapped here only because of formatting constraints.}
-                   %10Time_Estimate@{:@} %CLOCKSUM
+                   %10Time_Estimate@{:@} %CLOCKSUM %CLOCKSUM_T
 :Owner_ALL:    Tammy Mark Karl Lisa Don
 :Owner_ALL:    Tammy Mark Karl Lisa Don
 :Status_ALL:   "In progress" "Not started yet" "Finished" ""
 :Status_ALL:   "In progress" "Not started yet" "Finished" ""
 :Approved_ALL: "[ ]" "[X]"
 :Approved_ALL: "[ ]" "[X]"
@@ -5254,8 +5258,9 @@ modified title (@samp{Approved?}, with a question mark).  Summaries will
 be created for the @samp{Time_Estimate} column by adding time duration
 be created for the @samp{Time_Estimate} column by adding time duration
 expressions like HH:MM, and for the @samp{Approved} column, by providing
 expressions like HH:MM, and for the @samp{Approved} column, by providing
 an @samp{[X]} status if all children have been checked.  The
 an @samp{[X]} status if all children have been checked.  The
-@samp{CLOCKSUM} column is special, it lists the sum of CLOCK intervals
-in the subtree.
+@samp{CLOCKSUM} and @samp{CLOCKSUM_T} columns are special, they lists the
+sums of CLOCK intervals in the subtree, either for all clocks or just for
+today.
 
 
 @node Using column view, Capturing column view, Defining columns, Column view
 @node Using column view, Capturing column view, Defining columns, Column view
 @subsection Using column view
 @subsection Using column view
@@ -8940,6 +8945,14 @@ a column listing the planned total effort for a task---one of the major
 applications for column view in the agenda.  If you want information about
 applications for column view in the agenda.  If you want information about
 clocked time in the displayed period use clock table mode (press @kbd{R} in
 clocked time in the displayed period use clock table mode (press @kbd{R} in
 the agenda).
 the agenda).
+
+@item
+@cindex property, special, CLOCKSUM_T
+When the column view in the agenda shows the @code{CLOCKSUM_T}, that is
+always today's clocked time for this item.  So even in the weekly agenda,
+the clocksum listed in column view only originates from today.  This lets
+you compare the time you spent on a task for today, with the time already
+spent (via @code{CLOCKSUM}) and with the planned total effort for it.
 @end enumerate
 @end enumerate
 
 
 
 

+ 15 - 7
lisp/org-clock.el

@@ -1618,13 +1618,20 @@ With prefix arg SELECT, offer recently clocked tasks for selection."
   "Holds the file total time in minutes, after a call to `org-clock-sum'.")
   "Holds the file total time in minutes, after a call to `org-clock-sum'.")
 (make-variable-buffer-local 'org-clock-file-total-minutes)
 (make-variable-buffer-local 'org-clock-file-total-minutes)
 
 
-(defun org-clock-sum (&optional tstart tend headline-filter)
+(defun org-clock-sum-today (&optional headline-filter)
+  "Sum the times for each subtree for today."
+  (interactive)
+  (let ((range (org-clock-special-range 'today)))
+    (org-clock-sum (car range) (cadr range) nil :org-clock-minutes-today)))
+
+(defun org-clock-sum (&optional tstart tend headline-filter propname)
   "Sum the times for each subtree.
   "Sum the times for each subtree.
 Puts the resulting times in minutes as a text property on each headline.
 Puts the resulting times in minutes as a text property on each headline.
-TSTART and TEND can mark a time range to be considered.  HEADLINE-FILTER is a
-zero-arg function that, if specified, is called for each headline in the time
-range with point at the headline.  Headlines for which HEADLINE-FILTER returns
-nil are excluded from the clock summation."
+TSTART and TEND can mark a time range to be considered.
+HEADLINE-FILTER is a zero-arg function that, if specified, is called for
+each headline in the time range with point at the headline.  Headlines for
+which HEADLINE-FILTER returns nil are excluded from the clock summation.
+PROPNAME lets you set a custom text property instead of :org-clock-minutes."
   (interactive)
   (interactive)
   (let* ((bmp (buffer-modified-p))
   (let* ((bmp (buffer-modified-p))
 	 (re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
 	 (re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
@@ -1641,7 +1648,7 @@ nil are excluded from the clock summation."
     (if (consp tstart) (setq tstart (org-float-time tstart)))
     (if (consp tstart) (setq tstart (org-float-time tstart)))
     (if (consp tend) (setq tend (org-float-time tend)))
     (if (consp tend) (setq tend (org-float-time tend)))
     (remove-text-properties (point-min) (point-max)
     (remove-text-properties (point-min) (point-max)
-                            '(:org-clock-minutes t
+                            `(,(or propname :org-clock-minutes) t
                               :org-clock-force-headline-inclusion t))
                               :org-clock-force-headline-inclusion t))
     (save-excursion
     (save-excursion
       (goto-char (point-max))
       (goto-char (point-max))
@@ -1690,7 +1697,8 @@ nil are excluded from the clock summation."
                           (aset ltimes l (+ (aref ltimes l) t1))))
                           (aset ltimes l (+ (aref ltimes l) t1))))
 		(setq time (aref ltimes level))
 		(setq time (aref ltimes level))
 		(goto-char (match-beginning 0))
 		(goto-char (match-beginning 0))
-		(put-text-property (point) (point-at-eol) :org-clock-minutes time)
+		(put-text-property (point) (point-at-eol)
+				   (or propname :org-clock-minutes) time)
                 (if headline-filter
                 (if headline-filter
                     (save-excursion
                     (save-excursion
                       (save-match-data
                       (save-match-data

+ 16 - 9
lisp/org-colview.el

@@ -700,6 +700,11 @@ around it."
 	  (save-restriction
 	  (save-restriction
 	    (narrow-to-region beg end)
 	    (narrow-to-region beg end)
 	    (org-clock-sum))))
 	    (org-clock-sum))))
+      (when (assoc "CLOCKSUM_T" org-columns-current-fmt-compiled)
+	(save-excursion
+	  (save-restriction
+	    (narrow-to-region beg end)
+	    (org-clock-sum-today))))
       (while (re-search-forward org-outline-regexp-bol end t)
       (while (re-search-forward org-outline-regexp-bol end t)
 	(if (and org-columns-skip-archived-trees
 	(if (and org-columns-skip-archived-trees
 		 (looking-at (concat ".*:" org-archive-tag ":")))
 		 (looking-at (concat ".*:" org-archive-tag ":")))
@@ -1406,8 +1411,8 @@ and tailing newline characters."
   "Summarize the summarizable columns in column view in the agenda.
   "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."
 This will add overlays to the date lines, to show the summary for each day."
   (let* ((fmt (mapcar (lambda (x)
   (let* ((fmt (mapcar (lambda (x)
-			(if (equal (car x) "CLOCKSUM")
-			    (list "CLOCKSUM" (nth 1 x) (nth 2 x) ":" 'add_times
+			(if (string-match "CLOCKSUM.*" (car x))
+			    (list (match-string 0) (nth 1 x) (nth 2 x) ":" 'add_times
 				  nil '+ nil)
 				  nil '+ nil)
 			  x))
 			  x))
 		      org-columns-current-fmt-compiled))
 		      org-columns-current-fmt-compiled))
@@ -1494,13 +1499,15 @@ This will add overlays to the date lines, to show the summary for each day."
 	    (goto-char (point-min))
 	    (goto-char (point-min))
 	    (org-columns-get-format-and-top-level)
 	    (org-columns-get-format-and-top-level)
 	    (while (setq fm (pop fmt))
 	    (while (setq fm (pop fmt))
-	      (if (equal (car fm) "CLOCKSUM")
-		  (org-clock-sum)
-		(when (and (nth 4 fm)
-			   (setq a (assoc (car fm)
-					  org-columns-current-fmt-compiled))
-			   (equal (nth 4 a) (nth 4 fm)))
-		  (org-columns-compute (car fm)))))))))))
+	      (cond ((equal (car fm) "CLOCKSUM")
+		     (org-clock-sum))
+		    ((equal (car fm) "CLOCKSUM_T")
+		     (org-clock-sum-today))
+		    ((and (nth 4 fm)
+			  (setq a (assoc (car fm)
+					 org-columns-current-fmt-compiled))
+			  (equal (nth 4 a) (nth 4 fm)))
+		     (org-columns-compute (car fm)))))))))))
 
 
 (defun org-format-time-period (interval)
 (defun org-format-time-period (interval)
   "Convert time in fractional days to days/hours/minutes/seconds."
   "Convert time in fractional days to days/hours/minutes/seconds."

+ 9 - 3
lisp/org.el

@@ -14174,7 +14174,7 @@ a *different* entry, you cannot use these techniques."
 
 
 (defconst org-special-properties
 (defconst org-special-properties
   '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
   '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
-    "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED" "FILE" "CLOCKSUM")
+    "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED" "FILE" "CLOCKSUM" "CLOCKSUM_T")
   "The special properties valid in Org-mode.
   "The special properties valid in Org-mode.
 
 
 These are properties that are not defined in the property drawer,
 These are properties that are not defined in the property drawer,
@@ -14351,14 +14351,15 @@ things up because then unnecessary parsing is avoided."
     (let ((clockstr (substring org-clock-string 0 -1))
     (let ((clockstr (substring org-clock-string 0 -1))
 	  (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
 	  (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
 	  (case-fold-search nil)
 	  (case-fold-search nil)
-	  beg end range props sum-props key key1 value string clocksum)
+	  beg end range props sum-props key key1 value string clocksum clocksumt)
       (save-excursion
       (save-excursion
 	(when (condition-case nil
 	(when (condition-case nil
 		  (and (derived-mode-p 'org-mode) (org-back-to-heading t))
 		  (and (derived-mode-p 'org-mode) (org-back-to-heading t))
 		(error nil))
 		(error nil))
 	  (setq beg (point))
 	  (setq beg (point))
 	  (setq sum-props (get-text-property (point) 'org-summaries))
 	  (setq sum-props (get-text-property (point) 'org-summaries))
-	  (setq clocksum (get-text-property (point) :org-clock-minutes))
+	  (setq clocksum (get-text-property (point) :org-clock-minutes)
+		clocksumt (get-text-property (point) :org-clock-minutes-today))
 	  (outline-next-heading)
 	  (outline-next-heading)
 	  (setq end (point))
 	  (setq end (point))
 	  (when (memq which '(all special))
 	  (when (memq which '(all special))
@@ -14437,6 +14438,11 @@ things up because then unnecessary parsing is avoided."
 			  (org-columns-number-to-string (/ (float clocksum) 60.)
 			  (org-columns-number-to-string (/ (float clocksum) 60.)
 						       'add_times))
 						       'add_times))
 		    props))
 		    props))
+	  (if clocksumt
+	      (push (cons "CLOCKSUM_T"
+			  (org-columns-number-to-string (/ (float clocksumt) 60.)
+							'add_times))
+		    props))
 	  (unless (assoc "CATEGORY" props)
 	  (unless (assoc "CATEGORY" props)
 	    (push (cons "CATEGORY" (org-get-category)) props))
 	    (push (cons "CATEGORY" (org-get-category)) props))
 	  (append sum-props (nreverse props)))))))
 	  (append sum-props (nreverse props)))))))