diff options
| author | Paul Eggert | 2020-04-18 12:59:17 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-04-18 13:01:08 -0700 |
| commit | eebfb72c906755c0a80d92c11deee7ac9faf5f4b (patch) | |
| tree | 01337499496e5024a1d0bfd52ae6f6574812559e /doc/lispref/strings.texi | |
| parent | 6c187ed6b0a2b103ebb55a5f037073c8c31492b3 (diff) | |
| download | emacs-eebfb72c906755c0a80d92c11deee7ac9faf5f4b.tar.gz emacs-eebfb72c906755c0a80d92c11deee7ac9faf5f4b.zip | |
Document constant vs mutable objects better
This patch builds on a suggested patch by Mattias EngdegÄrd
and on further comments by Eli Zaretskii.
Original bug report by Kevin Vigouroux (Bug#40671).
* doc/lispintro/emacs-lisp-intro.texi (set & setq, Review)
(setcar, Lists diagrammed, Mail Aliases, Indent Tabs Mode):
setq is a special form, not a function or command.
* doc/lispintro/emacs-lisp-intro.texi (setcar):
* doc/lispref/lists.texi (Modifying Lists, Rearrangement):
* doc/lispref/sequences.texi (Sequence Functions)
(Array Functions, Vectors):
* doc/lispref/strings.texi (String Basics, Modifying Strings):
Mention mutable vs constant objects.
* doc/lispintro/emacs-lisp-intro.texi (setcar, setcdr)
(kill-new function, cons & search-fwd Review):
* doc/lispref/edebug.texi (Printing in Edebug):
* doc/lispref/keymaps.texi (Changing Key Bindings):
* doc/lispref/lists.texi (Setcar, Setcdr, Rearrangement)
(Sets And Lists, Association Lists, Plist Access):
* doc/lispref/sequences.texi (Sequence Functions)
(Array Functions):
* doc/lispref/strings.texi (Text Comparison):
Fix examples so that they do not try to change constants.
Diffstat (limited to 'doc/lispref/strings.texi')
| -rw-r--r-- | doc/lispref/strings.texi | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index 14cabc5d79d..3acbf538dce 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi | |||
| @@ -51,10 +51,8 @@ by a distinguished character code. | |||
| 51 | operate on them with the general array and sequence functions documented | 51 | operate on them with the general array and sequence functions documented |
| 52 | in @ref{Sequences Arrays Vectors}. For example, you can access or | 52 | in @ref{Sequences Arrays Vectors}. For example, you can access or |
| 53 | change individual characters in a string using the functions @code{aref} | 53 | change individual characters in a string using the functions @code{aref} |
| 54 | and @code{aset} (@pxref{Array Functions}). However, note that | 54 | and @code{aset} (@pxref{Array Functions}). However, you should not |
| 55 | @code{length} should @emph{not} be used for computing the width of a | 55 | try to change the contents of constant strings (@pxref{Modifying Strings}). |
| 56 | string on display; use @code{string-width} (@pxref{Size of Displayed | ||
| 57 | Text}) instead. | ||
| 58 | 56 | ||
| 59 | There are two text representations for non-@acronym{ASCII} | 57 | There are two text representations for non-@acronym{ASCII} |
| 60 | characters in Emacs strings (and in buffers): unibyte and multibyte. | 58 | characters in Emacs strings (and in buffers): unibyte and multibyte. |
| @@ -89,6 +87,9 @@ copy them into buffers. @xref{Character Type}, and @ref{String Type}, | |||
| 89 | for information about the syntax of characters and strings. | 87 | for information about the syntax of characters and strings. |
| 90 | @xref{Non-ASCII Characters}, for functions to convert between text | 88 | @xref{Non-ASCII Characters}, for functions to convert between text |
| 91 | representations and to encode and decode character codes. | 89 | representations and to encode and decode character codes. |
| 90 | Also, note that @code{length} should @emph{not} be used for computing | ||
| 91 | the width of a string on display; use @code{string-width} (@pxref{Size | ||
| 92 | of Displayed Text}) instead. | ||
| 92 | 93 | ||
| 93 | @node Predicates for Strings | 94 | @node Predicates for Strings |
| 94 | @section Predicates for Strings | 95 | @section Predicates for Strings |
| @@ -380,6 +381,10 @@ usual value is @w{@code{"[ \f\t\n\r\v]+"}}. | |||
| 380 | @cindex modifying strings | 381 | @cindex modifying strings |
| 381 | @cindex string modification | 382 | @cindex string modification |
| 382 | 383 | ||
| 384 | You can alter the contents of a mutable string via operations | ||
| 385 | described in this section. However, you should not try to use these | ||
| 386 | operations to alter the contents of a constant string. | ||
| 387 | |||
| 383 | The most basic way to alter the contents of an existing string is with | 388 | The most basic way to alter the contents of an existing string is with |
| 384 | @code{aset} (@pxref{Array Functions}). @code{(aset @var{string} | 389 | @code{aset} (@pxref{Array Functions}). @code{(aset @var{string} |
| 385 | @var{idx} @var{char})} stores @var{char} into @var{string} at index | 390 | @var{idx} @var{char})} stores @var{char} into @var{string} at index |
| @@ -591,7 +596,7 @@ for sorting (@pxref{Sequence Functions}): | |||
| 591 | 596 | ||
| 592 | @example | 597 | @example |
| 593 | @group | 598 | @group |
| 594 | (sort '("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp) | 599 | (sort (list "11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp) |
| 595 | @result{} ("11" "1 1" "1.1" "12" "1 2" "1.2") | 600 | @result{} ("11" "1 1" "1.1" "12" "1 2" "1.2") |
| 596 | @end group | 601 | @end group |
| 597 | @end example | 602 | @end example |
| @@ -608,7 +613,7 @@ systems. The @var{locale} value of @code{"POSIX"} or @code{"C"} lets | |||
| 608 | 613 | ||
| 609 | @example | 614 | @example |
| 610 | @group | 615 | @group |
| 611 | (sort '("11" "12" "1 1" "1 2" "1.1" "1.2") | 616 | (sort (list "11" "12" "1 1" "1 2" "1.1" "1.2") |
| 612 | (lambda (s1 s2) (string-collate-lessp s1 s2 "POSIX"))) | 617 | (lambda (s1 s2) (string-collate-lessp s1 s2 "POSIX"))) |
| 613 | @result{} ("1 1" "1 2" "1.1" "1.2" "11" "12") | 618 | @result{} ("1 1" "1 2" "1.1" "1.2" "11" "12") |
| 614 | @end group | 619 | @end group |