From: Alexis Roda <alexis.roda.villalonga@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Triggering clock in/out from org state change and progress logging
Date: Tue, 26 Aug 2014 13:00:46 +0200 [thread overview]
Message-ID: <53FC68DE.3000500@gmail.com> (raw)
Hi list,
as part of learning org I'm trying to configure it so that state changes
trigger clocking in/out tasks.
Why testing workflow is:
#+TODO: TODO(t) STRT(s!) PAUS(p!) WAIT(w!) | DONE(d!) CANC(c!)
What I try to accomplish:
* entering STRT pauses the active task (if any) and clocks-in the
current task.
* entering PAUS or WAIT clocks-out the current task (if clocking the
current task).
* entering TODO probably should reset the current task but I don't care
at that point.
Changing state and clocking in/out works great but logging is weird:
* Tasks
** STRT first task
- State "STRT" from "TODO" [2014-08-26 dt 12:27]
:20:
CLOCK: [2014-08-26 dt 12:27]
:END:
** TODO second task
Now I change "second task" from TODO to STRT:
* Tasks
** PAUS first task
- State "PAUS" from "STRT" [2014-08-26 dt 12:28]
- State "STRT" from "TODO" [2014-08-26 dt 12:27]
:20:
CLOCK: [2014-08-26 dt 12:27]--[2014-08-26 dt 12:28] => 0:01
:END:
** STRT second task
:20:
CLOCK: [2014-08-26 dt 12:28]
:END:
"first taks" gets paused and "second task" is started and clocking but
no logging "State 'STRT' from 'TODO' ..." is added to "second task".
Starting a task only logs in the other task.
After 6 hours struggling with that (clocked with org :) ) I can't figure
why that's happening. Any clue?
Thanks in advance
Here's the code:
(defvar arv/org-todo-entering-state-clocking-actions
'(("STRT" . start)
("PAUS" . stop)
("WAIT" . stop)))
(defvar arv/org-todo-state-change-triggers-clocking-enabled t)
(defvar arv/org-todo-paused-state "PAUS")
(defun arv/org-todo--pause-other-task ()
(when (org-clock-is-active)
(save-excursion
(org-clock-goto)
(org-clock-out)
(let ((arv/org-todo-state-change-triggers-clocking-enabled nil))
; avoid recursion
(org-todo arv/org-todo-paused-state)))))
(defun arv/org-todo--state-change (from to)
(when (and arv/org-todo-state-change-triggers-clocking-enabled
(not (string= from to)))
(let ((action (cdr (assoc to
arv/org-todo-entering-state-clocking-actions))))
(unless (null action)
(cond
((eq action 'start)
(arv/org-todo--pause-other-task)
(org-clock-in))
((eq action 'stop)
(let ((org-state "DONE") ; hackish, review
(org-clock-out-when-done t))
(org-clock-out-if-current)))
(t (user-error "Unknown action.")))))))
(defun arv/org-todo--state-change-trigger (p)
(let ((type (plist-get p :type))
(from (plist-get p :from))
(to (plist-get p :to)))
(when (eq type 'todo-state-change)
(arv/org-todo--state-change from to))))
(add-hook 'org-trigger-hook 'arv/org-todo--state-change-trigger)
next reply other threads:[~2014-08-26 11:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-26 11:00 Alexis Roda [this message]
2014-09-01 17:32 ` Triggering clock in/out from org state change and progress logging Alexis Roda
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=53FC68DE.3000500@gmail.com \
--to=alexis.roda.villalonga@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).