Procházet zdrojové kódy

Capture: Better error message for invalid entry-type templates

* lisp/org-capture.el (org-capture-place-entry):
(org-capture-insert-template-here): Check tree for validity before
pasting it.
Carsten Dominik před 14 roky
rodič
revize
8aacc708dd
1 změnil soubory, kde provedl 7 přidání a 0 odebrání
  1. 7 0
      lisp/org-capture.el

+ 7 - 0
lisp/org-capture.el

@@ -776,6 +776,7 @@ already gone.  Any prefix argument will be passed to the refile comand."
 	(or (bolp) (insert "\n")))))
     (org-capture-empty-lines-before)
     (setq beg (point))
+    (org-capture-verify-tree txt)
     (org-paste-subtree level txt 'for-yank)
     (org-capture-empty-lines-after 1)
     (org-capture-position-for-last-stored beg)
@@ -1017,6 +1018,7 @@ Point will remain at the first line after the inserted text."
     (setq beg (point))
     (cond
      ((and (eq type 'entry) (org-mode-p))
+      (org-capture-verify-tree txt)
       (org-paste-subtree nil template t))
      ((and (memq type '(item checkitem))
 	   (org-mode-p)
@@ -1084,6 +1086,11 @@ Use PREFIX as a prefix for the name of the indirect buffer."
       (error (make-indirect-buffer buffer bname)))))
 
 
+(defun org-capture-verify-tree (tree)
+  "Throw error if TREE is not a valid tree"
+  (unless (org-kill-is-subtree-p tree)
+    (error "Template is not a valid Org entry or tree")))
+
 ;;; The template code
 
 (defun org-capture-select-template (&optional keys)