Feature request: Allow full Lisp in capture-templates expansions (unobtrusive 
opt-in)

Currently, it is not possible to use variables directly in embedded lisp
templates in org-capture templates. For example this is not possible to
type:

%(default-directory)

since current embedded lisp evaluator can only evaluate functions.

The proposed patch suggests unintrosive, per-template opt-in that allows
for %() expansions with full lisp evaluation.

It adds a new keyword to the template keywords,
:allow-full-lisp as a selector for the new evaluator. The default is the
old one of course, so all old templates would run untouched. Newly
written templates have to explicitly opt-in with the new keyword. It also
adds a new optional argument to org-capture-fill-template, so it is
possible to select new evaluatore even if org-capture-fill-template is
called outside of org-capture itself.

New expander have also relaxed requirement for the return value of the
evaluation. Instead of asking the user to ensure that evaluation returns
a string, we are using printing representation of returned value. That
is slightly more convenient then calling (prin1 myvar) possibly in many
places in a template. With this patch we could type:

%(default-directory)    => "~/..."
%(most-positive-fixnum) => "230..."
%((buffer-name))        => "Capture..."

Motivation for this is a wish to use org-capture-templates as a more
general template expansion tool. Attached is an example of a template to
generate a README file in org format. As seen from the example, a
variable may be repeated many times. In this case there is only one,
'project-name' but there could be of course other repeated variables.
Having to basically repeat prin1 many times, leads to something this:

 '(prin1 project-name)',

on each use, whis elaborate and unnecessary repeating ourselves.

There are other template engines available, I am using Skeleton myself
in several places, but I find org-capture templates with
palceholders more convenient to work with. The only nuissance is we
can't use variables directly, but that is not hard to add in. The
proposed patch is a relatively short function, and is completely
unintrusive to all existing users of org-capture templates.

This is just a preliminary test of idea, if that would be acceptable in this
form I can rework other details, docs etc. I hope this one is more
acceptable than the previous suggestion.

Attachment: README.org
Description: README.org

Attachment: 0001-New-evaluator-for-in-capture-templates.patch
Description: 0001-New-evaluator-for-in-capture-templates.patch

Reply via email to