all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Capture Template Diary Entry: file+datetree+prompt use the prompted timestamp including the time when time is specified
@ 2020-05-18 10:59 Nils Schween
  2020-05-20  4:02 ` Kyle Meyer
  0 siblings, 1 reply; 3+ messages in thread
From: Nils Schween @ 2020-05-18 10:59 UTC (permalink / raw)
  To: emacs-orgmode

Dear members of the org-mode mailing list,

a week ago I spent some time to set up a capture template to
directly write appointments to my calendar file (i.e. to write
diary entries). It looks as follows:

("d" "Diary entry" entry (file+datetree+prompt "~/MPIK-Nextcloud/emacs/.org/kalender.org")
     		      "* %i%?\n  %T")

And it works as expected: When calling the capture template, I am prompted for a
date and I can also type a time, and on saving everything is stored at the
correct location in the datetree. Perfect. But in case I do not enter a time,
00:00 is inserted. This is unfortunate. Okay, I can replace "%T" in the template
with "%t", but then any specification of time is ignored.

Instead, I would love to mimic the behaviour of the function "org-time-stamp". Calling it
prompts for a date, and if I do not specify a time, only the date is inserted.
In case I specify a time or a range (i.e. 10:00-12:00) the timestamp is
supplemented with this additional information.

The use-case is the following: Some of my appointments last a whole day, and
others start at a specified time and some of them last e.g. only two hours. To
capture all these cases, I would need a template expansion inserting the
timestamp as I entered it when prompted, i.e. if a specify a time, it includes
it and if not it does not. Of course, this should also be true for e.g.
(10:00-12:00).

I tried a lot to get the desired behaviour by testing variants of the following
combination of org-mode functions and variables.
%(org-insert-time-stamp (org-read-date nil t org-read-date-final-answer) t)

I was not able to produce what I wanted.
Does anyone have a workaround or an idea how I could implement the described and
wished behaviour? Thanks.

With best regards,
Nils




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

* Re: Capture Template Diary Entry: file+datetree+prompt use the prompted timestamp including the time when time is specified
  2020-05-18 10:59 Capture Template Diary Entry: file+datetree+prompt use the prompted timestamp including the time when time is specified Nils Schween
@ 2020-05-20  4:02 ` Kyle Meyer
  2020-05-20  6:49   ` Aw: " Nils Schween
  0 siblings, 1 reply; 3+ messages in thread
From: Kyle Meyer @ 2020-05-20  4:02 UTC (permalink / raw)
  To: Nils Schween; +Cc: emacs-orgmode

Nils Schween writes:

> ("d" "Diary entry" entry (file+datetree+prompt "~/MPIK-Nextcloud/emacs/.org/kalender.org")
>      		      "* %i%?\n  %T")
>
> And it works as expected: When calling the capture template, I am prompted for a
> date and I can also type a time, and on saving everything is stored at the
> correct location in the datetree. Perfect. But in case I do not enter a time,
> 00:00 is inserted. This is unfortunate. Okay, I can replace "%T" in the template
> with "%t", but then any specification of time is ignored.
>
> Instead, I would love to mimic the behaviour of the function "org-time-stamp". Calling it
> prompts for a date, and if I do not specify a time, only the date is inserted.
> In case I specify a time or a range (i.e. 10:00-12:00) the timestamp is
> supplemented with this additional information.
>
> I tried a lot to get the desired behaviour by testing variants of the following
> combination of org-mode functions and variables.
> %(org-insert-time-stamp (org-read-date nil t org-read-date-final-answer) t)
>
> I was not able to produce what I wanted.
>
> Does anyone have a workaround or an idea how I could implement the described and
> wished behaviour? Thanks.

I'm not aware of any built-in way to do what you want.  For either
implementing or working around, org-capture-set-target-location and
org-capture-fill-template are the two places you'd probably want to
look.  As a start of a hacky workaround, with an entry like

    ("d" "Diary entry" entry (file+datetree "/tmp/scratch.org")
     "* %i%?\n  %T" :time-prompt t)

you should be able to get the time/no time behavior you're after with

    (advice-add 'org-capture-fill-template :around
                (lambda (fn &optional template &rest args)
                  (let ((template (and (not org-time-was-given)
                                       (replace-regexp-in-string
                                        "%T" "%t"
                                        (org-capture-get :template) t))))
                    (apply fn template args)))
                '((name . "org-capture-hack")))


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

* Aw: Re: Capture Template Diary Entry: file+datetree+prompt use the prompted timestamp including the time when time is specified
  2020-05-20  4:02 ` Kyle Meyer
@ 2020-05-20  6:49   ` Nils Schween
  0 siblings, 0 replies; 3+ messages in thread
From: Nils Schween @ 2020-05-20  6:49 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

Hi Kyle,
 
thanks a lot for your workaround! I just tested it and it almost does what I am looking for.
The only thing that does not work is to give a range of time, i.e. 10:00-12:00. And looking at your code it is clear, that this cannot work because neither "%t" nor "%T" can do this. 

I guess in the long run, it would make sense to adapt the template expansion "%t" to behave like the function "org-time-stamp". 
Such an adaption would create more consistent behaviour for org users and does not break any former usage.

I checked the the part in org-capture.el and it looks like this 
((or "t" "T" "u" "U")
		     ;; These are the date/time related ones.
		     (let* ((upcase? (equal (upcase key) key))
			    (org-end-time-was-given nil)
			    (time (org-read-date upcase? t nil prompt)))
		       (org-insert-time-stamp
			time (or org-time-was-given upcase?)
			(member key '("u" "U"))
			nil nil (list org-end-time-was-given))))

But unfortunately, I am not an elisp programmer and I cannot do the adaption myself.
I am sorry for that.

Once more, thanks.
Nils

Gesendet: Mittwoch, 20. Mai 2020 um 06:02 Uhr
Von: "Kyle Meyer" <kyle@kyleam.com>
An: "Nils Schween" <nils.schween@web.de>
Cc: emacs-orgmode@gnu.org
Betreff: Re: Capture Template Diary Entry: file+datetree+prompt use the prompted timestamp including the time when time is specified
Nils Schween writes:

> ("d" "Diary entry" entry (file+datetree+prompt "~/MPIK-Nextcloud/emacs/.org/kalender.org")
> "* %i%?\n %T")
>
> And it works as expected: When calling the capture template, I am prompted for a
> date and I can also type a time, and on saving everything is stored at the
> correct location in the datetree. Perfect. But in case I do not enter a time,
> 00:00 is inserted. This is unfortunate. Okay, I can replace "%T" in the template
> with "%t", but then any specification of time is ignored.
>
> Instead, I would love to mimic the behaviour of the function "org-time-stamp". Calling it
> prompts for a date, and if I do not specify a time, only the date is inserted.
> In case I specify a time or a range (i.e. 10:00-12:00) the timestamp is
> supplemented with this additional information.
>
> I tried a lot to get the desired behaviour by testing variants of the following
> combination of org-mode functions and variables.
> %(org-insert-time-stamp (org-read-date nil t org-read-date-final-answer) t)
>
> I was not able to produce what I wanted.
>
> Does anyone have a workaround or an idea how I could implement the described and
> wished behaviour? Thanks.

I'm not aware of any built-in way to do what you want. For either
implementing or working around, org-capture-set-target-location and
org-capture-fill-template are the two places you'd probably want to
look. As a start of a hacky workaround, with an entry like

("d" "Diary entry" entry (file+datetree "/tmp/scratch.org")
"* %i%?\n %T" :time-prompt t)

you should be able to get the time/no time behavior you're after with

(advice-add 'org-capture-fill-template :around
(lambda (fn &optional template &rest args)
(let ((template (and (not org-time-was-given)
(replace-regexp-in-string
"%T" "%t"
(org-capture-get :template) t))))
(apply fn template args)))
'((name . "org-capture-hack")))


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

end of thread, other threads:[~2020-05-20  6:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-18 10:59 Capture Template Diary Entry: file+datetree+prompt use the prompted timestamp including the time when time is specified Nils Schween
2020-05-20  4:02 ` Kyle Meyer
2020-05-20  6:49   ` Aw: " Nils Schween

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.