diff --git a/lisp/window.el b/lisp/window.el index 1fcfffcb53..b7d4b4d26f 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -3432,7 +3432,7 @@ (defun window--resize-mini-frame (frame) "Resize minibuffer-only frame FRAME." (if (functionp resize-mini-frames) (funcall resize-mini-frames frame) - (fit-frame-to-buffer frame))) + (fit-mini-frame-to-buffer frame))) (defun window--sanitize-window-sizes (horizontal) "Assert that all windows on selected frame are large enough. @@ -8925,8 +8925,17 @@ (defun window--sanitize-margin (margin left right) (declare-function tool-bar-height "xdisp.c" (&optional frame pixelwise)) +(defun fit-mini-frame-to-buffer (frame) + "Adjust size of minibuffer FRAME to display its contents. +Unlike `fit-frame-to-buffer' FRAME will fit to the contents with +any leading or trailing empty lines included." + (fit-frame-to-buffer-1 frame)) + (defun fit-frame-to-buffer (&optional frame max-height min-height max-width min-width only) "Adjust size of FRAME to display the contents of its buffer exactly. +Any leading or trailing empty lines of the buffers content are +not considered. + FRAME can be any live frame and defaults to the selected one. Fit only if FRAME's root window is live. @@ -8945,6 +8954,12 @@ (defun fit-frame-to-buffer (&optional frame max-height min-height max-width min- `fit-frame-to-buffer-margins' or setting the corresponding parameters of FRAME." (interactive) + (fit-frame-to-buffer-1 frame max-height min-height max-width min-width only t t)) + +(defun fit-frame-to-buffer-1 (&optional frame max-height min-height max-width min-width only from to) + "Helper function for `fit-frame-to-buffer'. +FROM and TO are the buffer positions to determine the size to fit +to, see `window-text-pixel-size'." (unless (fboundp 'display-monitor-attributes-list) (user-error "Cannot resize frame in non-graphic Emacs")) (setq frame (window-normalize-frame frame)) @@ -9079,7 +9094,7 @@ (defun fit-frame-to-buffer (&optional frame max-height min-height max-width min- ;; Note: Currently, for a new frame the sizes of the header ;; and mode line may be estimated incorrectly (size - (window-text-pixel-size window t t max-width max-height)) + (window-text-pixel-size window from to max-width max-height)) (width (max (car size) min-width)) (height (max (cdr size) min-height))) ;; Don't change height or width when the window's size is fixed