From: Allen Li <darkfeline@felesatra.moe>
To: Org Mode List <emacs-orgmode@gnu.org>
Subject: [PATCH] Bug: Org capture: Invalid use of ‘\’ in replacement text [9.1.14 (9.1.14-1049-g04641c-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181203/)]
Date: Fri, 7 Dec 2018 19:37:53 -0800 [thread overview]
Message-ID: <CADbSrJz2QnLyDooROkuzyZTkJigKS3-h-upeg+9i_8NsU_Cjkg@mail.gmail.com> (raw)
In-Reply-To: <CADbSrJy9jTja+azFL0kmK3iFAQ67bK8qzMmJJy_9YjiE+nhNNQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1256 bytes --]
Attached patch fixing this.
This was caused by a bug in a feature that I did not realize existed
(prefixing each line in %i). I have also included patches to clarify
the documentation.
On Fri, Dec 7, 2018 at 6:12 PM Allen Li <darkfeline@felesatra.moe> wrote:
>
> There's an escaping bug in Org capture:
>
> 1. emacs -Q
> 2. Evaluate:
>
> (setq org-capture-templates
> '(("Z" "org-protocol capture" entry
> (file "/tmp/tmp")
> "* %?
> %(let ((x \"%:annotation\")) (if (string= x \"\") \"\" (concat x
> \"\\n\")))%i")))
>
> 3. Evaluate (require 'org-protocol)
>
> 4. Evaluate to simulate org protocol capture:
>
> (org-protocol-capture '(:template "Z" :body "foo\nbar\n"))
>
> Causes error:
>
> (error "Capture abort: (error Invalid use of ‘\\’ in replacement text)")
>
> org-protocol is used in the example as that's where I encountered it,
> but the bug is in org-capture proper.
>
> Note that this works:
>
> (org-protocol-capture '(:template "Z" :body "foo"))
>
> Emacs : GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
> of 2018-07-05
> Package: Org mode version 9.1.14 (9.1.14-1049-g04641c-elpaplus @
> /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181203/)
[-- Attachment #2: 0002-Document-i-prefix-in-capture-templates.patch --]
[-- Type: text/x-patch, Size: 1995 bytes --]
From 9b0d43846694e0afac19289da8a4152bd0f9bd52 Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
Date: Fri, 7 Dec 2018 19:35:56 -0800
Subject: [PATCH 2/2] Document %i prefix in capture templates
* doc/org-manual.org (Template expansion): Fix documentation.
* lisp/org-capture.el (org-capture-templates): Fix docstring.
---
doc/org-manual.org | 5 +++--
lisp/org-capture.el | 6 ++++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 3d2211474..f96c326ae 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -7390,8 +7390,9 @@ here:
- ~%i~ ::
Initial content, the region when capture is called while the
- region is active. The entire text will be indented like ~%i~
- itself.
+ region is active. If there is text before %i on the same line,
+ such as indentation, and %i is not inside a %(sexp), that prefix
+ will be added before every line in the inserted text.
- ~%a~ ::
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 8505c2b92..745fbcd3d 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -287,8 +287,10 @@ be replaced with content and expanded:
with `org-capture-use-agenda-date' set.
%T Time stamp as above, with date and time.
%u, %U Like the above, but inactive time stamps.
- %i Initial content, copied from the active region. If %i is
- indented, the entire inserted text will be indented as well.
+ %i Initial content, copied from the active region. If
+ there is text before %i on the same line, such as
+ indentation, and %i is not inside a %(sexp), that prefix
+ will be added before every line in the inserted text.
%a Annotation, normally the link created with `org-store-link'.
%A Like %a, but prompt for the description part.
%l Like %a, but only insert the literal link.
--
2.19.2
[-- Attachment #3: 0001-org-capture-Quote-regexp-for-initial-content-prefix.patch --]
[-- Type: text/x-patch, Size: 901 bytes --]
From 4ac40f705f615105c208fcfa6e169ed08af153cf Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
Date: Fri, 7 Dec 2018 19:27:12 -0800
Subject: [PATCH 1/2] org-capture: Quote regexp for initial content prefix
* lisp/org-capture.el (org-capture-fill-template): Quote initial
content lead.
---
lisp/org-capture.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 2d72c39fd..8505c2b92 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1673,7 +1673,7 @@ The template may still contain \"%?\" for cursor positioning."
(let ((lead (buffer-substring-no-properties
(line-beginning-position) (point))))
(replace-regexp-in-string "\n\\(.\\)"
- (concat lead "\\1")
+ (concat (regexp-quote lead) "\\1")
v-i nil nil 1))))
(?a v-a)
(?A v-A)
--
2.19.2
next prev parent reply other threads:[~2018-12-08 3:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-08 2:12 Bug: Org capture: Invalid use of ‘\’ in replacement text [9.1.14 (9.1.14-1049-g04641c-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181203/)] Allen Li
2018-12-08 3:37 ` Allen Li [this message]
2018-12-08 9:54 ` [PATCH] " Nicolas Goaziou
2018-12-09 23:25 ` Nicolas Goaziou
2018-12-08 10:51 ` Nicolas Goaziou
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=CADbSrJz2QnLyDooROkuzyZTkJigKS3-h-upeg+9i_8NsU_Cjkg@mail.gmail.com \
--to=darkfeline@felesatra.moe \
--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).