emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-capture with LISP function template
@ 2010-07-19  1:45 Juan Pechiar
  2010-07-19  7:05 ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Juan Pechiar @ 2010-07-19  1:45 UTC (permalink / raw)
  To: carsten.dominik; +Cc: emacs-orgmode

Hi Carsten + crowd,

Below is a patch for org-capture when the template is given by a LISP
function.

Problem was that the function is inside a string (not a LISP form), so
the string has to be evaluated explicitly.

Now it's working for me. I use it to get a template formed by
URL/title and selected text from Opera browser (on Mac OSX). I´ll
publish this after polishing the code.

I've also been testing exotic org-capture templates and I've found no
other errors yet.

Best regards,
.j.

8<------------------------------------------------------------

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 2a3a1b8..409427f 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -440,8 +440,8 @@ bypassed."
          (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)))
+      (if (eval (concat "fboundp " (nth 1 txt)))
+         (setq txt (eval (read (nth 1 txt))))
        (setq txt (format "* Template function %s not found" (nth 1
        txt)))))
      ((not txt) (setq txt ""))
      ((stringp txt))

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

* Re: [PATCH] org-capture with LISP function template
  2010-07-19  1:45 [PATCH] org-capture with LISP function template Juan Pechiar
@ 2010-07-19  7:05 ` Carsten Dominik
  2010-07-19 12:26   ` Juan
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Dominik @ 2010-07-19  7:05 UTC (permalink / raw)
  To: Juan Pechiar; +Cc: emacs-orgmode

Hi Juan,

the function must be a symbol in this setup, not a string.
I am rejecting this patch.

Cheers.

- Carsten

On Jul 19, 2010, at 3:45 AM, Juan Pechiar wrote:

> Hi Carsten + crowd,
>
> Below is a patch for org-capture when the template is given by a LISP
> function.
>
> Problem was that the function is inside a string (not a LISP form), so
> the string has to be evaluated explicitly.
>
> Now it's working for me. I use it to get a template formed by
> URL/title and selected text from Opera browser (on Mac OSX). I´ll
> publish this after polishing the code.
>
> I've also been testing exotic org-capture templates and I've found no
> other errors yet.
>
> Best regards,
> .j.
>
> 8<------------------------------------------------------------
>
> diff --git a/lisp/org-capture.el b/lisp/org-capture.el
> index 2a3a1b8..409427f 100644
> --- a/lisp/org-capture.el
> +++ b/lisp/org-capture.el
> @@ -440,8 +440,8 @@ bypassed."
>          (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)))
> +      (if (eval (concat "fboundp " (nth 1 txt)))
> +         (setq txt (eval (read (nth 1 txt))))
>        (setq txt (format "* Template function %s not found" (nth 1
>        txt)))))
>      ((not txt) (setq txt ""))
>      ((stringp txt))

- Carsten

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

* Re: Re: [PATCH] org-capture with LISP function template
  2010-07-19  7:05 ` Carsten Dominik
@ 2010-07-19 12:26   ` Juan
  2010-07-19 12:43     ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Juan @ 2010-07-19 12:26 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

Hi Carsten,

I think the original problem is in the defcustom specification:

org-capture.el L292

	   (choice :tag "Template"
		   (string)
		   (list :tag "File"
			 (const :format "" file)
			 (file :tag "Template file"))
		   (list :tag "Function"
			 (const :format "" function)
			 (file :tag "Template function")))

The last line should read 'sexp' instead of 'file'. This is why the
function is being held as a string.

Saludos,
.j.

On Mon, Jul 19, 2010 at 09:05:06AM +0200, Carsten Dominik wrote:
> the function must be a symbol in this setup, not a string.
> I am rejecting this patch.
>
> On Jul 19, 2010, at 3:45 AM, Juan Pechiar wrote:

> >Below is a patch for org-capture when the template is given by a LISP
> >function.
> >
> >Problem was that the function is inside a string (not a LISP form), so
> >the string has to be evaluated explicitly.

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

* Re: Re: [PATCH] org-capture with LISP function template
  2010-07-19 12:26   ` Juan
@ 2010-07-19 12:43     ` Carsten Dominik
  0 siblings, 0 replies; 4+ messages in thread
From: Carsten Dominik @ 2010-07-19 12:43 UTC (permalink / raw)
  To: Juan; +Cc: emacs-orgmode


On Jul 19, 2010, at 2:26 PM, Juan wrote:

> Hi Carsten,
>
> I think the original problem is in the defcustom specification:
>
> org-capture.el L292
>
> 	   (choice :tag "Template"
> 		   (string)
> 		   (list :tag "File"
> 			 (const :format "" file)
> 			 (file :tag "Template file"))
> 		   (list :tag "Function"
> 			 (const :format "" function)
> 			 (file :tag "Template function")))
>
> The last line should read 'sexp' instead of 'file'. This is why the
> function is being held as a string.

Indeed, thanks.

- Carsten

>
> Saludos,
> .j.
>
> On Mon, Jul 19, 2010 at 09:05:06AM +0200, Carsten Dominik wrote:
>> the function must be a symbol in this setup, not a string.
>> I am rejecting this patch.
>>
>> On Jul 19, 2010, at 3:45 AM, Juan Pechiar wrote:
>
>>> Below is a patch for org-capture when the template is given by a  
>>> LISP
>>> function.
>>>
>>> Problem was that the function is inside a string (not a LISP  
>>> form), so
>>> the string has to be evaluated explicitly.

- Carsten

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

end of thread, other threads:[~2010-07-19 12:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-19  1:45 [PATCH] org-capture with LISP function template Juan Pechiar
2010-07-19  7:05 ` Carsten Dominik
2010-07-19 12:26   ` Juan
2010-07-19 12:43     ` 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).