diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2019-04-02 22:12:10 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2019-04-02 22:12:10 +0200 |
commit | da517aaeb80fac32fa2c23cbc3940f50c708e428 (patch) | |
tree | 01893eb2dd9f326bd29175af979292a7ab9f532e | |
parent | a9d3eaa9f341f57189c3e676b9bacff52f440fbf (diff) | |
parent | b913b7404b0e9ed183da8abf4af738e750c9f34c (diff) | |
download | org-mode-da517aaeb80fac32fa2c23cbc3940f50c708e428.tar.gz |
Merge branch 'maint'
-rw-r--r-- | lisp/org-capture.el | 16 | ||||
-rw-r--r-- | testing/lisp/test-org-capture.el | 11 |
2 files changed, 14 insertions, 13 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el index c7b038e..2548074 100644 --- a/lisp/org-capture.el +++ b/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) 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." |