Subject: Re: dired-pop-to-buffer in wrong place

From: Juri Linkov <[email-masked]>
Date: Wed, 26 Sep 2012 09:24:00 +0300

> Just that splitting the root will resize all windows proportionally and
> I just have another thread were people don't like that (recall that you
> want to do that for a large number of files).

Yes, there are more problems with `display-buffer-at-bottom' that could
be fixed later.  This is why I don't propose to make it default now.
But still we should fix the problems with the current default action
`display-buffer-below-selected' because they are regressions.

>> Then a new function with a name like `with-temp-buffer-window-pop-up'
>> might be necessary to use it in Dired, Proced, VC
>
> VC currently doesn't use `temp-buffer-resize-mode' and I'm not sure
> whether we should use `with-temp-buffer-window' for it.

Like Dired and Proced, VC shrinks the window to fit the buffer in
`log-edit-show-files', so it could use `with-temp-buffer-window' too
if it will retain the original behavior in the affected commands.

> It was earlier via `special-display-buffer-names' and
> `special-display-regexps' and is now via `display-buffer-alist'.  You
> just have to write the corresponding buffer display function.  The
> problem is that nobody liked my earlier approach to combine specifiers.
> So you now have to code within these functions how you want to display
> the buffer and possibly resize its window.

There is no need to combine specifiers and no need to add
`temp-buffer-resize-regexps'.  In your current implementation
it's perfectly possible to use the following call in `dired-mark-pop-up':

	  (with-temp-buffer-window
	   buffer
	   (cons 'display-buffer-below-selected
		 '((fit-window-to-buffer . t)))
           ...

and to add the following code to `display-buffer-below-selected'
(copied and adapted from `dired-pop-to-buffer'):

(defun display-buffer-below-selected (buffer alist)
  "Try displaying BUFFER in a window below the selected window.
This either splits the selected window or reuses the window below
the selected one."
  (let (window)
    (or (and (not (frame-parameter nil 'unsplittable))
	     (setq window (window--try-to-split-window (selected-window)))
	     (window--display-buffer
	      buffer window 'window display-buffer-mark-dedicated))
	(and (setq window (window-in-direction 'below))
	     (not (window-dedicated-p window))
	     (window--display-buffer
	      buffer window 'reuse display-buffer-mark-dedicated)))
    ;; See Bug#12281.
    (set-window-start window (point-min))
    ;; If fit-window-to-buffer is t, make its window fit its contents.
    (when (cdr (assq 'fit-window-to-buffer alist))
      ;; Try to not delete window when we want to display less than
      ;; `window-min-height' lines.
      (fit-window-to-buffer window nil 1))
    window))

> Too many people don't like to automatically fit windows to
> their buffers.  They must be able to turn that off.

With the fixes above, users will be able to turn that off by customizing
`display-buffer-alist' to the following value (this should be done via the
Customization UI, but `setq' is used below for testing purposes):

(setq display-buffer-alist '(("Marked Files" .
                              (display-buffer-below-selected
                               (fit-window-to-buffer . nil)))))