unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70894: [PATCH] * lisp/window.el (fit-window-to-buffer): Fix width calculation
@ 2024-05-12 13:25 Morgan Smith
  2024-05-18  9:39 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Morgan Smith @ 2024-05-12 13:25 UTC (permalink / raw)
  To: 70894

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

Tags: patch

Hello!

I was playing around with `fit-window-to-buffer' after setting
`fit-window-to-buffer-horizontally' to `t'.  I noticed that it kept
setting the window too narrow.  After a quick investigation, I found
some suspicious looking calculation that mixed pixel and column units.

Interactively, it looks like this fixes the issue.

Thanks,

Morgan



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-window.el-fit-window-to-buffer-Fix-width-calcul.patch --]
[-- Type: text/patch, Size: 1205 bytes --]

From f906b1a219ae7c9ec1374edf6e02b46b845ab776 Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Sun, 12 May 2024 09:19:30 -0400
Subject: [PATCH] * lisp/window.el (fit-window-to-buffer): Fix width
 calculation

When pixelwise is nil, we still calculate width in pixels and
then convert it to columns.  However, part of the calculation
was using columns where it should have used pixels.
---
 lisp/window.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/window.el b/lisp/window.el
index 639090752be..f03996fb682 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -9906,8 +9906,8 @@ fit-window-to-buffer
 			       ;; the bottom is wider than the window.
 			       (* (window-body-height window pixelwise)
 				  (if pixelwise 1 char-height))))
-                         (- total-width
-                            (window-body-width window pixelwise)))))
+                         (- (* total-width (if pixelwise 1 char-width))
+                            (window-body-width window t)))))
 	  (unless pixelwise
 	    (setq width (/ (+ width char-width -1) char-width)))
           (setq width (max min-width (min max-width width)))
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-19  9:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-12 13:25 bug#70894: [PATCH] * lisp/window.el (fit-window-to-buffer): Fix width calculation Morgan Smith
2024-05-18  9:39 ` Eli Zaretskii
2024-05-19  7:58   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-19  8:09     ` Eli Zaretskii
2024-05-19  9:22       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).