From 7b4c2a0e630ccdee99069f59f2b9a787999e0689 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 14:01:01 +0000 Subject: [PATCH] Fix tp-name property being incorrectly set for layer names in string form When calling (tp-set str 'layer-name), the layer name symbol was wrapped in a list by tp--parse-args. tp--resolve-props then incorrectly treated this single-element list as a plist and generated an anonymous tp-anon-X name instead of using the actual layer name. The fix adds detection in tp--resolve-props for single-element lists containing a defined layer/group name symbol, and correctly resolves them by recursing with just the symbol. Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com> --- tp-tests.el | 15 +++++++++++++++ tp.el | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/tp-tests.el b/tp-tests.el index 46208a6..6a1cc82 100644 --- a/tp-tests.el +++ b/tp-tests.el @@ -2070,6 +2070,21 @@ Returns list of (START END VALUE) intervals." ;; tp-name should be preserved for reactive text property support (should (eq (get-text-property 0 'tp-name str) 'my-style)))) +(ert-deftest tp-test-set-entire-string-with-layer-name () + "Test tp-set with layer name on entire string (string form). +This tests the fix for the bug where (tp-set str 'layer-name) would +incorrectly generate an anonymous tp-name instead of using the layer name." + (tp-test-with-temp-buffer + ;; Define a layer with reactive variables + (tp-define-layer my-entire-string-layer + :props (face (:background $my-entire-string-color)) + :data ((my-entire-string-color . "blue"))) + (let ((str (tp-set " " 'my-entire-string-layer))) + ;; tp-name should be the defined layer name, not an anonymous tp-anon-X + (should (eq (get-text-property 0 'tp-name str) 'my-entire-string-layer)) + ;; face should be correctly set + (should (equal (plist-get (get-text-property 0 'face str) :background) "blue"))))) + (ert-deftest tp-test-reset-with-layer-name () "Test tp-reset accepts a layer name defined by define-tp." (tp-test-with-temp-buffer diff --git a/tp.el b/tp.el index 602deab..2204619 100644 --- a/tp.el +++ b/tp.el @@ -2337,6 +2337,7 @@ Appends 'tp-name property to identify the layer." "Resolve PROPS to a property list with layer metadata. PROPS can be: - A symbol (layer name from `tp-layer-alist' or group name from `tp-layer-groups') +- A single-element list containing a layer/group symbol (from string form of tp-set) - A plist (handles anonymous layers with reactive variables) If PROPS is a symbol: @@ -2356,24 +2357,35 @@ For group names, includes `tp-layers' property with the full layer stack." (cond ;; Already a plist - check for reactive variables and add tp-name ((listp props) - (let* ((existing-tp-name (plist-get props 'tp-name)) - (reactive-syms (tp--collect-reactive-symbols props))) - (if reactive-syms - ;; Has reactive symbols - need to handle as anonymous reactive layer - (let* ((layer-name (or existing-tp-name (tp--generate-anonymous-layer-name))) - ;; Resolve reactive symbols to get current values - (resolved-props (tp--resolve-reactive-symbols props))) - ;; Register this anonymous layer in tp-layer-alist with resolved props - (tp--set-layer-props layer-name resolved-props) - ;; Register reactive dependencies with the original props - (tp--register-reactive-deps layer-name reactive-syms props) - ;; Return resolved props with tp-name - (append resolved-props (list 'tp-name layer-name))) - ;; No reactive symbols - just add tp-name if not present - (if existing-tp-name - props - (let ((layer-name (tp--generate-anonymous-layer-name))) - (append props (list 'tp-name layer-name))))))) + ;; Handle single-element list containing a layer/group name symbol. + ;; This can happen when tp-set is called with string form: (tp-set str 'layer-name) + ;; which produces props = (layer-name) in tp--parse-args. + (let ((first-elem (car-safe props))) + (if (and (= (length props) 1) + (symbolp first-elem) + (or (assoc first-elem tp-layer-alist) + (assoc first-elem tp-layer-groups))) + ;; It's a layer/group name wrapped in a list - recurse with the symbol + (tp--resolve-props first-elem) + ;; Normal plist processing + (let* ((existing-tp-name (plist-get props 'tp-name)) + (reactive-syms (tp--collect-reactive-symbols props))) + (if reactive-syms + ;; Has reactive symbols - need to handle as anonymous reactive layer + (let* ((layer-name (or existing-tp-name (tp--generate-anonymous-layer-name))) + ;; Resolve reactive symbols to get current values + (resolved-props (tp--resolve-reactive-symbols props))) + ;; Register this anonymous layer in tp-layer-alist with resolved props + (tp--set-layer-props layer-name resolved-props) + ;; Register reactive dependencies with the original props + (tp--register-reactive-deps layer-name reactive-syms props) + ;; Return resolved props with tp-name + (append resolved-props (list 'tp-name layer-name))) + ;; No reactive symbols - just add tp-name if not present + (if existing-tp-name + props + (let ((layer-name (tp--generate-anonymous-layer-name))) + (append props (list 'tp-name layer-name))))))))) ;; Symbol - check if it's a layer or group name ((symbolp props) (cond