How to change behaviour of magit buffer view function in Doom emacs?

27 views Asked by At

Doom emacs is using +magit--display-buffer-in-direction function to view commit. Function given below:

(defun +magit--display-buffer-in-direction (buffer alist)
  "`display-buffer-alist' handler that opens BUFFER in a direction.

This differs from `display-buffer-in-direction' in one way: it will try to use a
window that already exists in that direction. It will split otherwise."
  (let ((direction (or (alist-get 'direction alist)
                       +magit-open-windows-in-direction))
        (origin-window (selected-window)))
    (if-let (window (window-in-direction direction))
        (unless magit-display-buffer-noselect
          (select-window window))
      (if-let (window (and (not (one-window-p))
                           (window-in-direction
                            (pcase direction
                              (`right 'left)
                              (`left 'right)
                              ((or `up `above) 'down)
                              ((or `down `below) 'up)))))
        (unless magit-display-buffer-noselect
          (select-window window))
        (let ((window (split-window nil nil direction)))
          (when (and (not magit-display-buffer-noselect)
                     (memq direction '(right down below)))
            (select-window window))
          (display-buffer-record-window 'reuse window buffer)
          (set-window-buffer window buffer)
          (set-window-parameter window 'quit-restore (list 'window 'window origin-window buffer))
          (set-window-prev-buffers window nil))))
    (unless magit-display-buffer-noselect
      (switch-to-buffer buffer t t)
      (selected-window))))

My issue arises when there's another window specified in the direction set by +magit-open-windows-in-direction. This command takes the buffer in that direction, displays the commit inside it, and shifts focus to the new window. However, upon exiting from the commit, focus doesn't return to the previous window. This leads to significant friction when quickly navigating through multiple commits.

Since I am not experienced on elisp, I tried to update kill-buffer-hook only for magit-mode or tried to find a way to navigate between commits in commit views. However, none of them worked.

My current work around it is just to comment out magit-revision-mode line inside the +magit-display-buffer-fn function, so that it uses current buffer to view the commit.

Is there anyway solution or suggestion?

Kind Regards,

0

There are 0 answers