* 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/)]
@ 2018-12-08 2:12 Allen Li
2018-12-08 3:37 ` [PATCH] " Allen Li
2018-12-08 10:51 ` Nicolas Goaziou
0 siblings, 2 replies; 5+ messages in thread
From: Allen Li @ 2018-12-08 2:12 UTC (permalink / raw)
To: Org Mode List
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/)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [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/)]
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
2018-12-08 9:54 ` Nicolas Goaziou
2018-12-09 23:25 ` Nicolas Goaziou
2018-12-08 10:51 ` Nicolas Goaziou
1 sibling, 2 replies; 5+ messages in thread
From: Allen Li @ 2018-12-08 3:37 UTC (permalink / raw)
To: Org Mode List
[-- 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [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/)]
2018-12-08 3:37 ` [PATCH] " Allen Li
@ 2018-12-08 9:54 ` Nicolas Goaziou
2018-12-09 23:25 ` Nicolas Goaziou
1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Goaziou @ 2018-12-08 9:54 UTC (permalink / raw)
To: Allen Li; +Cc: Org Mode List
Hello,
Allen Li <darkfeline@felesatra.moe> writes:
> 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.
Thank you.
However, with the documentation patch, along with your past
contributions, you would be over the limit allowed for tiny changes.
IOW, you need to sign FSF papers so that we can apply it.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: 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/)]
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 ` [PATCH] " Allen Li
@ 2018-12-08 10:51 ` Nicolas Goaziou
1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Goaziou @ 2018-12-08 10:51 UTC (permalink / raw)
To: Allen Li; +Cc: Org Mode List
Hello,
Allen Li <darkfeline@felesatra.moe> writes:
> 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)")
Fixed. Thank you.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [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/)]
2018-12-08 3:37 ` [PATCH] " Allen Li
2018-12-08 9:54 ` Nicolas Goaziou
@ 2018-12-09 23:25 ` Nicolas Goaziou
1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Goaziou @ 2018-12-09 23:25 UTC (permalink / raw)
To: Allen Li; +Cc: Org Mode List
Hello,
Allen Li <darkfeline@felesatra.moe> writes:
> 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.
I applied the documentation patch. Thank you.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-12-09 23:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH] " Allen Li
2018-12-08 9:54 ` Nicolas Goaziou
2018-12-09 23:25 ` Nicolas Goaziou
2018-12-08 10:51 ` Nicolas Goaziou
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.