aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref
diff options
context:
space:
mode:
authorGlenn Morris2020-04-20 07:50:19 -0700
committerGlenn Morris2020-04-20 07:50:19 -0700
commit477b9eaf45da1ebc4f2117d69df3571f0bf61e47 (patch)
tree4600314923713c339c41cd450f50e64c3f16a8aa /doc/lispref
parent80f04b5d7c817977a365a999693443c4e04e5223 (diff)
parent05089a4d65831c5e873956f5f2d92a3d5672d405 (diff)
downloademacs-477b9eaf45da1ebc4f2117d69df3571f0bf61e47.tar.gz
emacs-477b9eaf45da1ebc4f2117d69df3571f0bf61e47.zip
Merge from origin/emacs-27
05089a4d65 (origin/emacs-27) Tweak wording re constant variables a1040861f1 Tweak setcar-related wording 751510f865 * lisp/image-mode.el: Add prefix key 's' and reduce depend... 9261a219ec * doc/emacs/windows.texi (Window Convenience): Decribe mor... e1d42da0d6 Fix mutability glitches reported by Drew Adams 5805df74f5 Improve mutability doc dca35b31d0 Improve mutability documentation 81e7d7f111 Document that quoting yields constants 5734339f40 * doc/lispref/keymaps.texi (Extended Menu Items, Easy Menu... 14a570afae Remove #' and function quoting from lambda forms in manual d5ec18c66b * src/regex-emacs.c (re_match_2_internal): Rework comment ... 4df8a61117 Add new node "Image Mode" to Emacs Manual. d7d5ee6c57 ; Fix a typo in cmdargs.texi (bug#40701) 5e9db48fbe * doc/lispref/display.texi (Customizing Bitmaps): Fix typo. eebfb72c90 Document constant vs mutable objects better 6c187ed6b0 Improve documentation of 'sort-lines' 52288f4b66 Mention 'spam-stat-process-directory-age' in the documenta... 067b070598 ; Fix some typos and doc issues (bug#40695) # Conflicts: # etc/NEWS
Diffstat (limited to 'doc/lispref')
-rw-r--r--doc/lispref/abbrevs.texi6
-rw-r--r--doc/lispref/backups.texi2
-rw-r--r--doc/lispref/display.texi6
-rw-r--r--doc/lispref/edebug.texi2
-rw-r--r--doc/lispref/elisp.texi1
-rw-r--r--doc/lispref/eval.texi15
-rw-r--r--doc/lispref/functions.texi4
-rw-r--r--doc/lispref/help.texi56
-rw-r--r--doc/lispref/keymaps.texi33
-rw-r--r--doc/lispref/lists.texi68
-rw-r--r--doc/lispref/objects.texi48
-rw-r--r--doc/lispref/os.texi2
-rw-r--r--doc/lispref/sequences.texi51
-rw-r--r--doc/lispref/strings.texi18
-rw-r--r--doc/lispref/syntax.texi6
-rw-r--r--doc/lispref/text.texi13
16 files changed, 205 insertions, 126 deletions
diff --git a/doc/lispref/abbrevs.texi b/doc/lispref/abbrevs.texi
index 6689b560c78..575be187d3f 100644
--- a/doc/lispref/abbrevs.texi
+++ b/doc/lispref/abbrevs.texi
@@ -370,9 +370,9 @@ definitions of @code{local-abbrev-table} and @code{text-mode-abbrev-table}.
370 (funcall expand)))) 370 (funcall expand))))
371 371
372(add-hook 'foo-mode-hook 372(add-hook 'foo-mode-hook
373 #'(lambda () 373 (lambda ()
374 (add-function :around (local 'abbrev-expand-function) 374 (add-function :around (local 'abbrev-expand-function)
375 #'foo-mode-abbrev-expand-function))) 375 #'foo-mode-abbrev-expand-function)))
376@end smallexample 376@end smallexample
377 377
378@node Standard Abbrev Tables 378@node Standard Abbrev Tables
diff --git a/doc/lispref/backups.texi b/doc/lispref/backups.texi
index b7318a99b8f..4ed1a10fcf6 100644
--- a/doc/lispref/backups.texi
+++ b/doc/lispref/backups.texi
@@ -807,7 +807,7 @@ If you just want to automatically auto-revert every
807 807
808@example 808@example
809(setq-local buffer-stale-function 809(setq-local buffer-stale-function
810 #'(lambda (&optional noconfirm) 'fast)) 810 (lambda (&optional noconfirm) 'fast))
811@end example 811@end example
812 812
813@noindent 813@noindent
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 132a3c85354..e01cfedc4b8 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -4358,7 +4358,7 @@ height.
4358@end defun 4358@end defun
4359 4359
4360@defun destroy-fringe-bitmap bitmap 4360@defun destroy-fringe-bitmap bitmap
4361This function destroy the fringe bitmap identified by @var{bitmap}. 4361This function destroys the fringe bitmap identified by @var{bitmap}.
4362If @var{bitmap} identifies a standard fringe bitmap, it actually 4362If @var{bitmap} identifies a standard fringe bitmap, it actually
4363restores the standard definition of that bitmap, instead of 4363restores the standard definition of that bitmap, instead of
4364eliminating it entirely. 4364eliminating it entirely.
@@ -6926,7 +6926,7 @@ end of the buffer continues from the other end. If
6926is displayed. Any button with a non-@code{nil} @code{skip} property 6926is displayed. Any button with a non-@code{nil} @code{skip} property
6927is skipped over. Returns the button found, and signals an error if no 6927is skipped over. Returns the button found, and signals an error if no
6928buttons can be found. If @var{no-error} in non-@code{nil}, return nil 6928buttons can be found. If @var{no-error} in non-@code{nil}, return nil
6929instead of signalling the error. 6929instead of signaling the error.
6930@end deffn 6930@end deffn
6931 6931
6932@deffn Command backward-button n &optional wrap display-message 6932@deffn Command backward-button n &optional wrap display-message
@@ -6938,7 +6938,7 @@ end of the buffer continues from the other end. If
6938is displayed. Any button with a non-@code{nil} @code{skip} property 6938is displayed. Any button with a non-@code{nil} @code{skip} property
6939is skipped over. Returns the button found, and signals an error if no 6939is skipped over. Returns the button found, and signals an error if no
6940buttons can be found. If @var{no-error} in non-@code{nil}, return nil 6940buttons can be found. If @var{no-error} in non-@code{nil}, return nil
6941instead of signalling the error. 6941instead of signaling the error.
6942@end deffn 6942@end deffn
6943 6943
6944@defun next-button pos &optional count-current 6944@defun next-button pos &optional count-current
diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi
index cfef5c12d1e..5970e7cf801 100644
--- a/doc/lispref/edebug.texi
+++ b/doc/lispref/edebug.texi
@@ -858,7 +858,7 @@ to a non-@code{nil} value.
858 Here is an example of code that creates a circular structure: 858 Here is an example of code that creates a circular structure:
859 859
860@example 860@example
861(setq a '(x y)) 861(setq a (list 'x 'y))
862(setcar a a) 862(setcar a a)
863@end example 863@end example
864 864
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index cfd96f7aa68..bba1b63115f 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -297,6 +297,7 @@ Lisp Data Types
297* Circular Objects:: Read syntax for circular structure. 297* Circular Objects:: Read syntax for circular structure.
298* Type Predicates:: Tests related to types. 298* Type Predicates:: Tests related to types.
299* Equality Predicates:: Tests of equality between any two objects. 299* Equality Predicates:: Tests of equality between any two objects.
300* Constants and Mutability:: Whether an object's value can change.
300 301
301Programming Types 302Programming Types
302 303
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi
index f6f36ed3427..021604c5142 100644
--- a/doc/lispref/eval.texi
+++ b/doc/lispref/eval.texi
@@ -158,6 +158,12 @@ contents unchanged.
158@end group 158@end group
159@end example 159@end example
160 160
161 A self-evaluating form yields constant conses, vectors and strings, and you
162should not attempt to modify their contents via @code{setcar}, @code{aset} or
163similar operations. The Lisp interpreter might unify the constants
164yielded by your program's self-evaluating forms, so that these
165constants might share structure. @xref{Constants and Mutability}.
166
161 It is common to write numbers, characters, strings, and even vectors 167 It is common to write numbers, characters, strings, and even vectors
162in Lisp code, taking advantage of the fact that they self-evaluate. 168in Lisp code, taking advantage of the fact that they self-evaluate.
163However, it is quite unusual to do this for types that lack a read 169However, it is quite unusual to do this for types that lack a read
@@ -558,6 +564,8 @@ and vectors.)
558 564
559@defspec quote object 565@defspec quote object
560This special form returns @var{object}, without evaluating it. 566This special form returns @var{object}, without evaluating it.
567The returned value is a constant, and should not be modified.
568@xref{Constants and Mutability}.
561@end defspec 569@end defspec
562 570
563@cindex @samp{'} for quoting 571@cindex @samp{'} for quoting
@@ -612,10 +620,12 @@ only part of a list, while computing and substituting other parts.
612 620
613 @dfn{Backquote constructs} allow you to quote a list, but 621 @dfn{Backquote constructs} allow you to quote a list, but
614selectively evaluate elements of that list. In the simplest case, it 622selectively evaluate elements of that list. In the simplest case, it
615is identical to the special form @code{quote} 623is identical to the special form
616@iftex 624@iftex
625@code{quote}.
617@end iftex 626@end iftex
618@ifnottex 627@ifnottex
628@code{quote}
619(described in the previous section; @pxref{Quoting}). 629(described in the previous section; @pxref{Quoting}).
620@end ifnottex 630@end ifnottex
621For example, these two forms yield identical results: 631For example, these two forms yield identical results:
@@ -693,6 +703,9 @@ Here are some examples:
693@end group 703@end group
694@end example 704@end example
695 705
706If a subexpression of a backquote construct has no substitutions or
707splices, it acts like @code{quote} in that it yields constant conses,
708vectors and strings that should not be modified.
696 709
697@node Eval 710@node Eval
698@section Eval 711@section Eval
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 5cf67ba6473..bc8ec0ef1b0 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -970,7 +970,7 @@ string.
970@end group 970@end group
971 971
972@group 972@group
973(mapconcat (function (lambda (x) (format "%c" (1+ x)))) 973(mapconcat (lambda (x) (format "%c" (1+ x)))
974 "HAL-8000" 974 "HAL-8000"
975 "") 975 "")
976 @result{} "IBM.9111" 976 @result{} "IBM.9111"
@@ -2287,7 +2287,7 @@ function) as a generalized variable. @var{setter} can be a symbol in which
2287case it will be passed to @code{gv-define-simple-setter}, or it can be of the 2287case it will be passed to @code{gv-define-simple-setter}, or it can be of the
2288form @code{(lambda (@var{arg}) @var{body})} in which case that function will 2288form @code{(lambda (@var{arg}) @var{body})} in which case that function will
2289additionally have access to the macro (or function)'s arguments and it will 2289additionally have access to the macro (or function)'s arguments and it will
2290passed to @code{gv-define-setter}. 2290be passed to @code{gv-define-setter}.
2291 2291
2292@end table 2292@end table
2293 2293
diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi
index eea1fd2e8f1..9b3c4fcb23d 100644
--- a/doc/lispref/help.texi
+++ b/doc/lispref/help.texi
@@ -175,49 +175,47 @@ All symbols that have PATTERN in their name are described
175in the *Help* buffer." 175in the *Help* buffer."
176 (interactive "sDescribe symbols matching: ") 176 (interactive "sDescribe symbols matching: ")
177 (let ((describe-func 177 (let ((describe-func
178 (function 178 (lambda (s)
179 (lambda (s)
180@end group 179@end group
181@group 180@group
182 ;; @r{Print description of symbol.} 181 ;; @r{Print description of symbol.}
183 (if (fboundp s) ; @r{It is a function.} 182 (if (fboundp s) ; @r{It is a function.}
184 (princ 183 (princ
185 (format "%s\t%s\n%s\n\n" s 184 (format "%s\t%s\n%s\n\n" s
186 (if (commandp s) 185 (if (commandp s)
187 (let ((keys (where-is-internal s))) 186 (let ((keys (where-is-internal s)))
188 (if keys 187 (if keys
189 (concat 188 (concat
190 "Keys: " 189 "Keys: "
191 (mapconcat 'key-description 190 (mapconcat 'key-description
192 keys " ")) 191 keys " "))
193 "Keys: none")) 192 "Keys: none"))
194 "Function") 193 "Function")
195@end group 194@end group
196@group 195@group
197 (or (documentation s) 196 (or (documentation s)
198 "not documented")))) 197 "not documented"))))
199 198
200 (if (boundp s) ; @r{It is a variable.} 199 (if (boundp s) ; @r{It is a variable.}
201@end group 200@end group
202@group 201@group
203 (princ 202 (princ
204 (format "%s\t%s\n%s\n\n" s 203 (format "%s\t%s\n%s\n\n" s
205 (if (custom-variable-p s) 204 (if (custom-variable-p s)
206 "Option " "Variable") 205 "Option " "Variable")
207@end group 206@end group
208@group 207@group
209 (or (documentation-property 208 (or (documentation-property
210 s 'variable-documentation) 209 s 'variable-documentation)
211 "not documented"))))))) 210 "not documented"))))))
212 sym-list) 211 sym-list)
213@end group 212@end group
214 213
215@group 214@group
216 ;; @r{Build a list of symbols that match pattern.} 215 ;; @r{Build a list of symbols that match pattern.}
217 (mapatoms (function 216 (mapatoms (lambda (sym)
218 (lambda (sym) 217 (if (string-match pattern (symbol-name sym))
219 (if (string-match pattern (symbol-name sym)) 218 (setq sym-list (cons sym sym-list)))))
220 (setq sym-list (cons sym sym-list))))))
221@end group 219@end group
222 220
223@group 221@group
diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi
index 2c90d208c02..130ff0d8671 100644
--- a/doc/lispref/keymaps.texi
+++ b/doc/lispref/keymaps.texi
@@ -1441,10 +1441,10 @@ Here is an example showing a keymap before and after substitution:
1441 1441
1442@smallexample 1442@smallexample
1443@group 1443@group
1444(setq map '(keymap 1444(setq map (list 'keymap
1445 (?1 . olddef-1) 1445 (cons ?1 olddef-1)
1446 (?2 . olddef-2) 1446 (cons ?2 olddef-2)
1447 (?3 . olddef-1))) 1447 (cons ?3 olddef-1)))
1448@result{} (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1)) 1448@result{} (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1))
1449@end group 1449@end group
1450 1450
@@ -2226,14 +2226,11 @@ right value for selecting that button. Clicking on the button should
2226set the variable so that the button you clicked on becomes selected. 2226set the variable so that the button you clicked on becomes selected.
2227 2227
2228@item :key-sequence @var{key-sequence} 2228@item :key-sequence @var{key-sequence}
2229This property specifies which key sequence is likely to be bound to the 2229This property specifies which key sequence to display as keyboard equivalent.
2230same command invoked by this menu item. If you specify a correct key 2230Before Emacs displays @var{key-sequence} in the menu, it verifies that
2231sequence, that sequence will be preferred over others. 2231@var{key-sequence} is really equivalent to this menu item, so it only
2232 2232has an effect if you specify a correct key sequence.
2233If you specify an incorrect key sequence, it has no effect; before Emacs 2233Specifying @code{nil} for @var{key-sequence} is equivalent to the
2234displays @var{key-sequence} in the menu, it verifies that
2235@var{key-sequence} is really equivalent to this menu item. Specifying
2236@code{nil} for @var{key-sequence} is equivalent to the
2237@code{:key-sequence} attribute being absent. 2234@code{:key-sequence} attribute being absent.
2238 2235
2239@item :keys @var{string} 2236@item :keys @var{string}
@@ -2916,17 +2913,17 @@ the following:
2916 2913
2917@table @code 2914@table @code
2918@item :keys @var{keys} 2915@item :keys @var{keys}
2919@var{keys} is a keyboard equivalent to the menu item (a string). This 2916@var{keys} is a string to display as keyboard equivalent to the menu item.
2920is normally not needed, as keyboard equivalents are computed 2917This is normally not needed, as keyboard equivalents are computed
2921automatically. @var{keys} is expanded with 2918automatically. @var{keys} is expanded with
2922@code{substitute-command-keys} before it is displayed (@pxref{Keys in 2919@code{substitute-command-keys} before it is displayed (@pxref{Keys in
2923Documentation}). 2920Documentation}).
2924 2921
2925@item :key-sequence @var{keys} 2922@item :key-sequence @var{keys}
2926@var{keys} is a hint for speeding up Emacs's first display of the 2923@var{keys} is a hint indicating which key sequence to display as
2927menu. It should be @code{nil} if you know that the menu item has no keyboard 2924keyboard equivalent, in case the command is bound to several key sequences.
2928equivalent; otherwise it should be a string or vector specifying a 2925It has no effect if @var{keys} is not bound to same command as this
2929keyboard equivalent for the menu item. 2926menu item.
2930 2927
2931@item :active @var{enable} 2928@item :active @var{enable}
2932@var{enable} is an expression; if it evaluates to @code{nil}, the item 2929@var{enable} is an expression; if it evaluates to @code{nil}, the item
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi
index 27fa5385e35..1125af7bec3 100644
--- a/doc/lispref/lists.texi
+++ b/doc/lispref/lists.texi
@@ -866,10 +866,15 @@ foo ;; @r{@code{foo} was changed.}
866@node Modifying Lists 866@node Modifying Lists
867@section Modifying Existing List Structure 867@section Modifying Existing List Structure
868@cindex destructive list operations 868@cindex destructive list operations
869@cindex mutable lists
869 870
870 You can modify the @sc{car} and @sc{cdr} contents of a cons cell with the 871 You can modify the @sc{car} and @sc{cdr} contents of a cons cell with the
871primitives @code{setcar} and @code{setcdr}. These are destructive 872primitives @code{setcar} and @code{setcdr}. These are destructive
872operations because they change existing list structure. 873operations because they change existing list structure.
874Destructive operations should be applied only to mutable lists,
875that is, lists constructed via @code{cons}, @code{list} or similar
876operations. Lists created by quoting are constants and should not be
877changed by destructive operations. @xref{Constants and Mutability}.
873 878
874@cindex CL note---@code{rplaca} vs @code{setcar} 879@cindex CL note---@code{rplaca} vs @code{setcar}
875@quotation 880@quotation
@@ -906,7 +911,7 @@ value @var{object}. For example:
906 911
907@example 912@example
908@group 913@group
909(setq x '(1 2)) 914(setq x (list 1 2)) ; @r{Create a mutable list.}
910 @result{} (1 2) 915 @result{} (1 2)
911@end group 916@end group
912@group 917@group
@@ -926,8 +931,8 @@ these lists. Here is an example:
926 931
927@example 932@example
928@group 933@group
929;; @r{Create two lists that are partly shared.} 934;; @r{Create two mutable lists that are partly shared.}
930(setq x1 '(a b c)) 935(setq x1 (list 'a 'b 'c))
931 @result{} (a b c) 936 @result{} (a b c)
932(setq x2 (cons 'z (cdr x1))) 937(setq x2 (cons 'z (cdr x1)))
933 @result{} (z b c) 938 @result{} (z b c)
@@ -1017,11 +1022,11 @@ reached via the @sc{cdr}.
1017 1022
1018@example 1023@example
1019@group 1024@group
1020(setq x '(1 2 3)) 1025(setq x (list 1 2 3)) ; @r{Create a mutable list.}
1021 @result{} (1 2 3) 1026 @result{} (1 2 3)
1022@end group 1027@end group
1023@group 1028@group
1024(setcdr x '(4)) 1029(setcdr x '(4)) ; @r{Modify the list's tail to be a constant list.}
1025 @result{} (4) 1030 @result{} (4)
1026@end group 1031@end group
1027@group 1032@group
@@ -1037,7 +1042,7 @@ the @sc{cdr} of the first cons cell:
1037 1042
1038@example 1043@example
1039@group 1044@group
1040(setq x1 '(a b c)) 1045(setq x1 (list 'a 'b 'c))
1041 @result{} (a b c) 1046 @result{} (a b c)
1042(setcdr x1 (cdr (cdr x1))) 1047(setcdr x1 (cdr (cdr x1)))
1043 @result{} (c) 1048 @result{} (c)
@@ -1069,7 +1074,7 @@ of this list.
1069 1074
1070@example 1075@example
1071@group 1076@group
1072(setq x1 '(a b c)) 1077(setq x1 (list 'a 'b 'c))
1073 @result{} (a b c) 1078 @result{} (a b c)
1074(setcdr x1 (cons 'd (cdr x1))) 1079(setcdr x1 (cons 'd (cdr x1)))
1075 @result{} (d b c) 1080 @result{} (d b c)
@@ -1130,11 +1135,11 @@ Unlike @code{append} (@pxref{Building Lists}), the @var{lists} are
1130 1135
1131@example 1136@example
1132@group 1137@group
1133(setq x '(1 2 3)) 1138(setq x (list 1 2 3)) ; @r{Create a mutable list.}
1134 @result{} (1 2 3) 1139 @result{} (1 2 3)
1135@end group 1140@end group
1136@group 1141@group
1137(nconc x '(4 5)) 1142(nconc x '(4 5)) ; @r{Modify the list's tail to be a constant list.}
1138 @result{} (1 2 3 4 5) 1143 @result{} (1 2 3 4 5)
1139@end group 1144@end group
1140@group 1145@group
@@ -1150,7 +1155,7 @@ list:
1150 1155
1151@example 1156@example
1152@group 1157@group
1153(setq x '(1 2 3)) 1158(setq x (list 1 2 3))
1154 @result{} (1 2 3) 1159 @result{} (1 2 3)
1155@end group 1160@end group
1156@group 1161@group
@@ -1163,11 +1168,13 @@ x
1163@end group 1168@end group
1164@end example 1169@end example
1165 1170
1166However, the other arguments (all but the last) must be lists. 1171However, the other arguments (all but the last) should be mutable lists.
1167 1172
1168A common pitfall is to use a quoted constant list as a non-last 1173A common pitfall is to use a constant list as a non-last
1169argument to @code{nconc}. If you do this, your program will change 1174argument to @code{nconc}. If you do this, the resulting behavior
1170each time you run it! Here is what happens: 1175is undefined. It is possible that your program will change
1176each time you run it! Here is what might happen (though this
1177is not guaranteed to happen):
1171 1178
1172@smallexample 1179@smallexample
1173@group 1180@group
@@ -1270,7 +1277,7 @@ removing it involves changing the @sc{cdr}s (@pxref{Setcdr}).
1270 1277
1271@example 1278@example
1272@group 1279@group
1273(setq sample-list '(a b c (4))) 1280(setq sample-list (list 'a 'b 'c '(4)))
1274 @result{} (a b c (4)) 1281 @result{} (a b c (4))
1275@end group 1282@end group
1276@group 1283@group
@@ -1303,12 +1310,12 @@ into the variable that held the original list:
1303(setq flowers (delq 'rose flowers)) 1310(setq flowers (delq 'rose flowers))
1304@end example 1311@end example
1305 1312
1306In the following example, the @code{(4)} that @code{delq} attempts to match 1313In the following example, the @code{(list 4)} that @code{delq} attempts to match
1307and the @code{(4)} in the @code{sample-list} are not @code{eq}: 1314and the @code{(4)} in the @code{sample-list} are @code{equal} but not @code{eq}:
1308 1315
1309@example 1316@example
1310@group 1317@group
1311(delq '(4) sample-list) 1318(delq (list 4) sample-list)
1312 @result{} (a c (4)) 1319 @result{} (a c (4))
1313@end group 1320@end group
1314@end example 1321@end example
@@ -1324,7 +1331,7 @@ of @code{list}.
1324 1331
1325@example 1332@example
1326@group 1333@group
1327(setq sample-list '(a b c a b c)) 1334(setq sample-list (list 'a 'b 'c 'a 'b 'c))
1328 @result{} (a b c a b c) 1335 @result{} (a b c a b c)
1329@end group 1336@end group
1330@group 1337@group
@@ -1349,12 +1356,12 @@ Compare this with @code{memq}:
1349 1356
1350@example 1357@example
1351@group 1358@group
1352(memql 1.2 '(1.1 1.2 1.3)) ; @r{@code{1.2} and @code{1.2} are @code{eql}.} 1359(memql 1.2 '(1.1 1.2 1.3)) ; @r{@code{1.2} and @code{1.2} must be @code{eql}.}
1353 @result{} (1.2 1.3) 1360 @result{} (1.2 1.3)
1354@end group 1361@end group
1355@group 1362@group
1356(memq 1.2 '(1.1 1.2 1.3)) ; @r{@code{1.2} and @code{1.2} are not @code{eq}.} 1363(memq 1.2 '(1.1 1.2 1.3)) ; @r{@code{1.2} and @code{1.2} need not be @code{eq}.}
1357 @result{} nil 1364 @result{} nil ; @r{... or it might be @code{(1.2 1.3)}.}
1358@end group 1365@end group
1359@end example 1366@end example
1360@end defun 1367@end defun
@@ -1373,11 +1380,11 @@ Compare this with @code{memq}:
1373 1380
1374@example 1381@example
1375@group 1382@group
1376(member '(2) '((1) (2))) ; @r{@code{(2)} and @code{(2)} are @code{equal}.} 1383(member (list 2) '((1) (2))) ; @r{@code{(list 2)} and @code{(2)} are @code{equal}.}
1377 @result{} ((2)) 1384 @result{} ((2))
1378@end group 1385@end group
1379@group 1386@group
1380(memq '(2) '((1) (2))) ; @r{@code{(2)} and @code{(2)} are not @code{eq}.} 1387(memq (list 2) '((1) (2))) ; @r{@code{(list 2)} and @code{(2)} are not @code{eq}.}
1381 @result{} nil 1388 @result{} nil
1382@end group 1389@end group
1383@group 1390@group
@@ -1407,7 +1414,7 @@ For example:
1407 1414
1408@example 1415@example
1409@group 1416@group
1410(setq l '((2) (1) (2))) 1417(setq l (list '(2) '(1) '(2)))
1411(delete '(2) l) 1418(delete '(2) l)
1412 @result{} ((1)) 1419 @result{} ((1))
1413l 1420l
@@ -1416,7 +1423,7 @@ l
1416;; @r{write @code{(setq l (delete '(2) l))}.} 1423;; @r{write @code{(setq l (delete '(2) l))}.}
1417@end group 1424@end group
1418@group 1425@group
1419(setq l '((2) (1) (2))) 1426(setq l (list '(2) '(1) '(2)))
1420(delete '(1) l) 1427(delete '(1) l)
1421 @result{} ((2) (2)) 1428 @result{} ((2) (2))
1422l 1429l
@@ -1618,9 +1625,10 @@ keys may not be symbols:
1618 '(("simple leaves" . oak) 1625 '(("simple leaves" . oak)
1619 ("compound leaves" . horsechestnut))) 1626 ("compound leaves" . horsechestnut)))
1620 1627
1621(assq "simple leaves" leaves) 1628;; @r{The @code{copy-sequence} means the keys are not @code{eq}.}
1629(assq (copy-sequence "simple leaves") leaves)
1622 @result{} nil 1630 @result{} nil
1623(assoc "simple leaves" leaves) 1631(assoc (copy-sequence "simple leaves") leaves)
1624 @result{} ("simple leaves" . oak) 1632 @result{} ("simple leaves" . oak)
1625@end smallexample 1633@end smallexample
1626@end defun 1634@end defun
@@ -1759,7 +1767,7 @@ correct results, use the return value of @code{assq-delete-all} rather
1759than looking at the saved value of @var{alist}. 1767than looking at the saved value of @var{alist}.
1760 1768
1761@example 1769@example
1762(setq alist '((foo 1) (bar 2) (foo 3) (lose 4))) 1770(setq alist (list '(foo 1) '(bar 2) '(foo 3) '(lose 4)))
1763 @result{} ((foo 1) (bar 2) (foo 3) (lose 4)) 1771 @result{} ((foo 1) (bar 2) (foo 3) (lose 4))
1764(assq-delete-all 'foo alist) 1772(assq-delete-all 'foo alist)
1765 @result{} ((bar 2) (lose 4)) 1773 @result{} ((bar 2) (lose 4))
@@ -1926,7 +1934,7 @@ function returns the modified property list, so you can store that back
1926in the place where you got @var{plist}. For example, 1934in the place where you got @var{plist}. For example,
1927 1935
1928@example 1936@example
1929(setq my-plist '(bar t foo 4)) 1937(setq my-plist (list 'bar t 'foo 4))
1930 @result{} (bar t foo 4) 1938 @result{} (bar t foo 4)
1931(setq my-plist (plist-put my-plist 'foo 69)) 1939(setq my-plist (plist-put my-plist 'foo 69))
1932 @result{} (bar t foo 69) 1940 @result{} (bar t foo 69)
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi
index 855dff2130a..3e9f2221020 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -46,6 +46,10 @@ you store in it, type and all. (Actually, a small number of Emacs
46Lisp variables can only take on values of a certain type. 46Lisp variables can only take on values of a certain type.
47@xref{Variables with Restricted Values}.) 47@xref{Variables with Restricted Values}.)
48 48
49 Some Lisp objects are @dfn{constant}: their values never change.
50Others are @dfn{mutable}: their values can be changed via destructive
51operations that involve side effects.
52
49 This chapter describes the purpose, printed representation, and read 53 This chapter describes the purpose, printed representation, and read
50syntax of each of the standard types in GNU Emacs Lisp. Details on how 54syntax of each of the standard types in GNU Emacs Lisp. Details on how
51to use these types can be found in later chapters. 55to use these types can be found in later chapters.
@@ -59,6 +63,7 @@ to use these types can be found in later chapters.
59* Circular Objects:: Read syntax for circular structure. 63* Circular Objects:: Read syntax for circular structure.
60* Type Predicates:: Tests related to types. 64* Type Predicates:: Tests related to types.
61* Equality Predicates:: Tests of equality between any two objects. 65* Equality Predicates:: Tests of equality between any two objects.
66* Constants and Mutability:: Whether an object's value can change.
62@end menu 67@end menu
63 68
64@node Printed Representation 69@node Printed Representation
@@ -2377,3 +2382,46 @@ that for two strings to be equal, they have the same text properties.
2377@end group 2382@end group
2378@end example 2383@end example
2379@end defun 2384@end defun
2385
2386@node Constants and Mutability
2387@section Constants and Mutability
2388@cindex constants
2389@cindex mutable objects
2390
2391 Some Lisp objects are constant: their values never change.
2392For example, you can create a new integer by calculating one, but you
2393cannot modify the value of an existing integer.
2394
2395 Other Lisp objects are mutable: their values can be changed
2396via destructive operations involving side effects. For example, an
2397existing marker can be changed by moving the marker to point to
2398somewhere else.
2399
2400 Although numbers are always constants and markers are always
2401mutable, some types contain both constant and mutable members. These
2402types include conses, vectors, strings, and symbols. For example, the string
2403literal @code{"aaa"} yields a constant string, whereas the function
2404call @code{(make-string 3 ?a)} yields a mutable string that can be
2405changed via later calls to @code{aset}.
2406
2407 Trying to modify a constant variable signals an error
2408(@pxref{Constant Variables}).
2409A program should not attempt to modify other types of constants because the
2410resulting behavior is undefined: the Lisp interpreter might or might
2411not detect the error, and if it does not detect the error the
2412interpreter can behave unpredictably thereafter. Another way to put
2413this is that although mutable objects are safe to change and constant
2414symbols reliably reject attempts to change them, other constants are
2415not safely mutable: if you try to change one your program might
2416behave as you expect but it might crash or worse. This problem occurs
2417with types that have both constant and mutable members, and that have
2418mutators like @code{setcar} and @code{aset} that are valid on mutable
2419objects but hazardous on constants.
2420
2421 When the same constant occurs multiple times in a program, the Lisp
2422interpreter might save time or space by reusing existing constants or
2423constant components. For example, @code{(eq "abc" "abc")} returns
2424@code{t} if the interpreter creates only one instance of the string
2425constant @code{"abc"}, and returns @code{nil} if it creates two
2426instances. Lisp programs should be written so that they work
2427regardless of whether this optimization is in use.
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index e72858bbf1a..5c0b1e2edf0 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -2617,7 +2617,7 @@ if it is non-@code{nil}; this can be overridden by binding
2617This variable is non-@code{nil} when Emacs is running in batch mode. 2617This variable is non-@code{nil} when Emacs is running in batch mode.
2618@end defvar 2618@end defvar
2619 2619
2620If Emacs exits due to signalling an error in batch mode, the exit 2620If Emacs exits due to signaling an error in batch mode, the exit
2621status of the Emacs command is non-zero: 2621status of the Emacs command is non-zero:
2622 2622
2623@example 2623@example
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 1a3a04f680b..1cb0d05cc7b 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -183,11 +183,11 @@ for other ways to copy sequences.
183 183
184@example 184@example
185@group 185@group
186(setq bar '(1 2)) 186(setq bar (list 1 2)) ; @r{Create a mutable list.}
187 @result{} (1 2) 187 @result{} (1 2)
188@end group 188@end group
189@group 189@group
190(setq x (vector 'foo bar)) 190(setq x (vector 'foo bar)) ; @r{Create a mutable vector.}
191 @result{} [foo (1 2)] 191 @result{} [foo (1 2)]
192@end group 192@end group
193@group 193@group
@@ -278,7 +278,7 @@ Unlike @code{reverse} the original @var{sequence} may be modified.
278 278
279@example 279@example
280@group 280@group
281(setq x '(a b c)) 281(setq x (list 'a 'b 'c)) ; @r{Create a mutable list.}
282 @result{} (a b c) 282 @result{} (a b c)
283@end group 283@end group
284@group 284@group
@@ -320,7 +320,7 @@ presented graphically:
320 For the vector, it is even simpler because you don't need setq: 320 For the vector, it is even simpler because you don't need setq:
321 321
322@example 322@example
323(setq x [1 2 3 4]) 323(setq x (copy-sequence [1 2 3 4])) ; @r{Create a mutable vector.}
324 @result{} [1 2 3 4] 324 @result{} [1 2 3 4]
325(nreverse x) 325(nreverse x)
326 @result{} [4 3 2 1] 326 @result{} [4 3 2 1]
@@ -330,7 +330,7 @@ x
330 330
331Note that unlike @code{reverse}, this function doesn't work with strings. 331Note that unlike @code{reverse}, this function doesn't work with strings.
332Although you can alter string data by using @code{aset}, it is strongly 332Although you can alter string data by using @code{aset}, it is strongly
333encouraged to treat strings as immutable. 333encouraged to treat strings as immutable even when they are mutable.
334 334
335@end defun 335@end defun
336 336
@@ -374,11 +374,11 @@ appears in a different position in the list due to the change of
374 374
375@example 375@example
376@group 376@group
377(setq nums '(1 3 2 6 5 4 0)) 377(setq nums (list 1 3 2 6 5 4 0)) ; @r{Create a mutable list.}
378 @result{} (1 3 2 6 5 4 0) 378 @result{} (1 3 2 6 5 4 0)
379@end group 379@end group
380@group 380@group
381(sort nums '<) 381(sort nums #'<)
382 @result{} (0 1 2 3 4 5 6) 382 @result{} (0 1 2 3 4 5 6)
383@end group 383@end group
384@group 384@group
@@ -396,7 +396,7 @@ of @code{sort} and use that. Most often we store the result back into
396the variable that held the original list: 396the variable that held the original list:
397 397
398@example 398@example
399(setq nums (sort nums '<)) 399(setq nums (sort nums #'<))
400@end example 400@end example
401 401
402For the better understanding of what stable sort is, consider the following 402For the better understanding of what stable sort is, consider the following
@@ -1228,7 +1228,7 @@ This function sets the @var{index}th element of @var{array} to be
1228 1228
1229@example 1229@example
1230@group 1230@group
1231(setq w [foo bar baz]) 1231(setq w (vector 'foo 'bar 'baz)) ; @r{Create a mutable vector.}
1232 @result{} [foo bar baz] 1232 @result{} [foo bar baz]
1233(aset w 0 'fu) 1233(aset w 0 'fu)
1234 @result{} fu 1234 @result{} fu
@@ -1237,7 +1237,8 @@ w
1237@end group 1237@end group
1238 1238
1239@group 1239@group
1240(setq x "asdfasfd") 1240;; @r{@code{copy-sequence} creates a mutable string.}
1241(setq x (copy-sequence "asdfasfd"))
1241 @result{} "asdfasfd" 1242 @result{} "asdfasfd"
1242(aset x 3 ?Z) 1243(aset x 3 ?Z)
1243 @result{} 90 1244 @result{} 90
@@ -1246,6 +1247,10 @@ x
1246@end group 1247@end group
1247@end example 1248@end example
1248 1249
1250The @var{array} should be mutable; that is, it should not be a constant,
1251such as the constants created via quoting or via self-evaluating forms.
1252@xref{Constants and Mutability}.
1253
1249If @var{array} is a string and @var{object} is not a character, a 1254If @var{array} is a string and @var{object} is not a character, a
1250@code{wrong-type-argument} error results. The function converts a 1255@code{wrong-type-argument} error results. The function converts a
1251unibyte string to multibyte if necessary to insert a character. 1256unibyte string to multibyte if necessary to insert a character.
@@ -1257,7 +1262,8 @@ each element of @var{array} is @var{object}. It returns @var{array}.
1257 1262
1258@example 1263@example
1259@group 1264@group
1260(setq a [a b c d e f g]) 1265;; @r{Create a mutable vector and then fill it with zeros.}
1266(setq a (copy-sequence [a b c d e f g]))
1261 @result{} [a b c d e f g] 1267 @result{} [a b c d e f g]
1262(fillarray a 0) 1268(fillarray a 0)
1263 @result{} [0 0 0 0 0 0 0] 1269 @result{} [0 0 0 0 0 0 0]
@@ -1265,7 +1271,8 @@ a
1265 @result{} [0 0 0 0 0 0 0] 1271 @result{} [0 0 0 0 0 0 0]
1266@end group 1272@end group
1267@group 1273@group
1268(setq s "When in the course") 1274;; @r{Create a mutable string and then fill it with "-".}
1275(setq s (copy-sequence "When in the course"))
1269 @result{} "When in the course" 1276 @result{} "When in the course"
1270(fillarray s ?-) 1277(fillarray s ?-)
1271 @result{} "------------------" 1278 @result{} "------------------"
@@ -1302,7 +1309,9 @@ same way in Lisp input.
1302 A vector, like a string or a number, is considered a constant for 1309 A vector, like a string or a number, is considered a constant for
1303evaluation: the result of evaluating it is the same vector. This does 1310evaluation: the result of evaluating it is the same vector. This does
1304not evaluate or even examine the elements of the vector. 1311not evaluate or even examine the elements of the vector.
1305@xref{Self-Evaluating Forms}. 1312@xref{Self-Evaluating Forms}. Vectors written with square brackets
1313are constants and should not be modified via @code{aset} or other
1314destructive operations. @xref{Constants and Mutability}.
1306 1315
1307 Here are examples illustrating these principles: 1316 Here are examples illustrating these principles:
1308 1317
@@ -1565,14 +1574,14 @@ For example, here is how to examine the elements of the syntax table:
1565@example 1574@example
1566(let (accumulator) 1575(let (accumulator)
1567 (map-char-table 1576 (map-char-table
1568 #'(lambda (key value) 1577 (lambda (key value)
1569 (setq accumulator 1578 (setq accumulator
1570 (cons (list 1579 (cons (list
1571 (if (consp key) 1580 (if (consp key)
1572 (list (car key) (cdr key)) 1581 (list (car key) (cdr key))
1573 key) 1582 key)
1574 value) 1583 value)
1575 accumulator))) 1584 accumulator)))
1576 (syntax-table)) 1585 (syntax-table))
1577 accumulator) 1586 accumulator)
1578@result{} 1587@result{}
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 14cabc5d79d..a4c9c2549c5 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -51,10 +51,8 @@ by a distinguished character code.
51operate on them with the general array and sequence functions documented 51operate on them with the general array and sequence functions documented
52in @ref{Sequences Arrays Vectors}. For example, you can access or 52in @ref{Sequences Arrays Vectors}. For example, you can access or
53change individual characters in a string using the functions @code{aref} 53change individual characters in a string using the functions @code{aref}
54and @code{aset} (@pxref{Array Functions}). However, note that 54and @code{aset} (@pxref{Array Functions}). However, you should not
55@code{length} should @emph{not} be used for computing the width of a 55try to change the contents of constant strings (@pxref{Modifying Strings}).
56string on display; use @code{string-width} (@pxref{Size of Displayed
57Text}) instead.
58 56
59 There are two text representations for non-@acronym{ASCII} 57 There are two text representations for non-@acronym{ASCII}
60characters in Emacs strings (and in buffers): unibyte and multibyte. 58characters in Emacs strings (and in buffers): unibyte and multibyte.
@@ -89,6 +87,9 @@ copy them into buffers. @xref{Character Type}, and @ref{String Type},
89for information about the syntax of characters and strings. 87for 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
91representations and to encode and decode character codes. 89representations and to encode and decode character codes.
90Also, note that @code{length} should @emph{not} be used for computing
91the width of a string on display; use @code{string-width} (@pxref{Size
92of 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,11 @@ 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
385described in this section. However, you should not try to use these
386operations to alter the contents of a constant string.
387@xref{Constants and Mutability}.
388
383 The most basic way to alter the contents of an existing string is with 389 The most basic way to alter the contents of an existing string is with
384@code{aset} (@pxref{Array Functions}). @code{(aset @var{string} 390@code{aset} (@pxref{Array Functions}). @code{(aset @var{string}
385@var{idx} @var{char})} stores @var{char} into @var{string} at index 391@var{idx} @var{char})} stores @var{char} into @var{string} at index
@@ -591,7 +597,7 @@ for sorting (@pxref{Sequence Functions}):
591 597
592@example 598@example
593@group 599@group
594(sort '("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp) 600(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") 601 @result{} ("11" "1 1" "1.1" "12" "1 2" "1.2")
596@end group 602@end group
597@end example 603@end example
@@ -608,7 +614,7 @@ systems. The @var{locale} value of @code{"POSIX"} or @code{"C"} lets
608 614
609@example 615@example
610@group 616@group
611(sort '("11" "12" "1 1" "1 2" "1.1" "1.2") 617(sort (list "11" "12" "1 1" "1 2" "1.1" "1.2")
612 (lambda (s1 s2) (string-collate-lessp s1 s2 "POSIX"))) 618 (lambda (s1 s2) (string-collate-lessp s1 s2 "POSIX")))
613 @result{} ("1 1" "1 2" "1.1" "1.2" "11" "12") 619 @result{} ("1 1" "1 2" "1.1" "1.2" "11" "12")
614@end group 620@end group
diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi
index ad45a8edaff..9eb99a0ac92 100644
--- a/doc/lispref/syntax.texi
+++ b/doc/lispref/syntax.texi
@@ -1118,9 +1118,9 @@ bidi-class}).
1118 ;; 'bidi-class' Unicode property is R, AL, or RLO -- 1118 ;; 'bidi-class' Unicode property is R, AL, or RLO --
1119 ;; these have a right-to-left directionality. 1119 ;; these have a right-to-left directionality.
1120 (map-char-table 1120 (map-char-table
1121 #'(lambda (key val) 1121 (lambda (key val)
1122 (if (memq val '(R AL RLO)) 1122 (if (memq val '(R AL RLO))
1123 (modify-category-entry key ?R category-table))) 1123 (modify-category-entry key ?R category-table)))
1124 uniprop-table) 1124 uniprop-table)
1125 category-table)) 1125 category-table))
1126@end example 1126@end example
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index ffdf952b081..58424a4231b 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -2073,11 +2073,10 @@ its @code{sort-subr} call looks like this:
2073@example 2073@example
2074@group 2074@group
2075(sort-subr reverse 2075(sort-subr reverse
2076 (function 2076 (lambda ()
2077 (lambda () 2077 (while (and (not (eobp))
2078 (while (and (not (eobp)) 2078 (looking-at paragraph-separate))
2079 (looking-at paragraph-separate)) 2079 (forward-line 1)))
2080 (forward-line 1))))
2081 'forward-paragraph) 2080 'forward-paragraph)
2082@end group 2081@end group
2083@end example 2082@end example
@@ -4679,7 +4678,7 @@ expanded when the header line is computed. To do this, the
4679above. @var{specification} is an alist that has elements where the 4678above. @var{specification} is an alist that has elements where the
4680@code{car} is a character and the @code{cdr} is the substitution. 4679@code{car} is a character and the @code{cdr} is the substitution.
4681 4680
4682If @code{ONLY-PRESENT} is @code{nil}, errors will be signalled if a 4681If @code{ONLY-PRESENT} is @code{nil}, errors will be signaled if a
4683format character has been used that's not present in 4682format character has been used that's not present in
4684@var{specification}. If it's non-@code{nil}, that format 4683@var{specification}. If it's non-@code{nil}, that format
4685specification is left verbatim in the result. 4684specification is left verbatim in the result.
@@ -5725,7 +5724,7 @@ made within the @code{combine-after-change-calls} body.
5725@code{after-change-functions} within 5724@code{after-change-functions} within
5726the body of a @code{combine-after-change-calls} form. 5725the body of a @code{combine-after-change-calls} form.
5727 5726
5728@strong{Warning:} if the changes you combine occur in widely scattered 5727@strong{Warning:} If the changes you combine occur in widely scattered
5729parts of the buffer, this will still work, but it is not advisable, 5728parts of the buffer, this will still work, but it is not advisable,
5730because it may lead to inefficient behavior for some change hook 5729because it may lead to inefficient behavior for some change hook
5731functions. 5730functions.