emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-capture - using `file' as template
@ 2010-07-14  2:30 Johan Friis
  2010-07-14  7:08 ` David Maus
  2010-07-14  9:04 ` Carsten Dominik
  0 siblings, 2 replies; 6+ messages in thread
From: Johan Friis @ 2010-07-14  2:30 UTC (permalink / raw)
  To: emacs-orgmode


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)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-07-14 20:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-14  2:30 [PATCH] org-capture - using `file' as template Johan Friis
2010-07-14  7:08 ` David Maus
2010-07-14 13:54   ` Johan Friis
2010-07-14  9:04 ` Carsten Dominik
2010-07-14 18:58   ` Johan Friis
2010-07-14 20:01     ` Carsten Dominik

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).