Fix tp--get-nested to handle face values with symbol prefix like (shadow :foreground ...)

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-14 15:37:47 +00:00
parent 85c8c5365b
commit 52999a2807

26
tp.el
View File

@ -407,20 +407,34 @@ Example: (tp--get-nested \\='(:a 1 :b 2 :c 3) \\='((:a :b))) => (:a 1 :b 2)"
value value
(let* ((key (car path)) (let* ((key (car path))
(rest (cdr path)) (rest (cdr path))
;; Check if value is a plist-like structure
;; A plist starts with keyword, or starts with symbol followed by keywords
;; e.g., (:foreground "red") or (shadow :foreground "red")
(is-plist-like (and (listp value)
(or (keywordp (car value))
(and (symbolp (car value))
(cdr value)
(keywordp (cadr value))))))
(next-value (next-value
(cond (cond
;; Key is a list of keys - extract multiple keys from value ;; Key is a list of keys - extract multiple keys from value
((and (listp key) (not (null key))) ((and (listp key) (not (null key)))
(when (and (listp value) (keywordp (car value))) (when is-plist-like
(let ((result nil)) (let ((result nil)
(plist-part (if (keywordp (car value))
value
(cdr value))))
(dolist (k key) (dolist (k key)
(let ((v (plist-get value k))) (let ((v (plist-get plist-part k)))
(when v (when v
(setq result (plist-put result k v))))) (setq result (plist-put result k v)))))
result))) result)))
;; Value is a plist with keyword keys ;; Value is a plist or plist-like (symbol followed by plist)
((and (listp value) (keywordp (car value))) (is-plist-like
(plist-get value key)) (let ((plist-part (if (keywordp (car value))
value
(cdr value))))
(plist-get plist-part key)))
;; Value is an alist ;; Value is an alist
((and (listp value) (consp (car value))) ((and (listp value) (consp (car value)))
(cdr (assoc key value))) (cdr (assoc key value)))