chiark / gitweb /
el/dot-emacs.el: Override Magit buffer display logic.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 2 May 2022 11:55:47 +0000 (12:55 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 2 May 2022 11:58:07 +0000 (12:58 +0100)
It's actually nearly right, except that it wants to cover existing Magit
windows with commit log and that's a mistake.

Implement a new version of `magit-display-buffer-traditional' which (a)
uses a list of modes in a variable rather than hardcoding it, and (b)
honours a designated window if there is one.

el/dot-emacs.el

index c7849f32e41415df668d2714eb6c4bb8c7f019a0..09b77085f35fa99a6271ba3c2fb464b5b0abee26 100644 (file)
@@ -5166,6 +5166,29 @@ (defun mdw-try-smerge ()
       (smerge-mode 1))))
 (add-hook 'find-file-hook 'mdw-try-smerge t)
 
+(defcustom mdw-magit-new-window-modes
+  '(magit-diff-mode
+    magit-log-mode
+    magit-process-mode
+    magit-revision-mode
+    magit-stash-mode
+    magit-status-mode)
+  "Magit modes which should cause a new window to be used."
+  :type '(repeat symbol))
+
+(defun mdw-display-magit-buffer (buffer)
+  "Like `magit-display-buffer-traditional'.
+But uses `mdw-magit-new-window-modes' for its list of modes
+rather than baking the list into the function."
+  (display-buffer buffer
+                 (if (and (not mdw-designated-window)
+                          (derived-mode-p 'magit-mode)
+                          (not (memq (with-current-buffer buffer major-mode)
+                                     mdw-magit-new-window-modes)))
+                     '(display-buffer-same-window . nil)
+                   nil)))
+(setq magit-display-buffer-function 'mdw-display-magit-buffer)
+
 ;;;--------------------------------------------------------------------------
 ;;; GUD, and especially GDB.