mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2025-01-04 11:40:40 +00:00
Fix bug in getting template from file or function
This commit is contained in:
parent
d044ad3f1c
commit
2235ecb422
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user