diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2025-05-18 08:53:35 +0200 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2025-05-18 08:53:35 +0200 |
| commit | 5469cbcf40fa542adbb9e9ca5b529a06d62cc607 (patch) | |
| tree | 98fdbdbce8bd61c2b01662c4908ecbb49a9ac701 /lisp | |
| parent | d1ac84ab23b639ff84eb7f7d02d45066cb6f77ba (diff) | |
Call magit-status-goto-initial-section before highlighting
`magit-post-create-buffer-hook' is called right after
`magit-refresh-buffer' returned, i.e., after that called
`magit-section-update-highlight'.
Move `magit-status-goto-initial-section' from that hook to the new
`magit--initial-section-hook', which `magit-refresh-buffer' calls,
but only when the buffer is being created, not merely refreshed.
This avoids highlighting the wrong section before highlighting the
correct one.
Using such a hook is a bit of a hack. It might be better to instead
add an option that maps modes to initial sections, instead of a hook,
but let's not commit to that just yet.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/magit-mode.el | 9 | ||||
| -rw-r--r-- | lisp/magit-status.el | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el index 56eb758..0ddfc10 100644 --- a/lisp/magit-mode.el +++ b/lisp/magit-mode.el @@ -662,7 +662,7 @@ The buffer's major-mode should derive from `magit-section-mode'." (magit-display-buffer buffer) (with-current-buffer buffer (run-hooks 'magit-setup-buffer-hook) - (magit-refresh-buffer) + (magit-refresh-buffer created) (when created (run-hooks 'magit-post-create-buffer-hook))) buffer)) @@ -1065,7 +1065,9 @@ Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'." (defvar-local magit--refresh-start-time nil) -(defun magit-refresh-buffer () +(defvar magit--initial-section-hook nil) + +(defun magit-refresh-buffer (&optional created) "Refresh the current Magit buffer." (interactive) (let ((magit--refresh-start-time (current-time)) @@ -1108,6 +1110,9 @@ Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'." (with-current-buffer buffer (let ((magit-section-movement-hook nil)) (apply #'magit-section-goto-successor args))))) + (when created + (run-hooks 'magit--initial-section-hook) + (setq-local magit--initial-section-hook nil)) (let ((magit-section-cache-visibility nil)) (magit-section-show magit-root-section)) (run-hooks 'magit-refresh-buffer-hook) diff --git a/lisp/magit-status.el b/lisp/magit-status.el index ff8d458..970d727 100644 --- a/lisp/magit-status.el +++ b/lisp/magit-status.el @@ -434,7 +434,7 @@ Type \\[magit-commit] to create a commit. :group 'magit-status (magit-hack-dir-local-variables) (when magit-status-initial-section - (add-hook 'magit-post-create-buffer-hook + (add-hook 'magit--initial-section-hook #'magit-status-goto-initial-section nil t)) (setq magit--imenu-group-types '(not branch commit))) |
