Fix tp-layer-props-with-arg to handle reactive parameterized layers
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
parent
7934749397
commit
c7db648e85
24
tp.el
24
tp.el
@ -2900,15 +2900,31 @@ where ARGLIST is a non-nil list of argument symbols."
|
|||||||
"Return properties for parameterized layer LAYER-NAME with ARG.
|
"Return properties for parameterized layer LAYER-NAME with ARG.
|
||||||
Evaluates the body form with the argument bound to the parameter.
|
Evaluates the body form with the argument bound to the parameter.
|
||||||
If INCLUDE-TP-NAME is non-nil, appends 'tp-name property to identify the layer.
|
If INCLUDE-TP-NAME is non-nil, appends 'tp-name property to identify the layer.
|
||||||
Recursively expands any nested layer names in the returned plist."
|
Recursively expands any nested layer names in the returned plist.
|
||||||
|
|
||||||
|
Handles two storage formats:
|
||||||
|
1. Simple parameterized: (ARGLIST BODY-FORM) - evaluate BODY-FORM with arg bound
|
||||||
|
2. Reactive parameterized: (ARGLIST FUNCTION) - call FUNCTION with arg to get keyword plist"
|
||||||
(when-let ((entry (cdr (assoc layer-name tp-layer-alist))))
|
(when-let ((entry (cdr (assoc layer-name tp-layer-alist))))
|
||||||
;; entry is (ARGLIST BODY-FORM)
|
;; entry is (ARGLIST BODY-FORM) or (ARGLIST FUNCTION)
|
||||||
(let ((arglist (car entry))
|
(let ((arglist (car entry))
|
||||||
(body (cadr entry)))
|
(body (cadr entry)))
|
||||||
(when arglist ; Only for parameterized layers
|
(when arglist ; Only for parameterized layers
|
||||||
(let* ((arg-sym (car arglist))
|
(let* ((arg-sym (car arglist))
|
||||||
;; Evaluate the body with the argument bound
|
;; Check if body is a function (reactive parameterized layer)
|
||||||
(plist (eval `(let ((,arg-sym ',arg)) ,body))))
|
(result (if (functionp body)
|
||||||
|
;; Reactive parameterized: call the function with arg
|
||||||
|
(funcall body arg)
|
||||||
|
;; Simple parameterized: evaluate with arg bound
|
||||||
|
(eval `(let ((,arg-sym ',arg)) ,body))))
|
||||||
|
;; For reactive parameterized, result is (:props ... :data ...), extract :props
|
||||||
|
(plist (if (and (listp result)
|
||||||
|
(keywordp (car result))
|
||||||
|
(eq (car result) :props))
|
||||||
|
;; It's a reactive keyword plist - get the :props value
|
||||||
|
(plist-get result :props)
|
||||||
|
;; It's already a direct plist
|
||||||
|
result)))
|
||||||
(when plist
|
(when plist
|
||||||
;; Recursively expand nested layer names
|
;; Recursively expand nested layer names
|
||||||
(when (tp--plist-has-layer-key-p plist)
|
(when (tp--plist-has-layer-key-p plist)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user