Subject: bug#20206: 25.0.50; [PATCH] keep diff-mode's window visible when we visit sources from diff-mode

From: Dima Kogan <[email-masked]>
Date: Thu, 26 Mar 2015 11:25:27 -0700

When looking at a patch in diff-mode, one can visit the sources being
patched with several functions, for instance (diff-goto-source). This
patch makes sure that the source buffer does not cover up the diff-mode
buffer in its window, but uses any other window instead.

This really is a continuation of bug 20034 (and 17675 and 19901). I feel
like the earlier display-buffer implementation had a nicer default in
this regard. Should we keep adding this patch wherever a user operation
on a buffer can cause a different buffer to be displayed, or should
display-buffer defaults be changed to make the "don't steal user's
focus" behavior the default?

>From fa88533777a500784cb5def1733aa182c6bd4135 Mon Sep 17 00:00:00 2001
From: Dima Kogan <[email-masked]>
Date: Thu, 26 Mar 2015 11:21:06 -0700
Subject: [PATCH] keep diff-mode's window visible when we visit sources from
 diff-mode

When looking at a patch in diff-mode, one can visit the sources being
patched with several functions, for instance (diff-goto-source).  This
patch makes sure that the source buffer does not cover up the
diff-mode buffer in its window, but uses any other window instead
---
 lisp/vc/diff-mode.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index a9614e9..15cdae9 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -1318,7 +1318,7 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
   ;; Select a window that displays the current buffer so that point
   ;; movements are reflected in that window.  Otherwise, the user might
   ;; never see the hunk corresponding to the source she's jumping to.
-  (pop-to-buffer (current-buffer))
+  (pop-to-buffer (current-buffer) '(display-buffer-use-some-window (inhibit-same-window . t)))
   (if reset (goto-char (point-min)))
   (diff-hunk-next arg)
   (diff-goto-source))
@@ -1801,7 +1801,7 @@ With a prefix argument, REVERSE the hunk."
 	(delete-region (car pos) (cdr pos))
 	(insert (car new)))
       ;; Display BUF in a window
-      (set-window-point (display-buffer buf) (+ (car pos) (cdr new)))
+      (set-window-point (display-buffer buf '(display-buffer-use-some-window (inhibit-same-window . t))) (+ (car pos) (cdr new)))
       (diff-hunk-status-msg line-offset (diff-xor switched reverse) nil)
       (when diff-advance-after-apply-hunk
 	(diff-hunk-next))))))
@@ -1813,7 +1813,7 @@ With a prefix argument, try to REVERSE the hunk."
   (interactive "P")
   (pcase-let ((`(,buf ,line-offset ,pos ,src ,_dst ,switched)
                (diff-find-source-location nil reverse)))
-    (set-window-point (display-buffer buf) (+ (car pos) (cdr src)))
+    (set-window-point (display-buffer buf '(display-buffer-use-some-window (inhibit-same-window . t))) (+ (car pos) (cdr src)))
     (diff-hunk-status-msg line-offset (diff-xor reverse switched) t)))

@@ -1843,7 +1843,7 @@ then `diff-jump-to-old-file' is also set, for the next invocations."
   (let ((rev (not (save-excursion (beginning-of-line) (looking-at "[-<]")))))
     (pcase-let ((`(,buf ,line-offset ,pos ,src ,_dst ,switched)
                  (diff-find-source-location other-file rev)))
-      (pop-to-buffer buf)
+      (pop-to-buffer buf '(display-buffer-use-some-window (inhibit-same-window . t)))
       (goto-char (+ (car pos) (cdr src)))
       (diff-hunk-status-msg line-offset (diff-xor rev switched) t))))
 
-- 
2.1.4