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.
Later,
Mehul
------------------------------------
Mehul Shah wrote:
Regarding my previous post about the Completion list being too wide,
I
could not find a configuration option that allowed me to fix the
problem.
Instead, what I had to do is read through the system lisp files to
find
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
buffer
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
completion
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,
in
the file list-mode.el, the function minibuffer-completion-help, I
added
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
display-completion-list
I added
:window-width (window-width (get-buffer-window (get-buffer
"*Completions*")))
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
seem
to find the code where the display-completion-list function call is
for
these completion commands. Can anyone help?
Thanks,
Mehul
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)
(selected-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
temp buffer).
Thanks,
Mehul