improve code

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

20
tp.el
View File

@ -528,13 +528,14 @@ 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
(substring object start end) (if (stringp object)
(if object (substring object start end)
(with-current-buffer object (if object
(buffer-substring-no-properties start end)) (with-current-buffer object
(buffer-substring-no-properties start end))))) (buffer-substring-no-properties start end))
(buffer-substring-no-properties start end)))))
(list (plist-put props 'tp-text current-text) end))) (list (plist-put props 'tp-text current-text) end)))
;; tp-text has a string value - replace the text in the region ;; tp-text has a string value - replace the text in the region
((stringp tp-text-val) ((stringp tp-text-val)
@ -569,8 +570,9 @@ 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
do (put-text-property start new-end key val object))) for (key val) on existing-props by #'cddr
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
(t (list props end)))))) (t (list props end))))))