branch: elpa/git-commit commit 632536ca9c2c7d5d9fe2a90ac102bee3817622a9 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
Add magit-status-goto-initial-section to magit-create-buffer-hook This helps avoid circular dependencies. --- lisp/magit-mode.el | 4 ---- lisp/magit-status.el | 19 +++++-------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el index 4b59e291b8..fc34e300c7 100644 --- a/lisp/magit-mode.el +++ b/lisp/magit-mode.el @@ -43,8 +43,6 @@ (declare-function magit-process-unset-mode-line-error-status "magit-process" ()) ;; For `magit-refresh-get-relative-position' (declare-function magit-hunk-section-p "magit-diff" (section) t) -;; For `magit-mode-setup-internal' -(declare-function magit-status-goto-initial-section "magit-status" ()) ;; For `magit-mode' (defvar bookmark-make-record-function) (declare-function magit--make-bookmark "magit-bookmark" ()) @@ -627,7 +625,6 @@ your mode instead of adding an entry to this variable.") (pcase-dolist (`(,var ,val) bindings) (set (make-local-variable var) val)) (when created - (magit-status-goto-initial-section) (run-hooks 'magit-create-buffer-hook))) (magit-display-buffer buffer) (with-current-buffer buffer @@ -665,7 +662,6 @@ locked to its value, which is derived from MODE and ARGS." (funcall mode) (magit-xref-setup 'magit-mode-setup-internal args) (when created - (magit-status-goto-initial-section) (run-hooks 'magit-create-buffer-hook))) (magit-display-buffer buffer) (with-current-buffer buffer diff --git a/lisp/magit-status.el b/lisp/magit-status.el index e928e7c3d5..53a4f17d49 100644 --- a/lisp/magit-status.el +++ b/lisp/magit-status.el @@ -403,6 +403,9 @@ Type \\[magit-commit] to create a commit. \\{magit-status-mode-map}" :group 'magit-status (hack-dir-local-variables-non-file-buffer) + (when magit-status-initial-section + (add-hook 'magit-refresh-buffer-hook + #'magit-status-goto-initial-section nil t)) (setq magit--imenu-group-types '(not branch commit))) (put 'magit-status-mode 'magit-diff-default-arguments @@ -449,19 +452,7 @@ Type \\[magit-commit] to create a commit. (magit-run-section-hook 'magit-status-sections-hook))) (defun magit-status-goto-initial-section () - "In a `magit-status-mode' buffer, jump `magit-status-initial-section'. -Actually doing so is deferred until `magit-refresh-buffer-hook' -runs `magit-status-goto-initial-section-1'. That function then -removes itself from the hook, so that this only happens when the -status buffer is first created." - (when (and magit-status-initial-section - (derived-mode-p 'magit-status-mode)) - (add-hook 'magit-refresh-buffer-hook - #'magit-status-goto-initial-section-1 nil t))) - -(defun magit-status-goto-initial-section-1 () - "In a `magit-status-mode' buffer, jump `magit-status-initial-section'. -This function removes itself from `magit-refresh-buffer-hook'." + "Jump to the section specified by `magit-status-initial-section'." (when-let ((section (--some (if (integerp it) (nth (1- it) @@ -476,7 +467,7 @@ This function removes itself from `magit-refresh-buffer-hook'." (magit-section-hide section) (magit-section-show section)))) (remove-hook 'magit-refresh-buffer-hook - #'magit-status-goto-initial-section-1 t)) + #'magit-status-goto-initial-section t)) (defun magit-status-maybe-update-revision-buffer (&optional _) "When moving in the status buffer, update the revision buffer.