Address code review feedback: improve efficiency and documentation

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-28 19:17:54 +00:00
parent 09b56b584e
commit 4abcb0fd33
2 changed files with 18 additions and 9 deletions

View File

@ -3506,6 +3506,7 @@ When using tp-set (direct property setting), tp-name is NOT added."
(define-tp tp-space (pixel)
`(display (space :width (,pixel))))
;; Define the button widget similar to the example
;; Note: Using tp-button as the property name to match problem statement
(tp-define-twidget button
:props '(action (bgcolor . "green"))
:slot 'label
@ -3516,7 +3517,7 @@ When using tp-set (direct property setting), tp-name is NOT added."
(tp-set " " 'tp-space 2)
slot (tp-set " " 'tp-space 2))
'face `(:background ,bgcolor)
'button-action `(:action ,action)))))
'tp-button `(:action ,action)))))
;; Parse the button widget
(let ((result (tp-widget-parse
'(button :action (lambda ()
@ -3527,8 +3528,8 @@ When using tp-set (direct property setting), tp-name is NOT added."
;; Check that the face property is applied
(let ((face (get-text-property 2 'face result)))
(should (equal (plist-get face :background) "green")))
;; Check that the button-action property is applied
(let ((action-prop (get-text-property 2 'button-action result)))
;; Check that the tp-button property is applied (matches problem statement)
(let ((action-prop (get-text-property 2 'tp-button result)))
(should (listp (plist-get action-prop :action)))))))
(ert-deftest tp-test-twidget-reset ()

20
tp.el
View File

@ -3586,9 +3586,10 @@ Example:
PROPS is a list of property definitions.
SLOT is the slot name symbol.
RENDER is the render function."
(let ((definition (list :props props :slot slot :render render)))
(if (assoc name tp-twidget-alist)
(setf (cdr (assoc name tp-twidget-alist)) definition)
(let ((definition (list :props props :slot slot :render render))
(existing (assoc name tp-twidget-alist)))
(if existing
(setcdr existing definition)
(push (cons name definition) tp-twidget-alist)))
(assoc name tp-twidget-alist))
@ -3614,7 +3615,12 @@ Returns nil if no default is specified."
"Parse and render a widget invocation.
WIDGET-FORM is a list starting with the widget name, followed by
keyword-value pairs for props, and ending with the slot value.
keyword-value pairs for props, and ending with a single slot value.
The format is: (WIDGET-NAME :prop1 val1 :prop2 val2 ... SLOT-VALUE)
Keyword arguments must come before the slot value. The slot value
is the last non-keyword argument and must be exactly one value.
Example:
(tp-widget-parse
@ -3646,9 +3652,11 @@ Returns the rendered string with text properties applied."
(val (cadr args)))
(push (cons key val) collected-props)
(setq args (cddr args))))
;; The remaining argument is the slot value
;; The remaining argument(s) should be the slot value (exactly one)
(when args
(setq slot-value (car args)))
(setq slot-value (car args))
(when (cdr args)
(warn "tp-widget-parse: Extra arguments after slot value ignored: %S" (cdr args))))
;; Build the props plist with defaults
(dolist (prop-def prop-defs)
(let* ((prop-name (tp--twidget-prop-name prop-def))