7

I am trying to create a org-capture template that re-uses some text given with the ‘%^{PROMPT}’ expansion along several points of the created note.

I have looked in org-mode Template-expansion doc and in Stack Overflow for such an option without success.

("J" "Jobs" entry (file+headline "~/org/NOTES.org" "Jobs") ; jobs
"* TODO %^{Name of Job}\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n 
- [[%x][Advert]] \n 
- Coverletter pdf \n 
- [[file:~/Documents/Personal/CV/CV.tex][CV]] [[file:~/Documents/Personal/CV/CV.pdf][pdf]] \n 
- [[shell:mkdir -p ~/Documents/Personal/$(date +%Y%M_%^{Name of Job})][makedir]]")

The above example prompts me for "Name of Job" (see 2nd and last line) in two separate instances. I would like to re-use the information that I have given to fill the template automatically.

1 Answer 1

10

On the page you linked, it says you can reuse a prompt value with %\1. Instead of %^{Name of Job} twice, use %\\1 for the second occurrence in your template. You'll need the extra \ because it's inside a string and needs to be escaped.

("J" "Jobs" entry (file+headline "~/org/NOTES.org" "Jobs") ; jobs
"* TODO %^{Name of Job}\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n 
- [[%x][Advert]] \n 
- Coverletter pdf \n 
- [[file:~/Documents/Personal/CV/CV.tex][CV]] [[file:~/Documents/Personal/CV/CV.pdf][pdf]] \n 
- [[shell:mkdir -p ~/Documents/Personal/$(date +%Y%M_%\\1)][makedir]]")
2
  • 1
    There are so many options that I've missed that one. Thank you very much for pointing it out, and the detail of the \.
    – Ajned
    Jun 14, 2019 at 23:38
  • 1
    Escaping the back slash inside a string. THANK YOU.
    – Pandian Le
    Dec 29, 2021 at 5:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.