Function: string-width
string-width is a function defined in character.c.
Signature
(string-width STRING &optional FROM TO)
Documentation
Return width of STRING when displayed in the current buffer.
Width is measured by how many columns it occupies on the screen.
Optional arguments FROM and TO specify the substring of STRING to
consider, and are interpreted as in substring.
When calculating width of a multibyte character in STRING,
only the base leading-code is considered; the validity of
the following bytes is not checked. Tabs in STRING are always
taken to occupy tab-width columns. The effect of faces and fonts
used for non-Latin and other unusual characters (such as emoji) is
ignored as well, as are display properties and invisible text.
For these reasons, the results are not generally reliable;
for accurate dimensions of text as it will be displayed,
use window-text-pixel-size instead.
Probably introduced at or before Emacs version 20.1.
Aliases
gnus-correct-length (obsolete since 27.1)
Source Code
// Defined in /usr/src/emacs/src/character.c
{
Lisp_Object val;
ptrdiff_t ifrom, ito;
CHECK_STRING (str);
validate_subarray (str, from, to, SCHARS (str), &ifrom, &ito);
XSETFASTINT (val, lisp_string_width (str, ifrom, ito, -1, NULL, NULL, true));
return val;
}