Subject: Re: bug#9949: 24.0.91; window-width function does not take text-scale-mode-amount into account

From: Eli Zaretskii <[email-masked]>
Date: Fri, 04 Nov 2011 12:25:57 +0200

> From: Josh <[email-masked]>
> Date: Thu, 3 Nov 2011 19:29:40 -0700
> 
> The window-width function does not take text scale adjustments
> into account.  This breaks code such as
> http://www.emacswiki.org/emacs/ErcFilling#toc2 which is meant to
> insert timestamps aligned to the right edge of the window.
> 
> To reproduce starting from emacs -Q,
> 1) M-: (window-width) RET  ; returns 80 here
> 2) C-x C-=                 ; window is now 70 characters wide
> 3) M-: (window-width) RET  ; still returns 80

This is a problem with imprecise documentation and incorrect
expectations that are caused by that.  window-width and window-height
report the window dimensions in frame's canonical units, i.e. for the
frame's default face.  Changing the font size does not, therefore,
affect the values they return.  AFAICS, this has been so since about
forever.

The code shown by the URL you cite should not use window-width.  It
should instead use posn-at-point after moving to the line end (e.g.,
with `end-of-visual-line').

I've updated the doc strings and the ELisp manual with this caveat and
committed that as trunk revision 106283.

If you are satisfied with this resolution, I will close the bug
report.  If not, then I think this should at best be tagged as
"wishlist", and it should request a different set of functions to
return the values you expected (because window-width and window-height
are used too widely to be able to sustain such a significant change in
functionality).

For someone to be able to implement these new functions, you (or
someone else) should come up with a specification of what they should
return in the presence of different faces in the window.  E.g., should
the function that returns the line's width return values for a
specific line, rather than for a window as a whole?  should it count
characters in that line or something else?  etc., etc.