emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Changing todo status to waiting before clocked out.
@ 2009-04-11 12:28 Deric Bytes
  2009-04-11 13:09 ` Bernt Hansen
  0 siblings, 1 reply; 4+ messages in thread
From: Deric Bytes @ 2009-04-11 12:28 UTC (permalink / raw)
  To: emacs-orgmode

How can I change the todo status before an item is clocked out. I was
hoping for something like the following


    (add-hook 'org-before-todo-state-change-hook
	   'dericbytes/org-clock-out-change-status-to-waiting)


   (defun dericbytes/org-clock-out-change-status-to-waiting ()
         (save-excursion
         (goto-char org-clock-marker)
         (org-todo "WAITING")))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Changing todo status to waiting before clocked out.
  2009-04-11 12:28 Changing todo status to waiting before clocked out Deric Bytes
@ 2009-04-11 13:09 ` Bernt Hansen
  2009-04-11 20:35   ` SOLVED: " dericbytes
  0 siblings, 1 reply; 4+ messages in thread
From: Bernt Hansen @ 2009-04-11 13:09 UTC (permalink / raw)
  To: Deric Bytes; +Cc: emacs-orgmode

Deric Bytes <dericbytes@gmail.com> writes:

> How can I change the todo status before an item is clocked out. I was
> hoping for something like the following
>
>
>     (add-hook 'org-before-todo-state-change-hook
> 	   'dericbytes/org-clock-out-change-status-to-waiting)
>
>
>    (defun dericbytes/org-clock-out-change-status-to-waiting ()
>          (save-excursion
>          (goto-char org-clock-marker)
>          (org-todo "WAITING")))

The clock does not stop until you move the state to a DONE state.  My
WAITING state is not a done state so I'm free to move the status from
TODO to WAITING and back without affecting the running clock.

You can also set 'org-clock-out-when-done' to nil to prevent the clock
from stopping when moving to done states as well.

HTH,
Bernt

^ permalink raw reply	[flat|nested] 4+ messages in thread

* SOLVED: Changing todo status to waiting before clocked out.
  2009-04-11 13:09 ` Bernt Hansen
@ 2009-04-11 20:35   ` dericbytes
  2009-04-12 11:09     ` fixed error in my code dericbytes
  0 siblings, 1 reply; 4+ messages in thread
From: dericbytes @ 2009-04-11 20:35 UTC (permalink / raw)
  To: emacs-orgmode

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")

^ permalink raw reply	[flat|nested] 4+ messages in thread

* fixed error in my code
  2009-04-11 20:35   ` SOLVED: " dericbytes
@ 2009-04-12 11:09     ` dericbytes
  0 siblings, 0 replies; 4+ messages in thread
From: dericbytes @ 2009-04-12 11:09 UTC (permalink / raw)
  To: emacs-orgmode

- changed regex
- it now works if there is no clock running

(defun change-todo-state-on-old-clock ()
; old-clock needs state changed if STARTED
(save-excursion
(progn
    (when (marker-buffer org-clock-marker)
(set-buffer (marker-buffer org-clock-marker))
(goto-char (point-min))
(when  (re-search-forward "^\*+ STARTED" nil t)
        (org-todo "WAITING"))))))

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-04-12 11:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-11 12:28 Changing todo status to waiting before clocked out Deric Bytes
2009-04-11 13:09 ` Bernt Hansen
2009-04-11 20:35   ` SOLVED: " dericbytes
2009-04-12 11:09     ` fixed error in my code dericbytes

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).