From b2ac7eac158ebdc092ec5f499089a4c7739aa1b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 13:06:50 +0000 Subject: [PATCH] Refactor: Extract duplicated lambda into named function with documentation Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com> --- tp.el | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/tp.el b/tp.el index 9c0bf76..3841768 100644 --- a/tp.el +++ b/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)." (let ((props (tp-layer-props layer-name))) (when props - (if (and where (bufferp where) (buffer-live-p where)) - ;; setq-local case: only update the specific buffer - (with-current-buffer where - (save-excursion - (tp-search-map - (lambda (_text start end) - (tp-add start end props) - nil) - 'tp-name layer-name))) - ;; 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 + ;; 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)) + ;; setq-local case: only update the specific buffer + (with-current-buffer where (save-excursion - (tp-search-map - (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))))))))) + (tp-search-map apply-props-fn 'tp-name layer-name))) + ;; setq case: update all buffers that have the text property + (dolist (buf (buffer-list)) + (when (buffer-live-p buf) + (with-current-buffer buf + (save-excursion + (tp-search-map apply-props-fn 'tp-name layer-name)))))))))) (defun tp-reactive-reset () "Reset all reactive text property watchers and dependencies."