Browse Source

New option `org-clock-out-switch-to-state'.

Can be used to change the TODO state when clocking out.
Carsten Dominik 16 years ago
parent
commit
a5dc9456dd
2 changed files with 32 additions and 1 deletions
  1. 3 0
      lisp/ChangeLog
  2. 29 1
      lisp/org-clock.el

+ 3 - 0
lisp/ChangeLog

@@ -1,5 +1,8 @@
 2009-06-02  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-clock.el (org-clock-out-switch-to-state): New option.
+	(org-clock-out): Honor `org-clock-out-switch-to-state'.
+
 	* org-compat.el (org-compatible-face): Improve macro.
 
 	* org.el (org-global-properties-fixed): Add default for

+ 29 - 1
lisp/org-clock.el

@@ -86,6 +86,19 @@ state to switch it to."
 	  (string :tag "State")
 	  (symbol :tag "Function")))
 
+(defcustom org-clock-out-switch-to-state nil
+  "Set task to a special todo state after clocking out.
+The value should be the state to which the entry should be
+switched. If the value is a function, it must take one
+parameter (the current TODO state of the item) and return the
+state to switch it to."
+  :group 'org-clock
+  :group 'org-todo
+  :type '(choice
+	  (const :tag "Don't force a state" nil)
+	  (string :tag "State")
+	  (symbol :tag "Function")))
+
 (defcustom org-clock-history-length 5
   "Number of clock tasks to remember in history."
   :group 'org-clock
@@ -541,7 +554,7 @@ decides which time to use."
      ((or (equal cmt "all")
 	  (and (or (not cmt) (equal cmt "auto"))
 	       (not lr)))
-      (setq msg-extra "Showing all task time.")
+      (setq msg-extra "Showing entire task time.")
       nil)
      ((or (equal cmt "repeat")
 	  (and (or (not cmt) (equal cmt "auto"))
@@ -680,6 +693,21 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
 	    (setq org-clock-mode-line-timer nil))
 	  (setq global-mode-string
 		(delq 'org-mode-line-string global-mode-string))
+	  (when org-clock-out-switch-to-state
+	    (save-excursion
+	      (org-back-to-heading t)
+	      (let ((org-inhibit-logging t))
+		(cond
+		 ((functionp org-clock-out-switch-to-state)
+		  (looking-at org-complex-heading-regexp)
+		  (let ((newstate (funcall org-clock-out-switch-to-state
+					   (match-string 2))))
+		    (if newstate (org-todo newstate))))
+		 ((and org-clock-out-switch-to-state
+		       (not (looking-at (concat outline-regexp "[ \t]*"
+						org-clock-out-switch-to-state
+						"\\>"))))
+		  (org-todo org-clock-out-switch-to-state))))))
 	  (force-mode-line-update)
 	  (message (concat "Clock stopped at %s after HH:MM = " org-time-clocksum-format "%s") te h m
 		   (if remove " => LINE REMOVED" "")))))))