I had a problem with the completion lists for file-completion or
buffer-name completion earlier this year. When I split my frame into two
vertically adjoining buffers, the list would be too wide and thus scroll
off the screen. I would then have to pick-up my mouse to see the whole
list. Below is a quick solution I found to the problem, and it seems to
work in most cases. I thought I would share it with you guys.
Mehul Shah wrote:
> Regarding my previous post about the Completion list being too wide,
> could not find a configuration option that allowed me to fix the
> Instead, what I had to do is read through the system lisp files to
> the appropriate functions that were called when displaying the
> completion list.
> The problem seems to have to with the "with-output-to-temp-buffer"
> function which is used throughout. It does not display the temp
> in a window until the display-completion-list is completed. The
> display-completion-list function does the formatting, and defaults to
> the width of the *frame* not the *window*, which is why the
> list is too wide. The only way to get the width of the window is to
> display empty output to a temp-buffer and then call it again with the
> output of the display-completion-list buffer. For file completions,
> the file list-mode.el, the function minibuffer-completion-help, I
> a dummy call:
> (with-output-to-temp-buffer *Completions* ())
> to display the *Completions* window.
> Then in minibuf.el, in read-file-name-1 in the call to
> I added
> :window-width (window-width (get-buffer-window (get-buffer
> This fixed the Completion list window being too wide for reading in
> file-names. However this does not fix the Completion lists when
> switching buffers or when looking for a command with M-x. I can't
> to find the code where the display-completion-list function call is
> these completion commands. Can anyone help?
Ignore the hack above, here is a better solution.
Okay, I have found a reasonable solution to the *Completion* list being
too wide problem. Here is the quick fix, although I believe the code
should be restructured so
that the temporary buffer is displayed before its contents are
formatted. This way, the code does not have to guess at what the width
is of the window in which the
temporary buffer is displayed.
In list-mode.el previously, in the function display-completion-list,
the width of the window was guessed with the following code:
(frame-width (or (last-nonminibuf-frame)
Basically, guessing that the width of the completion window would be
the same as the width of the last selected frame or the width of the
last non-minibuffer frame.
Unfortunately, this is no the case when you split the frame vertically.
So here is a better guess:
(window-width (get-lru-window (last-nonminibuf-frame)))
This basically gets the width of the least recently used window, which
happens to be the window in which the temp buffer tends to get displayed
in. I have not verified
this fact in the code, but seems to work when I use it.
So, in list-mode.el I simply replaced the previous guess with the new
one and the formatting came out much better (both in cases where a new
window is created for
the temp buffer and one in which there is an available window for the