From 4d933ee2cc91f93c8e78a792175751e27c9d03e4 Mon Sep 17 00:00:00 2001 From: Matthieu Lemerre Date: Fri, 17 Jun 2011 00:19:40 +0200 Subject: [PATCH 2/2] Allows org-capture template to be a function. The function should return a string, which is used as a template. --- lisp/org-capture.el | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 7e055f9..368532f 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1171,15 +1171,17 @@ Point will remain at the first line after the inserted text." (org-capture-put :key (car entry) :description (nth 1 entry) :target (nth 3 entry)) (let ((txt (nth 4 entry)) (type (or (nth 2 entry) 'entry))) - (when (or (not txt) (and (stringp txt) (not (string-match "\\S-" txt)))) - ;; The template may be empty or omitted for special types. - ;; Here we insert the default templates for such cases. - (cond - ((eq type 'item) (setq txt "- %?")) - ((eq type 'checkitem) (setq txt "- [ ] %?")) - ((eq type 'table-line) (setq txt "| %? |")) - ((eq type 'empty) (setq txt "")) - ((member type '(nil entry)) (setq txt "* %?\n %a")))) + (if (functionp txt) + (setq txt (funcall txt)) + (when (or (not txt) (and (stringp txt) (not (string-match "\\S-" txt)))) + ;; The template may be empty or omitted for special types. + ;; Here we insert the default templates for such cases. + (cond + ((eq type 'item) (setq txt "- %?")) + ((eq type 'checkitem) (setq txt "- [ ] %?")) + ((eq type 'table-line) (setq txt "| %? |")) + ((eq type 'empty) (setq txt "")) + ((member type '(nil entry)) (setq txt "* %?\n %a"))))) (org-capture-put :template txt :type type))) (defun org-capture-goto-target (&optional template-key) -- 1.7.4.1