[Orgmode] Re: Automatically insert inactive timestamps

2010-12-09 Thread Matt Lundin
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


Re: [Orgmode] Re: Automatically insert inactive timestamps

2010-12-09 Thread Andrew J. Korty

Nick Dokos nicholas.do...@hp.com wrote:


Andrew J. Korty a...@iu.edu wrote:

 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
 


I think you should be able to use org-entry-get in the hook to get the
TODO property of the entry and then conditionally add the timestamp -
something like this:

   (if (equal (org-entry-get (point) TODO) TODO)
  add the timestamp


Iirc, the problem is that the entry doesn't yet have a todo keyword at
the time the hook is run.

ajk

___
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


Re: [Orgmode] Re: Automatically insert inactive timestamps

2010-12-08 Thread Andrew J. Korty

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. :-)

ajk

___
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


Re: [Orgmode] Re: Automatically insert inactive timestamps

2010-12-08 Thread Nick Dokos
Andrew J. Korty a...@iu.edu wrote:

 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
 

I think you should be able to use org-entry-get in the hook to get the
TODO property of the entry and then conditionally add the timestamp -
something like this:

   (if (equal (org-entry-get (point) TODO) TODO)
  add the timestamp

Nick



   

___
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


[Orgmode] Re: Automatically insert inactive timestamps

2010-12-07 Thread Bernt Hansen
Julian Burgos jmbur...@uw.edu writes:

 This is the newbie question of the day.  I would like to get an inactive time 
 stamp automatically in each new
 entry in org mode. Could somebody explain me how to do this?

Hi Julian,

Here is what I use in my setup:

Creating new headlines insert inactive timestamps automatically:

--8---cut here---start-8---
(defun bh/insert-inactive-timestamp ()
(interactive)
(org-insert-time-stamp nil t t nil nil nil))

(defun bh/insert-heading-inactive-timestamp ()
(save-excursion
(org-return)
(org-cycle)
(bh/insert-inactive-timestamp)))

(add-hook 'org-insert-heading-hook 'bh/insert-heading-inactive-timestamp)
--8---cut here---end---8---

Manually add an inactive timestamp anywhere with f9-t

--8---cut here---start-8---
(global-set-key (kbd f9 t) 'bh/insert-inactive-timestamp)
--8---cut here---end---8---

and my Capture templates insert inactive timestamps when capture tasks
are created (using %U)

--8---cut here---start-8---
(setq org-capture-templates (quote ((t todo entry (file 
~/git/org/refile.org) * TODO %?
%U
%a :clock-in t :clock-resume t
--8---cut here---end---8---

HTH,
Bernt

___
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