Subject: bug#1806: dired-pop-to-buffer in wrong place

From: Juri Linkov <[email-masked]>
Date: Wed, 07 Jan 2009 19:47:59 +0200

> Usually this worked correctly due to the fact that directory buffers
> were sufficiently high.  But for `pop-up-frames' non-nil addicts this
> was not necessarily the right behavior.
>
> Anyway, I suppose you mean something like
>
> (defun dired-pop-to-buffer (buf)
>   (let* ((split-height-threshold 8)
> 	 split-width-threshold
> 	 (buffer (get-buffer-create buf))
> 	 (window (window--try-to-split-window (selected-window))))
>     (if window
> 	(progn
> 	  (select-window window)
> 	  (set-window-buffer window buffer))
>       (pop-to-buffer buffer))
>     (when dired-shrink-to-fit
>       (fit-window-to-buffer nil nil 1))))

Thank you, this works almost ideally.  The only problem I've encountered
is that sometimes it resizes existing windows:

    +------------+------------+        +------------+------------+
    |            |            |        |            |            |
    |            |            |        |            |            |
    |   dired    |   other2   |        |   dired    |   other2   |
    |            |            |        |            |            |
    |            |            |        +------------+            |
    |            |            |        | file list  |            |
    |            |            |  ===>  +------------+            |
    +------------+            |        |            |            |
    |            |            |        |            |            |
    |   other1   |            |        |   other1   |            |
    |            |            |        |            |            |
    |            |            |        |            |            |
    +------------+------------+        +------------+------------+

Please notice how the upper border of the lower window (other1)
was moved up.  I think it should keep the existing configuration
and create a new window at the cost of space from the original
dired buffer like this:

    +------------+------------+        +------------+------------+
    |            |            |        |            |            |
    |            |            |        |            |            |
    |   dired    |   other    |        |   dired    |   other    |
    |            |            |        |            |            |
    |            |            |        |            |            |
    |            |            |        +------------+            |
    |            |            |        | file list  |            |
    +------------+            |  ===>  +------------+            |
    |            |            |        |            |            |
    |   other    |            |        |   other    |            |
    |            |            |        |            |            |
    |            |            |        |            |            |
    +------------+------------+        +------------+------------+

As I can see currently `fit-window-to-buffer' always takes space
from the bottom window, but we need it from the top window.

>> Please see the code in calendar.el that creates such standard layout
>> for non-wide-screen configurations (i.e. when there is no right window).
>> I think we should keep exactly the same logic for wide-screen configurations,
>> i.e. treating the creation of such small low windows as if there is no
>> existing side window.
>
> Would the above code handle that?

I believe it would handle these cases.  Maybe it is possible to create
a single function e.g. `pop-to-buffer-below' that will display a new window
below from the current window taking its space.

-- 
Juri Linkov
http://www.jurta.org/emacs/