Subject: Re: bug#11810: 24.1.50; `vc-diff' shrinks pre-existing window

From: Dmitry Gutov <[email-masked]>
Date: Mon, 02 Jul 2012 17:33:03 +0400

On 02.07.2012 11:00, martin rudalics wrote:
>  >  From what I understand in `window-combination-resize' docstring, its
>  > value decides whether splitting a window borrows space only from
>  > adjacent window, or from all windows in a "combination" (so they all get
>  > resized). For that to happen, a window splitting should occur, right?
>  > But when we're displaying a buffer in pre-existing window, no splitting
>  > occurs, just resizing.
>  > And `even-window-heights' controls whether it should be resized at all.
>
> IIUC, the case we're talking about is that of a split frame where one
> window gets reused.  Now, with `window-combination-resize' non-nil,
> `display-buffer' practically always makes a new window in such a case
> because it can steal space from both existing windows.  Quitting or
> deleting the new window will restore the sizes of the original windows
> regardless of whether `temp-buffer-resize-mode' has been used or not.

I see. Still, I'm primarily interested in the scenario where the windows 
don't get split (with appropriate split-*-threshold values), and in this 
case `even-window-heights' value has effect.

Note that if the widow does get split, `vc-diff' behaves okay, because 
`q' deletes the used window, and the configuration becomes as it was (at 
least with `window-combination-resize' nil).

>  >> We could simply remove the `temp-buffer-resize-mode' check in
>  >> `quit-window'.  I hardly understand what implications this might have.
>  >
>  > I think it's just trying to making sure that (nth 3 quad) is of the
>  > right type, so that the comparison doesn't blow up.
>
> No (at least not as far as I originally conceived it).  My idea was as
> follows:
>
> (1) When `temp-buffer-resize-mode' is non-nil and the window size has
>      changed, chances are that the change was caused by
>      `temp-buffer-resize-mode' so it seems pretty safe to rescind that
>      change.

I don't think so. Like I said, the value saved in 'quit-restore 
parameter is the same in this case, whether `temp-buffer-resize-mode' is 
on or not.
So even if `temp-buffer-resize-mode' is on, we can't confidently decide 
that the value was set by it.

> (2) When `temp-buffer-resize-mode' is nil and the window size has
>      changed, the change was probably due to some manual intervention
>      probably needed to see more of a buffer originally present and it
>      seems better to leave that change alone.
>
> But maybe my conception was flawed.

Would it be harder to *not set* the 'quit-restore parameter in cases 
when we don't want the configuration restored, instead?

But as it is, I'm not sure what's the problem with always using its 
value when present. I've been running Emacs with the tiny patch I posted 
for a couple of days, and it seems fine.

Could you describe the scenario with "seeing more of a buffer originally 
present"?

>  > If I enable temp-buffer-resize-mode before doing vc-diff, after I quit
>  > the window, its size does get restored.
>
> It should be sufficient to set the variable `temp-buffer-resize-mode'
> locally in that buffer.

Yes, but that's not what I meant.

>  > Also, (nth 3 quad) is integer at that point even temp-buffer-resize-mode
>  > is disabled, so the mode check doesn't make sense.
>  > To be safe, though, we could replace it with `integerp' call.
>
> Yes, but the `condition-case' should handle any problems with it.

Don't we want to execute the code following (when resize ...) either way?

> In any case, we have to cater for the case where people (I'm not sure
> whether I got Andreas right) want to disable adjusting the window in the
> first place.  So I really think we should simply special-case this by
> providing some option like `vc-fit-diff-window-to-buffer' and adjust the
> window only if that variable has a non-nil value.  If it's non-nil, we
> can either

I'm fine with either behavior (not resizing or properly restoring), but 
`vc-diff' is not the only culprit. `vc-log-print' also does the 
shrinking, although it's harder to observe.
If there will be a variable, I don't see why it should be local to VC. 
Are there users who would want windows shrunk by VC, but not other 
packages, or vice versa?

> (1) set `temp-buffer-resize-mode' locally in such buffers, or
>
> (2) provide yet another variable which, when set, causes `quit-window'
>      to re-resize the window (we could misuse `even-window-heights' for
>      this purpose), or

That won't do if the original windows sizes were not even, like in the 
SO question linked to previously.

> (3) re-resize the window as in your patch.

-- Dmitry