emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Nils Schween <nils.schween@web.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: Capture Template Diary Entry: file+datetree+prompt use the prompted timestamp including the time when time is specified
Date: Wed, 20 May 2020 04:02:46 +0000	[thread overview]
Message-ID: <87lflns17d.fsf@kyleam.com> (raw)
In-Reply-To: <trinity-52453a23-7411-419c-8e84-f8dede1b8469-1589799587924@3c-app-webde-bap63>

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)
                                        "%T" "%t"
                                        (org-capture-get :template) t))))
                    (apply fn template args)))
                '((name . "org-capture-hack")))

  reply	other threads:[~2020-05-20  4:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18 10:59 Nils Schween
2020-05-20  4:02 ` Kyle Meyer [this message]
2020-05-20  6:49   ` Aw: " Nils Schween

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:

  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=87lflns17d.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=nils.schween@web.de \


* 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


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