summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2019-04-02 22:10:50 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2019-04-02 22:10:50 +0200
commitb913b7404b0e9ed183da8abf4af738e750c9f34c (patch)
tree2fd6982835e5fc3f0d8286279ba2d69da259daff
parent01182eb77562c5f39cc17a70e7083fb25b712cd8 (diff)
downloadorg-mode-b913b7404b0e9ed183da8abf4af738e750c9f34c.tar.gz
org-capture: Fix capture on empty entries
* lisp/org-capture.el (org-capture-fill-template): Prevent raising an error when template is an empty entry. * testing/lisp/test-org-capture.el (test-org-caputre/entry): Add test. Reported-by: Roland Everaert <reveatwork@gmail.com> <http://lists.gnu.org/r/emacs-orgmode/2019-04/msg00019.html>
-rw-r--r--lisp/org-capture.el16
-rw-r--r--testing/lisp/test-org-capture.el11
2 files changed, 14 insertions, 13 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index cb5b158..387daa4 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1608,10 +1608,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)
@@ -1623,7 +1621,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)
@@ -1640,10 +1637,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
@@ -1693,10 +1688,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
@@ -1814,7 +1807,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
@@ -1823,16 +1815,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)
diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el
index f0d86e9..cdc70f1 100644
--- a/testing/lisp/test-org-capture.el
+++ b/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."