From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Lundin Subject: Re: Automatically insert inactive timestamps Date: Wed, 08 Dec 2010 12:42:22 -0500 Message-ID: <877hfkxitd.fsf@fastmail.fm> References: <87y681nf2i.fsf@norang.ca> <83884.1291812788@iu.edu> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=36818 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQO27-0001wI-08 for emacs-orgmode@gnu.org; Wed, 08 Dec 2010 12:42:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PQO25-0004Ma-Hb for emacs-orgmode@gnu.org; Wed, 08 Dec 2010 12:42:26 -0500 Received: from out3.smtp.messagingengine.com ([66.111.4.27]:47486) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PQO25-0004M8-Fj for emacs-orgmode@gnu.org; Wed, 08 Dec 2010 12:42:25 -0500 In-Reply-To: <83884.1291812788@iu.edu> (Andrew J. Korty's message of "Wed, 08 Dec 2010 07:53:08 -0500") 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: "Andrew J. Korty" Cc: emacs-orgmode@gnu.org "Andrew J. Korty" writes: > Bernt Hansen 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