summaryrefslogtreecommitdiff
path: root/llama.el
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2024-09-15 18:29:30 +0200
committerJonas Bernoulli <jonas@bernoul.li>2024-09-15 18:29:30 +0200
commita5fb525684260dee7c3381740e61421f7bb0ecc3 (patch)
tree97c80507c7056d26eca5a3a162bb411ac5135f0c /llama.el
parent61cebe9223349754681ca6c188f7db1782e871c9 (diff)
Add special handling of backquote
Diffstat (limited to 'llama.el')
-rw-r--r--llama.el18
1 files changed, 14 insertions, 4 deletions
diff --git a/llama.el b/llama.el
index 7d58ba9..44a66c0 100644
--- a/llama.el
+++ b/llama.el
@@ -176,9 +176,16 @@ this trickery, you can alternatively use this macro under the name
(defconst llama--unused-argument (make-symbol "llama--unused-argument"))
-(defun llama--collect (expr args &optional fnpos)
+(defun llama--collect (expr args &optional fnpos backquoted)
(cond
((memq (car-safe expr) '(## quote)) expr)
+ ((and backquoted (symbolp expr)) expr)
+ ((and backquoted (eq (car-safe expr) backquote-unquote-symbol))
+ (cons backquote-unquote-symbol
+ (llama--collect (cdr expr) args)))
+ ((eq (car-safe expr) backquote-backquote-symbol)
+ (cons backquote-backquote-symbol
+ (llama--collect (cdr expr) args nil t)))
((symbolp expr)
(let ((name (symbol-name expr)))
(save-match-data
@@ -202,20 +209,23 @@ this trickery, you can alternatively use this macro under the name
(let* ((vectorp (vectorp expr))
(expr (if vectorp (append expr ()) expr))
(fnpos (and (not vectorp)
+ (not backquoted)
(ignore-errors (length expr)))) ;proper-list-p
(ret ()))
(catch t
(while t
- (let ((elt (llama--collect (car expr) args fnpos)))
+ (let ((elt (llama--collect (car expr) args fnpos backquoted)))
(unless (eq elt llama--unused-argument)
(push elt ret)))
(setq fnpos nil)
(setq expr (cdr expr))
- (unless (and expr (listp expr))
+ (unless (and expr
+ (listp expr)
+ (not (eq (car expr) backquote-unquote-symbol)))
(throw t nil))))
(setq ret (nreverse ret))
(when expr
- (setcdr (last ret) (llama--collect expr args)))
+ (setcdr (last ret) (llama--collect expr args nil backquoted)))
(if vectorp (vconcat ret) ret)))
(expr)))