From mboxrd@z Thu Jan 1 00:00:00 1970 From: Memnon Anon Subject: Re: Wish: switch active time-stamps to inactive when CANCELED Date: Mon, 21 Jan 2013 10:18:55 +0000 (UTC) Message-ID: <87wqv6ri13.fsf@mean.albasani.net> References: <2013-01-18T11-28-57@devnull.Karl-Voit.at> <923.1358518021@alphaville> <2013-01-18T22-22-21@devnull.Karl-Voit.at> <6810.1358546398@alphaville.americas.hpqcorp.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:42343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxET8-00072E-Io for emacs-orgmode@gnu.org; Mon, 21 Jan 2013 05:19:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TxET7-0003pl-Ea for emacs-orgmode@gnu.org; Mon, 21 Jan 2013 05:19:10 -0500 Received: from plane.gmane.org ([80.91.229.3]:33915) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxET7-0003pY-8Y for emacs-orgmode@gnu.org; Mon, 21 Jan 2013 05:19:09 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1TxETL-0007xW-BR for emacs-orgmode@gnu.org; Mon, 21 Jan 2013 11:19:23 +0100 Received: from e178235071.adsl.alicedsl.de ([85.178.235.71]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Jan 2013 11:19:23 +0100 Received: from gegendosenfleisch by e178235071.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Jan 2013 11:19:23 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Nick Dokos writes: >> But unfortunately, I know that little of ELISP, that I am not able >> to implement it by myself :-( > Time to learn some then - and there is no better way than scratching > your own itch :-) Two days later, no reply so far. I'll give it a shot. Karl, if you are still fiddling to make it work, ignore this posting and keep trying. :) >>> [...] accomplish this with org-after-todo-state-change-hook: >>> Write a function that checks if org-state is "CANCELED" >>> [...] looks for active timestamps and calls >>> org-toggle-timestamp-type on them. Everything there, so... --8<---------------cut here---------------start------------->8--- (defun my-org-active-to-inactive-ts () "Toggle type on active timestamp in current heading if state was changed to 'CNCL'. This function is supposed to be called by 'org-after-todo-state-change-hook. This function expects only one active timestamp to be in the headline." (when (string= org-state "CNCL") ; 1. (save-excursion ; 2. (save-restriction (widen) (outline-back-to-heading t) ; 3. (narrow-to-region (point) (or (outline-next-heading) (point-max))) (when (re-search-backward (org-re-timestamp 'active) nil t) ; 4. (org-toggle-timestamp-type)))))) (add-hook 'org-after-todo-state-change-hook 'my-org-active-to-inactive-ts) --8<---------------cut here---------------end--------------->8--- 1.: Only when org-state is CNCL, do the rest. 2.: We are jumping around and narrowing, so let's save the way things are, first. 3.: Move point to the beginning of the current headline, make sure we only touch it by narrowing to it. If there is no next headline, point-max will do. 4.: regex search for (only) one active timestamp. When there is one, point will end up there and we toggle it. When there is none, search returns nil, nothing happens. Memnon