Browse Source

org-capture: Fix %i with prefix containing "\\"

* lisp/org-capture.el (org-capture-fill-template): Fix %i with prefix
  containing "\\".
* testing/lisp/test-org-capture.el (test-org-capture/fill-template):
  Add test.
Nicolas Goaziou 1 year ago
parent
commit
e9108043e1
2 changed files with 9 additions and 6 deletions
  1. 3 5
      lisp/org-capture.el
  2. 6 1
      testing/lisp/test-org-capture.el

+ 3 - 5
lisp/org-capture.el

@@ -1670,11 +1670,9 @@ The template may still contain \"%?\" for cursor positioning."
 			     ;; Outside embedded Lisp, repeat leading
 			     ;; characters before initial place holder
 			     ;; every line.
-			     (let ((lead (buffer-substring-no-properties
-					  (line-beginning-position) (point))))
-			       (replace-regexp-in-string "\n\\(.\\)"
-							 (concat lead "\\1")
-							 v-i nil nil 1))))
+			     (let ((lead (concat "\n"
+						 (org-current-line-string t))))
+			       (replace-regexp-in-string "\n" lead v-i nil t))))
 			  (?a v-a)
 			  (?A v-A)
 			  (?c v-c)

+ 6 - 1
testing/lisp/test-org-capture.el

@@ -74,11 +74,16 @@
 	    (org-capture-fill-template
 	     "%i" "%(concat \"no \" \"evaluation\")"))))
   ;; When %i contents span over multiple line, repeat initial leading
-  ;; characters over each line.
+  ;; characters over each line.  Also try possibly problematic
+  ;; prefixes such as "\\".
   (should
    (equal "> line 1\n> line 2\n"
 	  (let ((org-store-link-plist nil))
 	    (org-capture-fill-template "> %i" "line 1\nline 2"))))
+  (should
+   (equal "\\ line 1\n\\ line 2\n"
+	  (let ((org-store-link-plist nil))
+	    (org-capture-fill-template "\\ %i" "line 1\nline 2"))))
   ;; Test %-escaping with \ character.
   (should
    (equal "%i\n"