Subject: bug#44080: 27.1; Display behavior of overlays `after-string` in resizable minibuffer frames

From: Clemens <[email-masked]>
Date: Thu, 22 Oct 2020 14:39:55 +0200

> It's called from xdisp.c as
> 
> 
>    if (FRAME_MINIBUF_ONLY_P (f))
>      {
>        if (!NILP (resize_mini_frames))
>      safe_call1 (Qwindow__resize_mini_frame, WINDOW_FRAME (w));
>      }
> 
> 
> which represents one of our ways to call a Lisp function from C.

Thanks, for some reason `debug-on-entry` did not invoke the debugger
when I tested it.

> Right.  And if you have any questions, ask here immediately.

I never dealt with the C side of Emacs and you suggested to offer the 
new function as first customization choice for `resize-mini-frames`.
I guess this needs to be done on the C side as the variable is defined 
there?

I have attached the patch I have worked on. Let me know how to proceed 
and thanks for your help!
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