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

From: Juri Linkov <[email-masked]>
Date: Sun, 03 May 2009 14:46:15 +0300

>> Wrong
>>
>> Wrong
>
> Kto-to majskij prazdnik otmechajet ;-)
>
> BTW, here we call a bridge day "Fenstertag" (window day) and since we
> didn't have any bridge day this week it _was_ the wrong day of the wrong
> week indeed ...

:-)

> I don't have any problems hard-coding `split-window-vertically' in
> `dired-pop-to-buffer' but:
>
> (1) `split-window-sensibly' with `split-width-threshold' nil _should_ do
>     `split-window-vertically' in the first place.  If it doesn't, I have
>     a bug somewhere and must fix that.
>
> (2) Someone might want `split-window-sensibly' do something special for
>     dired buffers.
>
> So please try to debug this and tell me why it doesn't split the window
> vertically with a dired-window-only-frame configuration in the first
> attempt.  It DTRT here for me.

I tried to debug this.  With your latest patch it works correctly
with a dired-window-only-frame configuration, but fails when
there are two horizontally split side-by-side windows with a dired
buffer in one of them.  It displays a list of dired files at the top
of another side window.

split-window-sensibly has three `or' branches:

1. Split window vertically.

   In my case this branch is not selected because my window-height (79)
   is less than split-height-threshold (80).

2. Split window horizontally.

   This branch is not selected since dired-pop-to-buffer sets
   split-width-threshold to nil (this is ok).

3. If the selected window is the only window on its frame and is
   not the minibuffer window, try to split it vertically.

   This branch is not selected since the dired buffer's window is
   not the only window on its frame.

So display-buffer displays a list of dired files in the existing
side window.

I see one way to fix this - it is necessary to force
the first branch to be selected.  It works when I tried
the following lambda in dired-pop-to-buffer:

    (lambda ()
      (let ((split-height-threshold 0)
            (split-width-threshold nil))
        (with-selected-window old-window (funcall old-fun))))

Setting split-height-threshold to 0 forces the vertical splitting.
Setting split-width-threshold to nil prevents the horizontal splitting
when the vertical splitting is not possible (the window is not splittable).

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