branch: elpa/magit
commit f199399d2fe8bda40f096d966fe7d03ab96ee00b
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    magit-refresh-buffer: Spin out magit--refresh-buffer-{get,set}-positions
---
 lisp/magit-mode.el | 51 +++++++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index d8e00d055f..0735aef00d 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1078,22 +1078,7 @@ Run hooks `magit-pre-refresh-hook' and 
`magit-post-refresh-hook'."
     (when (functionp refresh)
       (when magit-refresh-verbose
         (message "Refreshing buffer `%s'..." (buffer-name)))
-      (let* ((buffer (current-buffer))
-             (windows (mapcan
-                       (lambda (window)
-                         (with-selected-window window
-                           (with-current-buffer buffer
-                             (and-let* ((section (magit-section-at)))
-                               `(( ,window
-                                   ,section
-                                   ,@(magit-section-get-relative-position
-                                      section)))))))
-                       ;; If it qualifies, then the selected window
-                       ;; comes first, but we want to handle it last
-                       ;; so that its `magit-section-movement-hook'
-                       ;; run can override the effects of other runs.
-                       (or (nreverse (get-buffer-window-list buffer nil t))
-                           (list (selected-window))))))
+      (let ((positions (magit--refresh-buffer-get-positions)))
         (deactivate-mark)
         (setq magit-section-pre-command-section nil)
         (setq magit-section-highlight-overlays nil)
@@ -1104,13 +1089,7 @@ Run hooks `magit-pre-refresh-hook' and 
`magit-post-refresh-hook'."
           (erase-buffer)
           (save-excursion
             (funcall refresh)))
-        (pcase-dolist (`(,window . ,args) windows)
-          (if (eq buffer (window-buffer window))
-              (with-selected-window window
-                (apply #'magit-section-goto-successor args))
-            (with-current-buffer buffer
-              (let ((magit-section-movement-hook nil))
-                (apply #'magit-section-goto-successor args)))))
+        (magit--refresh-buffer-set-positions positions)
         (when created
           (run-hooks 'magit--initial-section-hook)
           (setq-local magit--initial-section-hook nil))
@@ -1119,11 +1098,35 @@ Run hooks `magit-pre-refresh-hook' and 
`magit-post-refresh-hook'."
         (run-hooks 'magit-refresh-buffer-hook)
         (magit-section-update-highlight)
         (set-buffer-modified-p nil)
-        (push buffer magit-section--refreshed-buffers))
+        (push (current-buffer) magit-section--refreshed-buffers))
       (when magit-refresh-verbose
         (message "Refreshing buffer `%s'...done (%.3fs)" (buffer-name)
                  (float-time (time-since magit--refresh-start-time)))))))
 
+(defun magit--refresh-buffer-get-positions ()
+  (let ((buffer (current-buffer)))
+    (mapcan (lambda (window)
+              (with-selected-window window
+                (with-current-buffer buffer
+                  (and-let* ((section (magit-section-at)))
+                    `((,window
+                       ,section
+                       ,@(magit-section-get-relative-position section)))))))
+            ;; If it qualifies, then the selected window
+            ;; comes first, but we want to handle it last
+            ;; so that its `magit-section-movement-hook'
+            ;; run can override the effects of other runs.
+            (or (nreverse (get-buffer-window-list buffer nil t))
+                (list (selected-window))))))
+
+(defun magit--refresh-buffer-set-positions (positions)
+  (pcase-dolist (`(,window . ,args) positions)
+    (if (eq (current-buffer) (window-buffer window))
+        (with-selected-window window
+          (apply #'magit-section-goto-successor args))
+      (let ((magit-section-movement-hook nil))
+        (apply #'magit-section-goto-successor args)))))
+
 (defun magit-revert-buffer (_ignore-auto _noconfirm)
   "Wrapper around `magit-refresh-buffer' suitable as `revert-buffer-function'."
   (magit-refresh-buffer))

Reply via email to