Browse Source

Merge branch 'maint'

Nicolas Goaziou 6 years ago
parent
commit
da517aaeb8
2 changed files with 14 additions and 13 deletions
  1. 4 12
      lisp/org-capture.el
  2. 10 1
      testing/lisp/test-org-capture.el

+ 4 - 12
lisp/org-capture.el

@@ -1617,10 +1617,8 @@ The template may still contain \"%?\" for cursor positioning."
 		      (org-get-x-clipboard 'CLIPBOARD)
 		      (org-get-x-clipboard 'SECONDARY)
 		      v-c))))
-
     (setq org-store-link-plist (plist-put org-store-link-plist :annotation v-a))
     (setq org-store-link-plist (plist-put org-store-link-plist :initial v-i))
-
     (unless template
       (setq template "")
       (message "no template") (ding)
@@ -1632,7 +1630,6 @@ The template may still contain \"%?\" for cursor positioning."
       (setq mark-active nil)
       (insert template)
       (goto-char (point-min))
-
       ;; %[] insert contents of a file.
       (save-excursion
 	(while (re-search-forward "%\\[\\(.+\\)\\]" nil t)
@@ -1649,10 +1646,8 @@ The template may still contain \"%?\" for cursor positioning."
 		 (insert (format "%%![couldn not insert %s: %s]"
 				 filename
 				 error))))))))
-
       ;; Mark %() embedded elisp for later evaluation.
       (org-capture-expand-embedded-elisp 'mark)
-
       ;; Expand non-interactive templates.
       (let ((regexp "%\\(:[-a-za-z]+\\|<\\([^>\n]+\\)>\\|[aAcfFikKlntTuUx]\\)"))
 	(save-excursion
@@ -1702,10 +1697,8 @@ The template may still contain \"%?\" for cursor positioning."
 		       ;; Escape sensitive characters.
 		       (replace-regexp-in-string "[\\\"]" "\\\\\\&" replacement)
 		     replacement))))))))
-
       ;; Expand %() embedded Elisp.  Limit to Sexp originally marked.
       (org-capture-expand-embedded-elisp)
-
       ;; Expand interactive templates.  This is the last step so that
       ;; template is mostly expanded when prompting happens.  Turn on
       ;; Org mode and set local variables.  This is to support
@@ -1823,7 +1816,6 @@ The template may still contain \"%?\" for cursor positioning."
 		    (_
 		     (error "Unknown template placeholder: \"%%^%s\""
 			    key))))))))
-
 	;; Replace %n escapes with nth %^{...} string.
 	(setq strings (nreverse strings))
 	(save-excursion
@@ -1832,16 +1824,16 @@ The template may still contain \"%?\" for cursor positioning."
 	      (replace-match
 	       (nth (1- (string-to-number (match-string 1))) strings)
 	       nil t)))))
-
       ;; Make sure there are no empty lines before the text, and that
       ;; it ends with a newline character or it is empty.
       (skip-chars-forward " \t\n")
       (delete-region (point-min) (line-beginning-position))
       (goto-char (point-max))
       (skip-chars-backward " \t\n")
-      (delete-region (point) (point-max))
-      (unless (bobp) (insert "\n"))
-
+      (if (bobp) (delete-region (point) (line-end-position))
+	(end-of-line)
+	(delete-region (point) (point-max))
+	(insert "\n"))
       ;; Return the expanded template and kill the capture buffer.
       (untabify (point-min) (point-max))
       (set-buffer-modified-p nil)

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

@@ -223,7 +223,16 @@
 		 :immediate-finish t))))
 	(org-capture nil "t")
 	(org-capture '(16))
-	(buffer-substring (point) (line-end-position)))))))
+	(buffer-substring (point) (line-end-position))))))
+  ;; Do not raise an error on empty entries.
+  (should
+   (org-test-with-temp-text-in-file ""
+     (let* ((file (buffer-file-name))
+	    (org-capture-templates
+	     `(("t" "Test" entry (file+headline ,file "A") "** "
+		:immediate-finish t))))
+       (org-capture nil "t")
+       (buffer-string)))))
 
 (ert-deftest test-org-capture/item ()
   "Test `item' type in capture template."