help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set max size for *Completions*


From: Ergus
Subject: Re: Set max size for *Completions*
Date: Mon, 7 Mar 2022 21:50:51 +0100

On Mon, Mar 07, 2022 at 03:17:45PM +0000, Philip Kaludercic wrote:
Ergus <spacibba@aol.com> writes:

Hi:

Do we have any way to specify a max size/height for the *Completions*
window??

One way it to enable temp-buffer-resize-mode and then set
temp-buffer-max-height to whatever size you want.  This might have the
unintended side effect that other windows are also affected.  I manged
to solve this by setting temp-buffer-max-height to a function:

     (lambda (buf)
       (if (string-match-p
            (rx bos (or "*Completions*") eos)
            (buffer-name buf))
           10 (window-height)))

--
        Philip Kaludercic


Thanks for your reply I actually did this:

(defcustom completions-max-height 10
  "Maximum height for *Completions* buffer.")

(defun my/completions-advise (&optional win &rest _)
  "Advise for completion resize."
  (when-let* (((windowp win))
              (bname (buffer-name (window-buffer win))))
    (when (string= bname "*Completions*")
      (fit-window-to-buffer win completions-max-height))))

(advice-add #'fit-window-to-buffer :after-until #'my/completions-advise)

So I don't need to set temp-buffer-resize-mode or override a
funtion... But of course, this only works with temp-buffer-resize-mode
disabled, maybe adding a custom for this in minibuffer.el changing these
lines:

 2278             ,(if temp-buffer-resize-mode
 2279                  '(window-height . resize-temp-buffer-window)
 2280                '(window-height . fit-window-to-buffer))

And use a wrapper only for completions.

(defcustom completions-max-height 10
  "Maximum height for *Completions* buffer.")

(defun completions--fit-window-to-buffer (&optional win &rest _)
  "Resize completions."
  (if temp-buffer-resize-mode
      (let ((temp-buffer-max-height (or completions-max-height
                                        temp-buffer-max-height)))
        (resize-temp-buffer-window win))
    (fit-window-to-buffer win completions-max-height)))

 2278             '(window-height . completions--fit-window-to-buffer)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]