diff --git a/etc/NEWS b/etc/NEWS index 587e7f6ade..78f41de2ea 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -554,6 +554,10 @@ This option controls the sorting of the completion candidates in the "*Completions*" buffer. Available styles are no sorting, alphabetical (the default), or a custom sort function. +*** New user option 'completions-max-height'. +This option limits the height of the "*Completions*" buffer. + + ** Isearch and Replace +++ diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 798cba0ac2..a06986fdb7 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2212,6 +2212,19 @@ completion--done (equal pre-msg (and exit-fun (current-message)))) (completion--message message)))) +(defcustom completions-max-height nil + "Maximum height for *Completions* buffer." + :type 'natnum + :version "29.1") + +(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))) + (defun minibuffer-completion-help (&optional start end) "Display a list of possible completions of the current minibuffer contents." (interactive) @@ -2275,9 +2288,7 @@ minibuffer-completion-help ,(if (eq (selected-window) (minibuffer-window)) 'display-buffer-at-bottom 'display-buffer-below-selected)) - ,(if temp-buffer-resize-mode - '(window-height . resize-temp-buffer-window) - '(window-height . fit-window-to-buffer)) + (window-height . completions--fit-window-to-buffer) ,(when temp-buffer-resize-mode '(preserve-size . (nil . t))) (body-function