"Andrew J. Korty" <a...@iu.edu> writes: > Bernt Hansen <be...@norang.ca> 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 _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode