Browse Source

Implement tag changes triggered automatically by TODO state changes.

Carsten Dominik 16 years ago
parent
commit
329a7a7d34
5 changed files with 60 additions and 1 deletions
  1. 13 0
      ORGWEBPAGE/Changes.org
  2. 4 0
      doc/ChangeLog
  3. 4 1
      doc/org.texi
  4. 2 0
      lisp/ChangeLog
  5. 37 0
      lisp/org.el

+ 13 - 0
ORGWEBPAGE/Changes.org

@@ -29,6 +29,19 @@
     : C-c C-e p     process to PDF.
     : C-c C-e d     process to PDF, and open the file.
 
+*** TODO state changes can trigger tag changes
+    The new option =org-todo-state-tags-triggers= can be used to
+    define automatic changes to tags when a TODO state changes.
+    For example, the setting
+
+    : (setq org-todo-state-tags-triggers
+    :       '((done ("Today" . nil) ("NEXT" . nil))
+    :         ("WAITING" ("Today" . t))))    
+
+    will make sure that any change to a DONE state will remove
+    tags "Today" and "NEXT", while switching to the "WAITING"
+    state will also trigger the tag "Today".
+
 * Version 6.09
 ** Incompatible
 *** =org-file-apps= now uses regular expressions, see [[*%20org%20file%20apps%20now%20uses%20regular%20repressions%20instead%20of%20extensions][below]]

+ 4 - 0
doc/ChangeLog

@@ -1,3 +1,7 @@
+2008-10-16  Carsten Dominik  <dominik@science.uva.nl>
+
+	* org.texi (TODO basics): Add documentation for tag triggers.
+
 2008-09-05  Carsten Dominik  <dominik@science.uva.nl>
 
 	* org.texi (Creating timestamps): Fix documentation of the "C-c ."

+ 4 - 1
doc/org.texi

@@ -2895,6 +2895,10 @@ commands}).  @xref{Global TODO list}, for more information.
 Insert a new TODO entry below the current one.
 @end table
 
+@noindent
+Changing a TODO state can also trigger tag changes.  See the docstring of the
+option @code{org-todo-state-tags-triggers} for details.
+
 @node TODO extensions, Progress logging, TODO basics, TODO Items
 @section Extended use of TODO keywords
 @cindex extended TODO keywords
@@ -3225,7 +3229,6 @@ settings like @code{TODO(!)}.  For example
   :END:
 @end example
 
-
 @node Priorities, Breaking down tasks, Progress logging, TODO Items
 @section Priorities
 @cindex priorities

+ 2 - 0
lisp/ChangeLog

@@ -3,6 +3,8 @@
 	* org.el (org-add-log-setup): Respect
 	`org-log-state-notes-insert-after-drawers'.
 	(org-log-state-notes-insert-after-drawers): New option.
+	(org-todo-trigger-tag-changes): New function.
+	(org-todo): Call `org-todo-trigger-tag-changes'.
 
 2008-10-15  Carsten Dominik  <dominik@science.uva.nl>
 

+ 37 - 0
lisp/org.el

@@ -1427,6 +1427,27 @@ Lisp variable `state'."
   :group 'org-todo
   :type 'hook)
 
+(defcustom org-todo-state-tags-triggers nil
+  "Tag changes that should be triggered by TODO state changes.
+This is a list.  Each entry is
+
+  (state-change (tag . flag) .......)
+
+State-change can be a string with a state, and empty string to indicate the
+state that has no TODO keyword, or it can be one of the symbols `todo'
+or `done', meaning any not-done or done state, respectively."
+  :group 'org-todo
+  :group 'org-tags
+  :type '(repeat
+	  (cons (choice :tag "When changing to"
+		 (const :tag "Not-done state" todo)
+		 (const :tag "Done state" done)
+		 (string :tag "State"))
+		(repeat
+		 (cons :tag "Tag action"
+		       (string :tag "Tag")
+		       (choice (const :tag "Add" t) (const :tag "Remove" nil)))))))
+
 (defcustom org-log-done nil
   "Non-nil means, record a CLOSED timestamp when moving an entry to DONE.
 When equal to the list (done), also prompt for a closing note.
@@ -7885,6 +7906,7 @@ For calling through lisp, arg is also interpreted in the following way:
 	    ;; This is a non-nil state, and we need to log it
 	    (org-add-log-setup 'state state 'findpos dolog)))
 	;; Fixup tag positioning
+	(org-todo-trigger-tag-changes state)
 	(and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
 	(when org-provide-todo-statistics
 	  (org-update-parent-todo-statistics))
@@ -7951,6 +7973,21 @@ when there is a statistics cookie in the headline!
    (let (org-log-done org-log-states)   ; turn off logging
      (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
 ")
+
+(defun org-todo-trigger-tag-changes (state)
+  "Apply the changes defined in `org-todo-state-tags-triggers'."
+  (let ((l org-todo-state-tags-triggers)
+	changes)
+    (when (or (not state) (equal state ""))
+      (setq changes (append changes (cdr (assoc "" l)))))
+    (when (and (stringp state) (> (length state) 0))
+      (setq changes (append changes (cdr (assoc state l)))))
+    (when (member state org-not-done-keywords)
+      (setq changes (append changes (cdr (assoc 'todo l)))))
+    (when (member state org-done-keywords)
+      (setq changes (append changes (cdr (assoc 'done l)))))
+    (dolist (c changes)
+      (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
 	 
 (defun org-local-logging (value)
   "Get logging settings from a property VALUE."