diff options
| author | Glenn Morris | 2020-05-23 07:50:29 -0700 |
|---|---|---|
| committer | Glenn Morris | 2020-05-23 07:50:29 -0700 |
| commit | fabcc1ee13f82297d0f5e41f58fb1774840ebd45 (patch) | |
| tree | 440b7026631d5a26922a7366e28dbb6b3e307347 | |
| parent | f8581bcf6a1942ebd331cae20e32945a3a86a3d1 (diff) | |
| parent | 4b9fbdb5a713745dfdb13042e33ba2345e6860e1 (diff) | |
| download | emacs-fabcc1ee13f82297d0f5e41f58fb1774840ebd45.tar.gz emacs-fabcc1ee13f82297d0f5e41f58fb1774840ebd45.zip | |
Merge from origin/emacs-27
4b9fbdb5a7 ; Update TODO item about ligature support
03d44acfdd * doc/lispref/control.texi (Processing of Errors): Improve...
b48ab743a8 Minor fixups for mutability doc
6ac2326e5b Don’t use “constant” for values you shouldn’t change
| -rw-r--r-- | doc/lispintro/emacs-lisp-intro.texi | 5 | ||||
| -rw-r--r-- | doc/lispref/control.texi | 1 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 2 | ||||
| -rw-r--r-- | doc/lispref/eval.texi | 21 | ||||
| -rw-r--r-- | doc/lispref/lists.texi | 16 | ||||
| -rw-r--r-- | doc/lispref/objects.texi | 93 | ||||
| -rw-r--r-- | doc/lispref/sequences.texi | 25 | ||||
| -rw-r--r-- | doc/lispref/strings.texi | 11 | ||||
| -rw-r--r-- | etc/TODO | 31 |
9 files changed, 116 insertions, 89 deletions
diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi index 7484ce57607..f6dd77a3d96 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi | |||
| @@ -7317,8 +7317,6 @@ which leave the original list as it was. One way to find out how this | |||
| 7317 | works is to experiment. We will start with the @code{setcar} function. | 7317 | works is to experiment. We will start with the @code{setcar} function. |
| 7318 | 7318 | ||
| 7319 | @need 1200 | 7319 | @need 1200 |
| 7320 | @cindex constant lists | ||
| 7321 | @cindex mutable lists | ||
| 7322 | First, we can make a list and then set the value of a variable to the | 7320 | First, we can make a list and then set the value of a variable to the |
| 7323 | list, using the @code{setq} special form. Because we intend to use | 7321 | list, using the @code{setq} special form. Because we intend to use |
| 7324 | @code{setcar} to change the list, this @code{setq} should not use the | 7322 | @code{setcar} to change the list, this @code{setq} should not use the |
| @@ -7327,8 +7325,7 @@ a list that is part of the program and bad things could happen if we | |||
| 7327 | tried to change part of the program while running it. Generally | 7325 | tried to change part of the program while running it. Generally |
| 7328 | speaking an Emacs Lisp program's components should be constant (or | 7326 | speaking an Emacs Lisp program's components should be constant (or |
| 7329 | unchanged) while the program is running. So we instead construct an | 7327 | unchanged) while the program is running. So we instead construct an |
| 7330 | animal list that is @dfn{mutable} (or changeable) by using the | 7328 | animal list by using the @code{list} function, as follows: |
| 7331 | @code{list} function, as follows: | ||
| 7332 | 7329 | ||
| 7333 | @smallexample | 7330 | @smallexample |
| 7334 | (setq animals (list 'antelope 'giraffe 'lion 'tiger)) | 7331 | (setq animals (list 'antelope 'giraffe 'lion 'tiger)) |
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index c601e3af9bc..7755cbb5f25 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi | |||
| @@ -1867,6 +1867,7 @@ concept of continuable errors. | |||
| 1867 | @node Processing of Errors | 1867 | @node Processing of Errors |
| 1868 | @subsubsection How Emacs Processes Errors | 1868 | @subsubsection How Emacs Processes Errors |
| 1869 | @cindex processing of errors | 1869 | @cindex processing of errors |
| 1870 | @cindex handle errors | ||
| 1870 | 1871 | ||
| 1871 | When an error is signaled, @code{signal} searches for an active | 1872 | When an error is signaled, @code{signal} searches for an active |
| 1872 | @dfn{handler} for the error. A handler is a sequence of Lisp | 1873 | @dfn{handler} for the error. A handler is a sequence of Lisp |
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index bba1b63115f..9a6796790c4 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -297,7 +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 | * Mutability:: Some objects should not be modified. |
| 301 | 301 | ||
| 302 | Programming Types | 302 | Programming Types |
| 303 | 303 | ||
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi index baddce4d9c9..39f342a798b 100644 --- a/doc/lispref/eval.texi +++ b/doc/lispref/eval.texi | |||
| @@ -158,11 +158,11 @@ 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 | 161 | A self-evaluating form yields a value that becomes part of the program, |
| 162 | should not attempt to modify their contents via @code{setcar}, @code{aset} or | 162 | and you should not try to modify it via @code{setcar}, @code{aset} or |
| 163 | similar operations. The Lisp interpreter might unify the constants | 163 | similar operations. The Lisp interpreter might unify the constants |
| 164 | yielded by your program's self-evaluating forms, so that these | 164 | yielded by your program's self-evaluating forms, so that these |
| 165 | constants might share structure. @xref{Constants and Mutability}. | 165 | constants might share structure. @xref{Mutability}. |
| 166 | 166 | ||
| 167 | It is common to write numbers, characters, strings, and even vectors | 167 | It is common to write numbers, characters, strings, and even vectors |
| 168 | in Lisp code, taking advantage of the fact that they self-evaluate. | 168 | in Lisp code, taking advantage of the fact that they self-evaluate. |
| @@ -564,8 +564,8 @@ and vectors.) | |||
| 564 | 564 | ||
| 565 | @defspec quote object | 565 | @defspec quote object |
| 566 | This special form returns @var{object}, without evaluating it. | 566 | This special form returns @var{object}, without evaluating it. |
| 567 | The returned value is a constant, and should not be modified. | 567 | The returned value might be shared and should not be modified. |
| 568 | @xref{Constants and Mutability}. | 568 | @xref{Self-Evaluating Forms}. |
| 569 | @end defspec | 569 | @end defspec |
| 570 | 570 | ||
| 571 | @cindex @samp{'} for quoting | 571 | @cindex @samp{'} for quoting |
| @@ -608,9 +608,9 @@ Here are some examples of expressions that use @code{quote}: | |||
| 608 | 608 | ||
| 609 | Although the expressions @code{(list '+ 1 2)} and @code{'(+ 1 2)} | 609 | Although the expressions @code{(list '+ 1 2)} and @code{'(+ 1 2)} |
| 610 | both yield lists equal to @code{(+ 1 2)}, the former yields a | 610 | both yield lists equal to @code{(+ 1 2)}, the former yields a |
| 611 | freshly-minted mutable list whereas the latter yields a constant list | 611 | freshly-minted mutable list whereas the latter yields a list |
| 612 | built from conses that may be shared with other constants. | 612 | built from conses that might be shared and should not be modified. |
| 613 | @xref{Constants and Mutability}. | 613 | @xref{Self-Evaluating Forms}. |
| 614 | 614 | ||
| 615 | Other quoting constructs include @code{function} (@pxref{Anonymous | 615 | Other quoting constructs include @code{function} (@pxref{Anonymous |
| 616 | Functions}), which causes an anonymous lambda expression written in Lisp | 616 | Functions}), which causes an anonymous lambda expression written in Lisp |
| @@ -710,8 +710,9 @@ Here are some examples: | |||
| 710 | @end example | 710 | @end example |
| 711 | 711 | ||
| 712 | If a subexpression of a backquote construct has no substitutions or | 712 | If a subexpression of a backquote construct has no substitutions or |
| 713 | splices, it acts like @code{quote} in that it yields constant conses, | 713 | splices, it acts like @code{quote} in that it yields conses, |
| 714 | vectors and strings that should not be modified. | 714 | vectors and strings that might be shared and should not be modified. |
| 715 | @xref{Self-Evaluating Forms}. | ||
| 715 | 716 | ||
| 716 | @node Eval | 717 | @node Eval |
| 717 | @section Eval | 718 | @section Eval |
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index fcaf4386b15..ae793d5e15e 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi | |||
| @@ -873,8 +873,8 @@ primitives @code{setcar} and @code{setcdr}. These are destructive | |||
| 873 | operations because they change existing list structure. | 873 | operations because they change existing list structure. |
| 874 | Destructive operations should be applied only to mutable lists, | 874 | Destructive operations should be applied only to mutable lists, |
| 875 | that is, lists constructed via @code{cons}, @code{list} or similar | 875 | that is, lists constructed via @code{cons}, @code{list} or similar |
| 876 | operations. Lists created by quoting are constants and should not be | 876 | operations. Lists created by quoting are part of the program and |
| 877 | changed by destructive operations. @xref{Constants and Mutability}. | 877 | should not be changed by destructive operations. @xref{Mutability}. |
| 878 | 878 | ||
| 879 | @cindex CL note---@code{rplaca} vs @code{setcar} | 879 | @cindex CL note---@code{rplaca} vs @code{setcar} |
| 880 | @quotation | 880 | @quotation |
| @@ -911,7 +911,7 @@ value @var{object}. For example: | |||
| 911 | 911 | ||
| 912 | @example | 912 | @example |
| 913 | @group | 913 | @group |
| 914 | (setq x (list 1 2)) ; @r{Create a mutable list.} | 914 | (setq x (list 1 2)) |
| 915 | @result{} (1 2) | 915 | @result{} (1 2) |
| 916 | @end group | 916 | @end group |
| 917 | @group | 917 | @group |
| @@ -931,7 +931,7 @@ these lists. Here is an example: | |||
| 931 | 931 | ||
| 932 | @example | 932 | @example |
| 933 | @group | 933 | @group |
| 934 | ;; @r{Create two mutable lists that are partly shared.} | 934 | ;; @r{Create two lists that are partly shared.} |
| 935 | (setq x1 (list 'a 'b 'c)) | 935 | (setq x1 (list 'a 'b 'c)) |
| 936 | @result{} (a b c) | 936 | @result{} (a b c) |
| 937 | (setq x2 (cons 'z (cdr x1))) | 937 | (setq x2 (cons 'z (cdr x1))) |
| @@ -1022,11 +1022,11 @@ reached via the @sc{cdr}. | |||
| 1022 | 1022 | ||
| 1023 | @example | 1023 | @example |
| 1024 | @group | 1024 | @group |
| 1025 | (setq x (list 1 2 3)) ; @r{Create a mutable list.} | 1025 | (setq x (list 1 2 3)) |
| 1026 | @result{} (1 2 3) | 1026 | @result{} (1 2 3) |
| 1027 | @end group | 1027 | @end group |
| 1028 | @group | 1028 | @group |
| 1029 | (setcdr x '(4)) ; @r{Modify the list's tail to be a constant list.} | 1029 | (setcdr x '(4)) |
| 1030 | @result{} (4) | 1030 | @result{} (4) |
| 1031 | @end group | 1031 | @end group |
| 1032 | @group | 1032 | @group |
| @@ -1135,11 +1135,11 @@ Unlike @code{append} (@pxref{Building Lists}), the @var{lists} are | |||
| 1135 | 1135 | ||
| 1136 | @example | 1136 | @example |
| 1137 | @group | 1137 | @group |
| 1138 | (setq x (list 1 2 3)) ; @r{Create a mutable list.} | 1138 | (setq x (list 1 2 3)) |
| 1139 | @result{} (1 2 3) | 1139 | @result{} (1 2 3) |
| 1140 | @end group | 1140 | @end group |
| 1141 | @group | 1141 | @group |
| 1142 | (nconc x '(4 5)) ; @r{Modify the list's tail to be a constant list.} | 1142 | (nconc x '(4 5)) |
| 1143 | @result{} (1 2 3 4 5) | 1143 | @result{} (1 2 3 4 5) |
| 1144 | @end group | 1144 | @end group |
| 1145 | @group | 1145 | @group |
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index cd037d663da..83066744121 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi | |||
| @@ -46,10 +46,6 @@ you store in it, type and all. (Actually, a small number of Emacs | |||
| 46 | Lisp variables can only take on values of a certain type. | 46 | Lisp 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 should never change. | ||
| 50 | Others are @dfn{mutable}: their values can be changed via destructive | ||
| 51 | operations that involve side effects. | ||
| 52 | |||
| 53 | This chapter describes the purpose, printed representation, and read | 49 | This chapter describes the purpose, printed representation, and read |
| 54 | syntax of each of the standard types in GNU Emacs Lisp. Details on how | 50 | syntax of each of the standard types in GNU Emacs Lisp. Details on how |
| 55 | to use these types can be found in later chapters. | 51 | to use these types can be found in later chapters. |
| @@ -63,7 +59,7 @@ to use these types can be found in later chapters. | |||
| 63 | * Circular Objects:: Read syntax for circular structure. | 59 | * Circular Objects:: Read syntax for circular structure. |
| 64 | * Type Predicates:: Tests related to types. | 60 | * Type Predicates:: Tests related to types. |
| 65 | * Equality Predicates:: Tests of equality between any two objects. | 61 | * Equality Predicates:: Tests of equality between any two objects. |
| 66 | * Constants and Mutability:: Whether an object's value can change. | 62 | * Mutability:: Some objects should not be modified. |
| 67 | @end menu | 63 | @end menu |
| 68 | 64 | ||
| 69 | @node Printed Representation | 65 | @node Printed Representation |
| @@ -2383,51 +2379,58 @@ that for two strings to be equal, they have the same text properties. | |||
| 2383 | @end example | 2379 | @end example |
| 2384 | @end defun | 2380 | @end defun |
| 2385 | 2381 | ||
| 2386 | @node Constants and Mutability | 2382 | @node Mutability |
| 2387 | @section Constants and Mutability | 2383 | @section Mutability |
| 2388 | @cindex constants | ||
| 2389 | @cindex mutable objects | 2384 | @cindex mutable objects |
| 2390 | 2385 | ||
| 2391 | Some Lisp objects are constant: their values should never change | 2386 | Some Lisp objects should never change. For example, the Lisp |
| 2392 | during a single execution of Emacs running well-behaved Lisp code. | 2387 | expression @code{"aaa"} yields a string, but you should not change |
| 2393 | For example, you can create a new integer by calculating one, but you | 2388 | its contents. And some objects cannot be changed; for example, |
| 2394 | cannot modify the value of an existing integer. | 2389 | although you can create a new number by calculating one, Lisp provides |
| 2395 | 2390 | no operation to change the value of an existing number. | |
| 2396 | Other Lisp objects are mutable: it is safe to change their values | 2391 | |
| 2397 | via destructive operations involving side effects. For example, an | 2392 | Other Lisp objects are @dfn{mutable}: it is safe to change their |
| 2398 | existing marker can be changed by moving the marker to point to | 2393 | values via destructive operations involving side effects. For |
| 2399 | somewhere else. | 2394 | example, an existing marker can be changed by moving the marker to |
| 2400 | 2395 | point to somewhere else. | |
| 2401 | Although all numbers are constants and all markers are | 2396 | |
| 2402 | mutable, some types contain both constant and mutable members. These | 2397 | Although numbers never change and all markers are mutable, |
| 2403 | types include conses, vectors, strings, and symbols. For example, the string | 2398 | some types have members some of which are mutable and others not. These |
| 2404 | literal @code{"aaa"} yields a constant string, whereas the function | 2399 | types include conses, vectors, and strings. For example, |
| 2405 | call @code{(make-string 3 ?a)} yields a mutable string that can be | 2400 | although @code{"cons"} and @code{(symbol-name 'cons)} both yield |
| 2401 | strings that should not be changed, @code{(copy-sequence "cons")} and | ||
| 2402 | @code{(make-string 3 ?a)} both yield mutable strings that can be | ||
| 2406 | changed via later calls to @code{aset}. | 2403 | changed via later calls to @code{aset}. |
| 2407 | 2404 | ||
| 2408 | A mutable object can become constant if it is part of an expression | 2405 | A mutable object stops being mutable if it is part of an expression |
| 2409 | that is evaluated. The reverse does not occur: constant objects | 2406 | that is evaluated. For example: |
| 2410 | should stay constant. | 2407 | |
| 2411 | 2408 | @example | |
| 2412 | Trying to modify a constant variable signals an error | 2409 | (let* ((x (list 0.5)) |
| 2413 | (@pxref{Constant Variables}). | 2410 | (y (eval (list 'quote x)))) |
| 2414 | A program should not attempt to modify other types of constants because the | 2411 | (setcar x 1.5) ;; The program should not do this. |
| 2415 | resulting behavior is undefined: the Lisp interpreter might or might | 2412 | y) |
| 2416 | not detect the error, and if it does not detect the error the | 2413 | @end example |
| 2417 | interpreter can behave unpredictably thereafter. Another way to put | 2414 | |
| 2418 | this is that although mutable objects are safe to change and constant | 2415 | @noindent |
| 2419 | variables reliably prevent attempts to change them, other constants | 2416 | Although the list @code{(0.5)} was mutable when it was created, it should not |
| 2420 | are not safely mutable: if a misbehaving program tries to change such a | 2417 | have been changed via @code{setcar} because it given to @code{eval}. The |
| 2421 | constant then the constant's value might actually change, or the | 2418 | reverse does not occur: an object that should not be changed never |
| 2422 | program might crash or worse. This problem occurs | 2419 | becomes mutable afterwards. |
| 2423 | with types that have both constant and mutable members, and that have | 2420 | |
| 2424 | mutators like @code{setcar} and @code{aset} that are valid on mutable | 2421 | If a program attempts to change objects that should not be |
| 2425 | objects but hazardous on constants. | 2422 | changed, the resulting behavior is undefined: the Lisp interpreter |
| 2426 | 2423 | might signal an error, or it might crash or behave unpredictably in | |
| 2427 | When the same constant occurs multiple times in a program, the Lisp | 2424 | other ways.@footnote{This is the behavior specified for languages like |
| 2425 | Common Lisp and C for constants, and this differs from languages like | ||
| 2426 | JavaScript and Python where an interpreter is required to signal an | ||
| 2427 | error if a program attempts to change an immutable object. Ideally the Emacs | ||
| 2428 | Lisp interpreter will evolve in latter direction.} | ||
| 2429 | |||
| 2430 | When similar constants occur as parts of a program, the Lisp | ||
| 2428 | interpreter might save time or space by reusing existing constants or | 2431 | interpreter might save time or space by reusing existing constants or |
| 2429 | constant components. For example, @code{(eq "abc" "abc")} returns | 2432 | their components. For example, @code{(eq "abc" "abc")} returns |
| 2430 | @code{t} if the interpreter creates only one instance of the string | 2433 | @code{t} if the interpreter creates only one instance of the string |
| 2431 | constant @code{"abc"}, and returns @code{nil} if it creates two | 2434 | literal @code{"abc"}, and returns @code{nil} if it creates two |
| 2432 | instances. Lisp programs should be written so that they work | 2435 | instances. Lisp programs should be written so that they work |
| 2433 | regardless of whether this optimization is in use. | 2436 | regardless of whether this optimization is in use. |
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 1cb0d05cc7b..91c3049f875 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 (list 1 2)) ; @r{Create a mutable list.} | 186 | (setq bar (list 1 2)) |
| 187 | @result{} (1 2) | 187 | @result{} (1 2) |
| 188 | @end group | 188 | @end group |
| 189 | @group | 189 | @group |
| 190 | (setq x (vector 'foo bar)) ; @r{Create a mutable vector.} | 190 | (setq x (vector 'foo bar)) |
| 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 (list 'a 'b 'c)) ; @r{Create a mutable list.} | 281 | (setq x (list 'a 'b 'c)) |
| 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 (copy-sequence [1 2 3 4])) ; @r{Create a mutable vector.} | 323 | (setq x (copy-sequence [1 2 3 4])) |
| 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] |
| @@ -331,6 +331,7 @@ x | |||
| 331 | Note that unlike @code{reverse}, this function doesn't work with strings. | 331 | Note that unlike @code{reverse}, this function doesn't work with strings. |
| 332 | Although you can alter string data by using @code{aset}, it is strongly | 332 | Although you can alter string data by using @code{aset}, it is strongly |
| 333 | encouraged to treat strings as immutable even when they are mutable. | 333 | encouraged to treat strings as immutable even when they are mutable. |
| 334 | @xref{Mutability}. | ||
| 334 | 335 | ||
| 335 | @end defun | 336 | @end defun |
| 336 | 337 | ||
| @@ -374,7 +375,7 @@ appears in a different position in the list due to the change of | |||
| 374 | 375 | ||
| 375 | @example | 376 | @example |
| 376 | @group | 377 | @group |
| 377 | (setq nums (list 1 3 2 6 5 4 0)) ; @r{Create a mutable list.} | 378 | (setq nums (list 1 3 2 6 5 4 0)) |
| 378 | @result{} (1 3 2 6 5 4 0) | 379 | @result{} (1 3 2 6 5 4 0) |
| 379 | @end group | 380 | @end group |
| 380 | @group | 381 | @group |
| @@ -1228,7 +1229,7 @@ This function sets the @var{index}th element of @var{array} to be | |||
| 1228 | 1229 | ||
| 1229 | @example | 1230 | @example |
| 1230 | @group | 1231 | @group |
| 1231 | (setq w (vector 'foo 'bar 'baz)) ; @r{Create a mutable vector.} | 1232 | (setq w (vector 'foo 'bar 'baz)) |
| 1232 | @result{} [foo bar baz] | 1233 | @result{} [foo bar baz] |
| 1233 | (aset w 0 'fu) | 1234 | (aset w 0 'fu) |
| 1234 | @result{} fu | 1235 | @result{} fu |
| @@ -1237,7 +1238,7 @@ w | |||
| 1237 | @end group | 1238 | @end group |
| 1238 | 1239 | ||
| 1239 | @group | 1240 | @group |
| 1240 | ;; @r{@code{copy-sequence} creates a mutable string.} | 1241 | ;; @r{@code{copy-sequence} copies the string to be modified later.} |
| 1241 | (setq x (copy-sequence "asdfasfd")) | 1242 | (setq x (copy-sequence "asdfasfd")) |
| 1242 | @result{} "asdfasfd" | 1243 | @result{} "asdfasfd" |
| 1243 | (aset x 3 ?Z) | 1244 | (aset x 3 ?Z) |
| @@ -1247,9 +1248,7 @@ x | |||
| 1247 | @end group | 1248 | @end group |
| 1248 | @end example | 1249 | @end example |
| 1249 | 1250 | ||
| 1250 | The @var{array} should be mutable; that is, it should not be a constant, | 1251 | The @var{array} should be mutable. @xref{Mutability}. |
| 1251 | such as the constants created via quoting or via self-evaluating forms. | ||
| 1252 | @xref{Constants and Mutability}. | ||
| 1253 | 1252 | ||
| 1254 | If @var{array} is a string and @var{object} is not a character, a | 1253 | If @var{array} is a string and @var{object} is not a character, a |
| 1255 | @code{wrong-type-argument} error results. The function converts a | 1254 | @code{wrong-type-argument} error results. The function converts a |
| @@ -1262,7 +1261,6 @@ each element of @var{array} is @var{object}. It returns @var{array}. | |||
| 1262 | 1261 | ||
| 1263 | @example | 1262 | @example |
| 1264 | @group | 1263 | @group |
| 1265 | ;; @r{Create a mutable vector and then fill it with zeros.} | ||
| 1266 | (setq a (copy-sequence [a b c d e f g])) | 1264 | (setq a (copy-sequence [a b c d e f g])) |
| 1267 | @result{} [a b c d e f g] | 1265 | @result{} [a b c d e f g] |
| 1268 | (fillarray a 0) | 1266 | (fillarray a 0) |
| @@ -1271,7 +1269,6 @@ a | |||
| 1271 | @result{} [0 0 0 0 0 0 0] | 1269 | @result{} [0 0 0 0 0 0 0] |
| 1272 | @end group | 1270 | @end group |
| 1273 | @group | 1271 | @group |
| 1274 | ;; @r{Create a mutable string and then fill it with "-".} | ||
| 1275 | (setq s (copy-sequence "When in the course")) | 1272 | (setq s (copy-sequence "When in the course")) |
| 1276 | @result{} "When in the course" | 1273 | @result{} "When in the course" |
| 1277 | (fillarray s ?-) | 1274 | (fillarray s ?-) |
| @@ -1310,8 +1307,8 @@ same way in Lisp input. | |||
| 1310 | evaluation: the result of evaluating it is the same vector. This does | 1307 | evaluation: the result of evaluating it is the same vector. This does |
| 1311 | not evaluate or even examine the elements of the vector. | 1308 | not evaluate or even examine the elements of the vector. |
| 1312 | @xref{Self-Evaluating Forms}. Vectors written with square brackets | 1309 | @xref{Self-Evaluating Forms}. Vectors written with square brackets |
| 1313 | are constants and should not be modified via @code{aset} or other | 1310 | should not be modified via @code{aset} or other destructive |
| 1314 | destructive operations. @xref{Constants and Mutability}. | 1311 | operations. @xref{Mutability}. |
| 1315 | 1312 | ||
| 1316 | Here are examples illustrating these principles: | 1313 | Here are examples illustrating these principles: |
| 1317 | 1314 | ||
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index a4c9c2549c5..70c3b3cf4be 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi | |||
| @@ -49,10 +49,9 @@ by a distinguished character code. | |||
| 49 | 49 | ||
| 50 | Since strings are arrays, and therefore sequences as well, you can | 50 | Since strings are arrays, and therefore sequences as well, you can |
| 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 |
| 53 | change individual characters in a string using the functions @code{aref} | 53 | individual characters in a string using the function @code{aref} |
| 54 | and @code{aset} (@pxref{Array Functions}). However, you should not | 54 | (@pxref{Array Functions}). |
| 55 | try to change the contents of constant strings (@pxref{Modifying Strings}). | ||
| 56 | 55 | ||
| 57 | There are two text representations for non-@acronym{ASCII} | 56 | There are two text representations for non-@acronym{ASCII} |
| 58 | characters in Emacs strings (and in buffers): unibyte and multibyte. | 57 | characters in Emacs strings (and in buffers): unibyte and multibyte. |
| @@ -382,9 +381,7 @@ usual value is @w{@code{"[ \f\t\n\r\v]+"}}. | |||
| 382 | @cindex string modification | 381 | @cindex string modification |
| 383 | 382 | ||
| 384 | You can alter the contents of a mutable string via operations | 383 | You can alter the contents of a mutable string via operations |
| 385 | described in this section. However, you should not try to use these | 384 | described in this section. @xref{Mutability}. |
| 386 | operations to alter the contents of a constant string. | ||
| 387 | @xref{Constants and Mutability}. | ||
| 388 | 385 | ||
| 389 | The most basic way to alter the contents of an existing string is with | 386 | The most basic way to alter the contents of an existing string is with |
| 390 | @code{aset} (@pxref{Array Functions}). @code{(aset @var{string} | 387 | @code{aset} (@pxref{Array Functions}). @code{(aset @var{string} |
| @@ -264,6 +264,37 @@ of the mode line. | |||
| 264 | The prettify-symbols-mode should be deprecated once ligature support | 264 | The prettify-symbols-mode should be deprecated once ligature support |
| 265 | is in place. | 265 | is in place. |
| 266 | 266 | ||
| 267 | A related, but somewhat independent, feature is being able to move the | ||
| 268 | cursor "into a ligature", whereby cursor motion commands shows some | ||
| 269 | pseudo-cursor on some part of a ligature. For example, if "ffi" is | ||
| 270 | displayed as a ligature, then moving by one buffer position should | ||
| 271 | show the middle part of the ligature's glyph similar to the cursor | ||
| 272 | display: some special background and perhaps also a special | ||
| 273 | foreground. There are two possible ways of figuring out the offset at | ||
| 274 | which to display the pseudo-cursor: | ||
| 275 | |||
| 276 | . Arbitrarily divide the ligature's glyph width W into N parts, | ||
| 277 | where N is the number of codepoints composed into the ligature, then | ||
| 278 | move that pseudo-cursor by W/N pixels each time a cursor-motion | ||
| 279 | command is invoked; | ||
| 280 | . Use the font information. For example, HarfBuzz has the | ||
| 281 | hb_ot_layout_get_ligature_carets API for that purpose. However, | ||
| 282 | it could be that few fonts actually have that information recorded | ||
| 283 | in them, in which case the previous heuristics will be needed as | ||
| 284 | fallback. | ||
| 285 | |||
| 286 | One subtle issue needs to be resolved to have this feature of | ||
| 287 | "sub-glyph" cursor movement inside composed characters. The way Emacs | ||
| 288 | currently displays the default block cursor is by simply redrawing the | ||
| 289 | glyph at point in reverse video. So Emacs currently doesn't have a | ||
| 290 | way of displaying a cursor that "covers" only part of a glyph. To | ||
| 291 | make this happen, the display code will probably need to be changed to | ||
| 292 | draw the cursor as part of drawing the foreground and/or background of | ||
| 293 | the corresponding glyph, which is against the current flow of the | ||
| 294 | display code: it generally first completely draws the background and | ||
| 295 | foreground of the entire text that needs to be redrawn, and only then | ||
| 296 | draws the cursor where it should be placed. | ||
| 297 | |||
| 267 | ** Support for Stylistic Sets | 298 | ** Support for Stylistic Sets |
| 268 | This will allow using "alternate glyphs" supported by modern fonts. | 299 | This will allow using "alternate glyphs" supported by modern fonts. |
| 269 | For an overview of this feature, see | 300 | For an overview of this feature, see |