emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: dericbytes <dericbytes@gmail.com>
To: emacs-orgmode@gnu.org
Subject: SOLVED: Changing todo status to waiting before clocked out.
Date: Sat, 11 Apr 2009 20:35:27 +0000 (UTC)	[thread overview]
Message-ID: <loom.20090411T201639-971@post.gmane.org> (raw)
In-Reply-To: 87iqlbl4kn.fsf@legolas.norang.ca

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

  reply	other threads:[~2009-04-11 20:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` dericbytes [this message]
2009-04-12 11:09     ` fixed error in my code dericbytes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20090411T201639-971@post.gmane.org \
    --to=dericbytes@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).