From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: martin rudalics via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74866: 29.4; fit-frame-to-window + no vertical scroll bar + ch Date: Mon, 23 Dec 2024 18:59:50 +0100 Message-ID: <44136318-1e16-406b-984f-b760f5fa4f8f@gmx.at> References: <87msgyzakk.fsf@toomas.mail-host-address-is-not-set> <86zfkytmyt.fsf@gnu.org> <20241214210901.14730@toomas> <7e7b4037-5f71-4c74-9a93-2db76d2eb86e@gmx.at> Reply-To: martin rudalics Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18315"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: Eli Zaretskii , 74866@debbugs.gnu.org To: Stefan Kangas , Toomas Rosin Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 23 19:00:47 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tPmjW-0004Rx-D2 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 23 Dec 2024 19:00:46 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPmj0-0000aP-TO; Mon, 23 Dec 2024 13:00:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPmiy-0000Zt-9n for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2024 13:00:12 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tPmiv-0006ZH-Ph for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2024 13:00:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:References:From:MIME-Version:Date:To:Subject; bh=zin/484uBy1cPAg9T5sfpbC51/cBNKvVyhZVhFPdjb0=; b=r+0JLsE3KolCeGAlB6gVhaYum4xtzdFp+kcoxxIhwtqK/Kb9HNuSvVC/irFl5cdTHpmBKg9rQraj6VYa1rRkvq8JO8siogUCWVpCYgM5SuvTm+2del5tUan0WF1YWMUMVk7ZdwRLpeAyc9EAHIuhEC+AAYXWqMcfBHZ6CQwAjqJPh81XZa4uLxKXzgd18riQ7jUe9sKzwi4e+vAeYJ1pjEbCT0AcovRLIShkqGXj6Rf+TlO+WAH1XeoCTmWbIUu8WEOmEWyjYQG66HLPw/0NCQoruJXZFhvSCi4BfMHELblARaY9BRUhQR1aCUt1rew6QPKYDG8l1JBaeiQfUS3SlA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tPmiv-0001sh-BZ for bug-gnu-emacs@gnu.org; Mon, 23 Dec 2024 13:00:09 -0500 X-Loop: help-debbugs@gnu.org Resent-From: martin rudalics Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 23 Dec 2024 18:00:09 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74866 X-GNU-PR-Package: emacs Original-Received: via spool by 74866-submit@debbugs.gnu.org id=B74866.17349768067185 (code B ref 74866); Mon, 23 Dec 2024 18:00:09 +0000 Original-Received: (at 74866) by debbugs.gnu.org; 23 Dec 2024 18:00:06 +0000 Original-Received: from localhost ([127.0.0.1]:56050 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPmio-0001ql-Mb for submit@debbugs.gnu.org; Mon, 23 Dec 2024 13:00:05 -0500 Original-Received: from mout.gmx.net ([212.227.17.21]:38537) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPmil-0001q2-Sz for 74866@debbugs.gnu.org; Mon, 23 Dec 2024 13:00:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.at; s=s31663417; t=1734976792; x=1735581592; i=rudalics@gmx.at; bh=zin/484uBy1cPAg9T5sfpbC51/cBNKvVyhZVhFPdjb0=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:From:To: Cc:References:In-Reply-To:Content-Type:Content-Transfer-Encoding: cc:content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=jrW7P4/4dtPoCPSsPzU8Lx5W3GKVAjlW8vT4qAWFGrqU86VCEYDCmw60f/OCJH/l 5tVijLF65ESemkZflIYONRWzdBn+oW5HluHA/EUZFsoXwvAeZR77lzw1pQHyiX2bg 1ww8sS8mOAUR2Sss1ptslVYCadAh2fCDpdtRizViK00WeiE/R3+z8S//2mjQsa/hH cv6xukVipmdIClFjF1MlOvBnBqQwAuq4oji6KsbP3+EjQENa0eSqipY1UO44bxYa6 ZVIy67kc4hxJxY32QIQ2o6Exm8k99Y2RaBHnlf4wKpFVvlmz0JyPwQ76qcEuIF3W8 dgQofq4HZoXKsBQ98w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from [192.168.31.113] ([212.95.5.6]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MgesG-1u2AP53iSy-00gFm6; Mon, 23 Dec 2024 18:59:51 +0100 Content-Language: en-US In-Reply-To: <7e7b4037-5f71-4c74-9a93-2db76d2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TALBiYjhSvyAecM0JYXj6cZlnXypMoY0pjuGCc X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297655 Archived-At: > Whether 'set-face-attribute' DTRT and how it is involved in the scenario > at hand is a question I'd prefer not to answer. If it affects the > canonical line height or column width of a frame, it should find its way > into the size hints for each frame. Otherwise, chaos may result. I now analyzed the problem and came to the conclusion below. Note that the scenario below is interesting only for window systems that employ size hints as is the case for most GNU/Linux based systems. The problem cannot be seen on Windows, for example, because it does not use size hints. With emacs -Q of the release version put the following code into *scratch* (which is the code from the OP plus two commented lines). (defun fit (lin col) "Fit some text (LIN lines and COL columns) into a newly created frame." (interactive) (let ((buf (get-buffer-create "*bar*")) (frm (make-frame '((z-group . above))))) (with-current-buffer buf (erase-buffer) (setq mode-line-format '("")) (dotimes (_ lin) (insert (format "%s\n" (make-string col ?x)))) (goto-char (point-min))) (with-selected-frame frm (switch-to-buffer buf) (fit-frame-to-buffer)))) ;;; LIN and COL are arbitrary, make them sufficiently small. ;; (setq frame-resize-pixelwise t) (setq-default vertical-scroll-bar nil) (set-face-attribute 'default nil :height 75) (fit 9 23) ;; (eval-buffer) Now first evaluate the (set-face-attribute 'default nil :height 75) line to shrink the selected frame. Note that if you call 'eval-buffer' immediately, total chaos will ensue because the face attribute handling code will annihilate any previous attempt to fit the frame. Next evaluate the buffer. You should see a new frame with wrapped lines. Now uncomment the ;; (setq frame-resize-pixelwise t) line and eval the buffer again. You should see a new frame fitting the buffer. What goes wrong when you see wrapped lines? 'fit-frame-to-buffer-1' inherently (assuming a fixed width font and other simplifications) calculates the frame width by multiplying the frame's character width (6 pixels) with the number of characters on the longest line (23) resulting in 138 pixels. It adds 16 pixels for the fringes resulting in a requested width of 154 pixels. Emacs asks the window manager via xg_frame_set_char_size to set the width to 154 pixels but the window manager allots us only 152 pixels. Emacs concurs and wraps the lines. The reason for this is deeply rooted in the way we calculate size hints. Emacs sets the base width of the frame to 32 pixels here (16 for the widths of the frame's fringes, 16 for the scroll bar width). So we have a "variable" frame width of 154 - 32 = 122 pixels. At the same time Emacs sets the width increment to the frame's default character width. Now the nearest multiple of 6 to 122 is 120 and that's the number of pixels the window manager gives us. I now installed a workaround in 'fit-frame-to-buffer-1' on master to make the frame at least as large as needed to not wrap lines in such a case (hopefully, it does not break anything on systems that do not use size hints). On the Emacs I daily use I do not see the problem because I calculate size hints in a way that adds the "missing" 2 pixels to the base width - resulting in a base width of 34 pixels and a "variable" width of 120 pixels. If and when I feel that it's save to install it, I will do that on master. Till then either live with the workaround or either remove the scroll bar from the frame (and not from the buffer) or set 'frame-resize-pixelwise' to t. martin