summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2012-03-10 11:55:54 +0200
committerEli Zaretskii <eliz@gnu.org>2012-03-10 11:55:54 +0200
commit83a96c0872b75177c023b344ce3658d1653d09d4 (patch)
treefe07fbe52a2ca7a30914ed36eb896811ffa894da
parentb9e501dee818df6860341c561f2951699c1e48cc (diff)
downloademacs-83a96c0872b75177c023b344ce3658d1653d09d4.tar.gz
emacs-83a96c0872b75177c023b344ce3658d1653d09d4.tar.bz2
emacs-83a96c0872b75177c023b344ce3658d1653d09d4.zip
Warn against using `length' to compute display width of a string.
doc/lispref/strings.texi (String Basics): doc/lispref/sequences.texi (Sequence Functions): Mention that `length' is not appropriate for computing the string width on display; add a cross-reference to the description of `string-width'. (Bug#10978)
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/sequences.texi5
-rw-r--r--doc/lispref/strings.texi4
3 files changed, 13 insertions, 1 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 06d5c541875..201128b9757 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,5 +1,10 @@
2012-03-10 Eli Zaretskii <eliz@gnu.org>
+ * strings.texi (String Basics):
+ * sequences.texi (Sequence Functions): Mention that `length' is
+ not appropriate for computing the string width on display; add a
+ cross-reference to the description of `string-width'. (Bug#10978)
+
* eval.texi (Autoloading): Minor change of wording.
2012-03-10 Chong Yidong <cyd@gnu.org>
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 94f1bf666d2..50f75da2de8 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -108,6 +108,11 @@ Emacs character code.
@noindent
See also @code{string-bytes}, in @ref{Text Representations}.
+If you need to compute the width of a string on display, you should
+use @code{string-width} (@pxref{Width}), not @code{length}, since
+@code{length} only counts the number of characters, but does not
+account for the display width of each character.
+
@defun elt sequence index
@cindex elements of sequences
This function returns the element of @var{sequence} indexed by
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index bbb75f1474d..64d0986493a 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -51,7 +51,9 @@ C are terminated by a character with @acronym{ASCII} code 0.)
operate on them with the general array and sequence functions.
(@xref{Sequences Arrays Vectors}.) For example, you can access or
change individual characters in a string using the functions @code{aref}
-and @code{aset} (@pxref{Array Functions}).
+and @code{aset} (@pxref{Array Functions}). However, note that
+@code{length} should @emph{not} be used for computing the width of a
+string on display; use @code{string-width} (@pxref{Width}) instead.
There are two text representations for non-@acronym{ASCII} characters in
Emacs strings (and in buffers): unibyte and multibyte (@pxref{Text