Search code examples
org-mode

Trouble using %\n in org-mode templates


The org documentation describes various %-escape codes in a capture template. I'm having difficulty getting %\n to work. The relevant portion of the doc says:

%\n Insert the text entered at the nth %^{prompt}, where n is a number, starting from 1.

The following is a snippet from my capture templates where I use that particular escape code:

("i" "Interrupts")
(
 "io"                  ; key
 "Other"               ; description
 entry                 ; type
 (file+headline "~/git/org/agenda/refile.org" "Interrupts") ; target
 "* IRQ from %^{Name}: %^{Subject} :%\1:\n\n%?"      ; template
 :prepend      t       ; properties
 :clock-in     t       ; properties
 :clock-resume t       ; 
 :empty-lines  1       ; properties
 )

My expectation for the entry header generated by that template, if I enter "Fred" and "SomeSubject" for the two prompts, is something like this:

  • IRQ from Fred: SomeSubject :Fred:

However, the %\1 is not being expanded correctly and instead I get:

  • IRQ from Fred: SomeSubject :^A:

To check in case the problem was that I had placed the %\1 inside a tag, I also tried it like this:

  • IRQ from Fred: SomeSubject Name is %\1

But it still didn't work and is giving:

  • IRQ from Fred: SomeSubject Name is ^A

Any ideas what I'm doing wrong?

thx.


Solution

  • You need to escape the the backslash similar to regular expressions. Try %\\1.