From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [PATCH] org-capture - using `file' as template Date: Wed, 14 Jul 2010 11:04:22 +0200 Message-ID: References: <87bpaavlpo.fsf@alterecco.net> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=46888 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OYxtF-0002fq-7v for emacs-orgmode@gnu.org; Wed, 14 Jul 2010 05:04:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OYxtD-0004Ci-FJ for emacs-orgmode@gnu.org; Wed, 14 Jul 2010 05:04:28 -0400 Received: from mail-ey0-f169.google.com ([209.85.215.169]:39186) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OYxtD-0004CX-6c for emacs-orgmode@gnu.org; Wed, 14 Jul 2010 05:04:27 -0400 Received: by eydd26 with SMTP id d26so1062815eyd.0 for ; Wed, 14 Jul 2010 02:04:26 -0700 (PDT) In-Reply-To: <87bpaavlpo.fsf@alterecco.net> 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: Johan Friis , David Maus Cc: emacs-orgmode list Hi Johan, thanks for the report and patch, hi David, thanks for further comments, I have checked in a fix. - Carsten On Jul 14, 2010, at 4:30 AM, Johan Friis wrote: > > 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) > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten