el/dot-emacs.el: Don't select the designated window when displaying buffer.
[profile] / el / dot-emacs.el
index 9088736..fc219b2 100644 (file)
@@ -75,6 +75,13 @@ This may be at the expense of cool features.")
       (and (= emacs-major-version major)
           (>= emacs-minor-version (or minor 0)))))
 
+(defun mdw-submode-p (mode parent)
+  "Return non-nil if MODE is indirectly derived from PARENT."
+  (let ((answer nil))
+    (while (cond ((eq mode parent) (setq answer t) nil)
+                (t (setq mode (get mode 'derived-mode-parent)))))
+    answer))
+
 ;; Some error trapping.
 ;;
 ;; If individual bits of this file go tits-up, we don't particularly want
@@ -670,8 +677,8 @@ With a prefix argument, clear the designated window."
   "Display function to use the designated window."
   (prog1 mdw-designated-window
     (when mdw-designated-window
-      (select-window mdw-designated-window)
-      (switch-to-buffer buffer nil t))
+      (with-selected-window mdw-designated-window
+       (switch-to-buffer buffer nil t)))
     (setq mdw-designated-window nil)))
 
 (setq display-buffer-base-action
@@ -5189,14 +5196,20 @@ there is sadness."
 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)))
+                 (let ((mode (with-current-buffer buffer major-mode)))
+                   (if (and (not mdw-designated-window)
+                            (derived-mode-p 'magit-mode)
+                            (mdw-submode-p mode 'magit-mode)
+                            (not (memq mode mdw-magit-new-window-modes)))
+                       '(display-buffer-same-window . nil)
+                     nil))))
 (setq magit-display-buffer-function 'mdw-display-magit-buffer)
 
+(defun mdw-display-magit-file-buffer (buffer)
+  "Show a file buffer from a diff."
+  (select-window (display-buffer buffer)))
+(setq magit-display-file-buffer-function 'mdw-display-magit-file-buffer)
+
 ;;;--------------------------------------------------------------------------
 ;;; GUD, and especially GDB.