1

For kontext: The emacs package "Yasnippet" let's you replace a keyword (like "/newagenda") with a predefined text. It lets you also modify some variable fields quickly after the text insertion. It's possible to execute elisp in order to calculate values or prompt the user at insertion, too.

Example:

Input: 
/newagenda <TAB>

Desired result: 

** Agenda for [2022-04-12 Tue]
Attending 
(YES) Person 1
(NO) Person 2
The concept with variables to be replaced:

** Agenda for $DATE
Attending 
($YESNO) Person 1
($YESNO) Person 2

where $XYZ is a variable field that can be modified 
after expanding the keyword /newagenda (by hitting TAB). 
The example in Yasnippet-Synthax:

* Agenda for ${1:`(org-insert-time-stamp (org-read-date nil t "-1tue") nil t)`}
Attending
(${2:YES}) Person 1
(${3:NO}) Person 2

Here are three values that are automatically calculated. 
Values after the colon are default values for each one 
of the fields. 

The Problem:

In general I would like to generate a heading with several variable elements. I would like expand those keywords at different locations and only change the variable parts. As far as I know, it is not possible to change the insert location with capture templates. If it weren't for the date, things would work out fine with Yasnippet.

But when I use ${1:`(org-time-stamp-inactive)`} the time stamp gets inserted two times, like reportet here

As @NichD pointed out

org-insert-time-stamp inserts a time stamp into the buffer and also returns that time stamp. It seems that whatever you are doing inserts that return value, so you get the time stamp twice.

There is an option to insert the current date with `(insert (format-time-string "[%Y-%m-%d %a %H:%M]"))`. But I would like to easily schedule a meeting for e. g. next Tuesday (+1tue) or the Tuesday after that (+2tue) like it is possible with org-insert-time-stamp or org-read-date

Ideally I would like to use the prompt of org-time-stamp-inactive to select a date via this interface.

I found this on how I could use the date arithmetics to engineer a time stamp. But it did not work out when I wanted to replace a value in an elisp expression interactively, like:

* Agenda for ${2:`(org-insert-time-stamp (org-read-date nil t "${1:+2tue}") nil t)`} [0/0]

Unfortunately this does not work for me. The expression with a fixed value +2tue instead of ${1:+2tue} returns also a double time stamp.

My Idea was that I could alter the elisp expression before it is executed, but this does not work.

So the question is: How can I insert a heading at different places with just one time stamp, that I specify similar to / with a prompt?

4
  • 2
    Please could you include a trivial before-and-after excerpt so we can see precisely what you want to achieve. Commented Apr 11, 2022 at 14:29
  • 1
    org-insert-time-stamp inserts a time stamp into the buffer and also returns that time stamp. It seems that whatever you are doing inserts that return value, so you get the time stamp twice. But you don't give enough details so that others (who are perhaps, like me, yasnippet-ignorant) can try it out for themselves.
    – NickD
    Commented Apr 11, 2022 at 17:55
  • @PhilHudson is it clearer now with the examples? Commented Apr 23, 2022 at 8:51
  • This worked for me: ${2:$$(yas-auto-next (unless yas-modified-p (with-temp-buffer (org-time-stamp nil) (buffer-string))))}. It prompts for a date using the usual Org-mode method when I get to that field, and once entered it substitutes the result for the field value and moves on to the next field. Commented Jun 1 at 22:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.