[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Orgmode] Re: Automatically insert inactive timestamps
From: |
Matt Lundin |
Subject: |
[Orgmode] Re: Automatically insert inactive timestamps |
Date: |
Wed, 08 Dec 2010 12:42:22 -0500 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) |
"Andrew J. Korty" <address@hidden> writes:
> Bernt Hansen <address@hidden> wrote:
>
>> (add-hook 'org-insert-heading-hook 'bh/insert-heading-inactive-timestamp)
>
> Using org-insert-heading-hook is more elegant than my way, but I only
> want timestamps on TODO entries, so I use
>
> #+begin_src emacs-lisp
> (defadvice org-insert-todo-heading (after ajk/org-time-stamp-new-headline
> activate
> compile)
> (let ((previous-location (point))) ; not sure why save-excursion doesn't
> work
> (org-insert-time-stamp (current-time) t t
> (concat "\n " (make-string (org-current-level) ? )))
> (goto-char previous-location)))
> #+end_src
>
> Here's my vote for a new hook, org-insert-todo-heading-hook. :-)
>
FWIW, I use the todo state hook to insert an inactive timestamp when
changing to an active todo state (provided a timestamp doesn't already
exist):
--8<---------------cut here---------------start------------->8---
(defun my-org-todo-insert-timestamp ()
"Insert an inactive timestamp if none exists."
(when (string-match (regexp-opt (append my-org-next-actions my-org-projects))
state)
(let ((ts (org-entry-get nil "TIMESTAMP_IA")))
(unless ts
(save-excursion
(org-back-to-heading)
(org-show-entry)
(next-line 1)
(unless (or (looking-at (concat "\\s-+" org-deadline-time-regexp))
(looking-at (concat "\\s-+" org-scheduled-time-regexp)))
(previous-line 1))
(end-of-line)
(org-insert-time-stamp (current-time) t t "\n")
(indent-for-tab-command))))))
;; Add a time stamp to the entry if an active todo state is added
;; and there is no timestamp
(add-hook 'org-after-todo-state-change-hook 'my-org-todo-insert-timestamp)
--8<---------------cut here---------------end--------------->8---
Then to use this hook when calling org-insert-todo-heading, I set the
following:
(setq org-treat-insert-todo-heading-as-state-change t)
Best,
Matt