From mboxrd@z Thu Jan 1 00:00:00 1970 From: dericbytes Subject: SOLVED: Changing todo status to waiting before clocked out. Date: Sat, 11 Apr 2009 20:35:27 +0000 (UTC) Message-ID: References: <59b700510904110528q420228a9y8b1849b460c65caf@mail.gmail.com> <87iqlbl4kn.fsf@legolas.norang.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LsjvW-0007Ws-W4 for emacs-orgmode@gnu.org; Sat, 11 Apr 2009 16:35:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LsjvS-0007TC-Dm for emacs-orgmode@gnu.org; Sat, 11 Apr 2009 16:35:46 -0400 Received: from [199.232.76.173] (port=42456 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LsjvS-0007T2-4y for emacs-orgmode@gnu.org; Sat, 11 Apr 2009 16:35:42 -0400 Received: from main.gmane.org ([80.91.229.2]:51121 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LsjvR-0004UL-Hm for emacs-orgmode@gnu.org; Sat, 11 Apr 2009 16:35:41 -0400 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1LsjvP-0002Pb-0W for emacs-orgmode@gnu.org; Sat, 11 Apr 2009 20:35:39 +0000 Received: from cpc3-hatf1-0-0-cust829.lutn.cable.ntl.com ([82.10.67.62]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 11 Apr 2009 20:35:39 +0000 Received: from dericbytes by cpc3-hatf1-0-0-cust829.lutn.cable.ntl.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 11 Apr 2009 20:35:39 +0000 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Bernt, thanks for your email. It helped solve the problem... I thought my reply would not get routed to the mailing list. He is my problem and solution, for all to see I used Sacha's code to automatically clock in and out when the TODO state swapped between STARTED and WAITING. I then added code to note if my remember template had the TODO state of STARTED. If so, I set it up to clock in that task on insertion (automatically clocking out my old task) My problem was the old task still had the STARTED state. ;; org-mode automatic clocking on TODO ;; ------------------------------------------------------------------ (defun sacha/org-clock-in-if-starting () "Clock in when the task is marked STARTED." (when (and (string= state "STARTED") (not (string= last-state state))) (org-clock-in))) (add-hook 'org-after-todo-state-change-hook 'sacha/org-clock-in-if-starting) (defadvice org-clock-in (after sacha activate) "Set this task's status to 'STARTED'." (org-todo "STARTED")) (defun sacha/org-clock-out-if-waiting () "Clock in when the task is marked STARTED." (when (and (string= state "WAITING") (not (string= last-state state))) (org-clock-out))) (add-hook 'org-after-todo-state-change-hook 'sacha/org-clock-out-if-waiting) ;; start the clock if there is a STARTED todo tag in template ;-------------------------------------------------------------------- (add-hook 'org-remember-before-finalize-hook 'my-start-clock-if-needed) (defun my-start-clock-if-needed () (save-excursion (goto-char (point-min)) (when (re-search-forward "* STARTED" nil t) (change-todo-state-on-old-clock) (org-clock-in)))) ; change the state of the old clock ;--------------------------------------------------------------------------- (defun change-todo-state-on-old-clock () ; old-clock needs state changed if STARTED (save-excursion (progn (if (not (marker-buffer org-clock-marker)) (if select (error "No task selected") (error "No active clock"))) (set-buffer (marker-buffer org-clock-marker)) (goto-char (point-min)) (when (re-search-forward "^\** STARTED" nil t) (org-todo "WAITING"))))) ; example template ;---------------------------------------------------------------------------- (setq org-remember-templates '(("Task" ?t "* %^{Task status|TODO|STARTED|SUBTASK|DONE} %^{Brief Description} %^G\n %^{subject}p %^{other-subjects}p %^{sub-subjects}p %^{keywords}p %?\n Added: %U \n" "~/notes/notes-log-090410.org" "Task")