branch: externals/tempel
commit bf95b3f1c236e9070da995376efd58e321b76f08
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>
Add support for (q (FORM ...) var)
---
README.org | 2 ++
tempel.el | 4 +++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index c366d493e1..7b79213349 100644
--- a/README.org
+++ b/README.org
@@ -116,5 +116,7 @@ important ones here:
Furthermore Tempel supports two syntax extensions:
- ~(q PROMPT NAME)~ Query the user via ~read-string~ and store the result in
variable ~NAME~.
+ - ~(q (form ...) NAME)~ Query the user using ~FORM~ and store the result in
variable ~NAME~.
+ Use caution with templates which execute code!
- ~(form ...)~ Other Lisp forms are evaluated. Named fields are lexically
bound.
Use caution with templates which execute code!
diff --git a/tempel.el b/tempel.el
index f817473f70..1a7e69ddc5 100644
--- a/tempel.el
+++ b/tempel.el
@@ -187,7 +187,9 @@ BEG and END are the boundaries of the modification."
(defun tempel--query (st prompt name)
"Read input with PROMPT and assign to binding NAME in ST."
- (setf (alist-get name (cdr st)) (read-string prompt)))
+ (setf (alist-get name (cdr st)) (if (stringp prompt)
+ (read-string prompt)
+ (eval prompt 'lexical-binding))))
(defun tempel--element (st element region)
"Add template ELEMENT to ST given the REGION."