diff --git a/ORGWEBPAGE/Changes.org b/ORGWEBPAGE/Changes.org index fc511f92a..7f6afa55d 100644 --- a/ORGWEBPAGE/Changes.org +++ b/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]] diff --git a/doc/ChangeLog b/doc/ChangeLog index 99fb6c5fe..f7b6d2fd1 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2008-10-16 Carsten Dominik + + * org.texi (TODO basics): Add documentation for tag triggers. + 2008-09-05 Carsten Dominik * org.texi (Creating timestamps): Fix documentation of the "C-c ." diff --git a/doc/org.texi b/doc/org.texi index ca9becfcd..156490f81 100644 --- a/doc/org.texi +++ b/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 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b2db9d792..25a67fce5 100755 --- a/lisp/ChangeLog +++ b/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 diff --git a/lisp/org.el b/lisp/org.el index ee6178d69..a4928bffe 100644 --- a/lisp/org.el +++ b/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."