]> git.eshelyaron.com Git - emacs.git/commitdiff
Make 'fit-frame-to-buffer' work around size hints (Bug#74866)
authorMartin Rudalics <rudalics@gmx.at>
Mon, 23 Dec 2024 09:59:11 +0000 (10:59 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Dec 2024 15:20:35 +0000 (16:20 +0100)
* lisp/window.el (fit-frame-to-buffer-1): When
'frame-resize-pixelwise' is nil, round up requested sizes to avoid
that lines get wrapped (Bug#74866).
* doc/lispref/windows.texi (Resizing Windows): Mention that with
size hints one may have to set 'frame-resize-pixelwise' to make
'fit-frame-to-buffer' fit the buffer exactly.

(cherry picked from commit 6017c6a986fd958732facb1bb6ea2c040981b023)

doc/lispref/windows.texi
lisp/window.el

index adc294e4c992d4baf308d6e8d940e1addf61f591..3ff78b599dee2280fbbb6c508ab24e7db15f0567 100644 (file)
@@ -1166,7 +1166,9 @@ frame to its buffer using the command @code{fit-frame-to-buffer}.
 This command adjusts the size of @var{frame} to display the contents of
 its buffer exactly.  @var{frame} can be any live frame and defaults to
 the selected one.  Fitting is done only if @var{frame}'s root window is
-live.
+a live window.  On window systems that use size hints, exact fitting can
+be often achieved if and only if @code{frame-resize-pixelwise}
+(@pxref{Frame Size}) is non-@code{nil}.
 
 The arguments @var{max-height}, @var{min-height}, @var{max-width} and
 @var{min-width}, if non-@code{nil}, specify bounds on the new body size
index 8f3e101d34cd515e8463ba053aefae60cf7006d7..b205c1d3517fb9dc3b43be07ca487706dc4eadb8 100644 (file)
@@ -9879,6 +9879,26 @@ for `fit-frame-to-buffer'."
             ;; Move frame down.
             (setq top top-margin)))))
       ;; Apply our changes.
+      (unless frame-resize-pixelwise
+       ;; When 'frame-resize-pixelwise' is nil, a frame cannot be
+       ;; necessarily fit completely even if the window's calculated
+       ;; width and height are integral multiples of the frame's
+       ;; character width and height.  The size hints Emacs produces
+       ;; are inept to handle that when the combined sizes of the
+       ;; frame's fringes, scroll bar and internal border are not an
+       ;; integral multiple of the frame's character width (Bug#74866).
+       ;; Consequently, the window manager will round sizes down and
+       ;; this may cause lines getting wrapped.  To avoid that, round
+       ;; sizes up here which will, however, leave a blank space at the
+       ;; end of the longest line(s).
+       (setq text-minus-body-width
+             (+ text-minus-body-width
+                (- char-width
+                   (% text-minus-body-width char-width))))
+       (setq text-minus-body-height
+             (+ text-minus-body-height
+                (- char-height
+                   (% text-minus-body-height char-height)))))
       (setq text-width
             (if width
                 (+ width text-minus-body-width)