Refactor: Extract duplicated lambda into named function with documentation

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-20 13:06:50 +00:00
parent 08e7dfc728
commit b2ac7eac15

38
tp.el
View File

@ -415,29 +415,23 @@ WHERE specifies which buffers to update:
- If WHERE is nil, update all buffers that have the text property (setq case)." - If WHERE is nil, update all buffers that have the text property (setq case)."
(let ((props (tp-layer-props layer-name))) (let ((props (tp-layer-props layer-name)))
(when props (when props
(if (and where (bufferp where) (buffer-live-p where)) ;; Callback for tp-search-map: applies props to matched region.
;; setq-local case: only update the specific buffer ;; _TEXT is unused (the matched text), START and END are buffer positions.
(with-current-buffer where ;; Returns nil to prevent tp-search-map from replacing the text.
(save-excursion (let ((apply-props-fn (lambda (_text start end)
(tp-search-map (tp-add start end props)
(lambda (_text start end) nil)))
(tp-add start end props) (if (and where (bufferp where) (buffer-live-p where))
nil) ;; setq-local case: only update the specific buffer
'tp-name layer-name))) (with-current-buffer where
;; setq case: update all buffers that have the text property
(dolist (buf (buffer-list))
(when (buffer-live-p buf)
(with-current-buffer buf
;; Use tp-search-map to find all regions with this layer
;; The callback uses start and end to set properties directly
(save-excursion (save-excursion
(tp-search-map (tp-search-map apply-props-fn 'tp-name layer-name)))
(lambda (_text start end) ;; setq case: update all buffers that have the text property
;; Apply the new properties directly to the buffer region (dolist (buf (buffer-list))
(tp-add start end props) (when (buffer-live-p buf)
;; Return nil to skip text replacement (with-current-buffer buf
nil) (save-excursion
'tp-name layer-name))))))))) (tp-search-map apply-props-fn 'tp-name layer-name))))))))))
(defun tp-reactive-reset () (defun tp-reactive-reset ()
"Reset all reactive text property watchers and dependencies." "Reset all reactive text property watchers and dependencies."