Replace put-text-property with tp-set in README examples

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-15 14:16:56 +00:00
parent f28b7858a7
commit 240e590f03
2 changed files with 22 additions and 22 deletions

View File

@ -421,21 +421,21 @@ For single position queries, use `tp-at` instead.
;; Get with property path as list ;; Get with property path as list
(let ((my-string (copy-sequence "Hello World Hello World"))) (let ((my-string (copy-sequence "Hello World Hello World")))
(put-text-property 5 20 'face '(:underline (:style wave)) my-string) (tp-set 5 20 '(face (:underline (:style wave))) my-string)
(tp-get 5 20 '(face :underline :style) my-string)) (tp-get 5 20 '(face :underline :style) my-string))
;; => ((5 20 wave)) ;; => ((5 20 wave))
;; Get deeply nested property from entire string ;; Get deeply nested property from entire string
(let ((str (copy-sequence "Hello World"))) (let ((str (copy-sequence "Hello World")))
(put-text-property 0 5 'face '(:underline (:color "green")) str) (tp-set 0 5 '(face (:underline (:color "green"))) str)
(put-text-property 6 11 'face '(:underline (:color "yellow")) str) (tp-set 6 11 '(face (:underline (:color "yellow"))) str)
(tp-get str 'face :underline :color)) (tp-get str 'face :underline :color))
;; => ((0 5 "green") (6 11 "yellow")) ;; => ((0 5 "green") (6 11 "yellow"))
;; Get multiple keys from nested property ;; Get multiple keys from nested property
(let ((str (copy-sequence "Hello World"))) (let ((str (copy-sequence "Hello World")))
(put-text-property 0 5 'face '(:underline (:color "green" :style wave)) str) (tp-set 0 5 '(face (:underline (:color "green" :style wave))) str)
(put-text-property 6 11 'face '(:underline (:color "yellow" :style line)) str) (tp-set 6 11 '(face (:underline (:color "yellow" :style line))) str)
(tp-get str 'face :underline '(:color :style))) (tp-get str 'face :underline '(:color :style)))
;; => ((0 5 (:color "green" :style wave)) (6 11 (:color "yellow" :style line))) ;; => ((0 5 (:color "green" :style wave)) (6 11 (:color "yellow" :style line)))
@ -507,14 +507,14 @@ For single-position property queries (previously done with `tp-get`), use `tp-at
;; Get nested sub-property at position ;; Get nested sub-property at position
(with-temp-buffer (with-temp-buffer
(insert "Hello World") (insert "Hello World")
(put-text-property 1 10 'face '(:foreground "red" :box (:color "blue"))) (tp-set 1 10 '(face (:foreground "red" :box (:color "blue"))))
(list (tp-at 5 '(face :foreground)) (list (tp-at 5 '(face :foreground))
(tp-at 5 '(face :box :color)))) (tp-at 5 '(face :box :color))))
;; => ("red" "blue") ;; => ("red" "blue")
;; Get nested sub-property from string ;; Get nested sub-property from string
(let ((str (copy-sequence "Hello"))) (let ((str (copy-sequence "Hello")))
(put-text-property 0 5 'face '(:foreground "red" :underline t) str) (tp-set 0 5 '(face (:foreground "red" :underline t)) str)
(tp-at 0 '(face :foreground) str)) (tp-at 0 '(face :foreground) str))
;; => "red" ;; => "red"
``` ```
@ -555,7 +555,7 @@ Remove a property or nested sub-property from a region or entire string.
;; Remove sub-property from face ;; Remove sub-property from face
(with-temp-buffer (with-temp-buffer
(insert "Hello World") (insert "Hello World")
(put-text-property 1 10 'face '(:foreground "red" :underline t)) (tp-set 1 10 '(face (:foreground "red" :underline t)))
(tp-remove 1 10 '(face :underline)) (tp-remove 1 10 '(face :underline))
(tp-at 1 'face)) (tp-at 1 'face))
;; => (:foreground "red") ;; => (:foreground "red")
@ -563,7 +563,7 @@ Remove a property or nested sub-property from a region or entire string.
;; Remove specific nested keys, keep others ;; Remove specific nested keys, keep others
(with-temp-buffer (with-temp-buffer
(insert "Hello World") (insert "Hello World")
(put-text-property 1 10 'face '(:underline (:style wave :position t :color "blue"))) (tp-set 1 10 '(face (:underline (:style wave :position t :color "blue"))))
(tp-remove 1 10 '(face :underline (:style :position))) (tp-remove 1 10 '(face :underline (:style :position)))
(tp-at 1 '(face :underline))) (tp-at 1 '(face :underline)))
;; => (:color "blue") ; :style and :position removed, :color preserved ;; => (:color "blue") ; :style and :position removed, :color preserved
@ -576,14 +576,14 @@ Remove a property or nested sub-property from a region or entire string.
;; Remove sub-property from string ;; Remove sub-property from string
(let ((str (copy-sequence "Hello World"))) (let ((str (copy-sequence "Hello World")))
(put-text-property 0 11 'face '(:foreground "red" :underline t) str) (tp-set 0 11 '(face (:foreground "red" :underline t)) str)
(tp-remove str 'face :underline) (tp-remove str 'face :underline)
(tp-at 0 'face str)) (tp-at 0 'face str))
;; => (:foreground "red") ;; => (:foreground "red")
;; Remove nested keys from string ;; Remove nested keys from string
(let ((str (copy-sequence "Hello World"))) (let ((str (copy-sequence "Hello World")))
(put-text-property 0 11 'face '(:underline (:style wave :color "blue")) str) (tp-set 0 11 '(face (:underline (:style wave :color "blue"))) str)
(tp-remove str 'face :underline '(:style)) (tp-remove str 'face :underline '(:style))
(tp-at 0 '(face :underline) str)) (tp-at 0 '(face :underline) str))
;; => (:color "blue") ;; => (:color "blue")

View File

@ -420,21 +420,21 @@ tp.el 所有函数按类别组织的完整概览:
;; 使用列表形式的属性路径 ;; 使用列表形式的属性路径
(let ((my-string (copy-sequence "Hello World Hello World"))) (let ((my-string (copy-sequence "Hello World Hello World")))
(put-text-property 5 20 'face '(:underline (:style wave)) my-string) (tp-set 5 20 '(face (:underline (:style wave))) my-string)
(tp-get 5 20 '(face :underline :style) my-string)) (tp-get 5 20 '(face :underline :style) my-string))
;; => ((5 20 wave)) ;; => ((5 20 wave))
;; 从整个字符串获取深层嵌套属性 ;; 从整个字符串获取深层嵌套属性
(let ((str (copy-sequence "Hello World"))) (let ((str (copy-sequence "Hello World")))
(put-text-property 0 5 'face '(:underline (:color "green")) str) (tp-set 0 5 '(face (:underline (:color "green"))) str)
(put-text-property 6 11 'face '(:underline (:color "yellow")) str) (tp-set 6 11 '(face (:underline (:color "yellow"))) str)
(tp-get str 'face :underline :color)) (tp-get str 'face :underline :color))
;; => ((0 5 "green") (6 11 "yellow")) ;; => ((0 5 "green") (6 11 "yellow"))
;; 从嵌套属性中获取多个键 ;; 从嵌套属性中获取多个键
(let ((str (copy-sequence "Hello World"))) (let ((str (copy-sequence "Hello World")))
(put-text-property 0 5 'face '(:underline (:color "green" :style wave)) str) (tp-set 0 5 '(face (:underline (:color "green" :style wave))) str)
(put-text-property 6 11 'face '(:underline (:color "yellow" :style line)) str) (tp-set 6 11 '(face (:underline (:color "yellow" :style line))) str)
(tp-get str 'face :underline '(:color :style))) (tp-get str 'face :underline '(:color :style)))
;; => ((0 5 (:color "green" :style wave)) (6 11 (:color "yellow" :style line))) ;; => ((0 5 (:color "green" :style wave)) (6 11 (:color "yellow" :style line)))
@ -506,14 +506,14 @@ tp.el 所有函数按类别组织的完整概览:
;; 获取位置的嵌套子属性 ;; 获取位置的嵌套子属性
(with-temp-buffer (with-temp-buffer
(insert "Hello World") (insert "Hello World")
(put-text-property 1 10 'face '(:foreground "red" :box (:color "blue"))) (tp-set 1 10 '(face (:foreground "red" :box (:color "blue"))))
(list (tp-at 5 '(face :foreground)) (list (tp-at 5 '(face :foreground))
(tp-at 5 '(face :box :color)))) (tp-at 5 '(face :box :color))))
;; => ("red" "blue") ;; => ("red" "blue")
;; 从字符串获取嵌套子属性 ;; 从字符串获取嵌套子属性
(let ((str (copy-sequence "Hello"))) (let ((str (copy-sequence "Hello")))
(put-text-property 0 5 'face '(:foreground "red" :underline t) str) (tp-set 0 5 '(face (:foreground "red" :underline t)) str)
(tp-at 0 '(face :foreground) str)) (tp-at 0 '(face :foreground) str))
;; => "red" ;; => "red"
``` ```
@ -554,7 +554,7 @@ tp.el 所有函数按类别组织的完整概览:
;; 从 face 移除子属性 ;; 从 face 移除子属性
(with-temp-buffer (with-temp-buffer
(insert "Hello World") (insert "Hello World")
(put-text-property 1 10 'face '(:foreground "red" :underline t)) (tp-set 1 10 '(face (:foreground "red" :underline t)))
(tp-remove 1 10 '(face :underline)) (tp-remove 1 10 '(face :underline))
(tp-at 1 'face)) (tp-at 1 'face))
;; => (:foreground "red") ;; => (:foreground "red")
@ -562,7 +562,7 @@ tp.el 所有函数按类别组织的完整概览:
;; 移除特定嵌套键,保留其他 ;; 移除特定嵌套键,保留其他
(with-temp-buffer (with-temp-buffer
(insert "Hello World") (insert "Hello World")
(put-text-property 1 10 'face '(:underline (:style wave :position t :color "blue"))) (tp-set 1 10 '(face (:underline (:style wave :position t :color "blue"))))
(tp-remove 1 10 '(face :underline (:style :position))) (tp-remove 1 10 '(face :underline (:style :position)))
(tp-at 1 '(face :underline))) (tp-at 1 '(face :underline)))
;; => (:color "blue") ; :style 和 :position 被移除, :color 保留 ;; => (:color "blue") ; :style 和 :position 被移除, :color 保留
@ -575,14 +575,14 @@ tp.el 所有函数按类别组织的完整概览:
;; 从字符串移除子属性 ;; 从字符串移除子属性
(let ((str (copy-sequence "Hello World"))) (let ((str (copy-sequence "Hello World")))
(put-text-property 0 11 'face '(:foreground "red" :underline t) str) (tp-set 0 11 '(face (:foreground "red" :underline t)) str)
(tp-remove str 'face :underline) (tp-remove str 'face :underline)
(tp-at 0 'face str)) (tp-at 0 'face str))
;; => (:foreground "red") ;; => (:foreground "red")
;; 从字符串移除嵌套键 ;; 从字符串移除嵌套键
(let ((str (copy-sequence "Hello World"))) (let ((str (copy-sequence "Hello World")))
(put-text-property 0 11 'face '(:underline (:style wave :color "blue")) str) (tp-set 0 11 '(face (:underline (:style wave :color "blue"))) str)
(tp-remove str 'face :underline '(:style)) (tp-remove str 'face :underline '(:style))
(tp-at 0 '(face :underline) str)) (tp-at 0 '(face :underline) str))
;; => (:color "blue") ;; => (:color "blue")