In my environment, I can only enter 130 single-byte characters in one line in the actual buffer while window-width is returning 160. Apparently window-width is returning columns, not characters. Is there a way to convert columns to number of characters or to calculate the number using the columns and some attributes of current font?(for now, only the case of fixed-width one)

Actual reference values are:

window-width: 159

window-total-width: 160

window-pixel-width: 1602

window-font-width: 10

  • 1
    Show what the 130 characters are? Some chars are double-width etc.
    – Drew
    Mar 10, 2023 at 4:40
  • Fixed the question. Thanks.
    – roomworoof
    Mar 10, 2023 at 4:45

1 Answer 1


window-width (which is an alias for window-body-width) has nothing to do with the buffer text. It's not the length of the longest line, it's the width of the window (and in columns, as you surmised).


On a graphical display, the latter actually correspond to the height and width of a default character specified by the frame’s default font as returned by ‘frame-char-height’ and ‘frame-char-width’ (*note Frame Font::). Thus, if a window is displaying text with a different font or size, the reported line height and column width for that window may differ from the actual number of text lines or columns displayed within it.

See C-hig (elisp)Window Sizes

  • Yes I know that, but I want to know how many letters can be stored in one line of current window(Is it possible to calculate using the columns and some attributes of current font?), regardless of what is entered currently in current-buffer.
    – roomworoof
    Mar 10, 2023 at 5:15
  • 1
    How many of which letters? Any given character may be a different width to any other character.
    – phils
    Mar 10, 2023 at 5:20
  • Maybe you want window-font-width ?
    – phils
    Mar 10, 2023 at 5:21
  • window-font-width: 10(shown in the question) might be used like (/ (window-pixel-width) (window-font-width)) to calculate window-width internal? It seems that the number I want does not come out from this value.
    – roomworoof
    Mar 10, 2023 at 5:44
  • 2
    With your accurate suggestions, I've come to feel like there is no such method because the calculation for the number of characters from window-width is nonsense in a world where there are variable-width fonts.
    – roomworoof
    Mar 10, 2023 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.