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

From: martin rudalics <[email-masked]>
Date: Tue, 05 May 2009 09:04:53 +0200

>> `dired-pop-to-buffer' could bind `split-window-preferred-function' to a
  >> function that tries to always split the selected window instead of
  >> whatever window was chosen by `display-buffer' but that would override
  >> any user customizations of `split-window-preferred-function'.
  >
  > Why would it override it?  It would of course bind
  > split-window-preferred-function to a function that selects the right
  > window and then calls the previous value.

As a matter of fact, we do have to override the users' customizations
here just as Juri suggested earlier.  Suppose a user has set
`split-window-preferred-function' to the standard option "horizontally"
which always splits a window horizontally.  Then `dired-pop-to-buffer'
simply cannot get a vertical split when it calls the original
`split-window-preferred-function'.  So we probably have to do this as in
the attached patch :-(

martin

*** dired.el.~1.422.~	2009-04-18 08:32:56.546875000 +0200
--- dired.el	2009-05-05 09:00:38.609375000 +0200
***************
*** 2686,2693 ****
  
  (defun dired-pop-to-buffer (buf)
    "Pop up buffer BUF in a way suitable for Dired."
!   ;; Don't split window horizontally.  (Bug#1806)
!   (let (split-width-threshold)
      (pop-to-buffer (get-buffer-create buf)))
    ;; If dired-shrink-to-fit is t, make its window fit its contents.
    (when dired-shrink-to-fit
--- 2686,2697 ----
  
  (defun dired-pop-to-buffer (buf)
    "Pop up buffer BUF in a way suitable for Dired."
!   (let ((split-window-preferred-function
! 	 (lambda (window)
! 	   ;; Split window vertically and deliberately ignore the WINDOW
! 	   ;; argument of `split-window-preferred-function' so the
! 	   ;; selected window gets split instead (Bug#1806).
! 	   (split-window-vertically))))
      (pop-to-buffer (get-buffer-create buf)))
    ;; If dired-shrink-to-fit is t, make its window fit its contents.
    (when dired-shrink-to-fit