emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Bruno Cardoso <cardoso.bc@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] org-capture: %\N template expansion
Date: Thu, 23 May 2024 11:13:38 +0000	[thread overview]
Message-ID: <87msogye59.fsf@localhost> (raw)
In-Reply-To: <87o78xz697.fsf@gmail.com>

Bruno Cardoso <cardoso.bc@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	other threads:[~2024-05-23 11:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-23  1:06 [BUG] org-capture: %\N template expansion Bruno Cardoso
2024-05-23 11:13 ` Ihor Radchenko [this message]
2024-05-23 12:37   ` Bruno Cardoso
2024-06-05 11:29     ` Ihor Radchenko
2024-06-05 22:58       ` Bruno Cardoso
2024-06-06 15:24         ` Ihor Radchenko

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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=87msogye59.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=cardoso.bc@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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