Subject: Re: 31.0.50; Change in fit-frame-to-buffer doesn't work with transient-posframe

From: martin rudalics <[email-masked]>
Date: Wed, 14 May 2025 15:46:23 +0200

> When I invoke a transient in the GUI, and with this diff
 >
 > 1 file changed, 6 insertions(+)
 > lisp/window.el | 6 ++++++
 >
 > modified   lisp/window.el
 > @@ -10126,9 +10126,11 @@ fit-frame-to-buffer-1
 >               (setq left left-margin)))))
 >         ;; Fit height to constraints.
 >         (when height
 > +        (message "1: height %S" height)
 >           (unless frame-resize-pixelwise
 >             (setq height (* (/ (+ height char-height -1) char-height)
 >                             char-height)))
 > +        (message "2: height %S" height)
 >           ;; The new outer height.
 >           (setq outer-height (+ height outer-minus-body-height))
 >           ;; Preserve margins.
 > @@ -10158,6 +10160,8 @@ fit-frame-to-buffer-1
 >   	    (setq text-minus-body-width
 >   		  (+ text-minus-body-width (- char-width remainder)))))
 >   	(let ((remainder (% text-minus-body-height char-height)))
 > +          (message "remainder %S text-minus-body-height %S char-height %S"
 > +                   remainder text-minus-body-height char-height)
 >   	  (unless (zerop remainder)
 >   	    (setq text-minus-body-height
 >   		  (+ text-minus-body-height(- char-height remainder))))))
 > @@ -10165,6 +10169,8 @@ fit-frame-to-buffer-1
 >               (if width
 >                   (+ width text-minus-body-width)
 >                 (frame-text-width frame)))
 > +      (message "height %S text-minus-body-height %S"
 > +               height text-minus-body-height)
 >         (setq text-height
 >               (if height
 >                   (+ height text-minus-body-height)
 >
 > I see that the function is apparently called twice?

Can you try to find out why?

 > And the output is
 >
 > 1: height 199
 > 2: height 199
 > height 199 text-minus-body-height 0
 > 1: height 199
 > 2: height 216
 > remainder 0 text-minus-body-height 0 char-height 18
 > height 216 text-minus-body-height 0
 >
 > Maybe the second '2:...' is what increases the frame size?

I think so.  216 is the smallest multiple of 18 at least as large as
199.  That's what you will get anyway and should have happened also
before my commit.  In a sense your were even lucky because if remainder
were non-zero, it might have added another 17.  I probably should
collapse these so at most 17 are added.

But anyone who uses 'fit-frame-to-buffer' should have set
'frame-resize-pixelwise' to t.

martin