Bruno Cardoso <cardoso...@gmail.com> writes:

> I'm having trouble expanding the '%\N' template in org-capture.
>
> For example, with the following template:
>
> (add-to-list 'org-capture-templates
>              '("t" "TEST" entry
>                (file+headline "~/org/test.org" "TEST")
>                "** TODO %?
> :PROPERTIES:
> :TITLE:    %^{TITLE}
> :AUTHOR:   %^{AUTHOR}p
> :END:
> %\1 %\2"))
>
> The properties are read correctly, but "%\1 %\2" expands to "%^A %^B".

That's expected - you do need to escape \ in Elisp strings. \1 in string
is ^A (Ctrl-A) and \2 is ^B.

> Either escaping the backslashes ("%\\1 %\\2") or reading the template above 
> from a file throws an error:
>
> : org-capture: Capture abort: Wrong type argument: stringp, nil

That's because you can only use %\N placeholder for %^{prompt} but not
for %^{prompt}X.

Try

(add-to-list 'org-capture-templates
             '("t" "TEST" entry
               (file+headline "~/org/test.org" "TEST")
               "** TODO %?
:PROPERTIES:
:TITLE:    %^{TITLE}
:AUTHOR:   %^{AUTHOR}
:END:
%\\1 %\\2"))

We can probably improve the error and the docstring to clarify this.

We may also make %^{prompt}X expansions to work with %\N, but it can
break the existing templates that are tuned to the current behaviour.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to