[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

38.10 Width

Since not all characters have the same width, these functions let you check the width of a character. Voir la section Indentation Primitives, and Motion by Screen Lines, for related functions.

Function: char-width char

This function returns the width in columns of the character char, if it were displayed in the current buffer and the selected window.

Function: string-width string

This function returns the width in columns of the string string, if it were displayed in the current buffer and the selected window.

Function: truncate-string-to-width string width &optional start-column padding ellipsis

This function returns the part of string that fits within width columns, as a new string.

If string does not reach width, then the result ends where string ends. If one multi-column character in string extends across the column width, that character is not included in the result. Thus, the result can fall short of width but cannot go beyond it.

The optional argument start-column specifies the starting column. If this is non-nil, then the first start-column columns of the string are omitted from the value. If one multi-column character in string extends across the column start-column, that character is not included.

The optional argument padding, if non-nil, is a padding character added at the beginning and end of the result string, to extend it to exactly width columns. The padding character is used at the end of the result if it falls short of width. It is also used at the beginning of the result if one multi-column character in string extends across the column start-column.

If ellipsis is non-nil, it should be a string which will replace the end of str (including any padding) if it extends beyond end-column, unless the display width of str is equal to or less than the display width of ellipsis. If ellipsis is non-nil and not a string, it stands for "...".

 
(truncate-string-to-width "\tab\t" 12 4)
     ⇒ "ab"
(truncate-string-to-width "\tab\t" 12 4 ?\s)
     ⇒ "    ab  "

[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.