emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Automatically clocking into parent items
@ 2011-03-12 20:00 Aankhen
  2011-03-14 11:00 ` Aankhen
  0 siblings, 1 reply; 2+ messages in thread
From: Aankhen @ 2011-03-12 20:00 UTC (permalink / raw)
  To: Org-mode ml

Hi,

I’ve been working on getting org-mode to automatically clock into an
item’s ancestor when clocking out of that item.  The way I have it set
up now, it walks up the tree looking for an item that has a particular
property set.  If that property is non-nil, it clocks in; if it’s nil,
it doesn’t.  Either way, it stops looking at that point.  Here’s what
I have so far:

,----[ Conditionally resuming parent clocks ]
| (defconst +aankh/org-resume-parent-clock-property+ "AUTO_RESUME_CLOCK"
|   "The name of the property that indicates whether a task's clock
|   should be restarted upon clocking out of its subtasks.  When
|   this is not `nil' according to `org-not-nil', the task's clock
|   will be restarted.")
|
| (defun aankh/maybe-resume-parent-clock ()
|   (save-excursion
|     (loop
|      until (= (org-current-level) 1)
|      do (org-up-heading-all 1)
|      when (member +aankh/org-resume-parent-clock-property+
|                   (mapcar 'car (org-entry-properties)))
|      do (let ((resume
|                (org-entry-get
|                 nil
|                 +aankh/org-resume-parent-clock-property+)))
|           (when (org-not-nil resume)
|             (org-clock-in))
|           (return resume)))))
|
| (setq aankh/org-resume-parent-clock-enable t)
|
| (defun aankh/read-resume-parent-clock-property (&rest rest)
|   (declare (ignore rest))
|   (org-icompleting-read
|    "Automatically restart this task's clock when clocking out of a subtask? "
|    '("t" "nil")))
|
| (when aankh/org-resume-parent-clock-enable
|   (add-hook 'org-clock-out-hook 'aankh/maybe-resume-parent-clock)
|   (add-to-list 'org-default-properties
|                +aankh/org-resume-parent-clock-property+)
|   (add-to-list 'org-property-set-functions-alist
|                `(,+aankh/org-resume-parent-clock-property+
|                  . aankh/read-resume-parent-clock-property)))
`----

So given this structure:

,----[ example.org ]
| * Foo
|
| * Bar
|   :PROPERTIES:
|   :AUTO_RESUME_CLOCK: t
|   :END:
|
| *** Quux
|     :PROPERTIES:
|     :AUTO_RESUME_CLOCK: t
|     :END:
|
| ***** Frob
|
| * Baz
`----

When I clock out of ‘Frob’, I’m automatically clocked into ‘Quux’, and
when I clock out of ‘Quux’, I’m automatically clocked into ‘Bar’.
This works pretty well, except for one problem: it happens *every
time* I clock out, meaning that if I’m clocked into ‘Quux’ and I then
hit C-c C-x C-i on ‘Frob’, I end up being clocked into both ‘Bar’ and
‘Frob’, because I’m automatically clocked out of ‘Quux’; my code is
run, clocking me into ‘Bar’; and then the normal clocking mechanism
clocks me into ‘Frob’ (at least, I *think* the hook runs first).

I guess what I’m wondering is, what’s a good way to avoid this
double-clocking?  And while I’m asking for help, can anyone think of
some less obnoxious names for the functions, variables and property?
:-)

I hope all this makes sense.  Thanks for your time.

Aankhen

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

* Re: Automatically clocking into parent items
  2011-03-12 20:00 Automatically clocking into parent items Aankhen
@ 2011-03-14 11:00 ` Aankhen
  0 siblings, 0 replies; 2+ messages in thread
From: Aankhen @ 2011-03-14 11:00 UTC (permalink / raw)
  To: Org-mode ml

On Sun, Mar 13, 2011 at 01:30, Aankhen <aankhen@gmail.com> wrote:
> I’ve been working on getting org-mode to automatically clock into an
> item’s ancestor when clocking out of that item.  The way I have it set
> up now, it walks up the tree looking for an item that has a particular
> property set.  If that property is non-nil, it clocks in; if it’s nil,
> it doesn’t.  Either way, it stops looking at that point.  Here’s what
> I have so far:
>
> [snip]
>
> So given this structure:
>
> [snip]
>
> When I clock out of ‘Frob’, I’m automatically clocked into ‘Quux’, and
> when I clock out of ‘Quux’, I’m automatically clocked into ‘Bar’.
> This works pretty well, except for one problem: it happens *every
> time* I clock out, meaning that if I’m clocked into ‘Quux’ and I then
> hit C-c C-x C-i on ‘Frob’, I end up being clocked into both ‘Bar’ and
> ‘Frob’, because I’m automatically clocked out of ‘Quux’; my code is
> run, clocking me into ‘Bar’; and then the normal clocking mechanism
> clocks me into ‘Frob’ (at least, I *think* the hook runs first).
>
> I guess what I’m wondering is, what’s a good way to avoid this
> double-clocking?  And while I’m asking for help, can anyone think of
> some less obnoxious names for the functions, variables and property?
> :-)

I think I managed to answer the first question myself.  As
‘org-clock-in’ sets ‘org-clock-clocking-in’ before calling
‘org-clock-out’, checking the value of that variable before clocking
into the parent item seems to have done the trick.

Aankhen

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

end of thread, other threads:[~2011-03-14 11:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-12 20:00 Automatically clocking into parent items Aankhen
2011-03-14 11:00 ` Aankhen

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