Refactor: simplify tp--string-has-properties-p and extract helper
- Remove unnecessary length check in tp--string-has-properties-p since object-intervals handles empty strings correctly - Extract tp--remove-internal-markers helper to reduce code duplication across tp-set, tp-reset, and tp-add functions Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
parent
ebe0922c9c
commit
6f61f5a457
20
tp.el
20
tp.el
@ -256,7 +256,6 @@ NEW values override BASE values."
|
|||||||
"Return non-nil if string STR has any text properties.
|
"Return non-nil if string STR has any text properties.
|
||||||
Scans the entire string, not just position 0."
|
Scans the entire string, not just position 0."
|
||||||
(and (stringp str)
|
(and (stringp str)
|
||||||
(> (length str) 0)
|
|
||||||
(not (null (object-intervals str)))))
|
(not (null (object-intervals str)))))
|
||||||
|
|
||||||
(defun tp--apply-string-props-to-region (str start &optional object)
|
(defun tp--apply-string-props-to-region (str start &optional object)
|
||||||
@ -276,6 +275,13 @@ This preserves the per-character text property variations in STR."
|
|||||||
key val object)))
|
key val object)))
|
||||||
(setq pos next-change)))))
|
(setq pos next-change)))))
|
||||||
|
|
||||||
|
(defun tp--remove-internal-markers (props)
|
||||||
|
"Remove internal marker properties from PROPS plist.
|
||||||
|
Returns a new plist with tp--text-has-props removed."
|
||||||
|
(cl-loop for (key val) on props by #'cddr
|
||||||
|
unless (eq key 'tp--text-has-props)
|
||||||
|
append (list key val)))
|
||||||
|
|
||||||
(defun tp--merge-face-values (face1 face2)
|
(defun tp--merge-face-values (face1 face2)
|
||||||
"Merge two face values into one.
|
"Merge two face values into one.
|
||||||
FACE1 is the earlier value, FACE2 is the later value.
|
FACE1 is the earlier value, FACE2 is the later value.
|
||||||
@ -1162,9 +1168,7 @@ Returns modified string or (START . END) cons for buffer."
|
|||||||
(let ((tp-text-has-props (plist-get props 'tp--text-has-props)))
|
(let ((tp-text-has-props (plist-get props 'tp--text-has-props)))
|
||||||
;; Remove the internal marker from props before applying
|
;; Remove the internal marker from props before applying
|
||||||
(when tp-text-has-props
|
(when tp-text-has-props
|
||||||
(setq props (cl-loop for (key val) on props by #'cddr
|
(setq props (tp--remove-internal-markers props)))
|
||||||
unless (eq key 'tp--text-has-props)
|
|
||||||
append (list key val))))
|
|
||||||
;; Check if we have any existing properties in the range
|
;; Check if we have any existing properties in the range
|
||||||
(let ((has-existing-props (or tp-text-has-props
|
(let ((has-existing-props (or tp-text-has-props
|
||||||
(text-properties-at start object))))
|
(text-properties-at start object))))
|
||||||
@ -1196,9 +1200,7 @@ Returns modified string or (START . END) cons for buffer."
|
|||||||
(let ((tp-text-has-props (plist-get props 'tp--text-has-props)))
|
(let ((tp-text-has-props (plist-get props 'tp--text-has-props)))
|
||||||
;; Remove the internal marker from props before applying
|
;; Remove the internal marker from props before applying
|
||||||
(when tp-text-has-props
|
(when tp-text-has-props
|
||||||
(setq props (cl-loop for (key val) on props by #'cddr
|
(setq props (tp--remove-internal-markers props)))
|
||||||
unless (eq key 'tp--text-has-props)
|
|
||||||
append (list key val))))
|
|
||||||
;; If tp-text has embedded props, apply props with put-text-property
|
;; If tp-text has embedded props, apply props with put-text-property
|
||||||
;; to preserve the embedded properties. Otherwise replace all.
|
;; to preserve the embedded properties. Otherwise replace all.
|
||||||
(if tp-text-has-props
|
(if tp-text-has-props
|
||||||
@ -1274,9 +1276,7 @@ Returns modified string or (START . END) cons for buffer."
|
|||||||
(setq start 0)))
|
(setq start 0)))
|
||||||
;; Remove the internal tp--text-has-props marker from props before applying
|
;; Remove the internal tp--text-has-props marker from props before applying
|
||||||
(when (plist-get props 'tp--text-has-props)
|
(when (plist-get props 'tp--text-has-props)
|
||||||
(setq props (cl-loop for (key val) on props by #'cddr
|
(setq props (tp--remove-internal-markers props)))
|
||||||
unless (eq key 'tp--text-has-props)
|
|
||||||
append (list key val))))
|
|
||||||
;; Process each property with deep merging
|
;; Process each property with deep merging
|
||||||
(let ((pos start))
|
(let ((pos start))
|
||||||
(while (< pos finish)
|
(while (< pos finish)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user