unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Lars Ingebrigtsen <larsi@gnus.org>,
	Joe Corneli <holtzermann17@gmail.com>
Cc: "20022@debbugs.gnu.org" <20022@debbugs.gnu.org>,
	"19194@debbugs.gnu.org" <19194@debbugs.gnu.org>
Subject: bug#19194: [External] : bug#19194: bug#20022: 24.4.90; window-body-height, window-body-width wrong value after text-scale-adjust
Date: Thu, 10 Feb 2022 17:39:44 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488C871DFDC94D6E0784A48F32F9@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <87a6ezb0hn.fsf@gnus.org>

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

> > Adjusting the font size, I would expect that the window's "body width"
> > would change -- more characters can be fit into the same amount of
> > screen space.  Current behaviour does not match this expectation.
> >
> > M-: (window-body-width) RET  [Note result.]
> > C-x C--
> > M-: (window-body-width) RET  [Result is the same.]
> >
> > The function is described:
> >
> > "This function returns the width, in columns, of the body of window
> > window."
> >
> > If for some reason the "nominal" number of columns needs to calculated
> > with reference to the default font, then there should be another
> > function to return the "actual" number of columns.
> 
> Skimming this thread, I think the conclusion here is that these
> functions work as designed.  `C-x C--' reduces the size of the font in
> the current buffer, but the "window body width" concept remains the
> same.  (I.e., if you create a new buffer and display it, that's what
> `window-body-width' is telling you the number of columns for.)
> 
> So I don't think there's anything to do here, and I'm closing this bug
> report.

The functions work as designed, yes.  But the design
could be improved.

You can decide whether this comment is relevant to
this bug report.  I think it's related, but it's not
exactly the same suggestion/problem.

I've proposed an enhancement to optionally resize
the window to fit the newly displayed text -
shrinking the text shrinks the window etc.  This
enhancement can free up frame or screen real estate
for other windows or frames.

This is not the same as the enhancement hinted at
in this bug report, which I guess is instead to
reflow the text to accommodate/fill the space
provided by the changed text size.  That makes
sense especially if `visual-line-mode' is used.
The enhancement I describe makes sense especially
if that mode is not used.

I've suggested my enhancement before, but it was
rejected, even though it's behavior change is
optional.  I describe it again here, FWIW.

I provide the enhancement in the tiny bit of code
that is library `face-remap+.el' (attached).  It
provides a user option, `text-scale-resize-window',
and it redefines `text-scale-increase' to respect
that option.  A patch is trivial.

[-- Attachment #2: face-remap+.el --]
[-- Type: application/octet-stream, Size: 8034 bytes --]

;;; face-remap+.el --- Extensions to standard library `face-remap.el'.
;;
;; Filename: face-remap+.el
;; Description: Extensions to standard library `face-remap.el'.
;; Author: Drew Adams
;; Maintainer: Drew Adams (concat "drew.adams" "@" "oracle" ".com")
;; Copyright (C) 2009-2018, Drew Adams, all rights reserved.
;; Created: Wed Jun 17 14:26:21 2009 (-0700)
;; Version: 0
;; Package-Requires: ()
;; Last-Updated: Mon Jan  1 11:18:18 2018 (-0800)
;;           By: dradams
;;     Update #: 179
;; URL: https://www.emacswiki.org/emacs/download/face-remap%2b.el
;; Doc URL: https://emacswiki.org/emacs/SetFonts
;; Keywords: window frame face font
;; Compatibility: GNU Emacs: 23.x, 24.x, 25.x, 26.x
;;
;; Features that might be required by this library:
;;
;;   `face-remap'.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;;
;;  Commands `text-scale-decrease', `text-scale-increase', and
;;  `text-scale-adjust' (bound to `C-x C--', `C-x C-+', `C-x C-=', and
;;  `C-x C-0') let you resize the text in the current buffer by
;;  changing its scale factor.  When you shrink or enlarge the
;;  apparent text size this way, however, the window takes no notice
;;  of it.  In particular, although shrinking text can result in extra
;;  horizontal space at the right, window commands do not see this
;;  space as extra.
;;
;;  With this library, user option `text-scale-resize-window' lets you
;;  automatically resize the selected window (horizontally,
;;  vertically, or both) when text is resized, so that the way the
;;  window fits the buffer text remains relatively constant.
;;  Shrinking the text in one window shrinks that window, giving more
;;  space to adjacent windows.
;;
;;  If you also use library `fit-frame.el', then one-window frames
;;  also respond to text resizing by scaling.  If not, then the
;;  text-scale commands have no effect on frame size for one-window
;;  frames.
;;
;;  See also:
;;
;;  * Library `zoom-frm.el', which provides commands `zoom-in' and
;;    `zoom-out', which let you zoom the text in a buffer (as in text
;;    scaling) or the text in an frame.  In the latter case, the
;;    default font of the frame is enlarged or shrunk dynamically.
;;
;;  * Library `doremi-frm.el', which provides commands
;;    `doremi-buffer-font-size+' and `doremi-frame-font-size+', which
;;    provide another way to zoom incrementally.
;;
;;  To use library `face-remap+.el', put it in your `load-path' and
;;  put this sexp in your init file (~/.emacs):
;;
;;   (require 'face-remap+)
;;
;;
;;  Options (user variables) defined here:
;;
;;    `text-scale-resize-window'.
;;
;;
;;  ***** NOTE: The following standard functions defined in `face-remap.el'
;;              have been REDEFINED HERE:
;;
;;    `text-scale-increase' -- Possibly resize the window or frame.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change Log:
;;
;; 2009/06/22 dadams
;;     Removed vestigial defvar (unused variable).
;; 2009/06/17 dadams
;;     Created.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(require 'face-remap)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;###autoload
(defcustom text-scale-resize-window t
  "*Non-nil means text scaling resizes the window or frame accordingly.
For example, if you use `C-x C--' (`text-scale-decrease')' to make the
text smaller, then the window or frame is made smaller by a similar
factor.

If the window is not alone in its frame, then the window is resized.
Otherwise, the frame is resized (provided you also use library
`fit-frame.el').  The frame is always resized both horizontally and
vertically."
  :type '(choice
          (const :tag "Do not resize window when scale text"  nil)
          (const :tag "Resize window when scale text"         t)
          (const :tag "Resize only horizontally"              horizontally)
          (const :tag "Resize only vertically"                vertically))
  :group 'display)


;; REPLACES ORIGINAL `text-scale-increase' defined in `face-remap.el',
;;
;; Resize window or frame if `text-scale-resize-window' is non-nil.
;;
;;;###autoload
(defun text-scale-increase (inc)
  "Increase the height of the default face in the current buffer by INC steps.
If the new height is other than the default, `text-scale-mode' is enabled.

Each step scales the height of the default face by the variable
`text-scale-mode-step' (a negative number of steps decreases the
height by the same amount).  As a special case, an argument of 0
removes any scaling currently active.

If option `text-scale-resize-window' is non-nil, then the selected
window or frame is resized accordingly, so as to keep roughly the same
text visible in the window.  Normally, it is the window that is
resized, but if the window is alone in its frame (and if you use
library `fit-frame.el'), then the frame is resized instead.

See option `text-scale-resize-window' for the possible behaviors."
  (interactive "p")
  (let* ((oamount       (if text-scale-mode text-scale-mode-amount 0))
         (scale-factor  (expt text-scale-mode-step (if (= inc 0) (- oamount) inc)))
         (use-frame-p   (and (fboundp 'fit-frame) (one-window-p 'nomini)))
         (edges         (if use-frame-p (window-inside-edges) (window-edges)))
         (owidth        (- (nth 2 edges) (nth 0 edges)))
         ;; If resizing frame, don't count header line offset (Top) - just use Bottom.
         (oheight       (- (nth 3 edges) (if use-frame-p 0 (nth 1 edges)))))
    (setq text-scale-mode-amount
          (if (= inc 0) 0 (+ (if text-scale-mode text-scale-mode-amount 0) inc)))
    (text-scale-mode (if (zerop text-scale-mode-amount) -1 1))
    (when text-scale-resize-window
      (if use-frame-p
          (let* ((width           (round (* owidth  scale-factor)))
                 (height          (round (* oheight scale-factor)))
                 (fparams         (frame-parameters))
                 (tool-bar-lines  (or (cdr (assq 'tool-bar-lines fparams)) 0))
                 (menu-bar-lines  (or (cdr (assq 'menu-bar-lines fparams)) 0))
                 ;; `window-line-height' doesn't seem to work - I filed Emacs bug #3602.
                 (header-line     (window-line-height 'header-line)))
            ;; `set-frame-size' includes frame's menu-bar, tool-bar, and minibuffer.
            (when (cdr (assq 'modeline  fparams)) (setq height  (1+ height)))
            (when (cdr (assq 'minibuffer fparams)) (setq height  (1+ height)))
            (when header-line (setq height (+ height 1)))
            (setq height  (+ height tool-bar-lines menu-bar-lines))
            (fit-frame nil width height))
        (unless (eq text-scale-resize-window 'vertically)
          (condition-case nil
              (enlarge-window-horizontally (round (- (* owidth scale-factor) owidth)))
            (error nil)))
        (unless (eq text-scale-resize-window 'horizontally)
          (condition-case nil
              (enlarge-window (round (- (* oheight scale-factor) oheight)))
            (error nil)))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(provide 'face-remap+)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; face-remap+.el ends here

      reply	other threads:[~2022-02-10 17:39 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26 13:47 bug#19194: 24.4.50; `window-body-width' is not dynamic relative to font size changes Joe Corneli
2014-11-26 15:55 ` Stefan Monnier
2014-11-26 16:34   ` Joe Corneli
2014-11-26 17:06     ` Eli Zaretskii
2014-11-26 16:04 ` Eli Zaretskii
2014-11-27  9:44 ` martin rudalics
2014-11-27 10:54   ` Joe Corneli
2014-11-27 18:35     ` martin rudalics
2014-11-27 18:52       ` Eli Zaretskii
2014-11-27 19:58         ` martin rudalics
2014-11-27 20:43           ` Eli Zaretskii
2014-11-28  7:29             ` martin rudalics
2014-11-28  8:49               ` Eli Zaretskii
2014-11-28 18:38                 ` martin rudalics
2014-11-28 19:20                   ` Eli Zaretskii
2014-12-19 19:40                   ` Eli Zaretskii
2014-12-20 10:10                     ` martin rudalics
2014-12-20 11:52                       ` Joe Corneli
2014-12-20 14:49                         ` martin rudalics
2014-12-20 16:18                           ` Eli Zaretskii
2014-12-20 16:31                             ` martin rudalics
2014-12-20 16:47                               ` Eli Zaretskii
2014-12-20 17:51                                 ` martin rudalics
2014-12-20 18:29                                   ` Eli Zaretskii
2014-11-27 20:23       ` Joe Corneli
2014-11-28  7:27         ` martin rudalics
2014-11-27 16:17   ` Eli Zaretskii
2014-11-27 18:35     ` martin rudalics
2014-11-27 18:46       ` Eli Zaretskii
2014-11-27 19:58         ` martin rudalics
2014-11-27 20:37           ` Eli Zaretskii
2014-11-28  7:27             ` martin rudalics
2014-11-28  8:42               ` Eli Zaretskii
2022-02-10  8:16 ` bug#19194: bug#20022: 24.4.90; window-body-height, window-body-width wrong value after text-scale-adjust Lars Ingebrigtsen
2022-02-10 17:39   ` Drew Adams [this message]

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=SJ0PR10MB5488C871DFDC94D6E0784A48F32F9@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=19194@debbugs.gnu.org \
    --cc=20022@debbugs.gnu.org \
    --cc=holtzermann17@gmail.com \
    --cc=larsi@gnus.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).