improve code

This commit is contained in:
Kinneyzhang 2025-12-28 17:51:13 +08:00
parent af5ba6b214
commit e52a9e8cd8

8
tp.el
View File

@ -528,8 +528,9 @@ the new end position after any text replacement."
(let ((tp-text-val (plist-get props 'tp-text))) (let ((tp-text-val (plist-get props 'tp-text)))
(cond (cond
;; tp-text is nil - initialize it to the current text ;; tp-text is nil - initialize it to the current text
((null tp-text-val) ((not (null tp-text-val))
(let ((current-text (if (stringp object) (let ((current-text
(if (stringp object)
(substring object start end) (substring object start end)
(if object (if object
(with-current-buffer object (with-current-buffer object
@ -569,7 +570,8 @@ the new end position after any text replacement."
(let ((new-end (+ start (length tp-text-val)))) (let ((new-end (+ start (length tp-text-val))))
;; Re-apply existing properties to new text region if preserving ;; Re-apply existing properties to new text region if preserving
(when existing-props (when existing-props
(cl-loop for (key val) on existing-props by #'cddr (cl-loop
for (key val) on existing-props by #'cddr
do (put-text-property start new-end key val object))) do (put-text-property start new-end key val object)))
(list props new-end))))))) (list props new-end)))))))
;; Other types - return unchanged ;; Other types - return unchanged