emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Automatically insert inactive timestamps
@ 2010-12-08  0:24 Julian Burgos
  2010-12-08  2:06 ` Russell Adams
  2010-12-08  3:01 ` Bernt Hansen
  0 siblings, 2 replies; 7+ messages in thread
From: Julian Burgos @ 2010-12-08  0:24 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 443 bytes --]

Dear list,

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?

Many thanks,

Julian

-- 
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: julian@hafro.is, jmburgos@uw.edu

[-- Attachment #1.2: Type: text/html, Size: 563 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Automatically insert inactive timestamps
  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
  1 sibling, 0 replies; 7+ messages in thread
From: Russell Adams @ 2010-12-08  2:06 UTC (permalink / raw)
  To: emacs-orgmode

On Wed, Dec 08, 2010 at 12:24:33AM +0000, Julian Burgos wrote:
> Dear list,
>
> 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?
>
> Many thanks,
>
> Julian

If you are using org-capture, you can include a timestamp with %U.

Alternatively, I don't know about "automatically", but I use a
one-touch timestamp via F9 with the following in my .emacs file. Every
time I switch tasks I hit F9....

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Insert immediate timestamp
(setq org-agenda-skip-additional-timestamps nil)
(define-key global-map (kbd "<f9>")
  '(lambda () (interactive)
              (when (eq major-mode 'org-mode)
                    (org-insert-time-stamp nil t t)
                    (insert "\n"))))

Good luck.


------------------------------------------------------------------
Russell Adams                            RLAdams@AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Automatically insert inactive timestamps
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Bernt Hansen @ 2010-12-08  3:01 UTC (permalink / raw)
  To: Julian Burgos; +Cc: emacs-orgmode

Julian Burgos <jmburgos@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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Re: Automatically insert inactive timestamps
  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:42     ` Matt Lundin
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew J. Korty @ 2010-12-08 12:53 UTC (permalink / raw)
  To: emacs-orgmode

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

ajk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Re: Automatically insert inactive timestamps
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Nick Dokos @ 2010-12-08 15:10 UTC (permalink / raw)
  To: Andrew J. Korty; +Cc: nicholas.dokos, emacs-orgmode

Andrew J. Korty <ajk@iu.edu> wrote:

> 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
> 

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



   

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Re: Automatically insert inactive timestamps
  2010-12-08 15:10     ` Nick Dokos
@ 2010-12-08 17:25       ` Andrew J. Korty
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew J. Korty @ 2010-12-08 17:25 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> wrote:

> Andrew J. Korty <ajk@iu.edu> wrote:
> 
> > 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
> > 
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Automatically insert inactive timestamps
  2010-12-08 12:53   ` Andrew J. Korty
  2010-12-08 15:10     ` Nick Dokos
@ 2010-12-08 17:42     ` Matt Lundin
  1 sibling, 0 replies; 7+ messages in thread
From: Matt Lundin @ 2010-12-08 17:42 UTC (permalink / raw)
  To: Andrew J. Korty; +Cc: emacs-orgmode

"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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-12-08 17:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

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