all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Ingo Lohmar <ingo.lohmar@posteo.net>, 37563@debbugs.gnu.org
Subject: bug#37563: 27.0.50; fit-frame-to-buffer does not account for line-spacing
Date: Tue, 1 Oct 2019 09:32:08 +0200	[thread overview]
Message-ID: <a1584786-1742-b515-2f5d-e911d1360940@gmx.at> (raw)
In-Reply-To: <87tv8tsk3f.fsf@kenko.localhost.com>

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

 > 1) When max-height is provided, the actual frame height is calculated in
 > ll 8736ff of window.el (as of commit
 > 5746202c182a9c69c732beb29b8507a6e6364799), and that just multiplies by
 > the char-height, which excludes the line-spacing.  This is the buggy
 > case.

I attached a fix.  Please try it.

Many thanks for the report, martin

[-- Attachment #2: fit-frame-to-buffer.diff --]
[-- Type: text/plain, Size: 3239 bytes --]

diff --git a/lisp/window.el b/lisp/window.el
index cf733153b8..3df463533c 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -8494,6 +8494,40 @@ window-buffer-height
 			     (eobp)
 			     window))))
 
+(defun window-char-height (&optional window)
+  "Return number of pixels of the height of a character in WINDOW.
+WINDOW must be a live window and defaults to the selected one.
+The return value accounts for any remapping of the default face
+of WINDOW's frame."
+  ;; Code mostly stolen from simple.el's `default-font-height'.
+  (let* ((window (window-normalize-window window t))
+	 (frame (window-frame window))
+	 (default-font (face-font 'default frame)))
+    (cond
+     ((and (display-multi-font-p (frame-parameter frame 'display))
+	   (not (string-equal (frame-parameter frame 'font) default-font)))
+      (aref (font-info default-font frame) 3))
+     (t (frame-char-height frame)))))
+
+(defun window-line-height (&optional window)
+  "Return number of pixels of a text line in WINDOW.
+WINDOW must be a live window and defaults to the selected one.
+The return value includes any line spacing defined for WINDOW's
+buffer or frame."
+  ;; Code mostly stolen from simple.el's `default-line-height'.
+  (let* ((window (window-normalize-window window t))
+	 (char-height (window-char-height window))
+	 (buffer (window-buffer window))
+	 (frame (window-frame window))
+	 (space-height
+	  (or (and (display-graphic-p)
+		   (or (buffer-local-value 'line-spacing buffer)
+		       (frame-parameter frame 'line-spacing)))
+	      0)))
+    (when (floatp space-height)
+      (setq space-height (truncate (* char-height space-height))))
+    (+ char-height space-height)))
+
 ;;; Resizing windows and frames to fit their contents exactly.
 (defcustom fit-window-to-buffer-horizontally nil
   "Non-nil means `fit-window-to-buffer' can resize windows horizontally.
@@ -8636,6 +8670,7 @@ fit-frame-to-buffer
            (char-height (frame-char-height frame))
            ;; WINDOW is FRAME's root window.
            (window (frame-root-window frame))
+           (line-height (window-line-height window))
            (parent (frame-parent frame))
            (monitor-attributes
             (unless parent
@@ -8732,16 +8767,16 @@ fit-frame-to-buffer
            (max-height
             (min
              (cond
-              ((numberp max-height) (* max-height char-height))
-              ((numberp (nth 0 sizes)) (* (nth 0 sizes) char-height))
+              ((numberp max-height) (* max-height line-height))
+              ((numberp (nth 0 sizes)) (* (nth 0 sizes) line-height))
               (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))))
            (min-height
             (cond
-             ((numberp min-height) (* min-height char-height))
-             ((numberp (nth 1 sizes)) (* (nth 1 sizes) char-height))
+             ((numberp min-height) (* min-height line-height))
+             ((numberp (nth 1 sizes)) (* (nth 1 sizes) line-height))
              (t (window-min-size window nil nil t))))
            (max-width
             (min


  reply	other threads:[~2019-10-01  7:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30 18:41 bug#37563: 27.0.50; fit-frame-to-buffer does not account for line-spacing Ingo Lohmar
2019-10-01  7:32 ` martin rudalics [this message]
     [not found]   ` <87lfu4aook.fsf@kenko.localhost.com>
2019-10-01  8:10     ` martin rudalics
2019-10-01  8:28       ` Ingo Lohmar
2019-10-02  8:54         ` martin rudalics
2019-10-03  8:15           ` martin rudalics
2019-10-03  8:48             ` Ingo Lohmar
2019-10-03 18:10               ` martin rudalics
2019-10-03 18:21                 ` Ingo Lohmar
2019-10-05  8:41                   ` martin rudalics
2019-10-05  9:05                     ` Ingo Lohmar
2019-10-07  9:25                       ` martin rudalics
2019-10-07 17:45                         ` Ingo Lohmar
2019-10-08  8:44                           ` martin rudalics
2019-10-11  8:16                             ` martin rudalics
2019-10-11 17:45                               ` Ingo Lohmar
2019-10-03  8:56             ` Ingo Lohmar
2019-10-03  9:12               ` Robert Pluim
2019-10-03 16:09               ` Eli Zaretskii
2019-10-03 18:10               ` martin rudalics
2019-10-03 18:22                 ` Ingo Lohmar
2019-10-01  7:39 ` bug#37563: [PATCH] please review Ingo Lohmar
2019-10-02  8:53   ` martin rudalics
     [not found] ` <handler.37563.B.156987198814967.ack@debbugs.gnu.org>
2019-10-11 17:50   ` bug#37563: Acknowledgement (27.0.50; fit-frame-to-buffer does not account for line-spacing) Ingo Lohmar

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

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

  git send-email \
    --in-reply-to=a1584786-1742-b515-2f5d-e911d1360940@gmx.at \
    --to=rudalics@gmx.at \
    --cc=37563@debbugs.gnu.org \
    --cc=ingo.lohmar@posteo.net \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.