From 2235ecb42242e1763cc97529d30d067994bd6e70 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 6 Jul 2010 12:45:26 +0200 Subject: [PATCH] Fix bug in getting template from file or function --- lisp/org-capture.el | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index c689d6de4..2e12ddcab 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -385,6 +385,7 @@ bypassed." (error "Abort")) (t (org-capture-set-plist entry) + (org-capture-get-template) (org-capture-put :original-buffer orig-buf :annotation annotation :initial initial) (org-capture-put :default-time @@ -424,6 +425,25 @@ bypassed." (error "Could not start the clock in this capture buffer"))))))))))) + +(defun org-capture-get-template () + "Get the template from a file or a function if necessary." + (let ((txt (org-capture-get :template)) file) + (cond + ((and (listp txt) (eq (car txt) 'file)) + (if (file-exists-p + (setq file (expand-file-name (nth 1 txt) org-directory))) + (setq txt (org-file-contents file)) + (setq txt (format "* Template file %s not found" (nth 1 txt))))) + ((and (listp txt) (eq (car txt) 'function)) + (if (fboundp (nth 1 txt)) + (setq txt (funcall (nth 1 txt))) + (setq txt (format "* Template function %s not found" (nth 1 txt))))) + ((not txt) (setq txt "")) + ((stringp txt)) + (t (setq txt "* Invalid capture template"))) + (org-capture-put :template txt))) + (defun org-capture-finalize () "Finalize the capture process." (interactive) @@ -661,20 +681,6 @@ already gone." (target-entry-p (org-capture-get :target-entry-p)) level beg end file) - ;; Get the full template - (cond - ((and (listp txt) (eq (car txt) 'file)) - (if (file-exists-p - (setq file (expand-file-name (nth 1 txt) org-directory))) - (setq txt (org-file-contents file)) - (setq txt (format "Template file %s not found" (nth 1 txt))))) - ((and (listp txt) (eq (car txt) 'function)) - (if (fboundp (nth 1 txt)) - (setq txt (funcall (nth 1 txt))) - (setq txt (format "Template function %s not found" (nth 1 txt))))) - ((not txt) (setq txt "")) - (t (setq txt "Invalid capture template"))) - (cond ((org-capture-get :exact-position) (goto-char (org-capture-get :exact-position))) -- 2.11.4.GIT