unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Aaron Jensen <aaronjensen@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, 56102@debbugs.gnu.org
Subject: bug#56102: 29.0.50; fit-frame-to-buffer's window-text-pixel-size calculation can be incorrect when only is set to vertically
Date: Tue, 28 Jun 2022 11:29:01 +0200	[thread overview]
Message-ID: <a3153ffb-9e74-f680-642c-c1e64aa4651e@gmx.at> (raw)
In-Reply-To: <CAHyO48w2GC7VszD+-Q32T9QvKph2VjHOW7jY-ZDjAjA_Uma5LQ@mail.gmail.com>

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

 >> I don't know yet either.  I'll send you a patch as soon as I have one.
 >
 > Sounds good, thanks.

I suppose we can manage by fixing some trivial silliness in the code and
making the documentation tell what the code does.  If you don't see any
problems with the attached diff within a week or so, I'll push it.

Thanks, martin

[-- Attachment #2: fit-frame-to-buffer.diff --]
[-- Type: text/x-patch, Size: 5274 bytes --]

diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index e070e84c67..6a6c91e356 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -1151,10 +1151,12 @@ Resizing Windows
 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.  The arguments @var{max-height}, @var{min-height}, @var{max-width}
-and @var{min-width} specify bounds on the new total size of
-@var{frame}'s root window.  @var{min-height} and @var{min-width} default
-to the values of @code{window-min-height} and @code{window-min-width}
-respectively.
+and @var{min-width}, if non-@code{nil}, specify bounds on the new body
+size of @var{frame}'s root window.  @var{min-height} and @var{min-width}
+default to the values of @code{window-safe-min-height} and
+@code{window-safe-min-width} respectively.  A non-@code{nil} value
+specified by any of these arguments overrides the corresponding value
+specified by @code{fit-frame-to-buffer-sizes}.
 
 If the optional argument @var{only} is @code{vertically}, this function
 may resize the frame vertically only.  If @var{only} is
@@ -1179,10 +1181,10 @@ Resizing Windows
 
 @defopt fit-frame-to-buffer-sizes
 This option specifies size boundaries for @code{fit-frame-to-buffer}.
-It specifies the total maximum and minimum lines and maximum and minimum
-columns of the root window of any frame that shall be fit to its buffer.
-If any of these values is non-@code{nil}, it overrides the corresponding
-argument of @code{fit-frame-to-buffer}.
+It specifies the maximum and minimum lines and maximum and minimum
+columns of the root window's body of any frame that shall be fit to its
+buffer.  Any value this option specifies will be overridden by the
+corresponding argument of @code{fit-frame-to-buffer}, if non-@code{nil}.
 @end defopt
 
 @deffn Command shrink-window-if-larger-than-buffer &optional window
diff --git a/lisp/window.el b/lisp/window.el
index a47a1216d1..cb59adc428 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -9053,10 +9053,11 @@ fit-frame-to-buffer-margins
 
 (defcustom fit-frame-to-buffer-sizes '(nil nil nil nil)
   "Size boundaries of frame for `fit-frame-to-buffer'.
-This list specifies the total maximum and minimum lines and
-maximum and minimum columns of the root window of any frame that
-shall be fit to its buffer.  If any of these values is non-nil,
-it overrides the corresponding argument of `fit-frame-to-buffer'.
+This list specifies the total maximum and minimum numbers of
+lines and the maximum and minimum numbers of columns of the body
+of the root window of any frame that shall be fit to its buffer.
+Any value specified by ths variable will be overridden by the
+corresponding argument of `fit-frame-to-buffer', if non-nil.
 
 On window systems where the menubar can wrap, fitting a frame to
 its buffer may swallow the last line(s).  Specifying an
@@ -9252,30 +9253,30 @@ fit-frame-to-buffer-1
               (t parent-or-display-height))
              ;; The following is the maximum height that fits into the
              ;; top and bottom margins.
-             (max (- bottom-margin top-margin outer-minus-body-height))))
+             (max (- bottom-margin top-margin outer-minus-body-height) 0)))
            (min-height
             (cond
              ((numberp min-height) (* min-height line-height))
              ((numberp (nth 1 sizes)) (* (nth 1 sizes) line-height))
-             (t (window-min-size window nil nil t))))
+             (t (window-safe-min-size window nil t))))
            (max-width
-            (min
-             (cond
-              ((numberp max-width) (* max-width char-width))
-              ((numberp (nth 2 sizes)) (* (nth 2 sizes) char-width))
-              (t parent-or-display-width))
-             ;; The following is the maximum width that fits into the
-             ;; left and right margins.
-             (max (- right-margin left-margin outer-minus-body-width))))
+            (unless (eq only 'vertically)
+              (min
+               (cond
+                ((numberp max-width) (* max-width char-width))
+                ((numberp (nth 2 sizes)) (* (nth 2 sizes) char-width))
+                (t parent-or-display-width))
+               ;; The following is the maximum width that fits into the
+               ;; left and right margins.
+               (max (- right-margin left-margin outer-minus-body-width) 0))))
            (min-width
             (cond
              ((numberp min-width) (* min-width char-width))
-             ((numberp (nth 3 sizes)) (nth 3 sizes))
-             (t (window-min-size window t nil t))))
+             ((numberp (nth 3 sizes)) (* (nth 3 sizes) char-width))
+             (t (window-safe-min-size window t t))))
            ;; Note: Currently, for a new frame the sizes of the header
            ;; and mode line may be estimated incorrectly
-           (size
-            (window-text-pixel-size window from to max-width max-height))
+           (size (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

  reply	other threads:[~2022-06-28  9:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20  3:03 bug#56102: 29.0.50; fit-frame-to-buffer's window-text-pixel-size calculation can be incorrect when only is set to vertically Aaron Jensen
2022-06-22 13:58 ` Eli Zaretskii
2022-06-22 14:15   ` Aaron Jensen
2022-06-23  7:30     ` martin rudalics
2022-06-24  2:28       ` Aaron Jensen
2022-06-24  9:20         ` martin rudalics
2022-06-24 14:28           ` Aaron Jensen
2022-06-26 10:09             ` martin rudalics
2022-06-26 13:12               ` Aaron Jensen
2022-06-27  8:24                 ` martin rudalics
2022-06-27 13:24                   ` Aaron Jensen
2022-06-28  9:29                     ` martin rudalics [this message]
2022-06-28 14:52                       ` Aaron Jensen
2022-07-05 13:07                         ` Aaron Jensen
2022-07-06  7:37                           ` martin rudalics
2022-07-06 13:17                             ` Aaron Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a3153ffb-9e74-f680-642c-c1e64aa4651e@gmx.at \
    --to=rudalics@gmx.at \
    --cc=56102@debbugs.gnu.org \
    --cc=aaronjensen@gmail.com \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).