Refactor: Extract duplicated lambda into named function with documentation
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
parent
08e7dfc728
commit
b2ac7eac15
22
tp.el
22
tp.el
@ -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
|
||||||
|
;; Callback for tp-search-map: applies props to matched region.
|
||||||
|
;; _TEXT is unused (the matched text), START and END are buffer positions.
|
||||||
|
;; Returns nil to prevent tp-search-map from replacing the text.
|
||||||
|
(let ((apply-props-fn (lambda (_text start end)
|
||||||
|
(tp-add start end props)
|
||||||
|
nil)))
|
||||||
(if (and where (bufferp where) (buffer-live-p where))
|
(if (and where (bufferp where) (buffer-live-p where))
|
||||||
;; setq-local case: only update the specific buffer
|
;; setq-local case: only update the specific buffer
|
||||||
(with-current-buffer where
|
(with-current-buffer where
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(tp-search-map
|
(tp-search-map apply-props-fn 'tp-name layer-name)))
|
||||||
(lambda (_text start end)
|
|
||||||
(tp-add start end props)
|
|
||||||
nil)
|
|
||||||
'tp-name layer-name)))
|
|
||||||
;; setq case: update all buffers that have the text property
|
;; setq case: update all buffers that have the text property
|
||||||
(dolist (buf (buffer-list))
|
(dolist (buf (buffer-list))
|
||||||
(when (buffer-live-p buf)
|
(when (buffer-live-p buf)
|
||||||
(with-current-buffer 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)
|
|
||||||
;; Apply the new properties directly to the buffer region
|
|
||||||
(tp-add start end props)
|
|
||||||
;; Return nil to skip text replacement
|
|
||||||
nil)
|
|
||||||
'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."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user