From: Matt Lundin <mdl@imapmail.org>
To: "Andrew J. Korty" <ajk@iu.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: Automatically insert inactive timestamps
Date: Wed, 08 Dec 2010 12:42:22 -0500 [thread overview]
Message-ID: <877hfkxitd.fsf@fastmail.fm> (raw)
In-Reply-To: <83884.1291812788@iu.edu> (Andrew J. Korty's message of "Wed, 08 Dec 2010 07:53:08 -0500")
"Andrew J. Korty" <ajk@iu.edu> writes:
> Bernt Hansen <bernt@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
prev parent reply other threads:[~2010-12-08 17:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-08 0:24 Automatically insert inactive timestamps Julian Burgos
2010-12-08 2:06 ` Russell Adams
2010-12-08 3:01 ` Bernt Hansen
2010-12-08 12:53 ` Andrew J. Korty
2010-12-08 15:10 ` Nick Dokos
2010-12-08 17:25 ` Andrew J. Korty
2010-12-08 17:42 ` Matt Lundin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877hfkxitd.fsf@fastmail.fm \
--to=mdl@imapmail.org \
--cc=ajk@iu.edu \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).