Subject: 24.1.50; `vc-diff' shrinks pre-existing window

From: Dmitry Gutov <[email-masked]>
Date: Thu, 28 Jun 2012 23:22:55 +0400

Steps to reproduce:

1) Have a frame with such width and height that when there are 4 equal
windows inside it, a `pop-to-window' invocation reuses an existing
window.

2) Start with just 1 window, do C-x 3, then C-x 2 in both resulting
windows.

3) Open a VC-backed file in one of the windows, make a tiny change,
save, do `vc-diff'. Diff will open in one of the existing windows, and
it will be shrunk to the height of the buffer.

4) Quit the diff buffer with `q'. See that the window height stays
shrunk.

In a similar scenario, open a file from a repository with tiny history
(1 commit or so), do `vc-print-log', observe the same behavior.
Thankfully, this is a much more rare occurrence.

Simple patch attached.

Commands messing up existing window configuration is one of my top
Emacs annoyances, and AFAIK it confuses the new users, too.
Maybe nil check for (window-prev-buffers) should be instead included in
`shrink-window-if-larger-than-buffer', with a way to override it?
>From e1f5971c81fabac74280f798802b7958a44db08c Mon Sep 17 00:00:00 2001
From: Dmitry Gutov <[email-masked]>
Date: Thu, 28 Jun 2012 23:18:41 +0400
Subject: [PATCH] * vc.el (vc-diff-finish, vc-log-internal-common): Never
 shrink   pre-existing windows

---
 lisp/vc/vc.el |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 87e4e1c..697b212 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1531,7 +1531,7 @@ to override the value of `vc-diff-switches' and `diff-switches'."
 	       (message "%s" (cdr messages))))
 	(diff-setup-whitespace)
 	(goto-char (point-min))
-	(when window
+	(when (and window (not (window-prev-buffers)))
 	  (shrink-window-if-larger-than-buffer window)))
       (when (and messages (not emptyp))
 	(message "%sdone" (car messages))))))
@@ -2147,7 +2147,8 @@ Not all VC backends support short logs!")
     (vc-exec-after
      `(let ((inhibit-read-only t))
 	(funcall ',setup-buttons-func ',backend ',files ',retval)
-	(shrink-window-if-larger-than-buffer)
+	(unless (window-prev-buffers)
+	  (shrink-window-if-larger-than-buffer))
 	(funcall ',goto-location-func ',backend)
 	(setq vc-sentinel-movepoint (point))
 	(set-buffer-modified-p nil)))))
-- 
1.7.10.msysgit.1