Browse Source

Allow nil as return of sexp in capture templates

* lisp/org-capture.el (org-capture-expand-embedded-elisp): Throw error if
result is not a string and not nil.  If the result is nil, treat it as
if it was the empty string.
oleh 11 years ago
parent
commit
1871bf6933
1 changed files with 8 additions and 4 deletions
  1. 8 4
      lisp/org-capture.el

+ 8 - 4
lisp/org-capture.el

@@ -1737,11 +1737,15 @@ The template may still contain \"%?\" for cursor positioning."
       (goto-char (match-beginning 0))
       (let ((template-start (point)))
 	(forward-char 1)
-	(let ((result (org-eval
-		       (org-capture--expand-keyword-in-embedded-elisp
-			(read (current-buffer))))))
+	(let* ((sexp (read (current-buffer)))
+	       (result (org-eval
+			(org-capture--expand-keyword-in-embedded-elisp sexp))))
 	  (delete-region template-start (point))
-	  (insert result))))))
+	  (when result
+	    (if (stringp result)
+		(insert result)
+	      (error "Capture template sexp `%s' must evaluate to string or nil"
+		     sexp))))))))
 
 (defun org-capture--expand-keyword-in-embedded-elisp (attr)
   "Recursively replace capture link keywords in ATTR sexp.