emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Wish: switch active time-stamps to inactive when CANCELED


From: Memnon Anon
Subject: Re: [O] Wish: switch active time-stamps to inactive when CANCELED
Date: Mon, 21 Jan 2013 10:18:55 +0000 (UTC)

Nick Dokos <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]