From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johan Friis Subject: [PATCH] org-capture - using `file' as template Date: Wed, 14 Jul 2010 03:30:43 +0100 Message-ID: <87bpaavlpo.fsf@alterecco.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=55277 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OYsRB-0003KE-Jc for emacs-orgmode@gnu.org; Tue, 13 Jul 2010 23:15:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OYsRA-0004ER-7R for emacs-orgmode@gnu.org; Tue, 13 Jul 2010 23:15:09 -0400 Received: from lo.gmane.org ([80.91.229.12]:32925) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OYsR9-0004EJ-OZ for emacs-orgmode@gnu.org; Tue, 13 Jul 2010 23:15:08 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OYsR6-0003Cs-Mt for emacs-orgmode@gnu.org; Wed, 14 Jul 2010 05:15:04 +0200 Received: from 212.red-88-19-72.staticip.rima-tde.net ([88.19.72.212]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Jul 2010 05:15:04 +0200 Received: from mail by 212.red-88-19-72.staticip.rima-tde.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Jul 2010 05:15:04 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Setting up capture to use templates from file in the latest git seemed to cause some errors. I looked into it and wrote this small patch. It could probably use some love, seeing as I am quite new to org-mode, elisp and emacs in general. The error I was getting was related to testing (string-match ...) on a list. The fix is to check if txt is a list before doing the test. In addition I updated the customize interface to use `file' instead of `file-contents'. This seems to be the current way of doing things. Please note: This is my first time posting here. Please let me know if there are some rules to follow that I missed. And thanks for a great piece of software :) Regards, Johan diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 2cb6876..da0925c 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -285,7 +285,7 @@ calendar | %:type %:date" (choice :tag "Template" (string) (list :tag "File" - (const :format "" file-contents) + (const :format "" file) (file :tag "Template file")) (list :tag "Function" (const :format "" function) @@ -981,14 +981,15 @@ 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) (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 "| %? |")) - ((member type '(nil entry)) (setq txt "* %?\n %a")))) + (when (or (not txt) (not (listp txt))) + (when (or (not 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 "| %? |")) + ((member type '(nil entry)) (setq txt "* %?\n %a"))))) (org-capture-put :template txt :type type))) (defun org-capture-goto-target (&optional template-key)