From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aankhen Subject: Automatically clocking into parent items Date: Sun, 13 Mar 2011 01:30:47 +0530 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=50817 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PyUzu-0006pd-3F for emacs-orgmode@gnu.org; Sat, 12 Mar 2011 15:01:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PyUzt-0001mt-0O for emacs-orgmode@gnu.org; Sat, 12 Mar 2011 15:01:10 -0500 Received: from mail-vw0-f41.google.com ([209.85.212.41]:64332) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PyUzs-0001me-So for emacs-orgmode@gnu.org; Sat, 12 Mar 2011 15:01:08 -0500 Received: by vws4 with SMTP id 4so1876426vws.0 for ; Sat, 12 Mar 2011 12:01:08 -0800 (PST) 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: Org-mode ml Hi, I=E2=80=99ve been working on getting org-mode to automatically clock into a= n item=E2=80=99s 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=E2=80=99s n= il, it doesn=E2=80=99t. Either way, it stops looking at that point. Here=E2= =80=99s 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 (=3D (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 subtas= k? " | '("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 =E2=80=98Frob=E2=80=99, I=E2=80=99m automatically clock= ed into =E2=80=98Quux=E2=80=99, and when I clock out of =E2=80=98Quux=E2=80=99, I=E2=80=99m automatically clock= ed into =E2=80=98Bar=E2=80=99. This works pretty well, except for one problem: it happens *every time* I clock out, meaning that if I=E2=80=99m clocked into =E2=80=98Quux= =E2=80=99 and I then hit C-c C-x C-i on =E2=80=98Frob=E2=80=99, I end up being clocked into both= =E2=80=98Bar=E2=80=99 and =E2=80=98Frob=E2=80=99, because I=E2=80=99m automatically clocked out of = =E2=80=98Quux=E2=80=99; my code is run, clocking me into =E2=80=98Bar=E2=80=99; and then the normal clocking m= echanism clocks me into =E2=80=98Frob=E2=80=99 (at least, I *think* the hook runs fi= rst). I guess what I=E2=80=99m wondering is, what=E2=80=99s a good way to avoid t= his double-clocking? And while I=E2=80=99m asking for help, can anyone think o= f some less obnoxious names for the functions, variables and property? :-) I hope all this makes sense. Thanks for your time. Aankhen