From: Clemens Radermacher Date: Tue, 27 Oct 2020 08:45:25 +0000 (+0100) Subject: Don't skip empty lines when fitting mini frame to buffer (Bug#44080) X-Git-Tag: emacs-27.1.90~97 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e0de9f3295b4c46cb7198ec0b9634809d7b7a36d;p=emacs.git Don't skip empty lines when fitting mini frame to buffer (Bug#44080) * lisp/window.el (fit-mini-frame-to-buffer, window--resize-mini-frame, fit-frame-to-buffer, fit-frame-to-buffer-1): By default, fit a mini frame without skipping its buffer's leading or trailing empty lines. * src/frame.c (resize-mini-frames): Update doc-string. * lisp/cus-start.el (resize-mini-frames): Update for customize. * doc/lispref/minibuf.texi (resize-mini-frames): Update description. --- diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index ecab882fed7..b955355dc0a 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -2445,8 +2445,10 @@ frame is the buffer whose contents will be shown the next time that window is redisplayed. The function is expected to fit the frame to the buffer in some appropriate way. -Any other non-@code{nil} value means to resize minibuffer-only frames -by calling @code{fit-frame-to-buffer} (@pxref{Resizing Windows}). +Any other non-@code{nil} value means to resize minibuffer-only frames by +calling @code{fit-mini-frame-to-buffer}, a function that behaves like +@code{fit-frame-to-buffer} (@pxref{Resizing Windows}) but does not strip +leading or trailing empty lines from the buffer text. @end defopt diff --git a/etc/NEWS b/etc/NEWS index c3ee1cdd6a9..f0b5dd088af 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -32,6 +32,14 @@ applies, and please also update docstrings as needed. This is a bug-fix release with no new features. + +* Lisp Changes in Emacs 27.2 + +*** The behavior of the user option 'resize-mini-frames' has changed. +If set to non-nil, resize the mini frame using the new function +'fit-mini-frame-to-buffer' which won't skip leading or trailing empty +lines of the buffer. + * Editing Changes in Emacs 27.2 diff --git a/lisp/cus-start.el b/lisp/cus-start.el index 6632687da47..1d344893a5a 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -317,9 +317,9 @@ Leaving \"Default\" unchecked is equivalent with specifying a default of (resize-mini-frames frames (choice (const :tag "Never" nil) - (const :tag "Fit frame to buffer" t) + (const :tag "Fit mini frame to buffer" t) (function :tag "User-defined function")) - "27.1") + "27.2") (menu-bar-mode frames boolean nil ;; FIXME? ;; :initialize custom-initialize-default diff --git a/lisp/window.el b/lisp/window.el index 7b75495ad84..48005fc93e0 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -3406,7 +3406,7 @@ routines." "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. @@ -8762,6 +8762,14 @@ Return 0 otherwise." (declare-function tool-bar-height "xdisp.c" (&optional frame pixelwise)) +(defun fit-mini-frame-to-buffer (&optional frame) + "Adjust size of minibuffer FRAME to display its contents. +FRAME should be a minibuffer-only frame and defaults to the +selected one. Unlike `fit-frame-to-buffer' FRAME will fit to the +contents of its buffer 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. FRAME can be any live frame and defaults to the selected one. @@ -8780,8 +8788,18 @@ horizontally only. The new position and size of FRAME can be additionally determined by customizing the options `fit-frame-to-buffer-sizes' and `fit-frame-to-buffer-margins' or setting the corresponding -parameters of FRAME." +parameters of FRAME. + +Any leading or trailing empty lines of the buffer content are not +considered." (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'. The remaining arguments are as +for `fit-frame-to-buffer'." (unless (fboundp 'display-monitor-attributes-list) (user-error "Cannot resize frame in non-graphic Emacs")) (setq frame (window-normalize-frame frame)) @@ -8916,7 +8934,7 @@ parameters of FRAME." ;; 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 diff --git a/src/frame.c b/src/frame.c index 255606957c2..adcc489a406 100644 --- a/src/frame.c +++ b/src/frame.c @@ -6204,7 +6204,7 @@ window of that frame is the buffer whose text will be eventually shown in the minibuffer window. Any other non-nil value means to resize minibuffer-only frames by -calling `fit-frame-to-buffer'. */); +calling `fit-mini-frame-to-buffer'. */); resize_mini_frames = Qnil; DEFVAR_LISP ("focus-follows-mouse", focus_follows_mouse,