Browse Source

org-capture.el: Conditionally throw an error on missing annotation

* lisp/org-capture.el (org-capture-fill-template): Throw a
user error when :immediate-finish is `t' and when the %a
template could not be expanded.

Thanks to Leo Gaspard for this idea.
Bastien 5 years ago
parent
commit
78ec8da52a
1 changed files with 7 additions and 1 deletions
  1. 7 1
      lisp/org-capture.el

+ 7 - 1
lisp/org-capture.el

@@ -1565,7 +1565,13 @@ The template may still contain \"%?\" for cursor positioning."
 	  (let ((a (or (plist-get org-store-link-plist :annotation)
 		       annotation
 		       (org-capture-get :annotation)
-		       "")))
+		       ;; When immediately finishing and %a cannot be
+		       ;; expanded, through a user error:
+		       (if (org-capture-get :immediate-finish)
+			   (user-error "Missing initial annotation in this template: %s"
+				       (replace-regexp-in-string
+					"\n" " " (org-capture-get :template)))
+			 ""))))
 	    ;; Is the link empty?  Then we do not want it...
 	    (if (equal a "[[]]") "" a)))
 	 (l-re "\\[\\[\\(.*?\\)\\]\\(\\[.*?\\]\\)?\\]")