diff options
| author | Kenichi Handa | 2012-10-30 20:38:37 +0900 |
|---|---|---|
| committer | Kenichi Handa | 2012-10-30 20:38:37 +0900 |
| commit | 6ccc848cd85e75d77d6b11a46f5f23f860db9ff5 (patch) | |
| tree | e10cb69f3bbe6f2d9616d3867f12bf035c70e0f8 /doc | |
| parent | aee5b18ec3c7844ca125249914113eeaef04342c (diff) | |
| parent | fcc1acdadbeae00d8dcabeb6dccb20da9672af2c (diff) | |
| download | emacs-6ccc848cd85e75d77d6b11a46f5f23f860db9ff5.tar.gz emacs-6ccc848cd85e75d77d6b11a46f5f23f860db9ff5.zip | |
merge trun
Diffstat (limited to 'doc')
42 files changed, 2089 insertions, 1805 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index 90beb08233d..ea5621e7ccf 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog | |||
| @@ -1,3 +1,53 @@ | |||
| 1 | 2012-10-29 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * dired.texi (Shell Commands in Dired): Document changes to the | ||
| 4 | dired-do-async-shell-command. | ||
| 5 | |||
| 6 | 2012-10-28 Glenn Morris <rgm@gnu.org> | ||
| 7 | |||
| 8 | * ack.texi (Acknowledgments): Mention gv.el. | ||
| 9 | |||
| 10 | 2012-10-27 Bastien Guerry <bzg@gnu.org> | ||
| 11 | |||
| 12 | * screen.texi (Menu Bar): Fix typo. | ||
| 13 | |||
| 14 | 2012-10-27 Chong Yidong <cyd@gnu.org> | ||
| 15 | |||
| 16 | * frames.texi (Mouse Avoidance): Mention new variable | ||
| 17 | mouse-avoidance-banish-position. | ||
| 18 | |||
| 19 | * programs.texi (Which Function): Which Function mode now works in | ||
| 20 | all major modes by default. | ||
| 21 | |||
| 22 | * mule.texi (Recognize Coding): Remove an unreferenced vindex. | ||
| 23 | |||
| 24 | * files.texi (Misc File Ops): Symbolic links on Windows only work | ||
| 25 | on Vista and later. | ||
| 26 | |||
| 27 | * building.texi (Compilation): Document compilation-always-kill. | ||
| 28 | |||
| 29 | * search.texi (Symbol Search): New node. | ||
| 30 | |||
| 31 | * package.texi (Package Menu): Document the "new" status. | ||
| 32 | |||
| 33 | * windows.texi (Window Choice): Don't refer to the obsolete | ||
| 34 | special-display feature. | ||
| 35 | |||
| 36 | 2012-10-24 Chong Yidong <cyd@gnu.org> | ||
| 37 | |||
| 38 | * mule.texi (Text Coding): set-buffer-file-coding-system can now | ||
| 39 | be invoked from the mode line. | ||
| 40 | |||
| 41 | * dired.texi (Dired Deletion, Marks vs Flags): Document Emacs 24.3 | ||
| 42 | changes to the mark and unmark commands. | ||
| 43 | (Comparison in Dired): Document chages to dired-diff. Remove M-=, | ||
| 44 | which is no longer bound to dired-backup-diff. | ||
| 45 | |||
| 46 | 2012-10-23 Bastien Guerry <bzg@gnu.org> | ||
| 47 | |||
| 48 | * text.texi (Org Authoring): Use a comma after @ref to avoid the | ||
| 49 | insertion of a period in the Info output. | ||
| 50 | |||
| 1 | 2012-10-23 Stefan Monnier <monnier@iro.umontreal.ca> | 51 | 2012-10-23 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 52 | ||
| 3 | * custom.texi (Hooks): Clarify that -hooks is deprecated. | 53 | * custom.texi (Hooks): Clarify that -hooks is deprecated. |
diff --git a/doc/emacs/ack.texi b/doc/emacs/ack.texi index 8d1e4221a6c..79710f4992b 100644 --- a/doc/emacs/ack.texi +++ b/doc/emacs/ack.texi | |||
| @@ -835,8 +835,9 @@ diffs; @file{css-mode.el} for Cascading Style Sheets; | |||
| 835 | client for the ``Music Player Daemon''; @file{smie.el}, a generic | 835 | client for the ``Music Player Daemon''; @file{smie.el}, a generic |
| 836 | indentation engine; and @file{pcase.el}, implementing ML-style pattern | 836 | indentation engine; and @file{pcase.el}, implementing ML-style pattern |
| 837 | matching. In Emacs 24, he integrated the lexical binding code, | 837 | matching. In Emacs 24, he integrated the lexical binding code, |
| 838 | and cleaned up the CL namespace (making it acceptable to use CL | 838 | cleaned up the CL namespace (making it acceptable to use CL |
| 839 | functions at runtime). | 839 | functions at runtime), and added generalized variables to core Emacs |
| 840 | Lisp. | ||
| 840 | 841 | ||
| 841 | @item | 842 | @item |
| 842 | Morioka Tomohiko wrote several packages for MIME support in Gnus and | 843 | Morioka Tomohiko wrote several packages for MIME support in Gnus and |
diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index eaee16ac8d5..3a3630138de 100644 --- a/doc/emacs/building.texi +++ b/doc/emacs/building.texi | |||
| @@ -108,11 +108,14 @@ directory, which is the directory in which the previous compilation | |||
| 108 | was started. | 108 | was started. |
| 109 | 109 | ||
| 110 | @findex kill-compilation | 110 | @findex kill-compilation |
| 111 | @vindex compilation-always-kill | ||
| 111 | Starting a new compilation also kills any compilation already | 112 | Starting a new compilation also kills any compilation already |
| 112 | running in @file{*compilation*}, as the buffer can only handle one | 113 | running in @file{*compilation*}, as the buffer can only handle one |
| 113 | compilation at any time. However, @kbd{M-x compile} asks for | 114 | compilation at any time. However, @kbd{M-x compile} asks for |
| 114 | confirmation before actually killing a compilation that is running. | 115 | confirmation before actually killing a compilation that is running; to |
| 115 | You can also kill the compilation process with @kbd{M-x | 116 | always automatically kill the compilation without asking, change the |
| 117 | variable @code{compilation-always-kill} to @code{t}. You can also | ||
| 118 | kill a compilation process with the command @kbd{M-x | ||
| 116 | kill-compilation}. | 119 | kill-compilation}. |
| 117 | 120 | ||
| 118 | To run two compilations at once, start the first one, then rename | 121 | To run two compilations at once, start the first one, then rename |
diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 0dcded78364..c08dc02b04b 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi | |||
| @@ -167,13 +167,14 @@ deletion, then delete the files that were flagged. | |||
| 167 | 167 | ||
| 168 | @table @kbd | 168 | @table @kbd |
| 169 | @item d | 169 | @item d |
| 170 | Flag this file for deletion. | 170 | Flag this file for deletion (@code{dired-flag-file-deletion}). |
| 171 | @item u | 171 | @item u |
| 172 | Remove deletion flag on this line. | 172 | Remove the deletion flag (@code{dired-unmark}). |
| 173 | @item @key{DEL} | 173 | @item @key{DEL} |
| 174 | Move point to previous line and remove the deletion flag on that line. | 174 | Move point to previous line and remove the deletion flag on that line |
| 175 | (@code{dired-unmark-backward}). | ||
| 175 | @item x | 176 | @item x |
| 176 | Delete the files that are flagged for deletion. | 177 | Delete files flagged for deletion (@code{dired-do-flagged-delete}). |
| 177 | @end table | 178 | @end table |
| 178 | 179 | ||
| 179 | @kindex d @r{(Dired)} | 180 | @kindex d @r{(Dired)} |
| @@ -182,8 +183,12 @@ Delete the files that are flagged for deletion. | |||
| 182 | the file and typing @kbd{d} (@code{dired-flag-file-deletion}). The | 183 | the file and typing @kbd{d} (@code{dired-flag-file-deletion}). The |
| 183 | deletion flag is visible as a @samp{D} at the beginning of the line. | 184 | deletion flag is visible as a @samp{D} at the beginning of the line. |
| 184 | This command moves point to the next line, so that repeated @kbd{d} | 185 | This command moves point to the next line, so that repeated @kbd{d} |
| 185 | commands flag successive files. A numeric argument serves as a repeat | 186 | commands flag successive files. A numeric prefix argument serves as a |
| 186 | count. | 187 | repeat count; a negative count means to flag preceding files. |
| 188 | |||
| 189 | If the region is active, the @kbd{d} command flags all files in the | ||
| 190 | region for deletion; in this case, the command does not move point, | ||
| 191 | and ignores any prefix argument. | ||
| 187 | 192 | ||
| 188 | @kindex u @r{(Dired deletion)} | 193 | @kindex u @r{(Dired deletion)} |
| 189 | @kindex DEL @r{(Dired)} | 194 | @kindex DEL @r{(Dired)} |
| @@ -194,14 +199,17 @@ can remove deletion flags using the commands @kbd{u} and @key{DEL}. | |||
| 194 | @kbd{u} (@code{dired-unmark}) works just like @kbd{d}, but removes | 199 | @kbd{u} (@code{dired-unmark}) works just like @kbd{d}, but removes |
| 195 | flags rather than making flags. @key{DEL} | 200 | flags rather than making flags. @key{DEL} |
| 196 | (@code{dired-unmark-backward}) moves upward, removing flags; it is | 201 | (@code{dired-unmark-backward}) moves upward, removing flags; it is |
| 197 | like @kbd{u} with argument @minus{}1. | 202 | like @kbd{u} with argument @minus{}1. A numeric prefix argument to |
| 203 | either command serves as a repeat count, with a negative count meaning | ||
| 204 | to unflag in the opposite direction. If the region is active, these | ||
| 205 | commands instead unflag all files in the region, without moving point. | ||
| 198 | 206 | ||
| 199 | @kindex x @r{(Dired)} | 207 | @kindex x @r{(Dired)} |
| 200 | @findex dired-do-flagged-delete | 208 | @findex dired-do-flagged-delete |
| 201 | To delete the flagged files, type @kbd{x} | 209 | To delete flagged files, type @kbd{x} |
| 202 | (@code{dired-do-flagged-delete}). This command first displays a list | 210 | (@code{dired-do-flagged-delete}). This command displays a list of all |
| 203 | of all the file names flagged for deletion, and requests confirmation | 211 | the file names flagged for deletion, and requests confirmation with |
| 204 | with @kbd{yes}. If you confirm, Dired deletes the flagged files, then | 212 | @kbd{yes}. If you confirm, Dired deletes the flagged files, then |
| 205 | deletes their lines from the text of the Dired buffer. The Dired | 213 | deletes their lines from the text of the Dired buffer. The Dired |
| 206 | buffer, with somewhat fewer lines, remains selected. | 214 | buffer, with somewhat fewer lines, remains selected. |
| 207 | 215 | ||
| @@ -387,10 +395,11 @@ and unflag files.) | |||
| 387 | @kindex m @r{(Dired)} | 395 | @kindex m @r{(Dired)} |
| 388 | @kindex * m @r{(Dired)} | 396 | @kindex * m @r{(Dired)} |
| 389 | @findex dired-mark | 397 | @findex dired-mark |
| 390 | Mark the current file with @samp{*} (@code{dired-mark}). With a numeric | 398 | Mark the current file with @samp{*} (@code{dired-mark}). If the |
| 391 | argument @var{n}, mark the next @var{n} files starting with the current | 399 | region is active, mark all files in the region instead; otherwise, if |
| 392 | file. (If @var{n} is negative, mark the previous @minus{}@var{n} | 400 | a numeric argument @var{n} is supplied, mark the next @var{n} files |
| 393 | files.) | 401 | instead, starting with the current file (if @var{n} is negative, mark |
| 402 | the previous @minus{}@var{n} files). | ||
| 394 | 403 | ||
| 395 | @item * * | 404 | @item * * |
| 396 | @kindex * * @r{(Dired)} | 405 | @kindex * * @r{(Dired)} |
| @@ -426,7 +435,11 @@ and @file{..} (@code{dired-mark-subdir-files}). | |||
| 426 | @kindex u @r{(Dired)} | 435 | @kindex u @r{(Dired)} |
| 427 | @kindex * u @r{(Dired)} | 436 | @kindex * u @r{(Dired)} |
| 428 | @findex dired-unmark | 437 | @findex dired-unmark |
| 429 | Remove any mark on this line (@code{dired-unmark}). | 438 | Remove any mark on this line (@code{dired-unmark}). If the region is |
| 439 | active, unmark all files in the region instead; otherwise, if a | ||
| 440 | numeric argument @var{n} is supplied, unmark the next @var{n} files | ||
| 441 | instead, starting with the current file (if @var{n} is negative, | ||
| 442 | unmark the previous @minus{}@var{n} files). | ||
| 430 | 443 | ||
| 431 | @item @key{DEL} | 444 | @item @key{DEL} |
| 432 | @itemx * @key{DEL} | 445 | @itemx * @key{DEL} |
| @@ -434,7 +447,11 @@ Remove any mark on this line (@code{dired-unmark}). | |||
| 434 | @findex dired-unmark-backward | 447 | @findex dired-unmark-backward |
| 435 | @cindex unmarking files (in Dired) | 448 | @cindex unmarking files (in Dired) |
| 436 | Move point to previous line and remove any mark on that line | 449 | Move point to previous line and remove any mark on that line |
| 437 | (@code{dired-unmark-backward}). | 450 | (@code{dired-unmark-backward}). If the region is active, unmark all |
| 451 | files in the region instead; otherwise, if a numeric argument @var{n} | ||
| 452 | is supplied, unmark the @var{n} preceding files instead, starting with | ||
| 453 | the current file (if @var{n} is negative, unmark the next | ||
| 454 | @minus{}@var{n} files). | ||
| 438 | 455 | ||
| 439 | @item * ! | 456 | @item * ! |
| 440 | @itemx U | 457 | @itemx U |
| @@ -782,15 +799,20 @@ more matches. @xref{Tags Search}. | |||
| 782 | @kindex ! @r{(Dired)} | 799 | @kindex ! @r{(Dired)} |
| 783 | @kindex X @r{(Dired)} | 800 | @kindex X @r{(Dired)} |
| 784 | The Dired command @kbd{!} (@code{dired-do-shell-command}) reads a | 801 | The Dired command @kbd{!} (@code{dired-do-shell-command}) reads a |
| 785 | shell command string in the minibuffer and runs that shell command on | 802 | shell command string in the minibuffer, and runs that shell command on |
| 786 | one or more files. The files that the shell command operates on are | 803 | one or more files. The files that the shell command operates on are |
| 787 | determined in the usual way for Dired commands (@pxref{Operating on | 804 | determined in the usual way for Dired commands (@pxref{Operating on |
| 788 | Files}). The command @kbd{X} is a synonym for @kbd{!}. | 805 | Files}). The command @kbd{X} is a synonym for @kbd{!}. |
| 789 | 806 | ||
| 790 | The command @kbd{&} (@code{dired-do-async-shell-command}) does the | 807 | The command @kbd{&} (@code{dired-do-async-shell-command}) does the |
| 791 | same, except that it runs the shell command asynchronously. You can | 808 | same, except that it runs the shell command asynchronously. (You can |
| 792 | also do this with @kbd{!}, by appending a @samp{&} character to the | 809 | also do this with @kbd{!}, by appending a @samp{&} character to the |
| 793 | end of the shell command. | 810 | end of the shell command.) When the command operates on more than one |
| 811 | file, it runs multiple parallel copies of the specified shell command, | ||
| 812 | one for each file. As an exception, if the specified shell command | ||
| 813 | ends in @samp{;} or @samp{;&}, the shell command is run in the | ||
| 814 | background on each file sequentially; Emacs waits for each invoked | ||
| 815 | shell command to terminate before running the next one. | ||
| 794 | 816 | ||
| 795 | For both @kbd{!} and @kbd{&}, the working directory for the shell | 817 | For both @kbd{!} and @kbd{&}, the working directory for the shell |
| 796 | command is the top-level directory of the Dired buffer. | 818 | command is the top-level directory of the Dired buffer. |
| @@ -936,32 +958,19 @@ default. | |||
| 936 | @cindex file comparison (in Dired) | 958 | @cindex file comparison (in Dired) |
| 937 | @cindex compare files (in Dired) | 959 | @cindex compare files (in Dired) |
| 938 | 960 | ||
| 939 | Here are two Dired commands that compare specified files using | ||
| 940 | @code{diff}. They show the output in a buffer using Diff mode | ||
| 941 | (@pxref{Comparing Files}). | ||
| 942 | |||
| 943 | @table @kbd | ||
| 944 | @item = | ||
| 945 | @findex dired-diff | 961 | @findex dired-diff |
| 946 | @kindex = @r{(Dired)} | 962 | @kindex = @r{(Dired)} |
| 947 | Compare the current file (the file at point) with another file (the | 963 | The @kbd{=} (@code{dired-diff}) command compares the current file |
| 948 | file at the mark) using the @code{diff} program (@code{dired-diff}). | 964 | (the file at point) with another file (read using the minibuffer) |
| 949 | The file at the mark is the first argument of @code{diff}, and the | 965 | using the @command{diff} program. The file specified with the |
| 950 | file at point is the second argument. This refers to the ordinary | 966 | minibuffer is the first argument of @command{diff}, and file at point |
| 951 | Emacs mark, not Dired marks; use @kbd{C-@key{SPC}} | 967 | is the second argument. The output of the @command{diff} program is |
| 952 | (@code{set-mark-command}) to set the mark at the first file's line | 968 | shown in a buffer using Diff mode (@pxref{Comparing Files}). |
| 953 | (@pxref{Setting Mark}). | 969 | |
| 954 | 970 | If the region is active, the default for the file read using the | |
| 955 | @findex dired-backup-diff | 971 | minibuffer is the file at the mark (i.e.@: the ordinary Emacs mark, |
| 956 | @kindex M-= @r{(Dired)} | 972 | not a Dired mark; @pxref{Setting Mark}). Otherwise, if the file at |
| 957 | @item M-= | 973 | point has a backup file (@pxref{Backup}), that is the default. |
| 958 | Compare the current file with its latest backup file | ||
| 959 | (@code{dired-backup-diff}). If the current file is itself a backup, | ||
| 960 | compare it with the file it is a backup of; this way, you can compare | ||
| 961 | a file with any one of its backups. | ||
| 962 | |||
| 963 | The backup file is the first file given to @code{diff}. | ||
| 964 | @end table | ||
| 965 | 974 | ||
| 966 | @node Subdirectories in Dired | 975 | @node Subdirectories in Dired |
| 967 | @section Subdirectories in Dired | 976 | @section Subdirectories in Dired |
diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi index a2eaaf673e5..e7e0feb9e88 100644 --- a/doc/emacs/emacs.texi +++ b/doc/emacs/emacs.texi | |||
| @@ -373,6 +373,7 @@ Searching and Replacement | |||
| 373 | * Incremental Search:: Search happens as you type the string. | 373 | * Incremental Search:: Search happens as you type the string. |
| 374 | * Nonincremental Search:: Specify entire string and then search. | 374 | * Nonincremental Search:: Specify entire string and then search. |
| 375 | * Word Search:: Search for sequence of words. | 375 | * Word Search:: Search for sequence of words. |
| 376 | * Symbol Search:: Search for a source code symbol. | ||
| 376 | * Regexp Search:: Search for match for a regexp. | 377 | * Regexp Search:: Search for match for a regexp. |
| 377 | * Regexps:: Syntax of regular expressions. | 378 | * Regexps:: Syntax of regular expressions. |
| 378 | * Regexp Backslash:: Regular expression constructs starting with `\'. | 379 | * Regexp Backslash:: Regular expression constructs starting with `\'. |
diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index e12bb385653..36cd3658e2d 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi | |||
| @@ -1564,9 +1564,8 @@ open file @var{linkname} will refer to whatever file is named | |||
| 1564 | @var{target} at the time the opening is done, or will get an error if | 1564 | @var{target} at the time the opening is done, or will get an error if |
| 1565 | the name @var{target} is nonexistent at that time. This command does | 1565 | the name @var{target} is nonexistent at that time. This command does |
| 1566 | not expand the argument @var{target}, so that it allows you to specify | 1566 | not expand the argument @var{target}, so that it allows you to specify |
| 1567 | a relative name as the target of the link. Not all systems support | 1567 | a relative name as the target of the link. On MS-Windows, this |
| 1568 | symbolic links; on systems that don't support them, this command is | 1568 | command works only on MS Windows Vista and later. |
| 1569 | not defined. | ||
| 1570 | 1569 | ||
| 1571 | @kindex C-x i | 1570 | @kindex C-x i |
| 1572 | @findex insert-file | 1571 | @findex insert-file |
diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi index e1b849e630e..0ce5c64c0eb 100644 --- a/doc/emacs/frames.texi +++ b/doc/emacs/frames.texi | |||
| @@ -1092,17 +1092,19 @@ to various values to move the mouse in several ways: | |||
| 1092 | 1092 | ||
| 1093 | @table @code | 1093 | @table @code |
| 1094 | @item banish | 1094 | @item banish |
| 1095 | Move the mouse to the upper-right corner on any key-press; | 1095 | Move the pointer to a corner of the frame on any key-press. You can |
| 1096 | customize the variable @code{mouse-avoidance-banish-position} to | ||
| 1097 | specify where the pointer goes when it is banished. | ||
| 1096 | @item exile | 1098 | @item exile |
| 1097 | Move the mouse to the corner only if the cursor gets too close, | 1099 | Banish the pointer only if the cursor gets too close, and allow it to |
| 1098 | and allow it to return once the cursor is out of the way; | 1100 | return once the cursor is out of the way. |
| 1099 | @item jump | 1101 | @item jump |
| 1100 | If the cursor gets too close to the mouse, displace the mouse | 1102 | If the cursor gets too close to the pointer, displace the pointer by a |
| 1101 | a random distance & direction; | 1103 | random distance and direction. |
| 1102 | @item animate | 1104 | @item animate |
| 1103 | As @code{jump}, but shows steps along the way for illusion of motion; | 1105 | As @code{jump}, but shows steps along the way for illusion of motion. |
| 1104 | @item cat-and-mouse | 1106 | @item cat-and-mouse |
| 1105 | The same as @code{animate}; | 1107 | The same as @code{animate}. |
| 1106 | @item proteus | 1108 | @item proteus |
| 1107 | As @code{animate}, but changes the shape of the mouse pointer too. | 1109 | As @code{animate}, but changes the shape of the mouse pointer too. |
| 1108 | @end table | 1110 | @end table |
diff --git a/doc/emacs/mule.texi b/doc/emacs/mule.texi index 1dfae79c788..ff0d43c566a 100644 --- a/doc/emacs/mule.texi +++ b/doc/emacs/mule.texi | |||
| @@ -920,7 +920,6 @@ Unlike the previous two, this variable does not override any | |||
| 920 | @samp{-*-coding:-*-} tag. | 920 | @samp{-*-coding:-*-} tag. |
| 921 | 921 | ||
| 922 | @c FIXME? This seems somewhat out of place. Move to the Rmail section? | 922 | @c FIXME? This seems somewhat out of place. Move to the Rmail section? |
| 923 | @vindex rmail-decode-mime-charset | ||
| 924 | @vindex rmail-file-coding-system | 923 | @vindex rmail-file-coding-system |
| 925 | When you get new mail in Rmail, each message is translated | 924 | When you get new mail in Rmail, each message is translated |
| 926 | automatically from the coding system it is written in, as if it were a | 925 | automatically from the coding system it is written in, as if it were a |
| @@ -1040,12 +1039,16 @@ decoding it using coding system @var{right} instead. | |||
| 1040 | @findex set-buffer-file-coding-system | 1039 | @findex set-buffer-file-coding-system |
| 1041 | The command @kbd{C-x @key{RET} f} | 1040 | The command @kbd{C-x @key{RET} f} |
| 1042 | (@code{set-buffer-file-coding-system}) sets the file coding system for | 1041 | (@code{set-buffer-file-coding-system}) sets the file coding system for |
| 1043 | the current buffer---in other words, it says which coding system to | 1042 | the current buffer (i.e.@: the coding system to use when saving or |
| 1044 | use when saving or reverting the visited file. You specify which | 1043 | reverting the file). You specify which coding system using the |
| 1045 | coding system using the minibuffer. If you specify a coding system | 1044 | minibuffer. You can also invoke this command by clicking with |
| 1046 | that cannot handle all of the characters in the buffer, Emacs warns | 1045 | @kbd{Mouse-3} on the coding system indicator in the mode line |
| 1047 | you about the troublesome characters when you actually save the | 1046 | (@pxref{Mode Line}). |
| 1048 | buffer. | 1047 | |
| 1048 | If you specify a coding system that cannot handle all the characters | ||
| 1049 | in the buffer, Emacs will warn you about the troublesome characters, | ||
| 1050 | and ask you to choose another coding system, when you try to save the | ||
| 1051 | buffer (@pxref{Output Coding}). | ||
| 1049 | 1052 | ||
| 1050 | @cindex specify end-of-line conversion | 1053 | @cindex specify end-of-line conversion |
| 1051 | You can also use this command to specify the end-of-line conversion | 1054 | You can also use this command to specify the end-of-line conversion |
diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi index 4435590536f..df87cf9cb23 100644 --- a/doc/emacs/package.texi +++ b/doc/emacs/package.texi | |||
| @@ -62,8 +62,12 @@ The package's status---normally one of @samp{available} (can be | |||
| 62 | downloaded from the package archive), @samp{installed}, or | 62 | downloaded from the package archive), @samp{installed}, or |
| 63 | @samp{built-in} (included in Emacs by default). | 63 | @samp{built-in} (included in Emacs by default). |
| 64 | 64 | ||
| 65 | In some instances, the status can be @samp{held}, @samp{disabled}, or | 65 | The status can also be @samp{new}. This is equivalent to |
| 66 | @samp{obsolete}. @xref{Package Installation}. | 66 | @samp{available}, except that it means the package became newly |
| 67 | available on the package archive after your last invocation of | ||
| 68 | @kbd{M-x list-packages}. In other instances, a package may have the | ||
| 69 | status @samp{held}, @samp{disabled}, or @samp{obsolete}. | ||
| 70 | @xref{Package Installation}. | ||
| 67 | 71 | ||
| 68 | @item | 72 | @item |
| 69 | A short description of the package. | 73 | A short description of the package. |
diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index e5340655770..b5bb33ad666 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi | |||
| @@ -326,12 +326,13 @@ as you move around in a buffer. | |||
| 326 | @findex which-function-mode | 326 | @findex which-function-mode |
| 327 | @vindex which-func-modes | 327 | @vindex which-func-modes |
| 328 | To either enable or disable Which Function mode, use the command | 328 | To either enable or disable Which Function mode, use the command |
| 329 | @kbd{M-x which-function-mode}. Although Which Function mode is a | 329 | @kbd{M-x which-function-mode}. Which Function mode is a global minor |
| 330 | global minor mode, it takes effect only in certain major modes: those | 330 | mode. By default, it takes effect in all major modes major modes that |
| 331 | listed in the variable @code{which-func-modes}. If the value of | 331 | know how to support it (i.e.@: all the major modes that support |
| 332 | @code{which-func-modes} is @code{t} rather than a list of modes, then | 332 | Imenu). You can restrict it to a specific list of major modes by |
| 333 | Which Function mode applies to all major modes that know how to | 333 | changing the value of the variable @code{which-func-modes} from |
| 334 | support it---in other words, all the major modes that support Imenu. | 334 | @code{t} (which means to support all available major modes) to a list |
| 335 | of major mode names. | ||
| 335 | 336 | ||
| 336 | @node Program Indent | 337 | @node Program Indent |
| 337 | @section Indentation for Programs | 338 | @section Indentation for Programs |
diff --git a/doc/emacs/screen.texi b/doc/emacs/screen.texi index 989cf998bfd..2b8edaf9375 100644 --- a/doc/emacs/screen.texi +++ b/doc/emacs/screen.texi | |||
| @@ -314,5 +314,5 @@ the echo area. You can use the up and down arrow keys to move through | |||
| 314 | the menu to different items, and then you can type @key{RET} to select | 314 | the menu to different items, and then you can type @key{RET} to select |
| 315 | the item. Each menu item is also designated by a letter or digit | 315 | the item. Each menu item is also designated by a letter or digit |
| 316 | (usually the initial of some word in the item's name). This letter or | 316 | (usually the initial of some word in the item's name). This letter or |
| 317 | digit is separated from the item name by @samp{=>}. You can type the | 317 | digit is separated from the item name by @samp{==>}. You can type the |
| 318 | item's letter or digit to select the item. | 318 | item's letter or digit to select the item. |
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index 7e46e416219..7dc5855cdfc 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi | |||
| @@ -21,6 +21,7 @@ thing, but search for patterns instead of fixed strings. | |||
| 21 | * Incremental Search:: Search happens as you type the string. | 21 | * Incremental Search:: Search happens as you type the string. |
| 22 | * Nonincremental Search:: Specify entire string and then search. | 22 | * Nonincremental Search:: Specify entire string and then search. |
| 23 | * Word Search:: Search for sequence of words. | 23 | * Word Search:: Search for sequence of words. |
| 24 | * Symbol Search:: Search for a source code symbol. | ||
| 24 | * Regexp Search:: Search for match for a regexp. | 25 | * Regexp Search:: Search for match for a regexp. |
| 25 | * Regexps:: Syntax of regular expressions. | 26 | * Regexps:: Syntax of regular expressions. |
| 26 | * Regexp Backslash:: Regular expression constructs starting with `\'. | 27 | * Regexp Backslash:: Regular expression constructs starting with `\'. |
| @@ -467,6 +468,47 @@ the search string can match part of a word, so that the matching | |||
| 467 | proceeds incrementally as you type. This additional laxity does not | 468 | proceeds incrementally as you type. This additional laxity does not |
| 468 | apply to the lazy highlight, which always matches whole words. | 469 | apply to the lazy highlight, which always matches whole words. |
| 469 | 470 | ||
| 471 | @node Symbol Search | ||
| 472 | @section Symbol Search | ||
| 473 | @cindex symbol search | ||
| 474 | |||
| 475 | A @dfn{symbol search} is much like an ordinary search, except that | ||
| 476 | the boundaries of the search must match the boundaries of a symbol. | ||
| 477 | The meaning of @dfn{symbol} in this context depends on the major mode, | ||
| 478 | and usually refers to a source code token, such as a Lisp symbol in | ||
| 479 | Emacs Lisp mode. For instance, if you perform an incremental symbol | ||
| 480 | search for the Lisp symbol @code{forward-word}, it would not match | ||
| 481 | @code{isearch-forward-word}. This feature is thus mainly useful for | ||
| 482 | searching source code. | ||
| 483 | |||
| 484 | @table @kbd | ||
| 485 | @item M-s _ | ||
| 486 | If incremental search is active, toggle symbol search mode | ||
| 487 | (@code{isearch-toggle-symbol}); otherwise, begin an incremental | ||
| 488 | forward symbol search (@code{isearch-forward-symbol}). | ||
| 489 | @item M-s _ @key{RET} @var{symbol} @key{RET} | ||
| 490 | Search forward for @var{symbol}, nonincrementally. | ||
| 491 | @item M-s _ C-r @key{RET} @var{symbol} @key{RET} | ||
| 492 | Search backward for @var{symbol}, nonincrementally. | ||
| 493 | @end table | ||
| 494 | |||
| 495 | @kindex M-s _ | ||
| 496 | @findex isearch-forward-symbol | ||
| 497 | To begin a forward incremental symbol search, type @kbd{M-s _}. If | ||
| 498 | incremental search is not already active, this runs the command | ||
| 499 | @code{isearch-forward-symbol}. If incremental search is already | ||
| 500 | active, @kbd{M-s _} switches to a symbol search, preserving the | ||
| 501 | direction of the search and the current search string; you can disable | ||
| 502 | symbol search by typing @kbd{M-s _} again. In incremental symbol | ||
| 503 | search, only the beginning of the search string is required to match | ||
| 504 | the beginning of a symbol. | ||
| 505 | |||
| 506 | To begin a nonincremental symbol search, type @kbd{M-s _ @key{RET}} | ||
| 507 | for a forward search, or @kbd{M-s _ C-r @key{RET}} or a backward | ||
| 508 | search. In nonincremental symbol searches, the beginning and end of | ||
| 509 | the search string are required to match the beginning and end of a | ||
| 510 | symbol, respectively. | ||
| 511 | |||
| 470 | @node Regexp Search | 512 | @node Regexp Search |
| 471 | @section Regular Expression Search | 513 | @section Regular Expression Search |
| 472 | @cindex regexp search | 514 | @cindex regexp search |
diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi index f10e78e17ad..6e895d3ac3c 100644 --- a/doc/emacs/text.texi +++ b/doc/emacs/text.texi | |||
| @@ -1399,7 +1399,7 @@ This is an example. | |||
| 1399 | #+end_example | 1399 | #+end_example |
| 1400 | @end example | 1400 | @end example |
| 1401 | 1401 | ||
| 1402 | For further details, see @ref{Exporting,,,org, The Org Manual} and | 1402 | For further details, @ref{Exporting,,,org, The Org Manual}, and |
| 1403 | @ref{Publishing,,,org, The Org Manual}. | 1403 | @ref{Publishing,,,org, The Org Manual}. |
| 1404 | 1404 | ||
| 1405 | @node TeX Mode | 1405 | @node TeX Mode |
diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi index 04d1353006f..f87da5f3913 100644 --- a/doc/emacs/windows.texi +++ b/doc/emacs/windows.texi | |||
| @@ -384,12 +384,6 @@ Otherwise, if the buffer is already displayed in an existing window, | |||
| 384 | are considered, but windows on other frames are also reusable if you | 384 | are considered, but windows on other frames are also reusable if you |
| 385 | change @code{pop-up-frames} (see below) to @code{t}. | 385 | change @code{pop-up-frames} (see below) to @code{t}. |
| 386 | 386 | ||
| 387 | @item | ||
| 388 | Otherwise, if you specified that the buffer should be displayed in a | ||
| 389 | special frame by customizing @code{special-display-buffer-names} or | ||
| 390 | @code{special-display-regexps}, do so. @xref{Choosing Window | ||
| 391 | Options,,, elisp, The Emacs Lisp Reference Manual}. | ||
| 392 | |||
| 393 | @vindex pop-up-frames | 387 | @vindex pop-up-frames |
| 394 | @item | 388 | @item |
| 395 | Otherwise, optionally create a new frame and display the buffer there. | 389 | Otherwise, optionally create a new frame and display the buffer there. |
diff --git a/doc/lispintro/ChangeLog b/doc/lispintro/ChangeLog index 6c524f5a0ae..396e3857c58 100644 --- a/doc/lispintro/ChangeLog +++ b/doc/lispintro/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2012-10-24 Paul Eggert <eggert@penguin.cs.ucla.edu> | ||
| 2 | |||
| 3 | * emacs-lisp-intro.texi (Files List): | ||
| 4 | Update manual for new time stamp format (Bug#12706). | ||
| 5 | |||
| 1 | 2012-10-17 Gregor Zattler <grfz@gmx.de> (tiny change) | 6 | 2012-10-17 Gregor Zattler <grfz@gmx.de> (tiny change) |
| 2 | 7 | ||
| 3 | * emacs-lisp-intro.texi (Narrowing advantages): | 8 | * emacs-lisp-intro.texi (Narrowing advantages): |
diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi index 70ddb81c776..f885d6c15e8 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi | |||
| @@ -238,7 +238,7 @@ GNU Press, @hfill @uref{http://www.fsf.org/campaigns/gnu-press/}@* | |||
| 238 | a division of the @hfill email: @email{sales@@fsf.org}@* | 238 | a division of the @hfill email: @email{sales@@fsf.org}@* |
| 239 | Free Software Foundation, Inc. @hfill Tel: +1 (617) 542-5942@* | 239 | Free Software Foundation, Inc. @hfill Tel: +1 (617) 542-5942@* |
| 240 | 51 Franklin Street, Fifth Floor @hfill Fax: +1 (617) 542-2652@* | 240 | 51 Franklin Street, Fifth Floor @hfill Fax: +1 (617) 542-2652@* |
| 241 | Boston, MA 02110-1301 USA | 241 | Boston, MA 02110-1301 USA |
| 242 | @end iftex | 242 | @end iftex |
| 243 | 243 | ||
| 244 | @ifnottex | 244 | @ifnottex |
| @@ -249,7 +249,7 @@ GNU Press, http://www.fsf.org/campaigns/gnu-press/ | |||
| 249 | a division of the email: sales@@fsf.org | 249 | a division of the email: sales@@fsf.org |
| 250 | Free Software Foundation, Inc. Tel: +1 (617) 542-5942 | 250 | Free Software Foundation, Inc. Tel: +1 (617) 542-5942 |
| 251 | 51 Franklin Street, Fifth Floor Fax: +1 (617) 542-2652 | 251 | 51 Franklin Street, Fifth Floor Fax: +1 (617) 542-2652 |
| 252 | Boston, MA 02110-1301 USA | 252 | Boston, MA 02110-1301 USA |
| 253 | @end example | 253 | @end example |
| 254 | @end ifnottex | 254 | @end ifnottex |
| 255 | 255 | ||
| @@ -15680,11 +15680,11 @@ nil | |||
| 15680 | 100 | 15680 | 100 |
| 15681 | @end group | 15681 | @end group |
| 15682 | @group | 15682 | @group |
| 15683 | (17733 259) | 15683 | (20615 27034 579989 697000) |
| 15684 | (17491 28834) | 15684 | (17905 55681 0 0) |
| 15685 | (17596 62124) | 15685 | (20615 26327 734791 805000) |
| 15686 | 13157 | 15686 | 13188 |
| 15687 | "-rw-rw-r--" | 15687 | "-rw-r--r--" |
| 15688 | @end group | 15688 | @end group |
| 15689 | @group | 15689 | @group |
| 15690 | nil | 15690 | nil |
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 26765e7a384..eca39e54203 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,86 @@ | |||
| 1 | 2012-10-30 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * variables.texi (Generalized Variables): Fix typo. | ||
| 4 | |||
| 5 | 2012-10-30 Chong Yidong <cyd@gnu.org> | ||
| 6 | |||
| 7 | * symbols.texi (Symbol Plists): Document function-get. | ||
| 8 | |||
| 9 | * loading.texi (Autoload): Document autoloadp, autoload-do-load. | ||
| 10 | |||
| 11 | * frames.texi (Visibility of Frames): Document tty-top-frame. | ||
| 12 | |||
| 13 | 2012-10-28 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 14 | |||
| 15 | * keymaps.texi (Format of Keymaps): Document the multiple | ||
| 16 | inheritance format. | ||
| 17 | |||
| 18 | 2012-10-28 Martin Rudalics <rudalics@gmx.at> | ||
| 19 | |||
| 20 | * windows.texi (Basic Windows): Reformulate description of live, | ||
| 21 | internal and valid windows. | ||
| 22 | (Cyclic Window Ordering): Describe new argument of | ||
| 23 | get-lru-window and get-largest-window. Add description of | ||
| 24 | window-in-direction. | ||
| 25 | |||
| 26 | 2012-10-27 Glenn Morris <rgm@gnu.org> | ||
| 27 | |||
| 28 | * variables.texi (Generalized Variables): New section, | ||
| 29 | adapted from misc/cl.texi. | ||
| 30 | * elisp.texi (Top): Add Generalized Variables to menu. | ||
| 31 | * lists.texi (List Elements, List Variables): | ||
| 32 | Mention generalized variables. | ||
| 33 | |||
| 34 | * lists.texi (List Elements): Typo fix. | ||
| 35 | |||
| 36 | 2012-10-27 Chong Yidong <cyd@gnu.org> | ||
| 37 | |||
| 38 | * minibuf.texi (High-Level Completion): Don't mention removed | ||
| 39 | function iswitchb-read-buffer. | ||
| 40 | |||
| 41 | * commands.texi (Event Input Misc): Remove last-input-char. | ||
| 42 | (Command Loop Info): Remove last-command-char. | ||
| 43 | |||
| 44 | * frames.texi (Initial Parameters): Don't mention the obsolete | ||
| 45 | special-display feature. | ||
| 46 | |||
| 47 | * windows.texi (Choosing Window): Don't mention the obsolete | ||
| 48 | special display feature. | ||
| 49 | (Choosing Window Options): Remove obsolete special-display | ||
| 50 | variables, and the functions special-display-p and | ||
| 51 | special-display-popup-frame. | ||
| 52 | |||
| 53 | * display.texi (Fringe Bitmaps): Add exclamation-mark bitmap. | ||
| 54 | |||
| 55 | * hooks.texi (Standard Hooks): Remove obsolete hooks. | ||
| 56 | |||
| 57 | * markers.texi (Information from Markers): Remove obsolete | ||
| 58 | function buffer-has-markers-at. | ||
| 59 | |||
| 60 | * text.texi (Yanking): Document yank-handled-properties. | ||
| 61 | |||
| 62 | 2012-10-24 Paul Eggert <eggert@penguin.cs.ucla.edu> | ||
| 63 | |||
| 64 | Update manual for new time stamp format (Bug#12706). | ||
| 65 | * buffers.texi (Modification Time): | ||
| 66 | * files.texi (Testing Accessibility, File Attributes): | ||
| 67 | * intro.texi (Version Info): | ||
| 68 | * os.texi (Time of Day): | ||
| 69 | Update for new time stamp format (HIGH LOW MICROSEC PICOSEC). | ||
| 70 | These instances were missed the first time around. | ||
| 71 | Problem reported by Glenn Morris in <http://bugs.gnu.org/12706#25>. | ||
| 72 | |||
| 73 | 2012-10-24 Chong Yidong <cyd@gnu.org> | ||
| 74 | |||
| 75 | * minibuf.texi (Text from Minibuffer): Document read-regexp | ||
| 76 | changes. | ||
| 77 | |||
| 78 | * nonascii.texi (Selecting a Representation): Document | ||
| 79 | set-buffer-multibyte changes. | ||
| 80 | |||
| 81 | * keymaps.texi (Toolkit Differences): Node deleted. | ||
| 82 | (Easy Menu): New node. | ||
| 83 | |||
| 1 | 2012-10-23 Stefan Monnier <monnier@iro.umontreal.ca> | 84 | 2012-10-23 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 85 | ||
| 3 | * hooks.texi (Standard Hooks): Clarify that -hooks is deprecated. | 86 | * hooks.texi (Standard Hooks): Clarify that -hooks is deprecated. |
diff --git a/doc/lispref/anti.texi b/doc/lispref/anti.texi index f1f4a089f1b..6ece2149733 100644 --- a/doc/lispref/anti.texi +++ b/doc/lispref/anti.texi | |||
| @@ -71,9 +71,8 @@ been removed, including @code{display-buffer-overriding-action} and | |||
| 71 | related variables, as well as the @var{action} argument to | 71 | related variables, as well as the @var{action} argument to |
| 72 | @code{display-buffer} and other functions. The way to | 72 | @code{display-buffer} and other functions. The way to |
| 73 | programmatically control how Emacs chooses a window to display a | 73 | programmatically control how Emacs chooses a window to display a |
| 74 | buffer is to bind the right combination of | 74 | buffer is to bind the right combination of @code{pop-up-frames} and |
| 75 | @code{special-display-regexps}, @code{pop-up-frames}, and other | 75 | other variables. |
| 76 | variables. | ||
| 77 | 76 | ||
| 78 | @item | 77 | @item |
| 79 | The standard completion interface has been simplified, eliminating the | 78 | The standard completion interface has been simplified, eliminating the |
diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index b9666a79f5b..4a556895de7 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi | |||
| @@ -634,7 +634,8 @@ file should not be done. | |||
| 634 | @c Emacs 19 feature | 634 | @c Emacs 19 feature |
| 635 | @defun visited-file-modtime | 635 | @defun visited-file-modtime |
| 636 | This function returns the current buffer's recorded last file | 636 | This function returns the current buffer's recorded last file |
| 637 | modification time, as a list of the form @code{(@var{high} @var{low})}. | 637 | modification time, as a list of the form @code{(@var{high} @var{low} |
| 638 | @var{microsec} @var{picosec})}. | ||
| 638 | (This is the same format that @code{file-attributes} uses to return | 639 | (This is the same format that @code{file-attributes} uses to return |
| 639 | time values; see @ref{File Attributes}.) | 640 | time values; see @ref{File Attributes}.) |
| 640 | 641 | ||
| @@ -664,9 +665,8 @@ is not @code{nil}, and otherwise to the last modification time of the | |||
| 664 | visited file. | 665 | visited file. |
| 665 | 666 | ||
| 666 | If @var{time} is neither @code{nil} nor zero, it should have the form | 667 | If @var{time} is neither @code{nil} nor zero, it should have the form |
| 667 | @code{(@var{high} . @var{low})} or @code{(@var{high} @var{low})}, in | 668 | @code{(@var{high} @var{low} @var{microsec} @var{picosec})}, |
| 668 | either case containing two integers, each of which holds 16 bits of the | 669 | the format used by @code{current-time} (@pxref{Time of Day}). |
| 669 | time. | ||
| 670 | 670 | ||
| 671 | This function is useful if the buffer was not read from the file | 671 | This function is useful if the buffer was not read from the file |
| 672 | normally, or if the file itself has been changed for some known benign | 672 | normally, or if the file itself has been changed for some known benign |
| @@ -1237,4 +1237,3 @@ This function returns the current gap position in the current buffer. | |||
| 1237 | @defun gap-size | 1237 | @defun gap-size |
| 1238 | This function returns the current gap size of the current buffer. | 1238 | This function returns the current gap size of the current buffer. |
| 1239 | @end defun | 1239 | @end defun |
| 1240 | |||
diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi index 9ffa2b74857..c42e4b3b6dc 100644 --- a/doc/lispref/commands.texi +++ b/doc/lispref/commands.texi | |||
| @@ -186,7 +186,6 @@ buffer: } prompts the user with @samp{Frobnicate buffer: } to enter | |||
| 186 | the name of an existing buffer, which becomes the second and final | 186 | the name of an existing buffer, which becomes the second and final |
| 187 | argument. | 187 | argument. |
| 188 | 188 | ||
| 189 | @c Emacs 19 feature | ||
| 190 | The prompt string can use @samp{%} to include previous argument values | 189 | The prompt string can use @samp{%} to include previous argument values |
| 191 | (starting with the first argument) in the prompt. This is done using | 190 | (starting with the first argument) in the prompt. This is done using |
| 192 | @code{format} (@pxref{Formatting Strings}). For example, here is how | 191 | @code{format} (@pxref{Formatting Strings}). For example, here is how |
| @@ -205,7 +204,6 @@ If @samp{*} appears at the beginning of the string, then an error is | |||
| 205 | signaled if the buffer is read-only. | 204 | signaled if the buffer is read-only. |
| 206 | 205 | ||
| 207 | @cindex @samp{@@} in @code{interactive} | 206 | @cindex @samp{@@} in @code{interactive} |
| 208 | @c Emacs 19 feature | ||
| 209 | If @samp{@@} appears at the beginning of the string, and if the key | 207 | If @samp{@@} appears at the beginning of the string, and if the key |
| 210 | sequence used to invoke the command includes any mouse events, then | 208 | sequence used to invoke the command includes any mouse events, then |
| 211 | the window associated with the first of those events is selected | 209 | the window associated with the first of those events is selected |
| @@ -910,7 +908,6 @@ up a menu. It is also used internally by @code{y-or-n-p} | |||
| 910 | @end defvar | 908 | @end defvar |
| 911 | 909 | ||
| 912 | @defvar last-command-event | 910 | @defvar last-command-event |
| 913 | @defvarx last-command-char | ||
| 914 | This variable is set to the last input event that was read by the | 911 | This variable is set to the last input event that was read by the |
| 915 | command loop as part of a command. The principal use of this variable | 912 | command loop as part of a command. The principal use of this variable |
| 916 | is in @code{self-insert-command}, which uses it to decide which | 913 | is in @code{self-insert-command}, which uses it to decide which |
| @@ -926,11 +923,8 @@ last-command-event | |||
| 926 | 923 | ||
| 927 | @noindent | 924 | @noindent |
| 928 | The value is 5 because that is the @acronym{ASCII} code for @kbd{C-e}. | 925 | The value is 5 because that is the @acronym{ASCII} code for @kbd{C-e}. |
| 929 | |||
| 930 | The alias @code{last-command-char} is obsolete. | ||
| 931 | @end defvar | 926 | @end defvar |
| 932 | 927 | ||
| 933 | @c Emacs 19 feature | ||
| 934 | @defvar last-event-frame | 928 | @defvar last-event-frame |
| 935 | This variable records which frame the last input event was directed to. | 929 | This variable records which frame the last input event was directed to. |
| 936 | Usually this is the frame that was selected when the event was | 930 | Usually this is the frame that was selected when the event was |
| @@ -2386,7 +2380,6 @@ mouse on the window's mode line, you get two events, like this: | |||
| 2386 | @end example | 2380 | @end example |
| 2387 | 2381 | ||
| 2388 | @defvar num-input-keys | 2382 | @defvar num-input-keys |
| 2389 | @c Emacs 19 feature | ||
| 2390 | This variable's value is the number of key sequences processed so far in | 2383 | This variable's value is the number of key sequences processed so far in |
| 2391 | this Emacs session. This includes key sequences read from the terminal | 2384 | this Emacs session. This includes key sequences read from the terminal |
| 2392 | and key sequences read from keyboard macros being executed. | 2385 | and key sequences read from keyboard macros being executed. |
| @@ -2539,7 +2532,6 @@ then continues to wait for a valid input character, or keyboard-quit. | |||
| 2539 | @code{keyboard-translate-table} (if applicable), before returning it | 2532 | @code{keyboard-translate-table} (if applicable), before returning it |
| 2540 | from @code{read-event}. | 2533 | from @code{read-event}. |
| 2541 | 2534 | ||
| 2542 | @c Emacs 19 feature | ||
| 2543 | @defvar extra-keyboard-modifiers | 2535 | @defvar extra-keyboard-modifiers |
| 2544 | This variable lets Lisp programs ``press'' the modifier keys on the | 2536 | This variable lets Lisp programs ``press'' the modifier keys on the |
| 2545 | keyboard. The value is a character. Only the modifiers of the | 2537 | keyboard. The value is a character. Only the modifiers of the |
| @@ -2755,7 +2747,6 @@ may return @code{t} when no input is available. | |||
| 2755 | @end defun | 2747 | @end defun |
| 2756 | 2748 | ||
| 2757 | @defvar last-input-event | 2749 | @defvar last-input-event |
| 2758 | @defvarx last-input-char | ||
| 2759 | This variable records the last terminal input event read, whether | 2750 | This variable records the last terminal input event read, whether |
| 2760 | as part of a command or explicitly by a Lisp program. | 2751 | as part of a command or explicitly by a Lisp program. |
| 2761 | 2752 | ||
| @@ -2774,8 +2765,6 @@ this expression) remains the value of @code{last-command-event}. | |||
| 2774 | @result{} 49 | 2765 | @result{} 49 |
| 2775 | @end group | 2766 | @end group |
| 2776 | @end example | 2767 | @end example |
| 2777 | |||
| 2778 | The alias @code{last-input-char} is obsolete. | ||
| 2779 | @end defvar | 2768 | @end defvar |
| 2780 | 2769 | ||
| 2781 | @defmac while-no-input body@dots{} | 2770 | @defmac while-no-input body@dots{} |
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 0b5ada43744..68701a47126 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -3550,8 +3550,8 @@ Used to indicate buffer boundaries. | |||
| 3550 | @itemx @code{vertical-bar}, @code{horizontal-bar} | 3550 | @itemx @code{vertical-bar}, @code{horizontal-bar} |
| 3551 | Used for different types of fringe cursors. | 3551 | Used for different types of fringe cursors. |
| 3552 | 3552 | ||
| 3553 | @item @code{empty-line}, @code{question-mark}, @code{exclamation-mark} | 3553 | @item @code{empty-line}, @code{exclamation-mark}, @code{question-mark}, @code{exclamation-mark} |
| 3554 | Unused. | 3554 | Not used by core Emacs features. |
| 3555 | @end table | 3555 | @end table |
| 3556 | 3556 | ||
| 3557 | @noindent | 3557 | @noindent |
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index d46cb071bf7..06a2ebfcaf8 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -486,6 +486,7 @@ Variables | |||
| 486 | * Variable Aliases:: Variables that are aliases for other variables. | 486 | * Variable Aliases:: Variables that are aliases for other variables. |
| 487 | * Variables with Restricted Values:: Non-constant variables whose value can | 487 | * Variables with Restricted Values:: Non-constant variables whose value can |
| 488 | @emph{not} be an arbitrary Lisp object. | 488 | @emph{not} be an arbitrary Lisp object. |
| 489 | * Generalized Variables:: Extending the concept of variables. | ||
| 489 | 490 | ||
| 490 | Scoping Rules for Variable Bindings | 491 | Scoping Rules for Variable Bindings |
| 491 | 492 | ||
| @@ -800,17 +801,14 @@ Menu Keymaps | |||
| 800 | * Menu Bar:: How to customize the menu bar. | 801 | * Menu Bar:: How to customize the menu bar. |
| 801 | * Tool Bar:: A tool bar is a row of images. | 802 | * Tool Bar:: A tool bar is a row of images. |
| 802 | * Modifying Menus:: How to add new items to a menu. | 803 | * Modifying Menus:: How to add new items to a menu. |
| 804 | * Easy Menu:: A convenience macro for defining menus. | ||
| 803 | 805 | ||
| 804 | Defining Menus | 806 | Defining Menus |
| 805 | 807 | ||
| 806 | * Simple Menu Items:: A simple kind of menu key binding, | 808 | * Simple Menu Items:: A simple kind of menu key binding. |
| 807 | limited in capabilities. | 809 | * Extended Menu Items:: More complex menu item definitions. |
| 808 | * Extended Menu Items:: More powerful menu item definitions | ||
| 809 | let you specify keywords to enable | ||
| 810 | various features. | ||
| 811 | * Menu Separators:: Drawing a horizontal line through a menu. | 810 | * Menu Separators:: Drawing a horizontal line through a menu. |
| 812 | * Alias Menu Items:: Using command aliases in menu items. | 811 | * Alias Menu Items:: Using command aliases in menu items. |
| 813 | * Toolkit Differences:: Not all toolkits provide the same features. | ||
| 814 | 812 | ||
| 815 | Major and Minor Modes | 813 | Major and Minor Modes |
| 816 | 814 | ||
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 285e6406426..a5710c789e9 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi | |||
| @@ -938,7 +938,7 @@ on the 19th, @file{aug-20} was written on the 20th, and the file | |||
| 938 | @end example | 938 | @end example |
| 939 | 939 | ||
| 940 | You can use @code{file-attributes} to get a file's last modification | 940 | You can use @code{file-attributes} to get a file's last modification |
| 941 | time as a list of two numbers. @xref{File Attributes}. | 941 | time as a list of four integers. @xref{File Attributes}. |
| 942 | @end defun | 942 | @end defun |
| 943 | 943 | ||
| 944 | @node Kinds of Files | 944 | @node Kinds of Files |
| @@ -1228,11 +1228,11 @@ so this time will always hold the midnight of the day of last access. | |||
| 1228 | 1228 | ||
| 1229 | @cindex modification time of file | 1229 | @cindex modification time of file |
| 1230 | @item | 1230 | @item |
| 1231 | The time of last modification as a list of two integers (as above). | 1231 | The time of last modification as a list of four integers (as above). |
| 1232 | This is the last time when the file's contents were modified. | 1232 | This is the last time when the file's contents were modified. |
| 1233 | 1233 | ||
| 1234 | @item | 1234 | @item |
| 1235 | The time of last status change as a list of two integers (as above). | 1235 | The time of last status change as a list of four integers (as above). |
| 1236 | This is the time of the last change to the file's access mode bits, | 1236 | This is the time of the last change to the file's access mode bits, |
| 1237 | its owner and group, and other information recorded in the filesystem | 1237 | its owner and group, and other information recorded in the filesystem |
| 1238 | for the file, beyond the file's contents. | 1238 | for the file, beyond the file's contents. |
| @@ -1275,9 +1275,9 @@ For example, here are the file attributes for @file{files.texi}: | |||
| 1275 | @group | 1275 | @group |
| 1276 | (file-attributes "files.texi" 'string) | 1276 | (file-attributes "files.texi" 'string) |
| 1277 | @result{} (nil 1 "lh" "users" | 1277 | @result{} (nil 1 "lh" "users" |
| 1278 | (19145 42977) | 1278 | (20614 64019 50040 152000) |
| 1279 | (19141 59576) | 1279 | (20000 23 0 0) |
| 1280 | (18340 17300) | 1280 | (20614 64555 902289 872000) |
| 1281 | 122295 "-rw-rw-rw-" | 1281 | 122295 "-rw-rw-rw-" |
| 1282 | nil (5888 2 . 43978) | 1282 | nil (5888 2 . 43978) |
| 1283 | (15479 . 46724)) | 1283 | (15479 . 46724)) |
| @@ -1301,14 +1301,14 @@ is owned by the user with name "lh". | |||
| 1301 | @item "users" | 1301 | @item "users" |
| 1302 | is in the group with name "users". | 1302 | is in the group with name "users". |
| 1303 | 1303 | ||
| 1304 | @item (19145 42977) | 1304 | @item (20614 64019 50040 152000) |
| 1305 | was last accessed on Oct 5 2009, at 10:01:37. | 1305 | was last accessed on October 23, 2012, at 20:12:03.050040152 UTC. |
| 1306 | 1306 | ||
| 1307 | @item (19141 59576) | 1307 | @item (20000 23 0 0) |
| 1308 | last had its contents modified on Oct 2 2009, at 13:49:12. | 1308 | was last modified on July 15, 2001, at 08:53:43 UTC. |
| 1309 | 1309 | ||
| 1310 | @item (18340 17300) | 1310 | @item (20614 64555 902289 872000) |
| 1311 | last had its status changed on Feb 2 2008, at 12:19:00. | 1311 | last had its status changed on October 23, 2012, at 20:20:59.902289872 UTC. |
| 1312 | 1312 | ||
| 1313 | @item 122295 | 1313 | @item 122295 |
| 1314 | is 122295 bytes long. (It may not contain 122295 characters, though, | 1314 | is 122295 bytes long. (It may not contain 122295 characters, though, |
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi index af6f4b4c079..f58d62675e5 100644 --- a/doc/lispref/frames.texi +++ b/doc/lispref/frames.texi | |||
| @@ -437,13 +437,11 @@ Emacs frames---the first frame, and subsequent frames. When using the X | |||
| 437 | Window System, you can get the same results by means of X resources | 437 | Window System, you can get the same results by means of X resources |
| 438 | in many cases. | 438 | in many cases. |
| 439 | 439 | ||
| 440 | Setting this variable does not affect existing frames. | 440 | Setting this variable does not affect existing frames. Furthermore, |
| 441 | functions that display a buffer in a separate frame may override the | ||
| 442 | default parameters by supplying their own parameters. | ||
| 441 | @end defopt | 443 | @end defopt |
| 442 | 444 | ||
| 443 | Functions that display a buffer in a separate frame can override the | ||
| 444 | default parameters by supplying their own parameters. @xref{Definition | ||
| 445 | of special-display-frame-alist}. | ||
| 446 | |||
| 447 | If you invoke Emacs with command-line options that specify frame | 445 | If you invoke Emacs with command-line options that specify frame |
| 448 | appearance, those options take effect by adding elements to either | 446 | appearance, those options take effect by adding elements to either |
| 449 | @code{initial-frame-alist} or @code{default-frame-alist}. Options | 447 | @code{initial-frame-alist} or @code{default-frame-alist}. Options |
| @@ -1495,8 +1493,9 @@ This function returns the visibility status of frame @var{frame}. The | |||
| 1495 | value is @code{t} if @var{frame} is visible, @code{nil} if it is | 1493 | value is @code{t} if @var{frame} is visible, @code{nil} if it is |
| 1496 | invisible, and @code{icon} if it is iconified. | 1494 | invisible, and @code{icon} if it is iconified. |
| 1497 | 1495 | ||
| 1498 | On a text terminal, all frames are considered visible, whether they | 1496 | On a text terminal, all frames are considered ``visible'' for the |
| 1499 | are currently being displayed or not. | 1497 | purposes of this function, even though only one frame is displayed. |
| 1498 | @xref{Raising and Lowering}. | ||
| 1500 | @end defun | 1499 | @end defun |
| 1501 | 1500 | ||
| 1502 | @deffn Command iconify-frame &optional frame | 1501 | @deffn Command iconify-frame &optional frame |
| @@ -1552,9 +1551,21 @@ If this is non-@code{nil}, activation of the minibuffer raises the frame | |||
| 1552 | that the minibuffer window is in. | 1551 | that the minibuffer window is in. |
| 1553 | @end defopt | 1552 | @end defopt |
| 1554 | 1553 | ||
| 1555 | You can also enable auto-raise (raising automatically when a frame is | 1554 | On window systems, you can also enable auto-raising (on frame |
| 1556 | selected) or auto-lower (lowering automatically when it is deselected) | 1555 | selection) or auto-lowering (on frame deselection) using frame |
| 1557 | for any frame using frame parameters. @xref{Management Parameters}. | 1556 | parameters. @xref{Management Parameters}. |
| 1557 | |||
| 1558 | @cindex top frame | ||
| 1559 | The concept of raising and lowering frames also applies to text | ||
| 1560 | terminal frames. On each text terminal, only the top frame is | ||
| 1561 | displayed at any one time. | ||
| 1562 | |||
| 1563 | @defun tty-top-frame terminal | ||
| 1564 | This function returns the top frame on @var{terminal}. @var{terminal} | ||
| 1565 | should be a terminal object, a frame (meaning that frame's terminal), | ||
| 1566 | or @code{nil} (meaning the selected frame's terminal). If it does not | ||
| 1567 | refer to a text terminal, the return value is @code{nil}. | ||
| 1568 | @end defun | ||
| 1558 | 1569 | ||
| 1559 | @node Frame Configurations | 1570 | @node Frame Configurations |
| 1560 | @section Frame Configurations | 1571 | @section Frame Configurations |
diff --git a/doc/lispref/hooks.texi b/doc/lispref/hooks.texi index a7f01243641..a6ac2c70e84 100644 --- a/doc/lispref/hooks.texi +++ b/doc/lispref/hooks.texi | |||
| @@ -120,14 +120,7 @@ The command loop runs this soon after @code{post-command-hook} (q.v.). | |||
| 120 | @item delete-terminal-functions | 120 | @item delete-terminal-functions |
| 121 | @xref{Multiple Terminals}. | 121 | @xref{Multiple Terminals}. |
| 122 | 122 | ||
| 123 | @ignore | ||
| 124 | @item disabled-command-function | ||
| 125 | @xref{Disabling Commands}. | ||
| 126 | @end ignore | ||
| 127 | |||
| 128 | @item display-buffer-function | ||
| 129 | @itemx pop-up-frame-function | 123 | @itemx pop-up-frame-function |
| 130 | @itemx special-display-function | ||
| 131 | @itemx split-window-preferred-function | 124 | @itemx split-window-preferred-function |
| 132 | @xref{Choosing Window Options}. | 125 | @xref{Choosing Window Options}. |
| 133 | 126 | ||
| @@ -272,7 +265,6 @@ deferred-action-function | |||
| 272 | input-method-function | 265 | input-method-function |
| 273 | load-read-function | 266 | load-read-function |
| 274 | load-source-file-function | 267 | load-source-file-function |
| 275 | macro-declaration-function | ||
| 276 | read-buffer-function | 268 | read-buffer-function |
| 277 | ring-bell-function | 269 | ring-bell-function |
| 278 | select-safe-coding-system-function | 270 | select-safe-coding-system-function |
diff --git a/doc/lispref/intro.texi b/doc/lispref/intro.texi index e61e13662db..4770701b601 100644 --- a/doc/lispref/intro.texi +++ b/doc/lispref/intro.texi | |||
| @@ -493,13 +493,13 @@ giving a prefix argument makes @var{here} non-@code{nil}. | |||
| 493 | 493 | ||
| 494 | @defvar emacs-build-time | 494 | @defvar emacs-build-time |
| 495 | The value of this variable indicates the time at which Emacs was | 495 | The value of this variable indicates the time at which Emacs was |
| 496 | built. It is a list of three integers, like the value of | 496 | built. It is a list of four integers, like the value of |
| 497 | @code{current-time} (@pxref{Time of Day}). | 497 | @code{current-time} (@pxref{Time of Day}). |
| 498 | 498 | ||
| 499 | @example | 499 | @example |
| 500 | @group | 500 | @group |
| 501 | emacs-build-time | 501 | emacs-build-time |
| 502 | @result{} (18846 52016 156039) | 502 | @result{} (20614 63694 515336 438000) |
| 503 | @end group | 503 | @end group |
| 504 | @end example | 504 | @end example |
| 505 | @end defvar | 505 | @end defvar |
diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi index 9fa6193a804..f658f7e66fb 100644 --- a/doc/lispref/keymaps.texi +++ b/doc/lispref/keymaps.texi | |||
| @@ -210,6 +210,11 @@ Aside from elements that specify bindings for keys, a keymap can also | |||
| 210 | have a string as an element. This is called the @dfn{overall prompt | 210 | have a string as an element. This is called the @dfn{overall prompt |
| 211 | string} and makes it possible to use the keymap as a menu. | 211 | string} and makes it possible to use the keymap as a menu. |
| 212 | @xref{Defining Menus}. | 212 | @xref{Defining Menus}. |
| 213 | |||
| 214 | @item (keymap @dots{}) | ||
| 215 | If an element of a keymap is itself a keymap, it counts as if this inner keymap | ||
| 216 | were inlined in the outer keymap. This is used for multiple-inheritance, such | ||
| 217 | as in @code{make-composed-keymap}. | ||
| 213 | @end table | 218 | @end table |
| 214 | 219 | ||
| 215 | When the binding is @code{nil}, it doesn't constitute a definition | 220 | When the binding is @code{nil}, it doesn't constitute a definition |
| @@ -1963,13 +1968,14 @@ is active for the next input event, that activates the keyboard menu | |||
| 1963 | feature. | 1968 | feature. |
| 1964 | 1969 | ||
| 1965 | @menu | 1970 | @menu |
| 1966 | * Defining Menus:: How to make a keymap that defines a menu. | 1971 | * Defining Menus:: How to make a keymap that defines a menu. |
| 1967 | * Mouse Menus:: How users actuate the menu with the mouse. | 1972 | * Mouse Menus:: How users actuate the menu with the mouse. |
| 1968 | * Keyboard Menus:: How users actuate the menu with the keyboard. | 1973 | * Keyboard Menus:: How users actuate the menu with the keyboard. |
| 1969 | * Menu Example:: Making a simple menu. | 1974 | * Menu Example:: Making a simple menu. |
| 1970 | * Menu Bar:: How to customize the menu bar. | 1975 | * Menu Bar:: How to customize the menu bar. |
| 1971 | * Tool Bar:: A tool bar is a row of images. | 1976 | * Tool Bar:: A tool bar is a row of images. |
| 1972 | * Modifying Menus:: How to add new items to a menu. | 1977 | * Modifying Menus:: How to add new items to a menu. |
| 1978 | * Easy Menu:: A convenience macro for making menus. | ||
| 1973 | @end menu | 1979 | @end menu |
| 1974 | 1980 | ||
| 1975 | @node Defining Menus | 1981 | @node Defining Menus |
| @@ -2015,17 +2021,12 @@ an existing menu, you can specify its position in the menu using | |||
| 2015 | @code{define-key-after} (@pxref{Modifying Menus}). | 2021 | @code{define-key-after} (@pxref{Modifying Menus}). |
| 2016 | 2022 | ||
| 2017 | @menu | 2023 | @menu |
| 2018 | * Simple Menu Items:: A simple kind of menu key binding, | 2024 | * Simple Menu Items:: A simple kind of menu key binding. |
| 2019 | limited in capabilities. | 2025 | * Extended Menu Items:: More complex menu item definitions. |
| 2020 | * Extended Menu Items:: More powerful menu item definitions | ||
| 2021 | let you specify keywords to enable | ||
| 2022 | various features. | ||
| 2023 | * Menu Separators:: Drawing a horizontal line through a menu. | 2026 | * Menu Separators:: Drawing a horizontal line through a menu. |
| 2024 | * Alias Menu Items:: Using command aliases in menu items. | 2027 | * Alias Menu Items:: Using command aliases in menu items. |
| 2025 | * Toolkit Differences:: Not all toolkits provide the same features. | ||
| 2026 | @end menu | 2028 | @end menu |
| 2027 | 2029 | ||
| 2028 | |||
| 2029 | @node Simple Menu Items | 2030 | @node Simple Menu Items |
| 2030 | @subsubsection Simple Menu Items | 2031 | @subsubsection Simple Menu Items |
| 2031 | 2032 | ||
| @@ -2312,28 +2313,6 @@ itself). To request this, give the alias symbol a non-@code{nil} | |||
| 2312 | causes menu items for @code{make-read-only} and @code{make-writable} to | 2313 | causes menu items for @code{make-read-only} and @code{make-writable} to |
| 2313 | show the keyboard bindings for @code{read-only-mode}. | 2314 | show the keyboard bindings for @code{read-only-mode}. |
| 2314 | 2315 | ||
| 2315 | @node Toolkit Differences | ||
| 2316 | @subsubsection Toolkit Differences | ||
| 2317 | |||
| 2318 | The various toolkits with which you can build Emacs do not all support | ||
| 2319 | the same set of features for menus. Some code works as expected with | ||
| 2320 | one toolkit, but not under another. | ||
| 2321 | |||
| 2322 | One example is menu actions or buttons in a top-level menu bar. The | ||
| 2323 | following works with the Lucid toolkit or on MS Windows, but not with | ||
| 2324 | GTK or Nextstep, where clicking on the item has no effect. | ||
| 2325 | |||
| 2326 | @example | ||
| 2327 | (defun menu-action-greet () | ||
| 2328 | (interactive) | ||
| 2329 | (message "Hello Emacs User!")) | ||
| 2330 | |||
| 2331 | (defun top-level-menu () | ||
| 2332 | (interactive) | ||
| 2333 | (define-key lisp-interaction-mode-map [menu-bar m] | ||
| 2334 | '(menu-item "Action Button" menu-action-greet))) | ||
| 2335 | @end example | ||
| 2336 | |||
| 2337 | @node Mouse Menus | 2316 | @node Mouse Menus |
| 2338 | @subsection Menus and the Mouse | 2317 | @subsection Menus and the Mouse |
| 2339 | 2318 | ||
| @@ -2813,3 +2792,125 @@ menu of Shell mode, after the item @code{break}: | |||
| 2813 | [work] '("Work" . work-command) 'break) | 2792 | [work] '("Work" . work-command) 'break) |
| 2814 | @end example | 2793 | @end example |
| 2815 | @end defun | 2794 | @end defun |
| 2795 | |||
| 2796 | @node Easy Menu | ||
| 2797 | @subsection Easy Menu | ||
| 2798 | |||
| 2799 | The following macro provides a convenient way to define pop-up menus | ||
| 2800 | and/or menu bar menus. | ||
| 2801 | |||
| 2802 | @defmac easy-menu-define symbol maps doc menu | ||
| 2803 | This macro defines a pop-up menu and/or menu bar submenu, whose | ||
| 2804 | contents are given by @var{menu}. | ||
| 2805 | |||
| 2806 | If @var{symbol} is non-@code{nil}, it should be a symbol; then this | ||
| 2807 | macro defines @var{symbol} as a function for popping up the menu | ||
| 2808 | (@pxref{Pop-Up Menus}), with @var{doc} as its documentation string. | ||
| 2809 | @var{symbol} should not be quoted. | ||
| 2810 | |||
| 2811 | Regardless of the value of @var{symbol}, if @var{maps} is a keymap, | ||
| 2812 | the menu is added to that keymap, as a top-level menu for the menu bar | ||
| 2813 | (@pxref{Menu Bar}). It can also be a list of keymaps, in which case | ||
| 2814 | the menu is added separately to each of those keymaps. | ||
| 2815 | |||
| 2816 | The first element of @var{menu} must be a string, which serves as the | ||
| 2817 | menu label. It may be followed by any number of the following | ||
| 2818 | keyword-argument pairs: | ||
| 2819 | |||
| 2820 | @table @code | ||
| 2821 | @item :filter @var{function} | ||
| 2822 | @var{function} must be a function which, if called with one | ||
| 2823 | argument---the list of the other menu items---returns the actual items | ||
| 2824 | to be displayed in the menu. | ||
| 2825 | |||
| 2826 | @item :visible @var{include} | ||
| 2827 | @var{include} is an expression; if it evaluates to @code{nil}, the | ||
| 2828 | menu is made invisible. @code{:included} is an alias for | ||
| 2829 | @code{:visible}. | ||
| 2830 | |||
| 2831 | @item :active @var{enable} | ||
| 2832 | @var{enable} is an expression; if it evaluates to @code{nil}, the menu | ||
| 2833 | is not selectable. @code{:enable} is an alias for @code{:active}. | ||
| 2834 | @end table | ||
| 2835 | |||
| 2836 | The remaining elements in @var{menu} are menu items. | ||
| 2837 | |||
| 2838 | A menu item can be a vector of three elements, @code{[@var{name} | ||
| 2839 | @var{callback} @var{enable}]}. @var{name} is the menu item name (a | ||
| 2840 | string). @var{callback} is a command to run, or an expression to | ||
| 2841 | evaluate, when the item is chosen. @var{enable} is an expression; if | ||
| 2842 | it evaluates to @code{nil}, the item is disabled for selection. | ||
| 2843 | |||
| 2844 | Alternatively, a menu item may have the form: | ||
| 2845 | |||
| 2846 | @smallexample | ||
| 2847 | [ @var{name} @var{callback} [ @var{keyword} @var{arg} ]... ] | ||
| 2848 | @end smallexample | ||
| 2849 | |||
| 2850 | @noindent | ||
| 2851 | where @var{name} and @var{callback} have the same meanings as above, | ||
| 2852 | and each optional @var{keyword} and @var{arg} pair should be one of | ||
| 2853 | the following: | ||
| 2854 | |||
| 2855 | @table @code | ||
| 2856 | @item :keys @var{keys} | ||
| 2857 | @var{keys} is a keyboard equivalent to the menu item (a string). This | ||
| 2858 | is normally not needed, as keyboard equivalents are computed | ||
| 2859 | automatically. @var{keys} is expanded with | ||
| 2860 | @code{substitute-command-keys} before it is displayed (@pxref{Keys in | ||
| 2861 | Documentation}). | ||
| 2862 | |||
| 2863 | @item :key-sequence @var{keys} | ||
| 2864 | @var{keys} is a hint for speeding up Emacs's first display of the | ||
| 2865 | menu. It should be nil if you know that the menu item has no keyboard | ||
| 2866 | equivalent; otherwise it should be a string or vector specifying a | ||
| 2867 | keyboard equivalent for the menu item. | ||
| 2868 | |||
| 2869 | @item :active @var{enable} | ||
| 2870 | @var{enable} is an expression; if it evaluates to @code{nil}, the item | ||
| 2871 | is make unselectable.. @code{:enable} is an alias for @code{:active}. | ||
| 2872 | |||
| 2873 | @item :visible @var{include} | ||
| 2874 | @var{include} is an expression; if it evaluates to @code{nil}, the | ||
| 2875 | item is made invisible. @code{:included} is an alias for | ||
| 2876 | @code{:visible}. | ||
| 2877 | |||
| 2878 | @item :label @var{form} | ||
| 2879 | @var{form} is an expression that is evaluated to obtain a value which | ||
| 2880 | serves as the menu item's label (the default is @var{name}). | ||
| 2881 | |||
| 2882 | @item :suffix @var{form} | ||
| 2883 | @var{form} is an expression that is dynamically evaluated and whose | ||
| 2884 | value is concatenated with the menu entry's label. | ||
| 2885 | |||
| 2886 | @item :style @var{style} | ||
| 2887 | @var{style} is a symbol describing the type of menu item; it should be | ||
| 2888 | @code{toggle} (a checkbox), or @code{radio} (a radio button), or | ||
| 2889 | anything else (meaning an ordinary menu item). | ||
| 2890 | |||
| 2891 | @item :selected @var{selected} | ||
| 2892 | @var{selected} is an expression; the checkbox or radio button is | ||
| 2893 | selected whenever the expression's value is non-nil. | ||
| 2894 | |||
| 2895 | @item :help @var{help} | ||
| 2896 | @var{help} is a string describing the menu item. | ||
| 2897 | @end table | ||
| 2898 | |||
| 2899 | Alternatively, a menu item can be a string. Then that string appears | ||
| 2900 | in the menu as unselectable text. A string consisting of dashes is | ||
| 2901 | displayed as a separator (@pxref{Menu Separators}). | ||
| 2902 | |||
| 2903 | Alternatively, a menu item can be a list with the same format as | ||
| 2904 | @var{menu}. This is a submenu. | ||
| 2905 | @end defmac | ||
| 2906 | |||
| 2907 | Here is an example of using @code{easy-menu-define} to define a menu | ||
| 2908 | similar to the one defined in the example in @ref{Menu Bar}: | ||
| 2909 | |||
| 2910 | @example | ||
| 2911 | (easy-menu-define words-menu global-map | ||
| 2912 | "Menu for word navigation commands." | ||
| 2913 | '("Words" | ||
| 2914 | ["Forward word" forward-word] | ||
| 2915 | ["Backward word" backward-word])) | ||
| 2916 | @end example | ||
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 4a8740a5734..09948caaa13 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi | |||
| @@ -236,6 +236,10 @@ This is in contrast to @code{cdr}, which signals an error if | |||
| 236 | @defmac pop listname | 236 | @defmac pop listname |
| 237 | This macro is a way of examining the @sc{car} of a list, | 237 | This macro is a way of examining the @sc{car} of a list, |
| 238 | and taking it off the list, all at once. | 238 | and taking it off the list, all at once. |
| 239 | @c FIXME I don't think is a particularly good way to do it, | ||
| 240 | @c but generalized variables have not been introduced yet. | ||
| 241 | (In fact, this macro can act on generalized variables, not just lists. | ||
| 242 | @xref{Generalized Variables}.) | ||
| 239 | 243 | ||
| 240 | It operates on the list which is stored in the symbol @var{listname}. | 244 | It operates on the list which is stored in the symbol @var{listname}. |
| 241 | It removes this element from the list by setting @var{listname} | 245 | It removes this element from the list by setting @var{listname} |
| @@ -252,7 +256,7 @@ x | |||
| 252 | @end example | 256 | @end example |
| 253 | 257 | ||
| 254 | @noindent | 258 | @noindent |
| 255 | For the @code{pop} macro, which removes an element from a list, | 259 | For the @code{push} macro, which adds an element to a list, |
| 256 | @xref{List Variables}. | 260 | @xref{List Variables}. |
| 257 | @end defmac | 261 | @end defmac |
| 258 | 262 | ||
| @@ -682,6 +686,10 @@ to modify a list which is stored in a variable. | |||
| 682 | @defmac push newelt listname | 686 | @defmac push newelt listname |
| 683 | This macro provides an alternative way to write | 687 | This macro provides an alternative way to write |
| 684 | @code{(setq @var{listname} (cons @var{newelt} @var{listname}))}. | 688 | @code{(setq @var{listname} (cons @var{newelt} @var{listname}))}. |
| 689 | @c FIXME I don't think is a particularly good way to do it, | ||
| 690 | @c but generalized variables have not been introduced yet. | ||
| 691 | (In fact, this macro can act on generalized variables, not just lists. | ||
| 692 | @xref{Generalized Variables}.) | ||
| 685 | 693 | ||
| 686 | @example | 694 | @example |
| 687 | (setq l '(a b)) | 695 | (setq l '(a b)) |
diff --git a/doc/lispref/loading.texi b/doc/lispref/loading.texi index 77a31cfde7a..6a18bea2977 100644 --- a/doc/lispref/loading.texi +++ b/doc/lispref/loading.texi | |||
| @@ -408,9 +408,9 @@ to load automatically from @var{filename}. The string @var{filename} | |||
| 408 | specifies the file to load to get the real definition of @var{function}. | 408 | specifies the file to load to get the real definition of @var{function}. |
| 409 | 409 | ||
| 410 | If @var{filename} does not contain either a directory name, or the | 410 | If @var{filename} does not contain either a directory name, or the |
| 411 | suffix @code{.el} or @code{.elc}, then @code{autoload} insists on adding | 411 | suffix @code{.el} or @code{.elc}, this function insists on adding one |
| 412 | one of these suffixes, and it will not load from a file whose name is | 412 | of these suffixes, and it will not load from a file whose name is just |
| 413 | just @var{filename} with no added suffix. (The variable | 413 | @var{filename} with no added suffix. (The variable |
| 414 | @code{load-suffixes} specifies the exact required suffixes.) | 414 | @code{load-suffixes} specifies the exact required suffixes.) |
| 415 | 415 | ||
| 416 | The argument @var{docstring} is the documentation string for the | 416 | The argument @var{docstring} is the documentation string for the |
| @@ -442,10 +442,11 @@ and calls @code{define-key}; not even if the variable name is the same | |||
| 442 | symbol @var{function}. | 442 | symbol @var{function}. |
| 443 | 443 | ||
| 444 | @cindex function cell in autoload | 444 | @cindex function cell in autoload |
| 445 | If @var{function} already has a non-void function definition that is not | 445 | if @var{function} already has non-void function definition that is not |
| 446 | an autoload object, @code{autoload} does nothing and returns @code{nil}. | 446 | an autoload object, this function does nothing and returns @code{nil}. |
| 447 | If the function cell of @var{function} is void, or is already an autoload | 447 | Otherwise, it constructs an autoload object (@pxref{Autoload Type}), |
| 448 | object, then it is defined as an autoload object like this: | 448 | and stores it as the function definition for @var{function}. The |
| 449 | autoload object has this form: | ||
| 449 | 450 | ||
| 450 | @example | 451 | @example |
| 451 | (autoload @var{filename} @var{docstring} @var{interactive} @var{type}) | 452 | (autoload @var{filename} @var{docstring} @var{interactive} @var{type}) |
| @@ -468,6 +469,16 @@ refers to the documentation string in the | |||
| 468 | not a macro or a keymap. | 469 | not a macro or a keymap. |
| 469 | @end defun | 470 | @end defun |
| 470 | 471 | ||
| 472 | @defun autoloadp object | ||
| 473 | This function returns non-@code{nil} if @var{object} is an autoload | ||
| 474 | object. For example, to check if @code{run-prolog} is defined as an | ||
| 475 | autoloaded function, evaluate | ||
| 476 | |||
| 477 | @smallexample | ||
| 478 | (autoloadp (symbol-function 'run-prolog)) | ||
| 479 | @end smallexample | ||
| 480 | @end defun | ||
| 481 | |||
| 471 | @cindex autoload errors | 482 | @cindex autoload errors |
| 472 | The autoloaded file usually contains other definitions and may require | 483 | The autoloaded file usually contains other definitions and may require |
| 473 | or provide one or more features. If the file is not completely loaded | 484 | or provide one or more features. If the file is not completely loaded |
| @@ -599,6 +610,19 @@ override that, e.g., in the ``Local Variables'' section of a | |||
| 599 | assumed to contain a trailer starting with a formfeed character. | 610 | assumed to contain a trailer starting with a formfeed character. |
| 600 | @end defvar | 611 | @end defvar |
| 601 | 612 | ||
| 613 | The following function may be used to explicitly load the library | ||
| 614 | specified by an autoload object: | ||
| 615 | |||
| 616 | @defun autoload-do-load autoload &optional name macro-only | ||
| 617 | This function performs the loading specified by @var{autoload}, which | ||
| 618 | whould be an autoload object. The optional argument @var{name}, if | ||
| 619 | non-@code{nil}, should be a symbol whose function value is | ||
| 620 | @var{autoload}; in that case, the return value of this function is the | ||
| 621 | symbol's new function value. If the value of the optional argument | ||
| 622 | @var{macro-only} is @code{macro}, this function avoids loading a | ||
| 623 | function, only a macro. | ||
| 624 | @end defun | ||
| 625 | |||
| 602 | @node Repeated Loading | 626 | @node Repeated Loading |
| 603 | @section Repeated Loading | 627 | @section Repeated Loading |
| 604 | @cindex repeated loading | 628 | @cindex repeated loading |
diff --git a/doc/lispref/markers.texi b/doc/lispref/markers.texi index 80136f2e6f4..fa884269b36 100644 --- a/doc/lispref/markers.texi +++ b/doc/lispref/markers.texi | |||
| @@ -307,11 +307,6 @@ This function returns the buffer that @var{marker} points into, or | |||
| 307 | @end example | 307 | @end example |
| 308 | @end defun | 308 | @end defun |
| 309 | 309 | ||
| 310 | @defun buffer-has-markers-at position | ||
| 311 | This function returns @code{t} if one or more markers | ||
| 312 | point at position @var{position} in the current buffer. | ||
| 313 | @end defun | ||
| 314 | |||
| 315 | @node Marker Insertion Types | 310 | @node Marker Insertion Types |
| 316 | @section Marker Insertion Types | 311 | @section Marker Insertion Types |
| 317 | 312 | ||
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 39b4fca3b25..7243f46b882 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi | |||
| @@ -211,22 +211,25 @@ This function works by calling the | |||
| 211 | @end smallexample | 211 | @end smallexample |
| 212 | @end defun | 212 | @end defun |
| 213 | 213 | ||
| 214 | @defun read-regexp prompt &optional default | 214 | @defun read-regexp prompt &optional default history |
| 215 | This function reads a regular expression as a string from the | 215 | This function reads a regular expression as a string from the |
| 216 | minibuffer and returns it. The argument @var{prompt} is used as in | 216 | minibuffer and returns it. The argument @var{prompt} is used as in |
| 217 | @code{read-from-minibuffer}. The keymap used is | 217 | @code{read-from-minibuffer}. |
| 218 | @code{minibuffer-local-map}, and @code{regexp-history} is used as the | ||
| 219 | history list (@pxref{Minibuffer History, regexp-history}). | ||
| 220 | 218 | ||
| 221 | The optional argument @var{default} specifies a default value to | 219 | The optional argument @var{default} specifies a default value to |
| 222 | return if the user enters null input; it should be a string, or | 220 | return if the user enters null input; it should be a string, or |
| 223 | @code{nil}, which is equivalent to an empty string. | 221 | @code{nil}, which is equivalent to an empty string. |
| 224 | 222 | ||
| 225 | In addition, @code{read-regexp} collects a few useful candidates for | 223 | The optional argument @var{history}, if non-@code{nil}, is a symbol |
| 226 | input and passes them to @code{read-from-minibuffer}, to make them | 224 | specifying a minibuffer history list to use (@pxref{Minibuffer |
| 227 | available to the user as the ``future minibuffer history list'' | 225 | History}). If it is omitted or @code{nil}, the history list defaults |
| 228 | (@pxref{Minibuffer History, future list,, emacs, The GNU Emacs | 226 | to @code{regexp-history}. |
| 229 | Manual}). These candidates are: | 227 | |
| 228 | @code{read-regexp} also collects a few useful candidates for input and | ||
| 229 | passes them to @code{read-from-minibuffer}, to make them available to | ||
| 230 | the user as the ``future minibuffer history list'' (@pxref{Minibuffer | ||
| 231 | History, future list,, emacs, The GNU Emacs Manual}). These | ||
| 232 | candidates are: | ||
| 230 | 233 | ||
| 231 | @itemize @minus | 234 | @itemize @minus |
| 232 | @item | 235 | @item |
| @@ -1215,11 +1218,9 @@ Buffer name (default foo): @point{} | |||
| 1215 | @end defun | 1218 | @end defun |
| 1216 | 1219 | ||
| 1217 | @defopt read-buffer-function | 1220 | @defopt read-buffer-function |
| 1218 | This variable specifies how to read buffer names. The function is | 1221 | This variable, if non-@code{nil}, specifies a function for reading |
| 1219 | called with the arguments passed to @code{read-buffer}. For example, | 1222 | buffer names. @code{read-buffer} calls this function instead of doing |
| 1220 | if you set this variable to @code{iswitchb-read-buffer}, all Emacs | 1223 | its usual work, with the same arguments passed to @code{read-buffer}. |
| 1221 | commands that call @code{read-buffer} to read a buffer name will | ||
| 1222 | actually use the @code{iswitchb} package to read it. | ||
| 1223 | @end defopt | 1224 | @end defopt |
| 1224 | 1225 | ||
| 1225 | @defopt read-buffer-completion-ignore-case | 1226 | @defopt read-buffer-completion-ignore-case |
diff --git a/doc/lispref/nonascii.texi b/doc/lispref/nonascii.texi index 2f6f516c587..e384d40176e 100644 --- a/doc/lispref/nonascii.texi +++ b/doc/lispref/nonascii.texi | |||
| @@ -241,8 +241,12 @@ representation is in use. It also adjusts various data in the buffer | |||
| 241 | (including overlays, text properties and markers) so that they cover the | 241 | (including overlays, text properties and markers) so that they cover the |
| 242 | same text as they did before. | 242 | same text as they did before. |
| 243 | 243 | ||
| 244 | You cannot use @code{set-buffer-multibyte} on an indirect buffer, | 244 | This function signals an error if the buffer is narrowed, since the |
| 245 | because indirect buffers always inherit the representation of the | 245 | narrowing might have occurred in the middle of multibyte character |
| 246 | sequences. | ||
| 247 | |||
| 248 | This function also signals an error if the buffer is an indirect | ||
| 249 | buffer. An indirect buffer always inherits the representation of its | ||
| 246 | base buffer. | 250 | base buffer. |
| 247 | @end defun | 251 | @end defun |
| 248 | 252 | ||
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index d3c3c6fd241..6c5f6e85683 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -1199,7 +1199,7 @@ Similarly, the fourth list element @var{picosec}, if present, gives | |||
| 1199 | the number of picoseconds from the start of that microsecond to the | 1199 | the number of picoseconds from the start of that microsecond to the |
| 1200 | specified time. | 1200 | specified time. |
| 1201 | 1201 | ||
| 1202 | The return value of @code{current-time} represents time using three | 1202 | The return value of @code{current-time} represents time using four |
| 1203 | integers, as do the timestamps in the return value of | 1203 | integers, as do the timestamps in the return value of |
| 1204 | @code{file-attributes} (@pxref{Definition of | 1204 | @code{file-attributes} (@pxref{Definition of |
| 1205 | file-attributes}). In function arguments, e.g.@: the @var{time-value} | 1205 | file-attributes}). In function arguments, e.g.@: the @var{time-value} |
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi index d7497ab6f3f..326c6cd4ab2 100644 --- a/doc/lispref/symbols.texi +++ b/doc/lispref/symbols.texi | |||
| @@ -487,6 +487,12 @@ using @code{eq}, so any object is a legitimate property. | |||
| 487 | See @code{put} for an example. | 487 | See @code{put} for an example. |
| 488 | @end defun | 488 | @end defun |
| 489 | 489 | ||
| 490 | @defun function-get symbol property | ||
| 491 | This function is identical to @code{get}, except that if @var{symbol} | ||
| 492 | is the name of a function alias, it looks in the property list of the | ||
| 493 | symbol naming the actual function. @xref{Defining Functions}. | ||
| 494 | @end defun | ||
| 495 | |||
| 490 | @defun put symbol property value | 496 | @defun put symbol property value |
| 491 | This function puts @var{value} onto @var{symbol}'s property list under | 497 | This function puts @var{value} onto @var{symbol}'s property list under |
| 492 | the property name @var{property}, replacing any previous property value. | 498 | the property name @var{property}, replacing any previous property value. |
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 50b97cd4204..57df02b74a0 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -899,31 +899,34 @@ In Lisp programs, it is better to use @code{kill-new} or | |||
| 899 | @node Yanking | 899 | @node Yanking |
| 900 | @subsection Yanking | 900 | @subsection Yanking |
| 901 | 901 | ||
| 902 | Yanking means inserting text from the kill ring, but it does | 902 | Yanking means inserting text from the kill ring, but it does not |
| 903 | not insert the text blindly. Yank commands and some other commands | 903 | insert the text blindly. The @code{yank} command, and related |
| 904 | use @code{insert-for-yank} to perform special processing on the | 904 | commands, use @code{insert-for-yank} to perform special processing on |
| 905 | text that they copy into the buffer. | 905 | the text before it is inserted. |
| 906 | 906 | ||
| 907 | @defun insert-for-yank string | 907 | @defun insert-for-yank string |
| 908 | This function normally works like @code{insert} except that it doesn't | 908 | This function works like @code{insert}, except that it processes the |
| 909 | insert the text properties (@pxref{Text Properties}) in the list | 909 | text in @var{string} according to the @code{yank-handler} text |
| 910 | variable @code{yank-excluded-properties}. However, if any part of | 910 | property, as well as the variables @code{yank-handled-properties} and |
| 911 | @var{string} has a non-@code{nil} @code{yank-handler} text property, | 911 | @code{yank-excluded-properties} (see below), before inserting the |
| 912 | that property can do various special processing on that part of the | 912 | result into the current buffer. |
| 913 | text being inserted. | ||
| 914 | @end defun | 913 | @end defun |
| 915 | 914 | ||
| 916 | @defun insert-buffer-substring-as-yank buf &optional start end | 915 | @defun insert-buffer-substring-as-yank buf &optional start end |
| 917 | This function resembles @code{insert-buffer-substring} except that it | 916 | This function resembles @code{insert-buffer-substring}, except that it |
| 918 | doesn't insert the text properties in the | 917 | processes the text according to @code{yank-handled-properties} and |
| 919 | @code{yank-excluded-properties} list. | 918 | @code{yank-excluded-properties}. (It does not handle the |
| 919 | @code{yank-handler} property, which does not normally occur in buffer | ||
| 920 | text anyway.) | ||
| 920 | @end defun | 921 | @end defun |
| 921 | 922 | ||
| 922 | You can put a @code{yank-handler} text property on all or part of | 923 | If you put a @code{yank-handler} text property on all or part of a |
| 923 | the text to control how it will be inserted if it is yanked. The | 924 | string, that alters how @code{insert-for-yank} inserts the string. If |
| 924 | @code{insert-for-yank} function looks for that property. The property | 925 | different parts of the string have different @code{yank-handler} |
| 925 | value must be a list of one to four elements, with the following | 926 | values (comparison being done with @code{eq}), each substring is |
| 926 | format (where elements after the first may be omitted): | 927 | handled separately. The property value must be a list of one to four |
| 928 | elements, with the following format (where elements after the first | ||
| 929 | may be omitted): | ||
| 927 | 930 | ||
| 928 | @example | 931 | @example |
| 929 | (@var{function} @var{param} @var{noexclude} @var{undo}) | 932 | (@var{function} @var{param} @var{noexclude} @var{undo}) |
| @@ -933,22 +936,21 @@ format (where elements after the first may be omitted): | |||
| 933 | 936 | ||
| 934 | @table @var | 937 | @table @var |
| 935 | @item function | 938 | @item function |
| 936 | When @var{function} is present and non-@code{nil}, it is called instead of | 939 | When @var{function} is non-@code{nil}, it is called instead of |
| 937 | @code{insert} to insert the string. @var{function} takes one | 940 | @code{insert} to insert the string, with one argument---the string to |
| 938 | argument---the string to insert. | 941 | insert. |
| 939 | 942 | ||
| 940 | @item param | 943 | @item param |
| 941 | If @var{param} is present and non-@code{nil}, it replaces @var{string} | 944 | If @var{param} is present and non-@code{nil}, it replaces @var{string} |
| 942 | (or the part of @var{string} being processed) as the object passed to | 945 | (or the substring of @var{string} being processed) as the object |
| 943 | @var{function} (or @code{insert}); for example, if @var{function} is | 946 | passed to @var{function} (or @code{insert}). For example, if |
| 944 | @code{yank-rectangle}, @var{param} should be a list of strings to | 947 | @var{function} is @code{yank-rectangle}, @var{param} should be a list |
| 945 | insert as a rectangle. | 948 | of strings to insert as a rectangle. |
| 946 | 949 | ||
| 947 | @item noexclude | 950 | @item noexclude |
| 948 | If @var{noexclude} is present and non-@code{nil}, the normal removal of the | 951 | If @var{noexclude} is present and non-@code{nil}, that disables the |
| 949 | yank-excluded-properties is not performed; instead @var{function} is | 952 | normal action of @code{yank-handled-properties} and |
| 950 | responsible for removing those properties. This may be necessary | 953 | @code{yank-excluded-properties} on the inserted string. |
| 951 | if @var{function} adjusts point before or after inserting the object. | ||
| 952 | 954 | ||
| 953 | @item undo | 955 | @item undo |
| 954 | If @var{undo} is present and non-@code{nil}, it is a function that will be | 956 | If @var{undo} is present and non-@code{nil}, it is a function that will be |
| @@ -959,14 +961,29 @@ the @var{undo} value. | |||
| 959 | @end table | 961 | @end table |
| 960 | 962 | ||
| 961 | @cindex yanking and text properties | 963 | @cindex yanking and text properties |
| 964 | @defopt yank-handled-properties | ||
| 965 | This variable specifies special text property handling conditions for | ||
| 966 | yanked text. It takes effect after the text has been inserted (either | ||
| 967 | normally, or via the @code{yank-handler} property), and prior to | ||
| 968 | @code{yank-excluded-properties} taking effect. | ||
| 969 | |||
| 970 | The value should be an alist of elements @code{(@var{prop} | ||
| 971 | . @var{fun})}. Each alist element is handled in order. The inserted | ||
| 972 | text is scanned for stretches of text having text properties @code{eq} | ||
| 973 | to @var{prop}; for each such stretch, @var{fun} is called with three | ||
| 974 | arguments: the value of the property, and the start and end positions | ||
| 975 | of the text. | ||
| 976 | @end defopt | ||
| 977 | |||
| 962 | @defopt yank-excluded-properties | 978 | @defopt yank-excluded-properties |
| 963 | Yanking discards certain text properties from the yanked text, as | 979 | The value of this variable is the list of properties to remove from |
| 964 | described above. The value of this variable is the list of properties | 980 | inserted text. Its default value contains properties that might lead |
| 965 | to discard. Its default value contains properties that might lead to | 981 | to annoying results, such as causing the text to respond to the mouse |
| 966 | annoying results, such as causing the text to respond to the mouse or | 982 | or specifying key bindings. It takes effect after |
| 967 | specifying key bindings. | 983 | @code{yank-handled-properties}. |
| 968 | @end defopt | 984 | @end defopt |
| 969 | 985 | ||
| 986 | |||
| 970 | @node Yank Commands | 987 | @node Yank Commands |
| 971 | @subsection Functions for Yanking | 988 | @subsection Functions for Yanking |
| 972 | 989 | ||
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 1c0abcb8e66..580dd8258df 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi | |||
| @@ -41,6 +41,7 @@ representing the variable. | |||
| 41 | * Variable Aliases:: Variables that are aliases for other variables. | 41 | * Variable Aliases:: Variables that are aliases for other variables. |
| 42 | * Variables with Restricted Values:: Non-constant variables whose value can | 42 | * Variables with Restricted Values:: Non-constant variables whose value can |
| 43 | @emph{not} be an arbitrary Lisp object. | 43 | @emph{not} be an arbitrary Lisp object. |
| 44 | * Generalized Variables:: Extending the concept of variables. | ||
| 44 | @end menu | 45 | @end menu |
| 45 | 46 | ||
| 46 | @node Global Variables | 47 | @node Global Variables |
| @@ -1946,3 +1947,105 @@ Attempting to assign them any other value will result in an error: | |||
| 1946 | (setq undo-limit 1000.0) | 1947 | (setq undo-limit 1000.0) |
| 1947 | @error{} Wrong type argument: integerp, 1000.0 | 1948 | @error{} Wrong type argument: integerp, 1000.0 |
| 1948 | @end example | 1949 | @end example |
| 1950 | |||
| 1951 | @c FIXME? Not sure this is the right place for this section. | ||
| 1952 | @node Generalized Variables | ||
| 1953 | @section Generalized Variables | ||
| 1954 | |||
| 1955 | A @dfn{generalized variable} or @dfn{place form} is one of the many places | ||
| 1956 | in Lisp memory where values can be stored. The simplest place form is | ||
| 1957 | a regular Lisp variable. But the @sc{car}s and @sc{cdr}s of lists, elements | ||
| 1958 | of arrays, properties of symbols, and many other locations are also | ||
| 1959 | places where Lisp values are stored. | ||
| 1960 | |||
| 1961 | @c FIXME? Not sure this is a useful analogy... | ||
| 1962 | Generalized variables are analogous to ``lvalues'' in the C | ||
| 1963 | language, where @samp{x = a[i]} gets an element from an array | ||
| 1964 | and @samp{a[i] = x} stores an element using the same notation. | ||
| 1965 | Just as certain forms like @code{a[i]} can be lvalues in C, there | ||
| 1966 | is a set of forms that can be generalized variables in Lisp. | ||
| 1967 | |||
| 1968 | The @code{setf} macro is the most basic way to operate on generalized | ||
| 1969 | variables. The @code{setf} form is like @code{setq}, except that it | ||
| 1970 | accepts arbitrary place forms on the left side rather than just | ||
| 1971 | symbols. For example, @code{(setf (car a) b)} sets the car of | ||
| 1972 | @code{a} to @code{b}, doing the same operation as @code{(setcar a b)}, | ||
| 1973 | but without having to remember two separate functions for setting and | ||
| 1974 | accessing every type of place. | ||
| 1975 | |||
| 1976 | @defmac setf [place form]@dots{} | ||
| 1977 | This macro evaluates @var{form} and stores it in @var{place}, which | ||
| 1978 | must be a valid generalized variable form. If there are several | ||
| 1979 | @var{place} and @var{form} pairs, the assignments are done sequentially | ||
| 1980 | just as with @code{setq}. @code{setf} returns the value of the last | ||
| 1981 | @var{form}. | ||
| 1982 | @end defmac | ||
| 1983 | |||
| 1984 | The following Lisp forms will work as generalized variables, and | ||
| 1985 | so may appear in the @var{place} argument of @code{setf}: | ||
| 1986 | |||
| 1987 | @itemize | ||
| 1988 | @item | ||
| 1989 | A symbol naming a variable. In other words, @code{(setf x y)} is | ||
| 1990 | exactly equivalent to @code{(setq x y)}, and @code{setq} itself is | ||
| 1991 | strictly speaking redundant given that @code{setf} exists. Many | ||
| 1992 | programmers continue to prefer @code{setq} for setting simple | ||
| 1993 | variables, though, purely for stylistic or historical reasons. | ||
| 1994 | The macro @code{(setf x y)} actually expands to @code{(setq x y)}, | ||
| 1995 | so there is no performance penalty for using it in compiled code. | ||
| 1996 | |||
| 1997 | @item | ||
| 1998 | A call to any of the following standard Lisp functions: | ||
| 1999 | |||
| 2000 | @smallexample | ||
| 2001 | car cdr nth nthcdr | ||
| 2002 | caar cadr cdar cddr | ||
| 2003 | aref elt get gethash | ||
| 2004 | symbol-function symbol-value symbol-plist | ||
| 2005 | @end smallexample | ||
| 2006 | |||
| 2007 | @item | ||
| 2008 | The following Emacs-specific functions are also @code{setf}-able: | ||
| 2009 | |||
| 2010 | @smallexample | ||
| 2011 | default-value process-get | ||
| 2012 | frame-parameter process-sentinel | ||
| 2013 | terminal-parameter window-buffer | ||
| 2014 | keymap-parent window-display-table | ||
| 2015 | match-data window-dedicated-p | ||
| 2016 | overlay-get window-hscroll | ||
| 2017 | overlay-start window-parameter | ||
| 2018 | overlay-end window-point | ||
| 2019 | process-buffer window-start | ||
| 2020 | process-filter | ||
| 2021 | @end smallexample | ||
| 2022 | @end itemize | ||
| 2023 | |||
| 2024 | @noindent | ||
| 2025 | Using any forms other than these in the @var{place} argument to | ||
| 2026 | @code{setf} will signal an error. | ||
| 2027 | |||
| 2028 | @c And for cl-lib's cl-getf. | ||
| 2029 | Note that for @code{nthcdr}, the list argument of the function must | ||
| 2030 | itself be a valid @var{place} form. For example, @code{(setf (nthcdr | ||
| 2031 | 0 foo) 7)} will set @code{foo} itself to 7. | ||
| 2032 | @c The use of @code{nthcdr} as a @var{place} form is an extension | ||
| 2033 | @c to standard Common Lisp. | ||
| 2034 | |||
| 2035 | @c FIXME I don't think is a particularly good way to do it, | ||
| 2036 | @c but these macros are introduced before gvs are. | ||
| 2037 | The macros @code{push} (@pxref{List Variables}) and @code{pop} | ||
| 2038 | (@pxref{List Elements}) can manipulate generalized variables, | ||
| 2039 | not just lists. @code{(pop @var{place})} removes and returns the first | ||
| 2040 | element of the list stored in @var{place}. It is analogous to | ||
| 2041 | @code{(prog1 (car @var{place}) (setf @var{place} (cdr @var{place})))}, | ||
| 2042 | except that it takes care to evaluate all subforms only once. | ||
| 2043 | @code{(push @var{x} @var{place})} inserts @var{x} at the front of | ||
| 2044 | the list stored in @var{place}. It is analogous to @code{(setf | ||
| 2045 | @var{place} (cons @var{x} @var{place}))}, except for evaluation of the | ||
| 2046 | subforms. Note that @code{push} and @code{pop} on an @code{nthcdr} | ||
| 2047 | place can be used to insert or delete at any position in a list. | ||
| 2048 | |||
| 2049 | The @file{cl-lib} library defines various extensions for generalized | ||
| 2050 | variables, including additional @code{setf} places. | ||
| 2051 | @xref{Generalized Variables,,, cl, Common Lisp Extensions}. | ||
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index ea48a46359c..d0e149eb165 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi | |||
| @@ -76,30 +76,35 @@ within the area of the frame. When a window is created, resized, or | |||
| 76 | deleted, the change in window space is taken from or given to the | 76 | deleted, the change in window space is taken from or given to the |
| 77 | adjacent windows, so that the total area of the frame is unchanged. | 77 | adjacent windows, so that the total area of the frame is unchanged. |
| 78 | 78 | ||
| 79 | @cindex live windows | ||
| 80 | @cindex internal windows | ||
| 81 | A @dfn{live window} is one that is actually displaying a buffer in a | ||
| 82 | frame. Such a window can be @dfn{deleted}, i.e. removed from the | ||
| 83 | frame (@pxref{Deleting Windows}); then it is no longer live, but the | ||
| 84 | Lisp object representing it might be still referenced from other Lisp | ||
| 85 | objects. A deleted window may be brought back to life by restoring a | ||
| 86 | saved window configuration (@pxref{Window Configurations}). | ||
| 87 | |||
| 88 | @defun windowp object | 79 | @defun windowp object |
| 89 | This function returns @code{t} if @var{object} is a window (whether or | 80 | This function returns @code{t} if @var{object} is a window (whether or |
| 90 | not it is live). Otherwise, it returns @code{nil}. | 81 | not it displays a buffer). Otherwise, it returns @code{nil}. |
| 91 | @end defun | 82 | @end defun |
| 92 | 83 | ||
| 84 | @cindex live windows | ||
| 85 | A @dfn{live window} is one that is actually displaying a buffer in a | ||
| 86 | frame. | ||
| 87 | |||
| 93 | @defun window-live-p object | 88 | @defun window-live-p object |
| 94 | This function returns @code{t} if @var{object} is a live window and | 89 | This function returns @code{t} if @var{object} is a live window and |
| 95 | @code{nil} otherwise. A live window is one that displays a buffer. | 90 | @code{nil} otherwise. A live window is one that displays a buffer. |
| 96 | @end defun | 91 | @end defun |
| 97 | 92 | ||
| 98 | The windows in each frame are organized into a @dfn{window tree}. | 93 | @cindex internal windows |
| 99 | @xref{Windows and Frames}. The leaf nodes of each window tree are | 94 | The windows in each frame are organized into a @dfn{window tree}. |
| 100 | live windows---the ones actually displaying buffers. The internal | 95 | @xref{Windows and Frames}. The leaf nodes of each window tree are live |
| 101 | nodes of the window tree are internal windows, which are not live. | 96 | windows---the ones actually displaying buffers. The internal nodes of |
| 102 | You can distinguish internal windows from deleted windows with | 97 | the window tree are @dfn{internal windows}, which are not live. |
| 98 | |||
| 99 | @cindex valid windows | ||
| 100 | A @dfn{valid window} is one that is either live or internal. A valid | ||
| 101 | window can be @dfn{deleted}, i.e. removed from its frame | ||
| 102 | (@pxref{Deleting Windows}); then it is no longer valid, but the Lisp | ||
| 103 | object representing it might be still referenced from other Lisp | ||
| 104 | objects. A deleted window may be made valid again by restoring a saved | ||
| 105 | window configuration (@pxref{Window Configurations}). | ||
| 106 | |||
| 107 | You can distinguish valid windows from deleted windows with | ||
| 103 | @code{window-valid-p}. | 108 | @code{window-valid-p}. |
| 104 | 109 | ||
| 105 | @defun window-valid-p object | 110 | @defun window-valid-p object |
| @@ -1317,31 +1322,37 @@ meaning as for @code{next-window}. | |||
| 1317 | criterion, without selecting it: | 1322 | criterion, without selecting it: |
| 1318 | 1323 | ||
| 1319 | @cindex least recently used window | 1324 | @cindex least recently used window |
| 1320 | @defun get-lru-window &optional all-frames dedicated | 1325 | @defun get-lru-window &optional all-frames dedicated not-selected |
| 1321 | This function returns a live window which is heuristically the ``least | 1326 | This function returns a live window which is heuristically the ``least |
| 1322 | recently used'' window. The optional argument @var{all-frames} has | 1327 | recently used'' window. The optional argument @var{all-frames} has |
| 1323 | the same meaning as in @code{next-window}. | 1328 | the same meaning as in @code{next-window}. |
| 1324 | 1329 | ||
| 1325 | If any full-width windows are present, only those windows are | 1330 | If any full-width windows are present, only those windows are |
| 1326 | considered. The selected window is never returned, unless it is the | 1331 | considered. A minibuffer window is never a candidate. A dedicated |
| 1327 | only candidate. A minibuffer window is never a candidate. A | 1332 | window (@pxref{Dedicated Windows}) is never a candidate unless the |
| 1328 | dedicated window (@pxref{Dedicated Windows}) is never a candidate | 1333 | optional argument @var{dedicated} is non-@code{nil}. The selected |
| 1329 | unless the optional argument @var{dedicated} is non-@code{nil}. | 1334 | window is never returned, unless it is the only candidate. However, if |
| 1335 | the optional argument @var{not-selected} is non-@code{nil}, this | ||
| 1336 | function returns @code{nil} in that case. | ||
| 1330 | @end defun | 1337 | @end defun |
| 1331 | 1338 | ||
| 1332 | @cindex largest window | 1339 | @cindex largest window |
| 1333 | @defun get-largest-window &optional all-frames dedicated | 1340 | @defun get-largest-window &optional all-frames dedicated not-selected |
| 1334 | This function returns the window with the largest area (height times | 1341 | This function returns the window with the largest area (height times |
| 1335 | width). A minibuffer window is never a candidate. A dedicated window | 1342 | width). The optional argument @var{all-frames} specifies the windows to |
| 1343 | search, and has the same meaning as in @code{next-window}. | ||
| 1344 | |||
| 1345 | A minibuffer window is never a candidate. A dedicated window | ||
| 1336 | (@pxref{Dedicated Windows}) is never a candidate unless the optional | 1346 | (@pxref{Dedicated Windows}) is never a candidate unless the optional |
| 1337 | argument @var{dedicated} is non-@code{nil}. | 1347 | argument @var{dedicated} is non-@code{nil}. The selected window is not |
| 1348 | a candidate if the optional argument @var{not-selected} is | ||
| 1349 | non-@code{nil}. If the optional argument @var{not-selected} is | ||
| 1350 | non-@code{nil} and the selected window is the only candidate, this | ||
| 1351 | function returns @code{nil}. | ||
| 1338 | 1352 | ||
| 1339 | If there are two candidate windows of the same size, this function | 1353 | If there are two candidate windows of the same size, this function |
| 1340 | prefers the one that comes first in the cyclic ordering of windows, | 1354 | prefers the one that comes first in the cyclic ordering of windows, |
| 1341 | starting from the selected window. | 1355 | starting from the selected window. |
| 1342 | |||
| 1343 | The optional argument @var{all-frames} specifies the windows to | ||
| 1344 | search, and has the same meaning as in @code{next-window}. | ||
| 1345 | @end defun | 1356 | @end defun |
| 1346 | 1357 | ||
| 1347 | @cindex window that satisfies a predicate | 1358 | @cindex window that satisfies a predicate |
| @@ -1359,6 +1370,26 @@ windows to search, and have the same meanings as in | |||
| 1359 | @code{next-window}. | 1370 | @code{next-window}. |
| 1360 | @end defun | 1371 | @end defun |
| 1361 | 1372 | ||
| 1373 | @cindex window in direction | ||
| 1374 | @defun window-in-direction direction &optional window ignore | ||
| 1375 | This function returns the nearest window in direction @var{direction} as | ||
| 1376 | seen from the position of @code{window-point} in window @var{window}. | ||
| 1377 | The argument @var{direction} must be one of @code{above}, @code{below}, | ||
| 1378 | @code{left} or @code{right}. The optional argument @var{window} must | ||
| 1379 | denote a live window and defaults to the selected one. | ||
| 1380 | |||
| 1381 | This function does not return a window whose @code{no-other-window} | ||
| 1382 | parameter is non-@code{nil}. If the nearest window's | ||
| 1383 | @code{no-other-window} parameter is non-@code{nil}, this function tries | ||
| 1384 | to find another window in the indicated direction whose | ||
| 1385 | @code{no-other-window} parameter is @code{nil}. If the optional | ||
| 1386 | argument @var{ignore} is non-@code{nil}, a window may be returned even | ||
| 1387 | if its @code{no-other-window} parameter is non-@code{nil}. | ||
| 1388 | |||
| 1389 | If it doesn't find a suitable window, this function returns @code{nil}. | ||
| 1390 | @end defun | ||
| 1391 | |||
| 1392 | |||
| 1362 | @node Buffers and Windows | 1393 | @node Buffers and Windows |
| 1363 | @section Buffers and Windows | 1394 | @section Buffers and Windows |
| 1364 | @cindex examining windows | 1395 | @cindex examining windows |
| @@ -1632,11 +1663,6 @@ The variable @code{display-buffer-overriding-action}. | |||
| 1632 | The user option @code{display-buffer-alist}. | 1663 | The user option @code{display-buffer-alist}. |
| 1633 | 1664 | ||
| 1634 | @item | 1665 | @item |
| 1635 | A special action for handling @code{special-display-buffer-names} and | ||
| 1636 | @code{special-display-regexps}, if either of those variables is | ||
| 1637 | non-@code{nil}. @xref{Choosing Window Options}. | ||
| 1638 | |||
| 1639 | @item | ||
| 1640 | The @var{action} argument. | 1666 | The @var{action} argument. |
| 1641 | 1667 | ||
| 1642 | @item | 1668 | @item |
| @@ -1864,91 +1890,6 @@ Parameters}), which is used by the default function in | |||
| 1864 | @code{nil}. | 1890 | @code{nil}. |
| 1865 | @end defopt | 1891 | @end defopt |
| 1866 | 1892 | ||
| 1867 | @defopt special-display-buffer-names | ||
| 1868 | A list of buffer names identifying buffers that should be displayed | ||
| 1869 | specially. If the name of @var{buffer-or-name} is in this list, | ||
| 1870 | @code{display-buffer} handles the buffer specially. By default, special | ||
| 1871 | display means to give the buffer a dedicated frame. | ||
| 1872 | |||
| 1873 | If an element is a list, instead of a string, then the @sc{car} of that | ||
| 1874 | list is the buffer name, and the rest of that list says how to create | ||
| 1875 | the frame. There are two possibilities for the rest of that list (its | ||
| 1876 | @sc{cdr}): It can be an alist, specifying frame parameters, or it can | ||
| 1877 | contain a function and arguments to give to it. (The function's first | ||
| 1878 | argument is always the buffer to be displayed; the arguments from the | ||
| 1879 | list come after that.) | ||
| 1880 | |||
| 1881 | For example: | ||
| 1882 | |||
| 1883 | @example | ||
| 1884 | (("myfile" (minibuffer) (menu-bar-lines . 0))) | ||
| 1885 | @end example | ||
| 1886 | |||
| 1887 | @noindent | ||
| 1888 | specifies to display a buffer named @samp{myfile} in a dedicated frame | ||
| 1889 | with specified @code{minibuffer} and @code{menu-bar-lines} parameters. | ||
| 1890 | |||
| 1891 | The list of frame parameters can also use the phony frame parameters | ||
| 1892 | @code{same-frame} and @code{same-window}. If the specified frame | ||
| 1893 | parameters include @code{(same-window . @var{value})} and @var{value} | ||
| 1894 | is non-@code{nil}, that means to display the buffer in the current | ||
| 1895 | selected window. Otherwise, if they include @code{(same-frame . | ||
| 1896 | @var{value})} and @var{value} is non-@code{nil}, that means to display | ||
| 1897 | the buffer in a new window in the currently selected frame. | ||
| 1898 | @end defopt | ||
| 1899 | |||
| 1900 | @defopt special-display-regexps | ||
| 1901 | A list of regular expressions specifying buffers that should be | ||
| 1902 | displayed specially. If the buffer's name matches any of the regular | ||
| 1903 | expressions in this list, @code{display-buffer} handles the buffer | ||
| 1904 | specially. By default, special display means to give the buffer a | ||
| 1905 | dedicated frame. | ||
| 1906 | |||
| 1907 | If an element is a list, instead of a string, then the @sc{car} of the | ||
| 1908 | list is the regular expression, and the rest of the list says how to | ||
| 1909 | create the frame. See @code{special-display-buffer-names} above. | ||
| 1910 | @end defopt | ||
| 1911 | |||
| 1912 | @defun special-display-p buffer-name | ||
| 1913 | This function returns non-@code{nil} if displaying a buffer | ||
| 1914 | named @var{buffer-name} with @code{display-buffer} would | ||
| 1915 | create a special frame. The value is @code{t} if it would | ||
| 1916 | use the default frame parameters, or else the specified list | ||
| 1917 | of frame parameters. | ||
| 1918 | @end defun | ||
| 1919 | |||
| 1920 | @defopt special-display-function | ||
| 1921 | This variable holds the function to call to display a buffer specially. | ||
| 1922 | It receives the buffer as an argument, and should return the window in | ||
| 1923 | which it is displayed. The default value of this variable is | ||
| 1924 | @code{special-display-popup-frame}, see below. | ||
| 1925 | @end defopt | ||
| 1926 | |||
| 1927 | @defun special-display-popup-frame buffer &optional args | ||
| 1928 | This function tries to make @var{buffer} visible in a frame of its own. | ||
| 1929 | If @var{buffer} is already displayed in some window, it makes that | ||
| 1930 | window's frame visible and raises it. Otherwise, it creates a frame | ||
| 1931 | that is dedicated to @var{buffer}. The return value is the window used | ||
| 1932 | to display @var{buffer}. | ||
| 1933 | |||
| 1934 | If @var{args} is an alist, it specifies frame parameters for the new | ||
| 1935 | frame. If @var{args} is a list whose @sc{car} is a symbol, then | ||
| 1936 | @code{(car @var{args})} is a function to actually create and | ||
| 1937 | set up the frame; it is called with @var{buffer} as first argument, and | ||
| 1938 | @code{(cdr @var{args})} as additional arguments. | ||
| 1939 | |||
| 1940 | This function always uses an existing window displaying @var{buffer}, | ||
| 1941 | whether or not it is in a frame of its own; but if you set up the above | ||
| 1942 | variables in your init file, before @var{buffer} was created, then | ||
| 1943 | presumably the window was previously made by this function. | ||
| 1944 | @end defun | ||
| 1945 | |||
| 1946 | @defopt special-display-frame-alist | ||
| 1947 | @anchor{Definition of special-display-frame-alist} | ||
| 1948 | This variable holds frame parameters for | ||
| 1949 | @code{special-display-popup-frame} to use when it creates a frame. | ||
| 1950 | @end defopt | ||
| 1951 | |||
| 1952 | @defopt same-window-buffer-names | 1893 | @defopt same-window-buffer-names |
| 1953 | A list of buffer names for buffers that should be displayed in the | 1894 | A list of buffer names for buffers that should be displayed in the |
| 1954 | selected window. If a buffer's name is in this list, | 1895 | selected window. If a buffer's name is in this list, |
| @@ -1969,19 +1910,6 @@ named @var{buffer-name} with @code{display-buffer} would | |||
| 1969 | put it in the selected window. | 1910 | put it in the selected window. |
| 1970 | @end defun | 1911 | @end defun |
| 1971 | 1912 | ||
| 1972 | @c Emacs 19 feature | ||
| 1973 | @defopt display-buffer-function | ||
| 1974 | This variable is the most flexible way to customize the behavior of | ||
| 1975 | @code{display-buffer}. If it is non-@code{nil}, it should be a function | ||
| 1976 | that @code{display-buffer} calls to do the work. The function should | ||
| 1977 | accept two arguments, the first two arguments that @code{display-buffer} | ||
| 1978 | received. It should choose or create a window, display the specified | ||
| 1979 | buffer in it, and then return the window. | ||
| 1980 | |||
| 1981 | This variable takes precedence over all the other options described | ||
| 1982 | above. | ||
| 1983 | @end defopt | ||
| 1984 | |||
| 1985 | @node Window History | 1913 | @node Window History |
| 1986 | @section Window History | 1914 | @section Window History |
| 1987 | @cindex window history | 1915 | @cindex window history |
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index cda4f272ca2..941c430ce74 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -1,3 +1,96 @@ | |||
| 1 | 2012-10-30 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * cl.texi (Modify Macros): Update for cl-letf changes. | ||
| 4 | (Obsolete Lexical Macros): Say a little more about letf/cl-letf. | ||
| 5 | (Setf Extensions): Partially restore note about cl-getf, | ||
| 6 | mainly moved to lispref/variables.texi. | ||
| 7 | (Property Lists): Fix cl-getf typos. | ||
| 8 | (Mapping over Sequences): Mention cl-mapc naming oddity. | ||
| 9 | |||
| 10 | 2012-10-29 Glenn Morris <rgm@gnu.org> | ||
| 11 | |||
| 12 | * cl.texi (Organization): More details on cl-lib.el versus cl.el. | ||
| 13 | (Setf Extensions): Remove `apply' setf since it seems to be disabled. | ||
| 14 | (Customizing Setf): Move contents to "Obsolete Setf Customization". | ||
| 15 | (Modify Macros, Multiple Values, Other Clauses): | ||
| 16 | Remove mentions of obsolete features. | ||
| 17 | (Obsolete Setf Customization): Don't mention `apply' setf. | ||
| 18 | |||
| 19 | 2012-10-28 Glenn Morris <rgm@gnu.org> | ||
| 20 | |||
| 21 | * cl.texi (Multiple Values, Common Lisp Compatibility): | ||
| 22 | More namespace updates. | ||
| 23 | (Obsolete Features): Copyedits. | ||
| 24 | (Obsolete Lexical Macros, Obsolete Setf Customization): | ||
| 25 | New subsections. | ||
| 26 | |||
| 27 | * cl.texi (Porting Common Lisp, Lexical Bindings): | ||
| 28 | Add some xrefs to the Elisp manual. | ||
| 29 | |||
| 30 | * cl.texi (Lexical Bindings): Move to appendix of obsolete features. | ||
| 31 | (Porting Common Lisp): Emacs Lisp can do true lexical binding now. | ||
| 32 | (Obsolete Features): New appendix. Move Lexical Bindings here. | ||
| 33 | |||
| 34 | 2012-10-27 Glenn Morris <rgm@gnu.org> | ||
| 35 | |||
| 36 | * cl.texi: Use defmac for macros rather than defspec. | ||
| 37 | (Efficiency Concerns): Related copyedit. | ||
| 38 | |||
| 39 | * cl.texi (Control Structure): Update for setf now being in core. | ||
| 40 | (Setf Extensions): Rename from Basic Setf. Move much of the | ||
| 41 | former content to lispref/variables.texi. | ||
| 42 | (Modify Macros): Move pop, push details to lispref/variables.texi. | ||
| 43 | (Customizing Setf): Copyedits for setf etc being in core. | ||
| 44 | (Modify Macros, Efficiency Concerns, Porting Common Lisp): | ||
| 45 | Further namespaces updates. | ||
| 46 | |||
| 47 | 2012-10-26 Bastien Guerry <bzg@gnu.org> | ||
| 48 | |||
| 49 | * org.texi (Installation): Update the link to Org's ELPA. Also | ||
| 50 | don't mention org-install.el anymore as the replacement file | ||
| 51 | org-loaddefs.el is now loaded by org.el. | ||
| 52 | |||
| 53 | 2012-10-25 Michael Albinus <michael.albinus@gmx.de> | ||
| 54 | |||
| 55 | * tramp.texi (Frequently Asked Questions): Mention | ||
| 56 | `tramp-completion-reread-directory-timeout' for performance | ||
| 57 | improvement. | ||
| 58 | |||
| 59 | 2012-10-25 Glenn Morris <rgm@gnu.org> | ||
| 60 | |||
| 61 | * cl.texi: Don't mess with the TeX section number counter. | ||
| 62 | Use Texinfo recommended convention for quotes+punctuation. | ||
| 63 | (Overview, Sequence Functions): Rephrase for better line-breaking. | ||
| 64 | (Time of Evaluation, Type Predicates, Modify Macros, Function Bindings) | ||
| 65 | (Macro Bindings, Conditionals, Iteration, Loop Basics) | ||
| 66 | (Random Numbers, Mapping over Sequences, Structures) | ||
| 67 | (Porting Common Lisp): Further updates for cl-lib namespace. | ||
| 68 | (Modify Macros, Declarations, Macro Bindings, Structures): | ||
| 69 | Break long lines in examples. | ||
| 70 | (Dynamic Bindings): Update for changed progv behavior. | ||
| 71 | (Loop Examples, Efficiency Concerns): Markup fixes. | ||
| 72 | (Structures): Remove TeX margin change. | ||
| 73 | (Declarations): Fix typos. | ||
| 74 | |||
| 75 | 2012-10-24 Glenn Morris <rgm@gnu.org> | ||
| 76 | |||
| 77 | * cl.texi (Overview, Multiple Values, Creating Symbols) | ||
| 78 | (Numerical Functions): Say less/nothing about the original cl.el. | ||
| 79 | (Old CL Compatibility): Remove. | ||
| 80 | (Assertions): Remove ignore-errors (standard Elisp for some time). | ||
| 81 | |||
| 82 | * cl.texi (Basic Setf, Macros, Declarations, Symbols, Numbers) | ||
| 83 | (Sequences, Lists, Structures, Assertions, Efficiency Concerns) | ||
| 84 | (Efficiency Concerns, Efficiency Concerns) | ||
| 85 | (Common Lisp Compatibility, Old CL Compatibility): | ||
| 86 | Further updates for cl-lib namespace. | ||
| 87 | |||
| 88 | 2012-10-24 Paul Eggert <eggert@penguin.cs.ucla.edu> | ||
| 89 | |||
| 90 | Update manual for new time stamp format (Bug#12706). | ||
| 91 | * emacs-mime.texi (time-date): Update for new format. | ||
| 92 | Also, fix bogus time stamp and modernize a bit. | ||
| 93 | |||
| 1 | 2012-10-23 Glenn Morris <rgm@gnu.org> | 94 | 2012-10-23 Glenn Morris <rgm@gnu.org> |
| 2 | 95 | ||
| 3 | * cl.texi: Include emacsver.texi. Use Emacs version number rather | 96 | * cl.texi: Include emacsver.texi. Use Emacs version number rather |
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 12fd76e2e1c..8cee1cf9639 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -57,7 +57,7 @@ developing GNU and promoting software freedom.'' | |||
| 57 | * Overview:: Basics, usage, etc. | 57 | * Overview:: Basics, usage, etc. |
| 58 | * Program Structure:: Arglists, @code{cl-eval-when}, @code{defalias}. | 58 | * Program Structure:: Arglists, @code{cl-eval-when}, @code{defalias}. |
| 59 | * Predicates:: @code{cl-typep} and @code{cl-equalp}. | 59 | * Predicates:: @code{cl-typep} and @code{cl-equalp}. |
| 60 | * Control Structure:: @code{setf}, @code{cl-do}, @code{cl-loop}, etc. | 60 | * Control Structure:: @code{cl-do}, @code{cl-loop}, etc. |
| 61 | * Macros:: Destructuring, @code{cl-define-compiler-macro}. | 61 | * Macros:: Destructuring, @code{cl-define-compiler-macro}. |
| 62 | * Declarations:: @code{cl-proclaim}, @code{cl-declare}, etc. | 62 | * Declarations:: @code{cl-proclaim}, @code{cl-declare}, etc. |
| 63 | * Symbols:: Property lists, @code{cl-gensym}. | 63 | * Symbols:: Property lists, @code{cl-gensym}. |
| @@ -65,12 +65,12 @@ developing GNU and promoting software freedom.'' | |||
| 65 | * Sequences:: Mapping, functions, searching, sorting. | 65 | * Sequences:: Mapping, functions, searching, sorting. |
| 66 | * Lists:: @code{cl-caddr}, @code{cl-sublis}, @code{cl-member}, @code{cl-assoc}, etc. | 66 | * Lists:: @code{cl-caddr}, @code{cl-sublis}, @code{cl-member}, @code{cl-assoc}, etc. |
| 67 | * Structures:: @code{cl-defstruct}. | 67 | * Structures:: @code{cl-defstruct}. |
| 68 | * Assertions:: @code{cl-check-type}, @code{cl-assert}, @code{ignore-errors}. | 68 | * Assertions:: @code{cl-check-type}, @code{cl-assert}. |
| 69 | 69 | ||
| 70 | * Efficiency Concerns:: Hints and techniques. | 70 | * Efficiency Concerns:: Hints and techniques. |
| 71 | * Common Lisp Compatibility:: All known differences with Steele. | 71 | * Common Lisp Compatibility:: All known differences with Steele. |
| 72 | * Old CL Compatibility:: All known differences with old cl.el. | ||
| 73 | * Porting Common Lisp:: Hints for porting Common Lisp code. | 72 | * Porting Common Lisp:: Hints for porting Common Lisp code. |
| 73 | * Obsolete Features:: Obsolete features. | ||
| 74 | 74 | ||
| 75 | * GNU Free Documentation License:: The license for this documentation. | 75 | * GNU Free Documentation License:: The license for this documentation. |
| 76 | * Function Index:: | 76 | * Function Index:: |
| @@ -116,19 +116,16 @@ features. | |||
| 116 | 116 | ||
| 117 | @end itemize | 117 | @end itemize |
| 118 | 118 | ||
| 119 | The package described here was originally written by Dave Gillespie, | 119 | This package was originally written by Dave Gillespie, |
| 120 | @file{daveg@@synaptics.com}, as a total rewrite of an earlier | 120 | @file{daveg@@synaptics.com}, as a total rewrite of an earlier 1986 |
| 121 | 1986 @file{cl.el} package by Cesar Quiroz. Most features of the | 121 | @file{cl.el} package by Cesar Quiroz. Care has been taken to ensure |
| 122 | Quiroz package were retained; any incompatibilities are | 122 | that each function is defined efficiently, concisely, and with minimal |
| 123 | noted in the descriptions below. Care has been taken in this | 123 | impact on the rest of the Emacs environment. Stefan Monnier added the |
| 124 | version to ensure that each function is defined efficiently, | 124 | file @file{cl-lib.el} and rationalized the namespace for Emacs 24.3. |
| 125 | concisely, and with minimal impact on the rest of the Emacs | ||
| 126 | environment. Stefan Monnier added the file @file{cl-lib.el} and | ||
| 127 | rationalized the namespace for Emacs 24.3. | ||
| 128 | 125 | ||
| 129 | @menu | 126 | @menu |
| 130 | * Usage:: How to use the CL package. | 127 | * Usage:: How to use the CL package. |
| 131 | * Organization:: The package's five component files. | 128 | * Organization:: The package's component files. |
| 132 | * Naming Conventions:: Notes on CL function names. | 129 | * Naming Conventions:: Notes on CL function names. |
| 133 | @end menu | 130 | @end menu |
| 134 | 131 | ||
| @@ -185,25 +182,37 @@ All you have to do is @code{(require 'cl-lib)}, and @file{cl-lib.el} | |||
| 185 | will take care of pulling in the other files when they are | 182 | will take care of pulling in the other files when they are |
| 186 | needed. | 183 | needed. |
| 187 | 184 | ||
| 188 | There is another file, @file{cl.el}, which was the main entry point | 185 | There is another file, @file{cl.el}, which was the main entry point to |
| 189 | to the CL package prior to Emacs 24.3. Nowadays, it is replaced | 186 | the CL package prior to Emacs 24.3. Nowadays, it is replaced by |
| 190 | by @file{cl-lib.el}. The two provide the same features, but use | 187 | @file{cl-lib.el}. The two provide the same features (in most cases), |
| 191 | different function names (in fact, @file{cl.el} just defines aliases | 188 | but use different function names (in fact, @file{cl.el} mainly just |
| 192 | to the @file{cl-lib.el} definitions). In particular, the old @file{cl.el} | 189 | defines aliases to the @file{cl-lib.el} definitions). Where |
| 193 | does not use a clean namespace. For this reason, Emacs has a policy | 190 | @file{cl-lib.el} defines a function called, for example, |
| 194 | that packages distributed with Emacs must not load @code{cl} at run time. | 191 | @code{cl-incf}, @file{cl.el} uses the same name but without the |
| 195 | (It is ok for them to load @code{cl} at @emph{compile} time, with | 192 | @samp{cl-} prefix, e.g. @code{incf} in this example. There are a few |
| 196 | @code{eval-when-compile}, and use the macros it provides.) There is | 193 | exceptions to this. First, functions such as @code{cl-defun} where |
| 197 | no such restriction on the use of @code{cl-lib}. New code should use | 194 | the unprefixed version was already used for a standard Emacs Lisp |
| 198 | @code{cl-lib} rather than @code{cl}. @xref{Naming Conventions}. | 195 | function. In such cases, the @file{cl.el} version adds a @samp{*} |
| 196 | suffix, e.g. @code{defun*}. Second, there are some obsolete features | ||
| 197 | that are only implemented in @file{cl.el}, not in @file{cl-lib.el}, | ||
| 198 | because they are replaced by other standard Emacs Lisp features. | ||
| 199 | Finally, in a very few cases the old @file{cl.el} versions do not | ||
| 200 | behave in exactly the same way as the @file{cl-lib.el} versions. | ||
| 201 | @xref{Obsolete Features}. | ||
| 202 | @c There is also cl-mapc, which was called cl-mapc even before cl-lib.el. | ||
| 203 | @c But not autoloaded, so maybe not much used? | ||
| 204 | |||
| 205 | Since the old @file{cl.el} does not use a clean namespace, Emacs has a | ||
| 206 | policy that packages distributed with Emacs must not load @code{cl} at | ||
| 207 | run time. (It is ok for them to load @code{cl} at @emph{compile} | ||
| 208 | time, with @code{eval-when-compile}, and use the macros it provides.) | ||
| 209 | There is no such restriction on the use of @code{cl-lib}. New code | ||
| 210 | should use @code{cl-lib} rather than @code{cl}. | ||
| 199 | 211 | ||
| 200 | There is one more file, @file{cl-compat.el}, which defines some | 212 | There is one more file, @file{cl-compat.el}, which defines some |
| 201 | routines from the older CL package that are not otherwise | 213 | routines from the older Quiroz CL package that are not otherwise |
| 202 | present in the new package. This includes internal routines | 214 | present in the new package. This file is obsolete and should not be |
| 203 | like @code{setelt} and @code{zip-lists}, deprecated features | 215 | used in new code. |
| 204 | like @code{defkeyword}, and an emulation of the old-style | ||
| 205 | multiple-values feature. This file is obsolete and should not be used | ||
| 206 | in new code. @xref{Old CL Compatibility}. | ||
| 207 | 216 | ||
| 208 | @node Naming Conventions | 217 | @node Naming Conventions |
| 209 | @section Naming Conventions | 218 | @section Naming Conventions |
| @@ -217,7 +226,6 @@ Internal function and variable names in the package are prefixed | |||
| 217 | by @code{cl--}. Here is a complete list of functions prefixed by | 226 | by @code{cl--}. Here is a complete list of functions prefixed by |
| 218 | @code{cl-} that were not taken from Common Lisp: | 227 | @code{cl-} that were not taken from Common Lisp: |
| 219 | 228 | ||
| 220 | @c FIXME lexical-let lexical-let* | ||
| 221 | @example | 229 | @example |
| 222 | cl-callf cl-callf2 cl-defsubst | 230 | cl-callf cl-callf2 cl-defsubst |
| 223 | cl-floatp-safe cl-letf cl-letf* | 231 | cl-floatp-safe cl-letf cl-letf* |
| @@ -260,10 +268,6 @@ and the @code{cl-eval-when} construct. | |||
| 260 | * Time of Evaluation:: The @code{cl-eval-when} construct. | 268 | * Time of Evaluation:: The @code{cl-eval-when} construct. |
| 261 | @end menu | 269 | @end menu |
| 262 | 270 | ||
| 263 | @iftex | ||
| 264 | @secno=1 | ||
| 265 | @end iftex | ||
| 266 | |||
| 267 | @node Argument Lists | 271 | @node Argument Lists |
| 268 | @section Argument Lists | 272 | @section Argument Lists |
| 269 | 273 | ||
| @@ -279,14 +283,14 @@ this package to implement Common Lisp argument lists seamlessly. | |||
| 279 | Instead, this package defines alternates for several Lisp forms | 283 | Instead, this package defines alternates for several Lisp forms |
| 280 | which you must use if you need Common Lisp argument lists. | 284 | which you must use if you need Common Lisp argument lists. |
| 281 | 285 | ||
| 282 | @defspec cl-defun name arglist body... | 286 | @defmac cl-defun name arglist body... |
| 283 | This form is identical to the regular @code{defun} form, except | 287 | This form is identical to the regular @code{defun} form, except |
| 284 | that @var{arglist} is allowed to be a full Common Lisp argument | 288 | that @var{arglist} is allowed to be a full Common Lisp argument |
| 285 | list. Also, the function body is enclosed in an implicit block | 289 | list. Also, the function body is enclosed in an implicit block |
| 286 | called @var{name}; @pxref{Blocks and Exits}. | 290 | called @var{name}; @pxref{Blocks and Exits}. |
| 287 | @end defspec | 291 | @end defmac |
| 288 | 292 | ||
| 289 | @defspec cl-defsubst name arglist body... | 293 | @defmac cl-defsubst name arglist body... |
| 290 | This is just like @code{cl-defun}, except that the function that | 294 | This is just like @code{cl-defun}, except that the function that |
| 291 | is defined is automatically proclaimed @code{inline}, i.e., | 295 | is defined is automatically proclaimed @code{inline}, i.e., |
| 292 | calls to it may be expanded into in-line code by the byte compiler. | 296 | calls to it may be expanded into in-line code by the byte compiler. |
| @@ -296,9 +300,9 @@ works in all versions of Emacs, and also generates somewhat more | |||
| 296 | efficient inline expansions. In particular, @code{cl-defsubst} | 300 | efficient inline expansions. In particular, @code{cl-defsubst} |
| 297 | arranges for the processing of keyword arguments, default values, | 301 | arranges for the processing of keyword arguments, default values, |
| 298 | etc., to be done at compile-time whenever possible. | 302 | etc., to be done at compile-time whenever possible. |
| 299 | @end defspec | 303 | @end defmac |
| 300 | 304 | ||
| 301 | @defspec cl-defmacro name arglist body... | 305 | @defmac cl-defmacro name arglist body... |
| 302 | This is identical to the regular @code{defmacro} form, | 306 | This is identical to the regular @code{defmacro} form, |
| 303 | except that @var{arglist} is allowed to be a full Common Lisp | 307 | except that @var{arglist} is allowed to be a full Common Lisp |
| 304 | argument list. The @code{&environment} keyword is supported as | 308 | argument list. The @code{&environment} keyword is supported as |
| @@ -307,13 +311,13 @@ within destructured lists (see below); top-level @code{&whole} | |||
| 307 | cannot be implemented with the current Emacs Lisp interpreter. | 311 | cannot be implemented with the current Emacs Lisp interpreter. |
| 308 | The macro expander body is enclosed in an implicit block called | 312 | The macro expander body is enclosed in an implicit block called |
| 309 | @var{name}. | 313 | @var{name}. |
| 310 | @end defspec | 314 | @end defmac |
| 311 | 315 | ||
| 312 | @defspec cl-function symbol-or-lambda | 316 | @defmac cl-function symbol-or-lambda |
| 313 | This is identical to the regular @code{function} form, | 317 | This is identical to the regular @code{function} form, |
| 314 | except that if the argument is a @code{lambda} form then that | 318 | except that if the argument is a @code{lambda} form then that |
| 315 | form may use a full Common Lisp argument list. | 319 | form may use a full Common Lisp argument list. |
| 316 | @end defspec | 320 | @end defmac |
| 317 | 321 | ||
| 318 | Also, all forms (such as @code{cl-flet} and @code{cl-labels}) defined | 322 | Also, all forms (such as @code{cl-flet} and @code{cl-labels}) defined |
| 319 | in this package that include @var{arglist}s in their syntax allow | 323 | in this package that include @var{arglist}s in their syntax allow |
| @@ -502,7 +506,7 @@ For example, the compiler effectively evaluates @code{defmacro} forms | |||
| 502 | at compile-time so that later parts of the file can refer to the | 506 | at compile-time so that later parts of the file can refer to the |
| 503 | macros that are defined. | 507 | macros that are defined. |
| 504 | 508 | ||
| 505 | @defspec cl-eval-when (situations...) forms... | 509 | @defmac cl-eval-when (situations...) forms... |
| 506 | This form controls when the body @var{forms} are evaluated. | 510 | This form controls when the body @var{forms} are evaluated. |
| 507 | The @var{situations} list may contain any set of the symbols | 511 | The @var{situations} list may contain any set of the symbols |
| 508 | @code{compile}, @code{load}, and @code{eval} (or their long-winded | 512 | @code{compile}, @code{load}, and @code{eval} (or their long-winded |
| @@ -572,19 +576,19 @@ last four would have been equivalent to the corresponding @code{setq}s. | |||
| 572 | Note that @code{(cl-eval-when (load eval) @dots{})} is equivalent | 576 | Note that @code{(cl-eval-when (load eval) @dots{})} is equivalent |
| 573 | to @code{(progn @dots{})} in all contexts. The compiler treats | 577 | to @code{(progn @dots{})} in all contexts. The compiler treats |
| 574 | certain top-level forms, like @code{defmacro} (sort-of) and | 578 | certain top-level forms, like @code{defmacro} (sort-of) and |
| 575 | @code{require}, as if they were wrapped in @code{(eval-when | 579 | @code{require}, as if they were wrapped in @code{(cl-eval-when |
| 576 | (compile load eval) @dots{})}. | 580 | (compile load eval) @dots{})}. |
| 577 | @end defspec | 581 | @end defmac |
| 578 | 582 | ||
| 579 | Emacs includes two special forms related to @code{cl-eval-when}. | 583 | Emacs includes two special forms related to @code{cl-eval-when}. |
| 580 | One of these, @code{eval-when-compile}, is not quite equivalent to | 584 | One of these, @code{eval-when-compile}, is not quite equivalent to |
| 581 | any @code{eval-when} construct and is described below. | 585 | any @code{cl-eval-when} construct and is described below. |
| 582 | 586 | ||
| 583 | The other form, @code{(eval-and-compile @dots{})}, is exactly | 587 | The other form, @code{(eval-and-compile @dots{})}, is exactly |
| 584 | equivalent to @samp{(eval-when (compile load eval) @dots{})} and | 588 | equivalent to @samp{(cl-eval-when (compile load eval) @dots{})} and |
| 585 | so is not itself defined by this package. | 589 | so is not itself defined by this package. |
| 586 | 590 | ||
| 587 | @defspec eval-when-compile forms... | 591 | @defmac eval-when-compile forms... |
| 588 | The @var{forms} are evaluated at compile-time; at execution time, | 592 | The @var{forms} are evaluated at compile-time; at execution time, |
| 589 | this form acts like a quoted constant of the resulting value. Used | 593 | this form acts like a quoted constant of the resulting value. Used |
| 590 | at top-level, @code{eval-when-compile} is just like @samp{eval-when | 594 | at top-level, @code{eval-when-compile} is just like @samp{eval-when |
| @@ -593,9 +597,9 @@ allows code to be evaluated once at compile-time for efficiency | |||
| 593 | or other reasons. | 597 | or other reasons. |
| 594 | 598 | ||
| 595 | This form is similar to the @samp{#.} syntax of true Common Lisp. | 599 | This form is similar to the @samp{#.} syntax of true Common Lisp. |
| 596 | @end defspec | 600 | @end defmac |
| 597 | 601 | ||
| 598 | @defspec cl-load-time-value form | 602 | @defmac cl-load-time-value form |
| 599 | The @var{form} is evaluated at load-time; at execution time, | 603 | The @var{form} is evaluated at load-time; at execution time, |
| 600 | this form acts like a quoted constant of the resulting value. | 604 | this form acts like a quoted constant of the resulting value. |
| 601 | 605 | ||
| @@ -636,7 +640,7 @@ Byte-compiled, the above defun will result in the following code | |||
| 636 | ", and loaded on: " | 640 | ", and loaded on: " |
| 637 | --temp--)) | 641 | --temp--)) |
| 638 | @end example | 642 | @end example |
| 639 | @end defspec | 643 | @end defmac |
| 640 | 644 | ||
| 641 | @node Predicates | 645 | @node Predicates |
| 642 | @chapter Predicates | 646 | @chapter Predicates |
| @@ -653,10 +657,6 @@ facts are true or false. | |||
| 653 | @node Type Predicates | 657 | @node Type Predicates |
| 654 | @section Type Predicates | 658 | @section Type Predicates |
| 655 | 659 | ||
| 656 | @noindent | ||
| 657 | The @code{CL} package defines a version of the Common Lisp @code{typep} | ||
| 658 | predicate. | ||
| 659 | |||
| 660 | @defun cl-typep object type | 660 | @defun cl-typep object type |
| 661 | Check if @var{object} is of type @var{type}, where @var{type} is a | 661 | Check if @var{object} is of type @var{type}, where @var{type} is a |
| 662 | (quoted) type name of the sort used by Common Lisp. For example, | 662 | (quoted) type name of the sort used by Common Lisp. For example, |
| @@ -737,7 +737,7 @@ related to @code{cl-typep}. | |||
| 737 | @defun cl-coerce object type | 737 | @defun cl-coerce object type |
| 738 | This function attempts to convert @var{object} to the specified | 738 | This function attempts to convert @var{object} to the specified |
| 739 | @var{type}. If @var{object} is already of that type as determined by | 739 | @var{type}. If @var{object} is already of that type as determined by |
| 740 | @code{typep}, it is simply returned. Otherwise, certain types of | 740 | @code{cl-typep}, it is simply returned. Otherwise, certain types of |
| 741 | conversions will be made: If @var{type} is any sequence type | 741 | conversions will be made: If @var{type} is any sequence type |
| 742 | (@code{string}, @code{list}, etc.) then @var{object} will be | 742 | (@code{string}, @code{list}, etc.) then @var{object} will be |
| 743 | converted to that type if possible. If @var{type} is | 743 | converted to that type if possible. If @var{type} is |
| @@ -748,7 +748,7 @@ floats. In all other circumstances, @code{cl-coerce} signals an | |||
| 748 | error. | 748 | error. |
| 749 | @end defun | 749 | @end defun |
| 750 | 750 | ||
| 751 | @defspec cl-deftype name arglist forms... | 751 | @defmac cl-deftype name arglist forms... |
| 752 | This macro defines a new type called @var{name}. It is similar | 752 | This macro defines a new type called @var{name}. It is similar |
| 753 | to @code{defmacro} in many ways; when @var{name} is encountered | 753 | to @code{defmacro} in many ways; when @var{name} is encountered |
| 754 | as a type name, the body @var{forms} are evaluated and should | 754 | as a type name, the body @var{forms} are evaluated and should |
| @@ -776,7 +776,7 @@ unsigned-byte @equiv{} (integer 0 *) | |||
| 776 | The last example shows how the Common Lisp @code{unsigned-byte} | 776 | The last example shows how the Common Lisp @code{unsigned-byte} |
| 777 | type specifier could be implemented if desired; this package does | 777 | type specifier could be implemented if desired; this package does |
| 778 | not implement @code{unsigned-byte} by default. | 778 | not implement @code{unsigned-byte} by default. |
| 779 | @end defspec | 779 | @end defmac |
| 780 | 780 | ||
| 781 | The @code{cl-typecase} and @code{cl-check-type} macros also use type | 781 | The @code{cl-typecase} and @code{cl-check-type} macros also use type |
| 782 | names. @xref{Conditionals}. @xref{Assertions}. The @code{cl-map}, | 782 | names. @xref{Conditionals}. @xref{Assertions}. The @code{cl-map}, |
| @@ -816,23 +816,21 @@ In Emacs, use @code{memq} (or @code{cl-member}) and @code{assq} (or | |||
| 816 | 816 | ||
| 817 | @noindent | 817 | @noindent |
| 818 | The features described in the following sections implement | 818 | The features described in the following sections implement |
| 819 | various advanced control structures, including the powerful | 819 | various advanced control structures, including extensions to the |
| 820 | @c FIXME setf is now in gv.el, not cl. | 820 | standard @code{setf} facility, and a number of looping and conditional |
| 821 | @code{setf} facility and a number of looping and conditional | ||
| 822 | constructs. | 821 | constructs. |
| 823 | 822 | ||
| 824 | @c FIXME setf, push are standard now. | 823 | @c FIXME |
| 825 | @c lexical-let is obsolete; flet is not cl-flet. | 824 | @c flet is not cl-flet. |
| 826 | @c values is not cl-values. | ||
| 827 | @menu | 825 | @menu |
| 828 | * Assignment:: The @code{cl-psetq} form. | 826 | * Assignment:: The @code{cl-psetq} form. |
| 829 | * Generalized Variables:: @code{setf}, @code{cl-incf}, @code{push}, etc. | 827 | * Generalized Variables:: Extensions to generalized variables. |
| 830 | * Variable Bindings:: @code{cl-progv}, @code{lexical-let}, @code{flet}, @code{cl-macrolet}. | 828 | * Variable Bindings:: @code{cl-progv}, @code{flet}, @code{cl-macrolet}. |
| 831 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. | 829 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. |
| 832 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. | 830 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. |
| 833 | * Iteration:: @code{cl-do}, @code{cl-dotimes}, @code{cl-dolist}, @code{cl-do-symbols}. | 831 | * Iteration:: @code{cl-do}, @code{cl-dotimes}, @code{cl-dolist}, @code{cl-do-symbols}. |
| 834 | * Loop Facility:: The Common Lisp @code{cl-loop} macro. | 832 | * Loop Facility:: The Common Lisp @code{cl-loop} macro. |
| 835 | * Multiple Values:: @code{values}, @code{cl-multiple-value-bind}, etc. | 833 | * Multiple Values:: @code{cl-values}, @code{cl-multiple-value-bind}, etc. |
| 836 | @end menu | 834 | @end menu |
| 837 | 835 | ||
| 838 | @node Assignment | 836 | @node Assignment |
| @@ -842,7 +840,7 @@ constructs. | |||
| 842 | The @code{cl-psetq} form is just like @code{setq}, except that multiple | 840 | The @code{cl-psetq} form is just like @code{setq}, except that multiple |
| 843 | assignments are done in parallel rather than sequentially. | 841 | assignments are done in parallel rather than sequentially. |
| 844 | 842 | ||
| 845 | @defspec cl-psetq [symbol form]@dots{} | 843 | @defmac cl-psetq [symbol form]@dots{} |
| 846 | This special form (actually a macro) is used to assign to several | 844 | This special form (actually a macro) is used to assign to several |
| 847 | variables simultaneously. Given only one @var{symbol} and @var{form}, | 845 | variables simultaneously. Given only one @var{symbol} and @var{form}, |
| 848 | it has the same effect as @code{setq}. Given several @var{symbol} | 846 | it has the same effect as @code{setq}. Given several @var{symbol} |
| @@ -870,132 +868,79 @@ provides an even more convenient way to swap two variables; | |||
| 870 | @pxref{Modify Macros}.) | 868 | @pxref{Modify Macros}.) |
| 871 | 869 | ||
| 872 | @code{cl-psetq} always returns @code{nil}. | 870 | @code{cl-psetq} always returns @code{nil}. |
| 873 | @end defspec | 871 | @end defmac |
| 874 | 872 | ||
| 875 | @c FIXME now in gv.el. | ||
| 876 | @node Generalized Variables | 873 | @node Generalized Variables |
| 877 | @section Generalized Variables | 874 | @section Generalized Variables |
| 878 | 875 | ||
| 879 | @noindent | 876 | A @dfn{generalized variable} or @dfn{place form} is one of the many |
| 880 | A ``generalized variable'' or ``place form'' is one of the many places | 877 | places in Lisp memory where values can be stored. The simplest place |
| 881 | in Lisp memory where values can be stored. The simplest place form is | 878 | form is a regular Lisp variable. But the cars and cdrs of lists, |
| 882 | a regular Lisp variable. But the cars and cdrs of lists, elements | 879 | elements of arrays, properties of symbols, and many other locations |
| 883 | of arrays, properties of symbols, and many other locations are also | 880 | are also places where Lisp values are stored. For basic information, |
| 884 | places where Lisp values are stored. | 881 | @pxref{Generalized Variables,,,elisp,GNU Emacs Lisp Reference Manual}. |
| 885 | 882 | This package provides several additional features related to | |
| 886 | The @code{setf} form is like @code{setq}, except that it accepts | 883 | generalized variables. |
| 887 | arbitrary place forms on the left side rather than just | ||
| 888 | symbols. For example, @code{(setf (car a) b)} sets the car of | ||
| 889 | @code{a} to @code{b}, doing the same operation as @code{(setcar a b)} | ||
| 890 | but without having to remember two separate functions for setting | ||
| 891 | and accessing every type of place. | ||
| 892 | |||
| 893 | Generalized variables are analogous to ``lvalues'' in the C | ||
| 894 | language, where @samp{x = a[i]} gets an element from an array | ||
| 895 | and @samp{a[i] = x} stores an element using the same notation. | ||
| 896 | Just as certain forms like @code{a[i]} can be lvalues in C, there | ||
| 897 | is a set of forms that can be generalized variables in Lisp. | ||
| 898 | 884 | ||
| 899 | @menu | 885 | @menu |
| 900 | * Basic Setf:: @code{setf} and place forms. | 886 | * Setf Extensions:: Additional @code{setf} places. |
| 901 | * Modify Macros:: @code{cl-incf}, @code{push}, @code{cl-rotatef}, @code{letf}, @code{cl-callf}, etc. | 887 | * Modify Macros:: @code{cl-incf}, @code{cl-rotatef}, @code{cl-letf}, @code{cl-callf}, etc. |
| 902 | * Customizing Setf:: @code{define-modify-macro}, @code{defsetf}, @code{define-setf-method}. | ||
| 903 | @end menu | 888 | @end menu |
| 904 | 889 | ||
| 905 | @node Basic Setf | 890 | @node Setf Extensions |
| 906 | @subsection Basic Setf | 891 | @subsection Setf Extensions |
| 907 | |||
| 908 | @noindent | ||
| 909 | The @code{setf} macro is the most basic way to operate on generalized | ||
| 910 | variables. | ||
| 911 | |||
| 912 | @defspec setf [place form]@dots{} | ||
| 913 | This macro evaluates @var{form} and stores it in @var{place}, which | ||
| 914 | must be a valid generalized variable form. If there are several | ||
| 915 | @var{place} and @var{form} pairs, the assignments are done sequentially | ||
| 916 | just as with @code{setq}. @code{setf} returns the value of the last | ||
| 917 | @var{form}. | ||
| 918 | |||
| 919 | The following Lisp forms will work as generalized variables, and | ||
| 920 | so may appear in the @var{place} argument of @code{setf}: | ||
| 921 | 892 | ||
| 922 | @itemize @bullet | 893 | Several standard (e.g. @code{car}) and Emacs-specific |
| 923 | @item | 894 | (e.g. @code{window-point}) Lisp functions are @code{setf}-able by default. |
| 924 | A symbol naming a variable. In other words, @code{(setf x y)} is | 895 | This package defines @code{setf} handlers for several additional functions: |
| 925 | exactly equivalent to @code{(setq x y)}, and @code{setq} itself is | ||
| 926 | strictly speaking redundant now that @code{setf} exists. Many | ||
| 927 | programmers continue to prefer @code{setq} for setting simple | ||
| 928 | variables, though, purely for stylistic or historical reasons. | ||
| 929 | The macro @code{(setf x y)} actually expands to @code{(setq x y)}, | ||
| 930 | so there is no performance penalty for using it in compiled code. | ||
| 931 | 896 | ||
| 897 | @itemize | ||
| 932 | @item | 898 | @item |
| 933 | A call to any of the following Lisp functions: | 899 | Functions from @code{CL} itself: |
| 934 | |||
| 935 | @smallexample | 900 | @smallexample |
| 936 | car cdr caar .. cddddr | 901 | cl-caaar .. cl-cddddr cl-first .. cl-tenth |
| 937 | nth rest first .. tenth | 902 | cl-rest cl-get cl-getf cl-subseq |
| 938 | aref elt nthcdr | ||
| 939 | symbol-function symbol-value symbol-plist | ||
| 940 | get get* getf | ||
| 941 | gethash subseq | ||
| 942 | @end smallexample | 903 | @end smallexample |
| 943 | 904 | ||
| 944 | @noindent | 905 | @noindent |
| 945 | Note that for @code{nthcdr} and @code{getf}, the list argument | 906 | Note that for @code{cl-getf} (as for @code{nthcdr}), the list argument |
| 946 | of the function must itself be a valid @var{place} form. For | 907 | of the function must itself be a valid @var{place} form. |
| 947 | example, @code{(setf (nthcdr 0 foo) 7)} will set @code{foo} itself | ||
| 948 | to 7. Note that @code{push} and @code{pop} on an @code{nthcdr} | ||
| 949 | place can be used to insert or delete at any position in a list. | ||
| 950 | The use of @code{nthcdr} as a @var{place} form is an extension | ||
| 951 | to standard Common Lisp. | ||
| 952 | 908 | ||
| 953 | @item | 909 | @item |
| 954 | The following Emacs-specific functions are also @code{setf}-able. | 910 | General Emacs Lisp functions: |
| 955 | |||
| 956 | @smallexample | 911 | @smallexample |
| 957 | buffer-file-name marker-position | 912 | buffer-file-name getenv |
| 958 | buffer-modified-p match-data | 913 | buffer-modified-p global-key-binding |
| 959 | buffer-name mouse-position | 914 | buffer-name local-key-binding |
| 960 | buffer-string overlay-end | 915 | buffer-string mark |
| 961 | buffer-substring overlay-get | 916 | buffer-substring mark-marker |
| 962 | current-buffer overlay-start | 917 | current-buffer marker-position |
| 963 | current-case-table point | 918 | current-case-table mouse-position |
| 964 | current-column point-marker | 919 | current-column point |
| 965 | current-global-map point-max | 920 | current-global-map point-marker |
| 966 | current-input-mode point-min | 921 | current-input-mode point-max |
| 967 | current-local-map process-buffer | 922 | current-local-map point-min |
| 968 | current-window-configuration process-filter | 923 | current-window-configuration read-mouse-position |
| 969 | default-file-modes process-sentinel | 924 | default-file-modes screen-height |
| 970 | default-value read-mouse-position | 925 | documentation-property screen-width |
| 971 | documentation-property screen-height | 926 | face-background selected-window |
| 972 | extent-data screen-menubar | 927 | face-background-pixmap selected-screen |
| 973 | extent-end-position screen-width | 928 | face-font selected-frame |
| 974 | extent-start-position selected-window | 929 | face-foreground standard-case-table |
| 975 | face-background selected-screen | 930 | face-underline-p syntax-table |
| 976 | face-background-pixmap selected-frame | 931 | file-modes visited-file-modtime |
| 977 | face-font standard-case-table | 932 | frame-height window-height |
| 978 | face-foreground syntax-table | 933 | frame-parameters window-width |
| 979 | face-underline-p window-buffer | 934 | frame-visible-p x-get-secondary-selection |
| 980 | file-modes window-dedicated-p | 935 | frame-width x-get-selection |
| 981 | frame-height window-display-table | 936 | get-register |
| 982 | frame-parameters window-height | ||
| 983 | frame-visible-p window-hscroll | ||
| 984 | frame-width window-point | ||
| 985 | get-register window-start | ||
| 986 | getenv window-width | ||
| 987 | global-key-binding x-get-secondary-selection | ||
| 988 | keymap-parent x-get-selection | ||
| 989 | local-key-binding | ||
| 990 | mark | ||
| 991 | mark-marker | ||
| 992 | @end smallexample | 937 | @end smallexample |
| 993 | 938 | ||
| 994 | Most of these have directly corresponding ``set'' functions, like | 939 | Most of these have directly corresponding ``set'' functions, like |
| 995 | @code{use-local-map} for @code{current-local-map}, or @code{goto-char} | 940 | @code{use-local-map} for @code{current-local-map}, or @code{goto-char} |
| 996 | for @code{point}. A few, like @code{point-min}, expand to longer | 941 | for @code{point}. A few, like @code{point-min}, expand to longer |
| 997 | sequences of code when they are @code{setf}'d (@code{(narrow-to-region | 942 | sequences of code when they are used with @code{setf} |
| 998 | x (point-max))} in this case). | 943 | (@code{(narrow-to-region x (point-max))} in this case). |
| 999 | 944 | ||
| 1000 | @item | 945 | @item |
| 1001 | A call of the form @code{(substring @var{subplace} @var{n} [@var{m}])}, | 946 | A call of the form @code{(substring @var{subplace} @var{n} [@var{m}])}, |
| @@ -1022,6 +967,10 @@ a | |||
| 1022 | The generalized variable @code{buffer-substring}, listed above, | 967 | The generalized variable @code{buffer-substring}, listed above, |
| 1023 | also works in this way by replacing a portion of the current buffer. | 968 | also works in this way by replacing a portion of the current buffer. |
| 1024 | 969 | ||
| 970 | @c FIXME? Also `eq'? (see cl-lib.el) | ||
| 971 | |||
| 972 | @c Currently commented out in cl.el. | ||
| 973 | @ignore | ||
| 1025 | @item | 974 | @item |
| 1026 | A call of the form @code{(apply '@var{func} @dots{})} or | 975 | A call of the form @code{(apply '@var{func} @dots{})} or |
| 1027 | @code{(apply (function @var{func}) @dots{})}, where @var{func} | 976 | @code{(apply (function @var{func}) @dots{})}, where @var{func} |
| @@ -1030,6 +979,8 @@ in the sense described in Steele's book; since none of the standard | |||
| 1030 | Emacs place functions are suitable in this sense, this feature is | 979 | Emacs place functions are suitable in this sense, this feature is |
| 1031 | only interesting when used with places you define yourself with | 980 | only interesting when used with places you define yourself with |
| 1032 | @code{define-setf-method} or the long form of @code{defsetf}. | 981 | @code{define-setf-method} or the long form of @code{defsetf}. |
| 982 | @xref{Obsolete Setf Customization}. | ||
| 983 | @end ignore | ||
| 1033 | 984 | ||
| 1034 | @item | 985 | @item |
| 1035 | A macro call, in which case the macro is expanded and @code{setf} | 986 | A macro call, in which case the macro is expanded and @code{setf} |
| @@ -1037,21 +988,21 @@ is applied to the resulting form. | |||
| 1037 | 988 | ||
| 1038 | @item | 989 | @item |
| 1039 | Any form for which a @code{defsetf} or @code{define-setf-method} | 990 | Any form for which a @code{defsetf} or @code{define-setf-method} |
| 1040 | has been made. | 991 | has been made. @xref{Obsolete Setf Customization}. |
| 1041 | @end itemize | 992 | @end itemize |
| 1042 | 993 | ||
| 1043 | Using any forms other than these in the @var{place} argument to | 994 | @c FIXME should this be in lispref? It seems self-evident. |
| 1044 | @code{setf} will signal an error. | 995 | @c Contrast with the cl-incf example later on. |
| 1045 | 996 | @c Here it really only serves as a constrast to wrong-order. | |
| 1046 | The @code{setf} macro takes care to evaluate all subforms in | 997 | The @code{setf} macro takes care to evaluate all subforms in |
| 1047 | the proper left-to-right order; for example, | 998 | the proper left-to-right order; for example, |
| 1048 | 999 | ||
| 1049 | @example | 1000 | @example |
| 1050 | (setf (aref vec (incf i)) i) | 1001 | (setf (aref vec (cl-incf i)) i) |
| 1051 | @end example | 1002 | @end example |
| 1052 | 1003 | ||
| 1053 | @noindent | 1004 | @noindent |
| 1054 | looks like it will evaluate @code{(incf i)} exactly once, before the | 1005 | looks like it will evaluate @code{(cl-incf i)} exactly once, before the |
| 1055 | following access to @code{i}; the @code{setf} expander will insert | 1006 | following access to @code{i}; the @code{setf} expander will insert |
| 1056 | temporary variables as necessary to ensure that it does in fact work | 1007 | temporary variables as necessary to ensure that it does in fact work |
| 1057 | this way no matter what setf-method is defined for @code{aref}. | 1008 | this way no matter what setf-method is defined for @code{aref}. |
| @@ -1071,35 +1022,34 @@ will be preserved. Adapting an example from Steele, given | |||
| 1071 | the form @code{(setf (wrong-order @var{a} @var{b}) 17)} will | 1022 | the form @code{(setf (wrong-order @var{a} @var{b}) 17)} will |
| 1072 | evaluate @var{b} first, then @var{a}, just as in an actual call | 1023 | evaluate @var{b} first, then @var{a}, just as in an actual call |
| 1073 | to @code{wrong-order}. | 1024 | to @code{wrong-order}. |
| 1074 | @end defspec | ||
| 1075 | 1025 | ||
| 1076 | @node Modify Macros | 1026 | @node Modify Macros |
| 1077 | @subsection Modify Macros | 1027 | @subsection Modify Macros |
| 1078 | 1028 | ||
| 1079 | @noindent | 1029 | @noindent |
| 1080 | This package defines a number of other macros besides @code{setf} | 1030 | This package defines a number of macros that operate on generalized |
| 1081 | that operate on generalized variables. Many are interesting and | 1031 | variables. Many are interesting and useful even when the @var{place} |
| 1082 | useful even when the @var{place} is just a variable name. | 1032 | is just a variable name. |
| 1083 | 1033 | ||
| 1084 | @defspec psetf [place form]@dots{} | 1034 | @defmac cl-psetf [place form]@dots{} |
| 1085 | This macro is to @code{setf} what @code{cl-psetq} is to @code{setq}: | 1035 | This macro is to @code{setf} what @code{cl-psetq} is to @code{setq}: |
| 1086 | When several @var{place}s and @var{form}s are involved, the | 1036 | When several @var{place}s and @var{form}s are involved, the |
| 1087 | assignments take place in parallel rather than sequentially. | 1037 | assignments take place in parallel rather than sequentially. |
| 1088 | Specifically, all subforms are evaluated from left to right, then | 1038 | Specifically, all subforms are evaluated from left to right, then |
| 1089 | all the assignments are done (in an undefined order). | 1039 | all the assignments are done (in an undefined order). |
| 1090 | @end defspec | 1040 | @end defmac |
| 1091 | 1041 | ||
| 1092 | @defspec incf place &optional x | 1042 | @defmac cl-incf place &optional x |
| 1093 | This macro increments the number stored in @var{place} by one, or | 1043 | This macro increments the number stored in @var{place} by one, or |
| 1094 | by @var{x} if specified. The incremented value is returned. For | 1044 | by @var{x} if specified. The incremented value is returned. For |
| 1095 | example, @code{(incf i)} is equivalent to @code{(setq i (1+ i))}, and | 1045 | example, @code{(cl-incf i)} is equivalent to @code{(setq i (1+ i))}, and |
| 1096 | @code{(incf (car x) 2)} is equivalent to @code{(setcar x (+ (car x) 2))}. | 1046 | @code{(cl-incf (car x) 2)} is equivalent to @code{(setcar x (+ (car x) 2))}. |
| 1097 | 1047 | ||
| 1098 | Once again, care is taken to preserve the ``apparent'' order of | 1048 | As with @code{setf}, care is taken to preserve the ``apparent'' order |
| 1099 | evaluation. For example, | 1049 | of evaluation. For example, |
| 1100 | 1050 | ||
| 1101 | @example | 1051 | @example |
| 1102 | (incf (aref vec (incf i))) | 1052 | (cl-incf (aref vec (cl-incf i))) |
| 1103 | @end example | 1053 | @end example |
| 1104 | 1054 | ||
| 1105 | @noindent | 1055 | @noindent |
| @@ -1109,93 +1059,81 @@ does, which means the above form is @emph{not} equivalent to the | |||
| 1109 | ``obvious'' expansion, | 1059 | ``obvious'' expansion, |
| 1110 | 1060 | ||
| 1111 | @example | 1061 | @example |
| 1112 | (setf (aref vec (incf i)) (1+ (aref vec (incf i)))) ; Wrong! | 1062 | (setf (aref vec (cl-incf i)) |
| 1063 | (1+ (aref vec (cl-incf i)))) ; wrong! | ||
| 1113 | @end example | 1064 | @end example |
| 1114 | 1065 | ||
| 1115 | @noindent | 1066 | @noindent |
| 1116 | but rather to something more like | 1067 | but rather to something more like |
| 1117 | 1068 | ||
| 1118 | @example | 1069 | @example |
| 1119 | (let ((temp (incf i))) | 1070 | (let ((temp (cl-incf i))) |
| 1120 | (setf (aref vec temp) (1+ (aref vec temp)))) | 1071 | (setf (aref vec temp) (1+ (aref vec temp)))) |
| 1121 | @end example | 1072 | @end example |
| 1122 | 1073 | ||
| 1123 | @noindent | 1074 | @noindent |
| 1124 | Again, all of this is taken care of automatically by @code{incf} and | 1075 | Again, all of this is taken care of automatically by @code{cl-incf} and |
| 1125 | the other generalized-variable macros. | 1076 | the other generalized-variable macros. |
| 1126 | 1077 | ||
| 1127 | As a more Emacs-specific example of @code{incf}, the expression | 1078 | As a more Emacs-specific example of @code{cl-incf}, the expression |
| 1128 | @code{(incf (point) @var{n})} is essentially equivalent to | 1079 | @code{(cl-incf (point) @var{n})} is essentially equivalent to |
| 1129 | @code{(forward-char @var{n})}. | 1080 | @code{(forward-char @var{n})}. |
| 1130 | @end defspec | 1081 | @end defmac |
| 1131 | 1082 | ||
| 1132 | @defspec decf place &optional x | 1083 | @defmac cl-decf place &optional x |
| 1133 | This macro decrements the number stored in @var{place} by one, or | 1084 | This macro decrements the number stored in @var{place} by one, or |
| 1134 | by @var{x} if specified. | 1085 | by @var{x} if specified. |
| 1135 | @end defspec | 1086 | @end defmac |
| 1136 | |||
| 1137 | @defspec pop place | ||
| 1138 | This macro removes and returns the first element of the list stored | ||
| 1139 | in @var{place}. It is analogous to @code{(prog1 (car @var{place}) | ||
| 1140 | (setf @var{place} (cdr @var{place})))}, except that it takes care | ||
| 1141 | to evaluate all subforms only once. | ||
| 1142 | @end defspec | ||
| 1143 | 1087 | ||
| 1144 | @defspec push x place | 1088 | @defmac cl-pushnew x place @t{&key :test :test-not :key} |
| 1145 | This macro inserts @var{x} at the front of the list stored in | ||
| 1146 | @var{place}. It is analogous to @code{(setf @var{place} (cons | ||
| 1147 | @var{x} @var{place}))}, except for evaluation of the subforms. | ||
| 1148 | @end defspec | ||
| 1149 | |||
| 1150 | @defspec pushnew x place @t{&key :test :test-not :key} | ||
| 1151 | This macro inserts @var{x} at the front of the list stored in | 1089 | This macro inserts @var{x} at the front of the list stored in |
| 1152 | @var{place}, but only if @var{x} was not @code{eql} to any | 1090 | @var{place}, but only if @var{x} was not @code{eql} to any |
| 1153 | existing element of the list. The optional keyword arguments | 1091 | existing element of the list. The optional keyword arguments |
| 1154 | are interpreted in the same way as for @code{adjoin}. | 1092 | are interpreted in the same way as for @code{cl-adjoin}. |
| 1155 | @xref{Lists as Sets}. | 1093 | @xref{Lists as Sets}. |
| 1156 | @end defspec | 1094 | @end defmac |
| 1157 | 1095 | ||
| 1158 | @defspec shiftf place@dots{} newvalue | 1096 | @defmac cl-shiftf place@dots{} newvalue |
| 1159 | This macro shifts the @var{place}s left by one, shifting in the | 1097 | This macro shifts the @var{place}s left by one, shifting in the |
| 1160 | value of @var{newvalue} (which may be any Lisp expression, not just | 1098 | value of @var{newvalue} (which may be any Lisp expression, not just |
| 1161 | a generalized variable), and returning the value shifted out of | 1099 | a generalized variable), and returning the value shifted out of |
| 1162 | the first @var{place}. Thus, @code{(shiftf @var{a} @var{b} @var{c} | 1100 | the first @var{place}. Thus, @code{(cl-shiftf @var{a} @var{b} @var{c} |
| 1163 | @var{d})} is equivalent to | 1101 | @var{d})} is equivalent to |
| 1164 | 1102 | ||
| 1165 | @example | 1103 | @example |
| 1166 | (prog1 | 1104 | (prog1 |
| 1167 | @var{a} | 1105 | @var{a} |
| 1168 | (psetf @var{a} @var{b} | 1106 | (cl-psetf @var{a} @var{b} |
| 1169 | @var{b} @var{c} | 1107 | @var{b} @var{c} |
| 1170 | @var{c} @var{d})) | 1108 | @var{c} @var{d})) |
| 1171 | @end example | 1109 | @end example |
| 1172 | 1110 | ||
| 1173 | @noindent | 1111 | @noindent |
| 1174 | except that the subforms of @var{a}, @var{b}, and @var{c} are actually | 1112 | except that the subforms of @var{a}, @var{b}, and @var{c} are actually |
| 1175 | evaluated only once each and in the apparent order. | 1113 | evaluated only once each and in the apparent order. |
| 1176 | @end defspec | 1114 | @end defmac |
| 1177 | 1115 | ||
| 1178 | @defspec rotatef place@dots{} | 1116 | @defmac cl-rotatef place@dots{} |
| 1179 | This macro rotates the @var{place}s left by one in circular fashion. | 1117 | This macro rotates the @var{place}s left by one in circular fashion. |
| 1180 | Thus, @code{(rotatef @var{a} @var{b} @var{c} @var{d})} is equivalent to | 1118 | Thus, @code{(cl-rotatef @var{a} @var{b} @var{c} @var{d})} is equivalent to |
| 1181 | 1119 | ||
| 1182 | @example | 1120 | @example |
| 1183 | (psetf @var{a} @var{b} | 1121 | (cl-psetf @var{a} @var{b} |
| 1184 | @var{b} @var{c} | 1122 | @var{b} @var{c} |
| 1185 | @var{c} @var{d} | 1123 | @var{c} @var{d} |
| 1186 | @var{d} @var{a}) | 1124 | @var{d} @var{a}) |
| 1187 | @end example | 1125 | @end example |
| 1188 | 1126 | ||
| 1189 | @noindent | 1127 | @noindent |
| 1190 | except for the evaluation of subforms. @code{rotatef} always | 1128 | except for the evaluation of subforms. @code{cl-rotatef} always |
| 1191 | returns @code{nil}. Note that @code{(rotatef @var{a} @var{b})} | 1129 | returns @code{nil}. Note that @code{(cl-rotatef @var{a} @var{b})} |
| 1192 | conveniently exchanges @var{a} and @var{b}. | 1130 | conveniently exchanges @var{a} and @var{b}. |
| 1193 | @end defspec | 1131 | @end defmac |
| 1194 | 1132 | ||
| 1195 | The following macros were invented for this package; they have no | 1133 | The following macros were invented for this package; they have no |
| 1196 | analogues in Common Lisp. | 1134 | analogues in Common Lisp. |
| 1197 | 1135 | ||
| 1198 | @defspec letf (bindings@dots{}) forms@dots{} | 1136 | @defmac cl-letf (bindings@dots{}) forms@dots{} |
| 1199 | This macro is analogous to @code{let}, but for generalized variables | 1137 | This macro is analogous to @code{let}, but for generalized variables |
| 1200 | rather than just symbols. Each @var{binding} should be of the form | 1138 | rather than just symbols. Each @var{binding} should be of the form |
| 1201 | @code{(@var{place} @var{value})}; the original contents of the | 1139 | @code{(@var{place} @var{value})}; the original contents of the |
| @@ -1208,294 +1146,91 @@ error. | |||
| 1208 | For example, | 1146 | For example, |
| 1209 | 1147 | ||
| 1210 | @example | 1148 | @example |
| 1211 | (letf (((point) (point-min)) | 1149 | (cl-letf (((point) (point-min)) |
| 1212 | (a 17)) | 1150 | (a 17)) |
| 1213 | ...) | 1151 | ...) |
| 1214 | @end example | 1152 | @end example |
| 1215 | 1153 | ||
| 1216 | @noindent | 1154 | @noindent |
| 1217 | moves ``point'' in the current buffer to the beginning of the buffer, | 1155 | moves point in the current buffer to the beginning of the buffer, |
| 1218 | and also binds @code{a} to 17 (as if by a normal @code{let}, since | 1156 | and also binds @code{a} to 17 (as if by a normal @code{let}, since |
| 1219 | @code{a} is just a regular variable). After the body exits, @code{a} | 1157 | @code{a} is just a regular variable). After the body exits, @code{a} |
| 1220 | is set back to its original value and point is moved back to its | 1158 | is set back to its original value and point is moved back to its |
| 1221 | original position. | 1159 | original position. |
| 1222 | 1160 | ||
| 1223 | Note that @code{letf} on @code{(point)} is not quite like a | 1161 | Note that @code{cl-letf} on @code{(point)} is not quite like a |
| 1224 | @code{save-excursion}, as the latter effectively saves a marker | 1162 | @code{save-excursion}, as the latter effectively saves a marker |
| 1225 | which tracks insertions and deletions in the buffer. Actually, | 1163 | which tracks insertions and deletions in the buffer. Actually, |
| 1226 | a @code{letf} of @code{(point-marker)} is much closer to this | 1164 | a @code{cl-letf} of @code{(point-marker)} is much closer to this |
| 1227 | behavior. (@code{point} and @code{point-marker} are equivalent | 1165 | behavior. (@code{point} and @code{point-marker} are equivalent |
| 1228 | as @code{setf} places; each will accept either an integer or a | 1166 | as @code{setf} places; each will accept either an integer or a |
| 1229 | marker as the stored value.) | 1167 | marker as the stored value.) |
| 1230 | 1168 | ||
| 1231 | Since generalized variables look like lists, @code{let}'s shorthand | 1169 | Since generalized variables look like lists, @code{let}'s shorthand |
| 1232 | of using @samp{foo} for @samp{(foo nil)} as a @var{binding} would | 1170 | of using @samp{foo} for @samp{(foo nil)} as a @var{binding} would |
| 1233 | be ambiguous in @code{letf} and is not allowed. | 1171 | be ambiguous in @code{cl-letf} and is not allowed. |
| 1234 | 1172 | ||
| 1235 | However, a @var{binding} specifier may be a one-element list | 1173 | However, a @var{binding} specifier may be a one-element list |
| 1236 | @samp{(@var{place})}, which is similar to @samp{(@var{place} | 1174 | @samp{(@var{place})}, which is similar to @samp{(@var{place} |
| 1237 | @var{place})}. In other words, the @var{place} is not disturbed | 1175 | @var{place})}. In other words, the @var{place} is not disturbed |
| 1238 | on entry to the body, and the only effect of the @code{letf} is | 1176 | on entry to the body, and the only effect of the @code{cl-letf} is |
| 1239 | to restore the original value of @var{place} afterwards. (The | 1177 | to restore the original value of @var{place} afterwards. |
| 1240 | redundant access-and-store suggested by the @code{(@var{place} | 1178 | @c I suspect this may no longer be true; either way it's |
| 1179 | @c implementation detail and so not essential to document. | ||
| 1180 | @ignore | ||
| 1181 | (The redundant access-and-store suggested by the @code{(@var{place} | ||
| 1241 | @var{place})} example does not actually occur.) | 1182 | @var{place})} example does not actually occur.) |
| 1242 | 1183 | @end ignore | |
| 1243 | In most cases, the @var{place} must have a well-defined value on | 1184 | |
| 1244 | entry to the @code{letf} form. The only exceptions are plain | 1185 | Note that in this case, and in fact almost every case, @var{place} |
| 1245 | variables and calls to @code{symbol-value} and @code{symbol-function}. | 1186 | must have a well-defined value outside the @code{cl-letf} body. |
| 1246 | If the symbol is not bound on entry, it is simply made unbound by | 1187 | There is essentially only one exception to this, which is @var{place} |
| 1247 | @code{makunbound} or @code{fmakunbound} on exit. | 1188 | a plain variable with a specified @var{value} (such as @code{(a 17)} |
| 1248 | @end defspec | 1189 | in the above example). |
| 1249 | 1190 | @c See http://debbugs.gnu.org/12758 | |
| 1250 | @defspec letf* (bindings@dots{}) forms@dots{} | 1191 | @c Some or all of this was true for cl.el, but not for cl-lib.el. |
| 1251 | This macro is to @code{letf} what @code{let*} is to @code{let}: | 1192 | @ignore |
| 1193 | The only exceptions are plain variables and calls to | ||
| 1194 | @code{symbol-value} and @code{symbol-function}. If the symbol is not | ||
| 1195 | bound on entry, it is simply made unbound by @code{makunbound} or | ||
| 1196 | @code{fmakunbound} on exit. | ||
| 1197 | @end ignore | ||
| 1198 | @end defmac | ||
| 1199 | |||
| 1200 | @defmac cl-letf* (bindings@dots{}) forms@dots{} | ||
| 1201 | This macro is to @code{cl-letf} what @code{let*} is to @code{let}: | ||
| 1252 | It does the bindings in sequential rather than parallel order. | 1202 | It does the bindings in sequential rather than parallel order. |
| 1253 | @end defspec | 1203 | @end defmac |
| 1254 | 1204 | ||
| 1255 | @defspec callf @var{function} @var{place} @var{args}@dots{} | 1205 | @defmac cl-callf @var{function} @var{place} @var{args}@dots{} |
| 1256 | This is the ``generic'' modify macro. It calls @var{function}, | 1206 | This is the ``generic'' modify macro. It calls @var{function}, |
| 1257 | which should be an unquoted function name, macro name, or lambda. | 1207 | which should be an unquoted function name, macro name, or lambda. |
| 1258 | It passes @var{place} and @var{args} as arguments, and assigns the | 1208 | It passes @var{place} and @var{args} as arguments, and assigns the |
| 1259 | result back to @var{place}. For example, @code{(incf @var{place} | 1209 | result back to @var{place}. For example, @code{(cl-incf @var{place} |
| 1260 | @var{n})} is the same as @code{(callf + @var{place} @var{n})}. | 1210 | @var{n})} is the same as @code{(cl-callf + @var{place} @var{n})}. |
| 1261 | Some more examples: | 1211 | Some more examples: |
| 1262 | 1212 | ||
| 1263 | @example | 1213 | @example |
| 1264 | (callf abs my-number) | 1214 | (cl-callf abs my-number) |
| 1265 | (callf concat (buffer-name) "<" (int-to-string n) ">") | 1215 | (cl-callf concat (buffer-name) "<" (number-to-string n) ">") |
| 1266 | (callf union happy-people (list joe bob) :test 'same-person) | 1216 | (cl-callf cl-union happy-people (list joe bob) :test 'same-person) |
| 1267 | @end example | 1217 | @end example |
| 1268 | 1218 | ||
| 1269 | @xref{Customizing Setf}, for @code{define-modify-macro}, a way | 1219 | Note again that @code{cl-callf} is an extension to standard Common Lisp. |
| 1270 | to create even more concise notations for modify macros. Note | 1220 | @end defmac |
| 1271 | again that @code{callf} is an extension to standard Common Lisp. | ||
| 1272 | @end defspec | ||
| 1273 | 1221 | ||
| 1274 | @defspec callf2 @var{function} @var{arg1} @var{place} @var{args}@dots{} | 1222 | @defmac cl-callf2 @var{function} @var{arg1} @var{place} @var{args}@dots{} |
| 1275 | This macro is like @code{callf}, except that @var{place} is | 1223 | This macro is like @code{cl-callf}, except that @var{place} is |
| 1276 | the @emph{second} argument of @var{function} rather than the | 1224 | the @emph{second} argument of @var{function} rather than the |
| 1277 | first. For example, @code{(push @var{x} @var{place})} is | 1225 | first. For example, @code{(push @var{x} @var{place})} is |
| 1278 | equivalent to @code{(callf2 cons @var{x} @var{place})}. | 1226 | equivalent to @code{(cl-callf2 cons @var{x} @var{place})}. |
| 1279 | @end defspec | 1227 | @end defmac |
| 1280 | 1228 | ||
| 1281 | The @code{callf} and @code{callf2} macros serve as building | 1229 | The @code{cl-callf} and @code{cl-callf2} macros serve as building |
| 1282 | blocks for other macros like @code{incf}, @code{pushnew}, and | 1230 | blocks for other macros like @code{cl-incf}, and @code{cl-pushnew}. |
| 1283 | @code{define-modify-macro}. The @code{letf} and @code{letf*} | 1231 | The @code{cl-letf} and @code{cl-letf*} macros are used in the processing |
| 1284 | macros are used in the processing of symbol macros; | 1232 | of symbol macros; @pxref{Macro Bindings}. |
| 1285 | @pxref{Macro Bindings}. | ||
| 1286 | 1233 | ||
| 1287 | @node Customizing Setf | ||
| 1288 | @subsection Customizing Setf | ||
| 1289 | |||
| 1290 | @noindent | ||
| 1291 | Common Lisp defines three macros, @code{define-modify-macro}, | ||
| 1292 | @code{defsetf}, and @code{define-setf-method}, that allow the | ||
| 1293 | user to extend generalized variables in various ways. | ||
| 1294 | |||
| 1295 | @defspec define-modify-macro name arglist function [doc-string] | ||
| 1296 | This macro defines a ``read-modify-write'' macro similar to | ||
| 1297 | @code{incf} and @code{decf}. The macro @var{name} is defined | ||
| 1298 | to take a @var{place} argument followed by additional arguments | ||
| 1299 | described by @var{arglist}. The call | ||
| 1300 | |||
| 1301 | @example | ||
| 1302 | (@var{name} @var{place} @var{args}...) | ||
| 1303 | @end example | ||
| 1304 | |||
| 1305 | @noindent | ||
| 1306 | will be expanded to | ||
| 1307 | |||
| 1308 | @example | ||
| 1309 | (callf @var{func} @var{place} @var{args}...) | ||
| 1310 | @end example | ||
| 1311 | |||
| 1312 | @noindent | ||
| 1313 | which in turn is roughly equivalent to | ||
| 1314 | |||
| 1315 | @example | ||
| 1316 | (setf @var{place} (@var{func} @var{place} @var{args}...)) | ||
| 1317 | @end example | ||
| 1318 | |||
| 1319 | For example: | ||
| 1320 | |||
| 1321 | @example | ||
| 1322 | (define-modify-macro incf (&optional (n 1)) +) | ||
| 1323 | (define-modify-macro concatf (&rest args) concat) | ||
| 1324 | @end example | ||
| 1325 | |||
| 1326 | Note that @code{&key} is not allowed in @var{arglist}, but | ||
| 1327 | @code{&rest} is sufficient to pass keywords on to the function. | ||
| 1328 | |||
| 1329 | Most of the modify macros defined by Common Lisp do not exactly | ||
| 1330 | follow the pattern of @code{define-modify-macro}. For example, | ||
| 1331 | @code{push} takes its arguments in the wrong order, and @code{pop} | ||
| 1332 | is completely irregular. You can define these macros ``by hand'' | ||
| 1333 | using @code{get-setf-method}, or consult the source file | ||
| 1334 | @file{cl-macs.el} to see how to use the internal @code{setf} | ||
| 1335 | building blocks. | ||
| 1336 | @end defspec | ||
| 1337 | |||
| 1338 | @defspec defsetf access-fn update-fn | ||
| 1339 | This is the simpler of two @code{defsetf} forms. Where | ||
| 1340 | @var{access-fn} is the name of a function which accesses a place, | ||
| 1341 | this declares @var{update-fn} to be the corresponding store | ||
| 1342 | function. From now on, | ||
| 1343 | |||
| 1344 | @example | ||
| 1345 | (setf (@var{access-fn} @var{arg1} @var{arg2} @var{arg3}) @var{value}) | ||
| 1346 | @end example | ||
| 1347 | |||
| 1348 | @noindent | ||
| 1349 | will be expanded to | ||
| 1350 | |||
| 1351 | @example | ||
| 1352 | (@var{update-fn} @var{arg1} @var{arg2} @var{arg3} @var{value}) | ||
| 1353 | @end example | ||
| 1354 | |||
| 1355 | @noindent | ||
| 1356 | The @var{update-fn} is required to be either a true function, or | ||
| 1357 | a macro which evaluates its arguments in a function-like way. Also, | ||
| 1358 | the @var{update-fn} is expected to return @var{value} as its result. | ||
| 1359 | Otherwise, the above expansion would not obey the rules for the way | ||
| 1360 | @code{setf} is supposed to behave. | ||
| 1361 | |||
| 1362 | As a special (non-Common-Lisp) extension, a third argument of @code{t} | ||
| 1363 | to @code{defsetf} says that the @code{update-fn}'s return value is | ||
| 1364 | not suitable, so that the above @code{setf} should be expanded to | ||
| 1365 | something more like | ||
| 1366 | |||
| 1367 | @example | ||
| 1368 | (let ((temp @var{value})) | ||
| 1369 | (@var{update-fn} @var{arg1} @var{arg2} @var{arg3} temp) | ||
| 1370 | temp) | ||
| 1371 | @end example | ||
| 1372 | |||
| 1373 | Some examples of the use of @code{defsetf}, drawn from the standard | ||
| 1374 | suite of setf methods, are: | ||
| 1375 | |||
| 1376 | @example | ||
| 1377 | (defsetf car setcar) | ||
| 1378 | (defsetf symbol-value set) | ||
| 1379 | (defsetf buffer-name rename-buffer t) | ||
| 1380 | @end example | ||
| 1381 | @end defspec | ||
| 1382 | |||
| 1383 | @defspec defsetf access-fn arglist (store-var) forms@dots{} | ||
| 1384 | This is the second, more complex, form of @code{defsetf}. It is | ||
| 1385 | rather like @code{defmacro} except for the additional @var{store-var} | ||
| 1386 | argument. The @var{forms} should return a Lisp form which stores | ||
| 1387 | the value of @var{store-var} into the generalized variable formed | ||
| 1388 | by a call to @var{access-fn} with arguments described by @var{arglist}. | ||
| 1389 | The @var{forms} may begin with a string which documents the @code{setf} | ||
| 1390 | method (analogous to the doc string that appears at the front of a | ||
| 1391 | function). | ||
| 1392 | |||
| 1393 | For example, the simple form of @code{defsetf} is shorthand for | ||
| 1394 | |||
| 1395 | @example | ||
| 1396 | (defsetf @var{access-fn} (&rest args) (store) | ||
| 1397 | (append '(@var{update-fn}) args (list store))) | ||
| 1398 | @end example | ||
| 1399 | |||
| 1400 | The Lisp form that is returned can access the arguments from | ||
| 1401 | @var{arglist} and @var{store-var} in an unrestricted fashion; | ||
| 1402 | macros like @code{setf} and @code{incf} which invoke this | ||
| 1403 | setf-method will insert temporary variables as needed to make | ||
| 1404 | sure the apparent order of evaluation is preserved. | ||
| 1405 | |||
| 1406 | Another example drawn from the standard package: | ||
| 1407 | |||
| 1408 | @example | ||
| 1409 | (defsetf nth (n x) (store) | ||
| 1410 | (list 'setcar (list 'nthcdr n x) store)) | ||
| 1411 | @end example | ||
| 1412 | @end defspec | ||
| 1413 | |||
| 1414 | @defspec define-setf-method access-fn arglist forms@dots{} | ||
| 1415 | This is the most general way to create new place forms. When | ||
| 1416 | a @code{setf} to @var{access-fn} with arguments described by | ||
| 1417 | @var{arglist} is expanded, the @var{forms} are evaluated and | ||
| 1418 | must return a list of five items: | ||
| 1419 | |||
| 1420 | @enumerate | ||
| 1421 | @item | ||
| 1422 | A list of @dfn{temporary variables}. | ||
| 1423 | |||
| 1424 | @item | ||
| 1425 | A list of @dfn{value forms} corresponding to the temporary variables | ||
| 1426 | above. The temporary variables will be bound to these value forms | ||
| 1427 | as the first step of any operation on the generalized variable. | ||
| 1428 | |||
| 1429 | @item | ||
| 1430 | A list of exactly one @dfn{store variable} (generally obtained | ||
| 1431 | from a call to @code{gensym}). | ||
| 1432 | |||
| 1433 | @item | ||
| 1434 | A Lisp form which stores the contents of the store variable into | ||
| 1435 | the generalized variable, assuming the temporaries have been | ||
| 1436 | bound as described above. | ||
| 1437 | |||
| 1438 | @item | ||
| 1439 | A Lisp form which accesses the contents of the generalized variable, | ||
| 1440 | assuming the temporaries have been bound. | ||
| 1441 | @end enumerate | ||
| 1442 | |||
| 1443 | This is exactly like the Common Lisp macro of the same name, | ||
| 1444 | except that the method returns a list of five values rather | ||
| 1445 | than the five values themselves, since Emacs Lisp does not | ||
| 1446 | support Common Lisp's notion of multiple return values. | ||
| 1447 | |||
| 1448 | Once again, the @var{forms} may begin with a documentation string. | ||
| 1449 | |||
| 1450 | A setf-method should be maximally conservative with regard to | ||
| 1451 | temporary variables. In the setf-methods generated by | ||
| 1452 | @code{defsetf}, the second return value is simply the list of | ||
| 1453 | arguments in the place form, and the first return value is a | ||
| 1454 | list of a corresponding number of temporary variables generated | ||
| 1455 | by @code{gensym}. Macros like @code{setf} and @code{incf} which | ||
| 1456 | use this setf-method will optimize away most temporaries that | ||
| 1457 | turn out to be unnecessary, so there is little reason for the | ||
| 1458 | setf-method itself to optimize. | ||
| 1459 | @end defspec | ||
| 1460 | |||
| 1461 | @defun get-setf-method place &optional env | ||
| 1462 | This function returns the setf-method for @var{place}, by | ||
| 1463 | invoking the definition previously recorded by @code{defsetf} | ||
| 1464 | or @code{define-setf-method}. The result is a list of five | ||
| 1465 | values as described above. You can use this function to build | ||
| 1466 | your own @code{incf}-like modify macros. (Actually, it is | ||
| 1467 | better to use the internal functions @code{cl-setf-do-modify} | ||
| 1468 | and @code{cl-setf-do-store}, which are a bit easier to use and | ||
| 1469 | which also do a number of optimizations; consult the source | ||
| 1470 | code for the @code{incf} function for a simple example.) | ||
| 1471 | |||
| 1472 | The argument @var{env} specifies the ``environment'' to be | ||
| 1473 | passed on to @code{macroexpand} if @code{get-setf-method} should | ||
| 1474 | need to expand a macro in @var{place}. It should come from | ||
| 1475 | an @code{&environment} argument to the macro or setf-method | ||
| 1476 | that called @code{get-setf-method}. | ||
| 1477 | |||
| 1478 | See also the source code for the setf-methods for @code{apply} | ||
| 1479 | and @code{substring}, each of which works by calling | ||
| 1480 | @code{get-setf-method} on a simpler case, then massaging | ||
| 1481 | the result in various ways. | ||
| 1482 | @end defun | ||
| 1483 | |||
| 1484 | Modern Common Lisp defines a second, independent way to specify | ||
| 1485 | the @code{setf} behavior of a function, namely ``@code{setf} | ||
| 1486 | functions'' whose names are lists @code{(setf @var{name})} | ||
| 1487 | rather than symbols. For example, @code{(defun (setf foo) @dots{})} | ||
| 1488 | defines the function that is used when @code{setf} is applied to | ||
| 1489 | @code{foo}. This package does not currently support @code{setf} | ||
| 1490 | functions. In particular, it is a compile-time error to use | ||
| 1491 | @code{setf} on a form which has not already been @code{defsetf}'d | ||
| 1492 | or otherwise declared; in newer Common Lisps, this would not be | ||
| 1493 | an error since the function @code{(setf @var{func})} might be | ||
| 1494 | defined later. | ||
| 1495 | |||
| 1496 | @iftex | ||
| 1497 | @secno=4 | ||
| 1498 | @end iftex | ||
| 1499 | 1234 | ||
| 1500 | @node Variable Bindings | 1235 | @node Variable Bindings |
| 1501 | @section Variable Bindings | 1236 | @section Variable Bindings |
| @@ -1504,14 +1239,13 @@ defined later. | |||
| 1504 | These Lisp forms make bindings to variables and function names, | 1239 | These Lisp forms make bindings to variables and function names, |
| 1505 | analogous to Lisp's built-in @code{let} form. | 1240 | analogous to Lisp's built-in @code{let} form. |
| 1506 | 1241 | ||
| 1507 | @xref{Modify Macros}, for the @code{letf} and @code{letf*} forms which | 1242 | @xref{Modify Macros}, for the @code{cl-letf} and @code{cl-letf*} forms which |
| 1508 | are also related to variable bindings. | 1243 | are also related to variable bindings. |
| 1509 | 1244 | ||
| 1510 | @menu | 1245 | @menu |
| 1511 | * Dynamic Bindings:: The @code{progv} form. | 1246 | * Dynamic Bindings:: The @code{cl-progv} form. |
| 1512 | * Lexical Bindings:: @code{lexical-let} and lexical closures. | ||
| 1513 | * Function Bindings:: @code{flet} and @code{labels}. | 1247 | * Function Bindings:: @code{flet} and @code{labels}. |
| 1514 | * Macro Bindings:: @code{macrolet} and @code{symbol-macrolet}. | 1248 | * Macro Bindings:: @code{cl-macrolet} and @code{cl-symbol-macrolet}. |
| 1515 | @end menu | 1249 | @end menu |
| 1516 | 1250 | ||
| 1517 | @node Dynamic Bindings | 1251 | @node Dynamic Bindings |
| @@ -1519,134 +1253,20 @@ are also related to variable bindings. | |||
| 1519 | 1253 | ||
| 1520 | @noindent | 1254 | @noindent |
| 1521 | The standard @code{let} form binds variables whose names are known | 1255 | The standard @code{let} form binds variables whose names are known |
| 1522 | at compile-time. The @code{progv} form provides an easy way to | 1256 | at compile-time. The @code{cl-progv} form provides an easy way to |
| 1523 | bind variables whose names are computed at run-time. | 1257 | bind variables whose names are computed at run-time. |
| 1524 | 1258 | ||
| 1525 | @defspec progv symbols values forms@dots{} | 1259 | @defmac cl-progv symbols values forms@dots{} |
| 1526 | This form establishes @code{let}-style variable bindings on a | 1260 | This form establishes @code{let}-style variable bindings on a |
| 1527 | set of variables computed at run-time. The expressions | 1261 | set of variables computed at run-time. The expressions |
| 1528 | @var{symbols} and @var{values} are evaluated, and must return lists | 1262 | @var{symbols} and @var{values} are evaluated, and must return lists |
| 1529 | of symbols and values, respectively. The symbols are bound to the | 1263 | of symbols and values, respectively. The symbols are bound to the |
| 1530 | corresponding values for the duration of the body @var{form}s. | 1264 | corresponding values for the duration of the body @var{form}s. |
| 1531 | If @var{values} is shorter than @var{symbols}, the last few symbols | 1265 | If @var{values} is shorter than @var{symbols}, the last few symbols |
| 1532 | are made unbound (as if by @code{makunbound}) inside the body. | 1266 | are bound to @code{nil}. |
| 1533 | If @var{symbols} is shorter than @var{values}, the excess values | 1267 | If @var{symbols} is shorter than @var{values}, the excess values |
| 1534 | are ignored. | 1268 | are ignored. |
| 1535 | @end defspec | 1269 | @end defmac |
| 1536 | |||
| 1537 | @node Lexical Bindings | ||
| 1538 | @subsection Lexical Bindings | ||
| 1539 | |||
| 1540 | @noindent | ||
| 1541 | The @code{CL} package defines the following macro which | ||
| 1542 | more closely follows the Common Lisp @code{let} form: | ||
| 1543 | |||
| 1544 | @defspec lexical-let (bindings@dots{}) forms@dots{} | ||
| 1545 | This form is exactly like @code{let} except that the bindings it | ||
| 1546 | establishes are purely lexical. Lexical bindings are similar to | ||
| 1547 | local variables in a language like C: Only the code physically | ||
| 1548 | within the body of the @code{lexical-let} (after macro expansion) | ||
| 1549 | may refer to the bound variables. | ||
| 1550 | |||
| 1551 | @example | ||
| 1552 | (setq a 5) | ||
| 1553 | (defun foo (b) (+ a b)) | ||
| 1554 | (let ((a 2)) (foo a)) | ||
| 1555 | @result{} 4 | ||
| 1556 | (lexical-let ((a 2)) (foo a)) | ||
| 1557 | @result{} 7 | ||
| 1558 | @end example | ||
| 1559 | |||
| 1560 | @noindent | ||
| 1561 | In this example, a regular @code{let} binding of @code{a} actually | ||
| 1562 | makes a temporary change to the global variable @code{a}, so @code{foo} | ||
| 1563 | is able to see the binding of @code{a} to 2. But @code{lexical-let} | ||
| 1564 | actually creates a distinct local variable @code{a} for use within its | ||
| 1565 | body, without any effect on the global variable of the same name. | ||
| 1566 | |||
| 1567 | The most important use of lexical bindings is to create @dfn{closures}. | ||
| 1568 | A closure is a function object that refers to an outside lexical | ||
| 1569 | variable. For example: | ||
| 1570 | |||
| 1571 | @example | ||
| 1572 | (defun make-adder (n) | ||
| 1573 | (lexical-let ((n n)) | ||
| 1574 | (function (lambda (m) (+ n m))))) | ||
| 1575 | (setq add17 (make-adder 17)) | ||
| 1576 | (funcall add17 4) | ||
| 1577 | @result{} 21 | ||
| 1578 | @end example | ||
| 1579 | |||
| 1580 | @noindent | ||
| 1581 | The call @code{(make-adder 17)} returns a function object which adds | ||
| 1582 | 17 to its argument. If @code{let} had been used instead of | ||
| 1583 | @code{lexical-let}, the function object would have referred to the | ||
| 1584 | global @code{n}, which would have been bound to 17 only during the | ||
| 1585 | call to @code{make-adder} itself. | ||
| 1586 | |||
| 1587 | @example | ||
| 1588 | (defun make-counter () | ||
| 1589 | (lexical-let ((n 0)) | ||
| 1590 | (function* (lambda (&optional (m 1)) (incf n m))))) | ||
| 1591 | (setq count-1 (make-counter)) | ||
| 1592 | (funcall count-1 3) | ||
| 1593 | @result{} 3 | ||
| 1594 | (funcall count-1 14) | ||
| 1595 | @result{} 17 | ||
| 1596 | (setq count-2 (make-counter)) | ||
| 1597 | (funcall count-2 5) | ||
| 1598 | @result{} 5 | ||
| 1599 | (funcall count-1 2) | ||
| 1600 | @result{} 19 | ||
| 1601 | (funcall count-2) | ||
| 1602 | @result{} 6 | ||
| 1603 | @end example | ||
| 1604 | |||
| 1605 | @noindent | ||
| 1606 | Here we see that each call to @code{make-counter} creates a distinct | ||
| 1607 | local variable @code{n}, which serves as a private counter for the | ||
| 1608 | function object that is returned. | ||
| 1609 | |||
| 1610 | Closed-over lexical variables persist until the last reference to | ||
| 1611 | them goes away, just like all other Lisp objects. For example, | ||
| 1612 | @code{count-2} refers to a function object which refers to an | ||
| 1613 | instance of the variable @code{n}; this is the only reference | ||
| 1614 | to that variable, so after @code{(setq count-2 nil)} the garbage | ||
| 1615 | collector would be able to delete this instance of @code{n}. | ||
| 1616 | Of course, if a @code{lexical-let} does not actually create any | ||
| 1617 | closures, then the lexical variables are free as soon as the | ||
| 1618 | @code{lexical-let} returns. | ||
| 1619 | |||
| 1620 | Many closures are used only during the extent of the bindings they | ||
| 1621 | refer to; these are known as ``downward funargs'' in Lisp parlance. | ||
| 1622 | When a closure is used in this way, regular Emacs Lisp dynamic | ||
| 1623 | bindings suffice and will be more efficient than @code{lexical-let} | ||
| 1624 | closures: | ||
| 1625 | |||
| 1626 | @example | ||
| 1627 | (defun add-to-list (x list) | ||
| 1628 | (mapcar (lambda (y) (+ x y))) list) | ||
| 1629 | (add-to-list 7 '(1 2 5)) | ||
| 1630 | @result{} (8 9 12) | ||
| 1631 | @end example | ||
| 1632 | |||
| 1633 | @noindent | ||
| 1634 | Since this lambda is only used while @code{x} is still bound, | ||
| 1635 | it is not necessary to make a true closure out of it. | ||
| 1636 | |||
| 1637 | You can use @code{defun} or @code{flet} inside a @code{lexical-let} | ||
| 1638 | to create a named closure. If several closures are created in the | ||
| 1639 | body of a single @code{lexical-let}, they all close over the same | ||
| 1640 | instance of the lexical variable. | ||
| 1641 | |||
| 1642 | The @code{lexical-let} form is an extension to Common Lisp. In | ||
| 1643 | true Common Lisp, all bindings are lexical unless declared otherwise. | ||
| 1644 | @end defspec | ||
| 1645 | |||
| 1646 | @defspec lexical-let* (bindings@dots{}) forms@dots{} | ||
| 1647 | This form is just like @code{lexical-let}, except that the bindings | ||
| 1648 | are made sequentially in the manner of @code{let*}. | ||
| 1649 | @end defspec | ||
| 1650 | 1270 | ||
| 1651 | @node Function Bindings | 1271 | @node Function Bindings |
| 1652 | @subsection Function Bindings | 1272 | @subsection Function Bindings |
| @@ -1655,12 +1275,12 @@ are made sequentially in the manner of @code{let*}. | |||
| 1655 | These forms make @code{let}-like bindings to functions instead | 1275 | These forms make @code{let}-like bindings to functions instead |
| 1656 | of variables. | 1276 | of variables. |
| 1657 | 1277 | ||
| 1658 | @defspec flet (bindings@dots{}) forms@dots{} | 1278 | @defmac flet (bindings@dots{}) forms@dots{} |
| 1659 | This form establishes @code{let}-style bindings on the function | 1279 | This form establishes @code{let}-style bindings on the function |
| 1660 | cells of symbols rather than on the value cells. Each @var{binding} | 1280 | cells of symbols rather than on the value cells. Each @var{binding} |
| 1661 | must be a list of the form @samp{(@var{name} @var{arglist} | 1281 | must be a list of the form @samp{(@var{name} @var{arglist} |
| 1662 | @var{forms}@dots{})}, which defines a function exactly as if | 1282 | @var{forms}@dots{})}, which defines a function exactly as if |
| 1663 | it were a @code{defun*} form. The function @var{name} is defined | 1283 | it were a @code{cl-defun} form. The function @var{name} is defined |
| 1664 | accordingly for the duration of the body of the @code{flet}; then | 1284 | accordingly for the duration of the body of the @code{flet}; then |
| 1665 | the old function definition, or lack thereof, is restored. | 1285 | the old function definition, or lack thereof, is restored. |
| 1666 | 1286 | ||
| @@ -1696,12 +1316,12 @@ handling. Attempts to redefine such functions using @code{flet} will | |||
| 1696 | fail if byte-compiled. In such cases, use @code{labels} instead. | 1316 | fail if byte-compiled. In such cases, use @code{labels} instead. |
| 1697 | 1317 | ||
| 1698 | Functions defined by @code{flet} may use the full Common Lisp | 1318 | Functions defined by @code{flet} may use the full Common Lisp |
| 1699 | argument notation supported by @code{defun*}; also, the function | 1319 | argument notation supported by @code{cl-defun}; also, the function |
| 1700 | body is enclosed in an implicit block as if by @code{defun*}. | 1320 | body is enclosed in an implicit block as if by @code{cl-defun}. |
| 1701 | @xref{Program Structure}. | 1321 | @xref{Program Structure}. |
| 1702 | @end defspec | 1322 | @end defmac |
| 1703 | 1323 | ||
| 1704 | @defspec labels (bindings@dots{}) forms@dots{} | 1324 | @defmac labels (bindings@dots{}) forms@dots{} |
| 1705 | The @code{labels} form is like @code{flet}, except that it | 1325 | The @code{labels} form is like @code{flet}, except that it |
| 1706 | makes lexical bindings of the function names rather than | 1326 | makes lexical bindings of the function names rather than |
| 1707 | dynamic bindings. (In true Common Lisp, both @code{flet} and | 1327 | dynamic bindings. (In true Common Lisp, both @code{flet} and |
| @@ -1722,29 +1342,33 @@ functions. | |||
| 1722 | A ``reference'' to a function name is either a call to that | 1342 | A ``reference'' to a function name is either a call to that |
| 1723 | function, or a use of its name quoted by @code{quote} or | 1343 | function, or a use of its name quoted by @code{quote} or |
| 1724 | @code{function} to be passed on to, say, @code{mapcar}. | 1344 | @code{function} to be passed on to, say, @code{mapcar}. |
| 1725 | @end defspec | 1345 | @end defmac |
| 1726 | 1346 | ||
| 1727 | @node Macro Bindings | 1347 | @node Macro Bindings |
| 1728 | @subsection Macro Bindings | 1348 | @subsection Macro Bindings |
| 1729 | 1349 | ||
| 1730 | @noindent | 1350 | @noindent |
| 1731 | These forms create local macros and ``symbol macros.'' | 1351 | These forms create local macros and ``symbol macros''. |
| 1732 | 1352 | ||
| 1733 | @defspec macrolet (bindings@dots{}) forms@dots{} | 1353 | @defmac cl-macrolet (bindings@dots{}) forms@dots{} |
| 1734 | This form is analogous to @code{flet}, but for macros instead of | 1354 | This form is analogous to @code{flet}, but for macros instead of |
| 1735 | functions. Each @var{binding} is a list of the same form as the | 1355 | functions. Each @var{binding} is a list of the same form as the |
| 1736 | arguments to @code{defmacro*} (i.e., a macro name, argument list, | 1356 | arguments to @code{cl-defmacro} (i.e., a macro name, argument list, |
| 1737 | and macro-expander forms). The macro is defined accordingly for | 1357 | and macro-expander forms). The macro is defined accordingly for |
| 1738 | use within the body of the @code{macrolet}. | 1358 | use within the body of the @code{cl-macrolet}. |
| 1739 | 1359 | ||
| 1740 | Because of the nature of macros, @code{macrolet} is lexically | 1360 | @c FIXME this should be modified to say ``even when lexical-binding |
| 1741 | scoped even in Emacs Lisp: The @code{macrolet} binding will | 1361 | @c is code{nil}'', but is that true? The doc of cl-macrolet just |
| 1362 | @c refers us to cl-flet, which refers to cl-labels, which says that it | ||
| 1363 | @c behaves differently according to whether l-b is true or not. | ||
| 1364 | Because of the nature of macros, @code{cl-macrolet} is lexically | ||
| 1365 | scoped even in Emacs Lisp: The @code{cl-macrolet} binding will | ||
| 1742 | affect only calls that appear physically within the body | 1366 | affect only calls that appear physically within the body |
| 1743 | @var{forms}, possibly after expansion of other macros in the | 1367 | @var{forms}, possibly after expansion of other macros in the |
| 1744 | body. | 1368 | body. |
| 1745 | @end defspec | 1369 | @end defmac |
| 1746 | 1370 | ||
| 1747 | @defspec symbol-macrolet (bindings@dots{}) forms@dots{} | 1371 | @defmac cl-symbol-macrolet (bindings@dots{}) forms@dots{} |
| 1748 | This form creates @dfn{symbol macros}, which are macros that look | 1372 | This form creates @dfn{symbol macros}, which are macros that look |
| 1749 | like variable references rather than function calls. Each | 1373 | like variable references rather than function calls. Each |
| 1750 | @var{binding} is a list @samp{(@var{var} @var{expansion})}; | 1374 | @var{binding} is a list @samp{(@var{var} @var{expansion})}; |
| @@ -1753,8 +1377,8 @@ replaced by @var{expansion}. | |||
| 1753 | 1377 | ||
| 1754 | @example | 1378 | @example |
| 1755 | (setq bar '(5 . 9)) | 1379 | (setq bar '(5 . 9)) |
| 1756 | (symbol-macrolet ((foo (car bar))) | 1380 | (cl-symbol-macrolet ((foo (car bar))) |
| 1757 | (incf foo)) | 1381 | (cl-incf foo)) |
| 1758 | bar | 1382 | bar |
| 1759 | @result{} (6 . 9) | 1383 | @result{} (6 . 9) |
| 1760 | @end example | 1384 | @end example |
| @@ -1764,25 +1388,28 @@ I.e., @code{(setq foo 4)} in the above would be equivalent to | |||
| 1764 | @code{(setf foo 4)}, which in turn expands to @code{(setf (car bar) 4)}. | 1388 | @code{(setf foo 4)}, which in turn expands to @code{(setf (car bar) 4)}. |
| 1765 | 1389 | ||
| 1766 | Likewise, a @code{let} or @code{let*} binding a symbol macro is | 1390 | Likewise, a @code{let} or @code{let*} binding a symbol macro is |
| 1767 | treated like a @code{letf} or @code{letf*}. This differs from true | 1391 | treated like a @code{cl-letf} or @code{cl-letf*}. This differs from true |
| 1392 | @c FIXME does it work like this in Emacs with lexical-binding = t? | ||
| 1768 | Common Lisp, where the rules of lexical scoping cause a @code{let} | 1393 | Common Lisp, where the rules of lexical scoping cause a @code{let} |
| 1769 | binding to shadow a @code{symbol-macrolet} binding. In this package, | 1394 | binding to shadow a @code{cl-symbol-macrolet} binding. In this package, |
| 1395 | @c FIXME obsolete. | ||
| 1770 | only @code{lexical-let} and @code{lexical-let*} will shadow a symbol | 1396 | only @code{lexical-let} and @code{lexical-let*} will shadow a symbol |
| 1771 | macro. | 1397 | macro. |
| 1772 | 1398 | ||
| 1773 | There is no analogue of @code{defmacro} for symbol macros; all symbol | 1399 | There is no analogue of @code{defmacro} for symbol macros; all symbol |
| 1774 | macros are local. A typical use of @code{symbol-macrolet} is in the | 1400 | macros are local. A typical use of @code{cl-symbol-macrolet} is in the |
| 1775 | expansion of another macro: | 1401 | expansion of another macro: |
| 1776 | 1402 | ||
| 1777 | @example | 1403 | @example |
| 1778 | (defmacro* my-dolist ((x list) &rest body) | 1404 | (cl-defmacro my-dolist ((x list) &rest body) |
| 1779 | (let ((var (gensym))) | 1405 | (let ((var (gensym))) |
| 1780 | (list 'loop 'for var 'on list 'do | 1406 | (list 'cl-loop 'for var 'on list 'do |
| 1781 | (list* 'symbol-macrolet (list (list x (list 'car var))) | 1407 | (cl-list* 'cl-symbol-macrolet |
| 1782 | body)))) | 1408 | (list (list x (list 'car var))) |
| 1409 | body)))) | ||
| 1783 | 1410 | ||
| 1784 | (setq mylist '(1 2 3 4)) | 1411 | (setq mylist '(1 2 3 4)) |
| 1785 | (my-dolist (x mylist) (incf x)) | 1412 | (my-dolist (x mylist) (cl-incf x)) |
| 1786 | mylist | 1413 | mylist |
| 1787 | @result{} (2 3 4 5) | 1414 | @result{} (2 3 4 5) |
| 1788 | @end example | 1415 | @end example |
| @@ -1794,22 +1421,22 @@ reference onto the elements of the list. The @code{my-dolist} call | |||
| 1794 | shown here expands to | 1421 | shown here expands to |
| 1795 | 1422 | ||
| 1796 | @example | 1423 | @example |
| 1797 | (loop for G1234 on mylist do | 1424 | (cl-loop for G1234 on mylist do |
| 1798 | (symbol-macrolet ((x (car G1234))) | 1425 | (cl-symbol-macrolet ((x (car G1234))) |
| 1799 | (incf x))) | 1426 | (cl-incf x))) |
| 1800 | @end example | 1427 | @end example |
| 1801 | 1428 | ||
| 1802 | @noindent | 1429 | @noindent |
| 1803 | which in turn expands to | 1430 | which in turn expands to |
| 1804 | 1431 | ||
| 1805 | @example | 1432 | @example |
| 1806 | (loop for G1234 on mylist do (incf (car G1234))) | 1433 | (cl-loop for G1234 on mylist do (cl-incf (car G1234))) |
| 1807 | @end example | 1434 | @end example |
| 1808 | 1435 | ||
| 1809 | @xref{Loop Facility}, for a description of the @code{loop} macro. | 1436 | @xref{Loop Facility}, for a description of the @code{cl-loop} macro. |
| 1810 | This package defines a nonstandard @code{in-ref} loop clause that | 1437 | This package defines a nonstandard @code{in-ref} loop clause that |
| 1811 | works much like @code{my-dolist}. | 1438 | works much like @code{my-dolist}. |
| 1812 | @end defspec | 1439 | @end defmac |
| 1813 | 1440 | ||
| 1814 | @node Conditionals | 1441 | @node Conditionals |
| 1815 | @section Conditionals | 1442 | @section Conditionals |
| @@ -1818,11 +1445,11 @@ works much like @code{my-dolist}. | |||
| 1818 | These conditional forms augment Emacs Lisp's simple @code{if}, | 1445 | These conditional forms augment Emacs Lisp's simple @code{if}, |
| 1819 | @code{and}, @code{or}, and @code{cond} forms. | 1446 | @code{and}, @code{or}, and @code{cond} forms. |
| 1820 | 1447 | ||
| 1821 | @defspec case keyform clause@dots{} | 1448 | @defmac cl-case keyform clause@dots{} |
| 1822 | This macro evaluates @var{keyform}, then compares it with the key | 1449 | This macro evaluates @var{keyform}, then compares it with the key |
| 1823 | values listed in the various @var{clause}s. Whichever clause matches | 1450 | values listed in the various @var{clause}s. Whichever clause matches |
| 1824 | the key is executed; comparison is done by @code{eql}. If no clause | 1451 | the key is executed; comparison is done by @code{eql}. If no clause |
| 1825 | matches, the @code{case} form returns @code{nil}. The clauses are | 1452 | matches, the @code{cl-case} form returns @code{nil}. The clauses are |
| 1826 | of the form | 1453 | of the form |
| 1827 | 1454 | ||
| 1828 | @example | 1455 | @example |
| @@ -1833,7 +1460,7 @@ of the form | |||
| 1833 | where @var{keylist} is a list of key values. If there is exactly | 1460 | where @var{keylist} is a list of key values. If there is exactly |
| 1834 | one value, and it is not a cons cell or the symbol @code{nil} or | 1461 | one value, and it is not a cons cell or the symbol @code{nil} or |
| 1835 | @code{t}, then it can be used by itself as a @var{keylist} without | 1462 | @code{t}, then it can be used by itself as a @var{keylist} without |
| 1836 | being enclosed in a list. All key values in the @code{case} form | 1463 | being enclosed in a list. All key values in the @code{cl-case} form |
| 1837 | must be distinct. The final clauses may use @code{t} in place of | 1464 | must be distinct. The final clauses may use @code{t} in place of |
| 1838 | a @var{keylist} to indicate a default clause that should be taken | 1465 | a @var{keylist} to indicate a default clause that should be taken |
| 1839 | if none of the other clauses match. (The symbol @code{otherwise} | 1466 | if none of the other clauses match. (The symbol @code{otherwise} |
| @@ -1846,28 +1473,28 @@ four things depending on whether it is an @samp{a}, a @samp{b}, | |||
| 1846 | a @key{RET} or @kbd{C-j}, or anything else. | 1473 | a @key{RET} or @kbd{C-j}, or anything else. |
| 1847 | 1474 | ||
| 1848 | @example | 1475 | @example |
| 1849 | (case (read-char) | 1476 | (cl-case (read-char) |
| 1850 | (?a (do-a-thing)) | 1477 | (?a (do-a-thing)) |
| 1851 | (?b (do-b-thing)) | 1478 | (?b (do-b-thing)) |
| 1852 | ((?\r ?\n) (do-ret-thing)) | 1479 | ((?\r ?\n) (do-ret-thing)) |
| 1853 | (t (do-other-thing))) | 1480 | (t (do-other-thing))) |
| 1854 | @end example | 1481 | @end example |
| 1855 | @end defspec | 1482 | @end defmac |
| 1856 | 1483 | ||
| 1857 | @defspec ecase keyform clause@dots{} | 1484 | @defmac cl-ecase keyform clause@dots{} |
| 1858 | This macro is just like @code{case}, except that if the key does | 1485 | This macro is just like @code{cl-case}, except that if the key does |
| 1859 | not match any of the clauses, an error is signaled rather than | 1486 | not match any of the clauses, an error is signaled rather than |
| 1860 | simply returning @code{nil}. | 1487 | simply returning @code{nil}. |
| 1861 | @end defspec | 1488 | @end defmac |
| 1862 | 1489 | ||
| 1863 | @defspec typecase keyform clause@dots{} | 1490 | @defmac cl-typecase keyform clause@dots{} |
| 1864 | This macro is a version of @code{case} that checks for types | 1491 | This macro is a version of @code{cl-case} that checks for types |
| 1865 | rather than values. Each @var{clause} is of the form | 1492 | rather than values. Each @var{clause} is of the form |
| 1866 | @samp{(@var{type} @var{body}...)}. @xref{Type Predicates}, | 1493 | @samp{(@var{type} @var{body}...)}. @xref{Type Predicates}, |
| 1867 | for a description of type specifiers. For example, | 1494 | for a description of type specifiers. For example, |
| 1868 | 1495 | ||
| 1869 | @example | 1496 | @example |
| 1870 | (typecase x | 1497 | (cl-typecase x |
| 1871 | (integer (munch-integer x)) | 1498 | (integer (munch-integer x)) |
| 1872 | (float (munch-float x)) | 1499 | (float (munch-float x)) |
| 1873 | (string (munch-integer (string-to-int x))) | 1500 | (string (munch-integer (string-to-int x))) |
| @@ -1877,13 +1504,13 @@ for a description of type specifiers. For example, | |||
| 1877 | The type specifier @code{t} matches any type of object; the word | 1504 | The type specifier @code{t} matches any type of object; the word |
| 1878 | @code{otherwise} is also allowed. To make one clause match any of | 1505 | @code{otherwise} is also allowed. To make one clause match any of |
| 1879 | several types, use an @code{(or ...)} type specifier. | 1506 | several types, use an @code{(or ...)} type specifier. |
| 1880 | @end defspec | 1507 | @end defmac |
| 1881 | 1508 | ||
| 1882 | @defspec etypecase keyform clause@dots{} | 1509 | @defmac cl-etypecase keyform clause@dots{} |
| 1883 | This macro is just like @code{typecase}, except that if the key does | 1510 | This macro is just like @code{cl-typecase}, except that if the key does |
| 1884 | not match any of the clauses, an error is signaled rather than | 1511 | not match any of the clauses, an error is signaled rather than |
| 1885 | simply returning @code{nil}. | 1512 | simply returning @code{nil}. |
| 1886 | @end defspec | 1513 | @end defmac |
| 1887 | 1514 | ||
| 1888 | @node Blocks and Exits | 1515 | @node Blocks and Exits |
| 1889 | @section Blocks and Exits | 1516 | @section Blocks and Exits |
| @@ -1891,26 +1518,26 @@ simply returning @code{nil}. | |||
| 1891 | @noindent | 1518 | @noindent |
| 1892 | Common Lisp @dfn{blocks} provide a non-local exit mechanism very | 1519 | Common Lisp @dfn{blocks} provide a non-local exit mechanism very |
| 1893 | similar to @code{catch} and @code{throw}, but lexically rather than | 1520 | similar to @code{catch} and @code{throw}, but lexically rather than |
| 1894 | dynamically scoped. This package actually implements @code{block} | 1521 | dynamically scoped. This package actually implements @code{cl-block} |
| 1895 | in terms of @code{catch}; however, the lexical scoping allows the | 1522 | in terms of @code{catch}; however, the lexical scoping allows the |
| 1896 | optimizing byte-compiler to omit the costly @code{catch} step if the | 1523 | optimizing byte-compiler to omit the costly @code{catch} step if the |
| 1897 | body of the block does not actually @code{return-from} the block. | 1524 | body of the block does not actually @code{cl-return-from} the block. |
| 1898 | 1525 | ||
| 1899 | @defspec block name forms@dots{} | 1526 | @defmac cl-block name forms@dots{} |
| 1900 | The @var{forms} are evaluated as if by a @code{progn}. However, | 1527 | The @var{forms} are evaluated as if by a @code{progn}. However, |
| 1901 | if any of the @var{forms} execute @code{(return-from @var{name})}, | 1528 | if any of the @var{forms} execute @code{(cl-return-from @var{name})}, |
| 1902 | they will jump out and return directly from the @code{block} form. | 1529 | they will jump out and return directly from the @code{cl-block} form. |
| 1903 | The @code{block} returns the result of the last @var{form} unless | 1530 | The @code{cl-block} returns the result of the last @var{form} unless |
| 1904 | a @code{return-from} occurs. | 1531 | a @code{cl-return-from} occurs. |
| 1905 | 1532 | ||
| 1906 | The @code{block}/@code{return-from} mechanism is quite similar to | 1533 | The @code{cl-block}/@code{cl-return-from} mechanism is quite similar to |
| 1907 | the @code{catch}/@code{throw} mechanism. The main differences are | 1534 | the @code{catch}/@code{throw} mechanism. The main differences are |
| 1908 | that block @var{name}s are unevaluated symbols, rather than forms | 1535 | that block @var{name}s are unevaluated symbols, rather than forms |
| 1909 | (such as quoted symbols) which evaluate to a tag at run-time; and | 1536 | (such as quoted symbols) which evaluate to a tag at run-time; and |
| 1910 | also that blocks are lexically scoped whereas @code{catch}/@code{throw} | 1537 | also that blocks are lexically scoped whereas @code{catch}/@code{throw} |
| 1911 | are dynamically scoped. This means that functions called from the | 1538 | are dynamically scoped. This means that functions called from the |
| 1912 | body of a @code{catch} can also @code{throw} to the @code{catch}, | 1539 | body of a @code{catch} can also @code{throw} to the @code{catch}, |
| 1913 | but the @code{return-from} referring to a block name must appear | 1540 | but the @code{cl-return-from} referring to a block name must appear |
| 1914 | physically within the @var{forms} that make up the body of the block. | 1541 | physically within the @var{forms} that make up the body of the block. |
| 1915 | They may not appear within other called functions, although they may | 1542 | They may not appear within other called functions, although they may |
| 1916 | appear within macro expansions or @code{lambda}s in the body. Block | 1543 | appear within macro expansions or @code{lambda}s in the body. Block |
| @@ -1919,11 +1546,11 @@ names and @code{catch} names form independent name-spaces. | |||
| 1919 | In true Common Lisp, @code{defun} and @code{defmacro} surround | 1546 | In true Common Lisp, @code{defun} and @code{defmacro} surround |
| 1920 | the function or expander bodies with implicit blocks with the | 1547 | the function or expander bodies with implicit blocks with the |
| 1921 | same name as the function or macro. This does not occur in Emacs | 1548 | same name as the function or macro. This does not occur in Emacs |
| 1922 | Lisp, but this package provides @code{defun*} and @code{defmacro*} | 1549 | Lisp, but this package provides @code{cl-defun} and @code{cl-defmacro} |
| 1923 | forms which do create the implicit block. | 1550 | forms which do create the implicit block. |
| 1924 | 1551 | ||
| 1925 | The Common Lisp looping constructs defined by this package, | 1552 | The Common Lisp looping constructs defined by this package, |
| 1926 | such as @code{loop} and @code{dolist}, also create implicit blocks | 1553 | such as @code{cl-loop} and @code{cl-dolist}, also create implicit blocks |
| 1927 | just as in Common Lisp. | 1554 | just as in Common Lisp. |
| 1928 | 1555 | ||
| 1929 | Because they are implemented in terms of Emacs Lisp @code{catch} | 1556 | Because they are implemented in terms of Emacs Lisp @code{catch} |
| @@ -1931,24 +1558,24 @@ and @code{throw}, blocks have the same overhead as actual | |||
| 1931 | @code{catch} constructs (roughly two function calls). However, | 1558 | @code{catch} constructs (roughly two function calls). However, |
| 1932 | the optimizing byte compiler will optimize away the @code{catch} | 1559 | the optimizing byte compiler will optimize away the @code{catch} |
| 1933 | if the block does | 1560 | if the block does |
| 1934 | not in fact contain any @code{return} or @code{return-from} calls | 1561 | not in fact contain any @code{cl-return} or @code{cl-return-from} calls |
| 1935 | that jump to it. This means that @code{do} loops and @code{defun*} | 1562 | that jump to it. This means that @code{cl-do} loops and @code{cl-defun} |
| 1936 | functions which don't use @code{return} don't pay the overhead to | 1563 | functions which don't use @code{cl-return} don't pay the overhead to |
| 1937 | support it. | 1564 | support it. |
| 1938 | @end defspec | 1565 | @end defmac |
| 1939 | 1566 | ||
| 1940 | @defspec return-from name [result] | 1567 | @defmac cl-return-from name [result] |
| 1941 | This macro returns from the block named @var{name}, which must be | 1568 | This macro returns from the block named @var{name}, which must be |
| 1942 | an (unevaluated) symbol. If a @var{result} form is specified, it | 1569 | an (unevaluated) symbol. If a @var{result} form is specified, it |
| 1943 | is evaluated to produce the result returned from the @code{block}. | 1570 | is evaluated to produce the result returned from the @code{block}. |
| 1944 | Otherwise, @code{nil} is returned. | 1571 | Otherwise, @code{nil} is returned. |
| 1945 | @end defspec | 1572 | @end defmac |
| 1946 | 1573 | ||
| 1947 | @defspec return [result] | 1574 | @defmac cl-return [result] |
| 1948 | This macro is exactly like @code{(return-from nil @var{result})}. | 1575 | This macro is exactly like @code{(cl-return-from nil @var{result})}. |
| 1949 | Common Lisp loops like @code{do} and @code{dolist} implicitly enclose | 1576 | Common Lisp loops like @code{cl-do} and @code{cl-dolist} implicitly enclose |
| 1950 | themselves in @code{nil} blocks. | 1577 | themselves in @code{nil} blocks. |
| 1951 | @end defspec | 1578 | @end defmac |
| 1952 | 1579 | ||
| 1953 | @node Iteration | 1580 | @node Iteration |
| 1954 | @section Iteration | 1581 | @section Iteration |
| @@ -1958,27 +1585,27 @@ The macros described here provide more sophisticated, high-level | |||
| 1958 | looping constructs to complement Emacs Lisp's basic @code{while} | 1585 | looping constructs to complement Emacs Lisp's basic @code{while} |
| 1959 | loop. | 1586 | loop. |
| 1960 | 1587 | ||
| 1961 | @defspec loop forms@dots{} | 1588 | @defmac cl-loop forms@dots{} |
| 1962 | The @code{CL} package supports both the simple, old-style meaning of | 1589 | The @code{CL} package supports both the simple, old-style meaning of |
| 1963 | @code{loop} and the extremely powerful and flexible feature known as | 1590 | @code{loop} and the extremely powerful and flexible feature known as |
| 1964 | the @dfn{Loop Facility} or @dfn{Loop Macro}. This more advanced | 1591 | the @dfn{Loop Facility} or @dfn{Loop Macro}. This more advanced |
| 1965 | facility is discussed in the following section; @pxref{Loop Facility}. | 1592 | facility is discussed in the following section; @pxref{Loop Facility}. |
| 1966 | The simple form of @code{loop} is described here. | 1593 | The simple form of @code{loop} is described here. |
| 1967 | 1594 | ||
| 1968 | If @code{loop} is followed by zero or more Lisp expressions, | 1595 | If @code{cl-loop} is followed by zero or more Lisp expressions, |
| 1969 | then @code{(loop @var{exprs}@dots{})} simply creates an infinite | 1596 | then @code{(cl-loop @var{exprs}@dots{})} simply creates an infinite |
| 1970 | loop executing the expressions over and over. The loop is | 1597 | loop executing the expressions over and over. The loop is |
| 1971 | enclosed in an implicit @code{nil} block. Thus, | 1598 | enclosed in an implicit @code{nil} block. Thus, |
| 1972 | 1599 | ||
| 1973 | @example | 1600 | @example |
| 1974 | (loop (foo) (if (no-more) (return 72)) (bar)) | 1601 | (cl-loop (foo) (if (no-more) (return 72)) (bar)) |
| 1975 | @end example | 1602 | @end example |
| 1976 | 1603 | ||
| 1977 | @noindent | 1604 | @noindent |
| 1978 | is exactly equivalent to | 1605 | is exactly equivalent to |
| 1979 | 1606 | ||
| 1980 | @example | 1607 | @example |
| 1981 | (block nil (while t (foo) (if (no-more) (return 72)) (bar))) | 1608 | (cl-block nil (while t (foo) (if (no-more) (return 72)) (bar))) |
| 1982 | @end example | 1609 | @end example |
| 1983 | 1610 | ||
| 1984 | If any of the expressions are plain symbols, the loop is instead | 1611 | If any of the expressions are plain symbols, the loop is instead |
| @@ -1986,9 +1613,9 @@ interpreted as a Loop Macro specification as described later. | |||
| 1986 | (This is not a restriction in practice, since a plain symbol | 1613 | (This is not a restriction in practice, since a plain symbol |
| 1987 | in the above notation would simply access and throw away the | 1614 | in the above notation would simply access and throw away the |
| 1988 | value of a variable.) | 1615 | value of a variable.) |
| 1989 | @end defspec | 1616 | @end defmac |
| 1990 | 1617 | ||
| 1991 | @defspec do (spec@dots{}) (end-test [result@dots{}]) forms@dots{} | 1618 | @defmac cl-do (spec@dots{}) (end-test [result@dots{}]) forms@dots{} |
| 1992 | This macro creates a general iterative loop. Each @var{spec} is | 1619 | This macro creates a general iterative loop. Each @var{spec} is |
| 1993 | of the form | 1620 | of the form |
| 1994 | 1621 | ||
| @@ -2004,15 +1631,15 @@ evaluated, then each @var{var} is set to the associated @var{step} | |||
| 2004 | expression (as if by a @code{cl-psetq} form) and the next iteration | 1631 | expression (as if by a @code{cl-psetq} form) and the next iteration |
| 2005 | begins. Once the @var{end-test} becomes true, the @var{result} | 1632 | begins. Once the @var{end-test} becomes true, the @var{result} |
| 2006 | forms are evaluated (with the @var{var}s still bound to their | 1633 | forms are evaluated (with the @var{var}s still bound to their |
| 2007 | values) to produce the result returned by @code{do}. | 1634 | values) to produce the result returned by @code{cl-do}. |
| 2008 | 1635 | ||
| 2009 | The entire @code{do} loop is enclosed in an implicit @code{nil} | 1636 | The entire @code{cl-do} loop is enclosed in an implicit @code{nil} |
| 2010 | block, so that you can use @code{(return)} to break out of the | 1637 | block, so that you can use @code{(cl-return)} to break out of the |
| 2011 | loop at any time. | 1638 | loop at any time. |
| 2012 | 1639 | ||
| 2013 | If there are no @var{result} forms, the loop returns @code{nil}. | 1640 | If there are no @var{result} forms, the loop returns @code{nil}. |
| 2014 | If a given @var{var} has no @var{step} form, it is bound to its | 1641 | If a given @var{var} has no @var{step} form, it is bound to its |
| 2015 | @var{init} value but not otherwise modified during the @code{do} | 1642 | @var{init} value but not otherwise modified during the @code{cl-do} |
| 2016 | loop (unless the code explicitly modifies it); this case is just | 1643 | loop (unless the code explicitly modifies it); this case is just |
| 2017 | a shorthand for putting a @code{(let ((@var{var} @var{init})) @dots{})} | 1644 | a shorthand for putting a @code{(let ((@var{var} @var{init})) @dots{})} |
| 2018 | around the loop. If @var{init} is also omitted it defaults to | 1645 | around the loop. If @var{init} is also omitted it defaults to |
| @@ -2023,21 +1650,21 @@ in place of @samp{(@var{var})}, again following the analogy with | |||
| 2023 | This example (from Steele) illustrates a loop which applies the | 1650 | This example (from Steele) illustrates a loop which applies the |
| 2024 | function @code{f} to successive pairs of values from the lists | 1651 | function @code{f} to successive pairs of values from the lists |
| 2025 | @code{foo} and @code{bar}; it is equivalent to the call | 1652 | @code{foo} and @code{bar}; it is equivalent to the call |
| 2026 | @code{(mapcar* 'f foo bar)}. Note that this loop has no body | 1653 | @code{(cl-mapcar 'f foo bar)}. Note that this loop has no body |
| 2027 | @var{forms} at all, performing all its work as side effects of | 1654 | @var{forms} at all, performing all its work as side effects of |
| 2028 | the rest of the loop. | 1655 | the rest of the loop. |
| 2029 | 1656 | ||
| 2030 | @example | 1657 | @example |
| 2031 | (do ((x foo (cdr x)) | 1658 | (cl-do ((x foo (cdr x)) |
| 2032 | (y bar (cdr y)) | 1659 | (y bar (cdr y)) |
| 2033 | (z nil (cons (f (car x) (car y)) z))) | 1660 | (z nil (cons (f (car x) (car y)) z))) |
| 2034 | ((or (null x) (null y)) | 1661 | ((or (null x) (null y)) |
| 2035 | (nreverse z))) | 1662 | (nreverse z))) |
| 2036 | @end example | 1663 | @end example |
| 2037 | @end defspec | 1664 | @end defmac |
| 2038 | 1665 | ||
| 2039 | @defspec do* (spec@dots{}) (end-test [result@dots{}]) forms@dots{} | 1666 | @defmac cl-do* (spec@dots{}) (end-test [result@dots{}]) forms@dots{} |
| 2040 | This is to @code{do} what @code{let*} is to @code{let}. In | 1667 | This is to @code{cl-do} what @code{let*} is to @code{let}. In |
| 2041 | particular, the initial values are bound as if by @code{let*} | 1668 | particular, the initial values are bound as if by @code{let*} |
| 2042 | rather than @code{let}, and the steps are assigned as if by | 1669 | rather than @code{let}, and the steps are assigned as if by |
| 2043 | @code{setq} rather than @code{cl-psetq}. | 1670 | @code{setq} rather than @code{cl-psetq}. |
| @@ -2045,18 +1672,18 @@ rather than @code{let}, and the steps are assigned as if by | |||
| 2045 | Here is another way to write the above loop: | 1672 | Here is another way to write the above loop: |
| 2046 | 1673 | ||
| 2047 | @example | 1674 | @example |
| 2048 | (do* ((xp foo (cdr xp)) | 1675 | (cl-do* ((xp foo (cdr xp)) |
| 2049 | (yp bar (cdr yp)) | 1676 | (yp bar (cdr yp)) |
| 2050 | (x (car xp) (car xp)) | 1677 | (x (car xp) (car xp)) |
| 2051 | (y (car yp) (car yp)) | 1678 | (y (car yp) (car yp)) |
| 2052 | z) | 1679 | z) |
| 2053 | ((or (null xp) (null yp)) | 1680 | ((or (null xp) (null yp)) |
| 2054 | (nreverse z)) | 1681 | (nreverse z)) |
| 2055 | (push (f x y) z)) | 1682 | (push (f x y) z)) |
| 2056 | @end example | 1683 | @end example |
| 2057 | @end defspec | 1684 | @end defmac |
| 2058 | 1685 | ||
| 2059 | @defspec dolist (var list [result]) forms@dots{} | 1686 | @defmac cl-dolist (var list [result]) forms@dots{} |
| 2060 | This is a more specialized loop which iterates across the elements | 1687 | This is a more specialized loop which iterates across the elements |
| 2061 | of a list. @var{list} should evaluate to a list; the body @var{forms} | 1688 | of a list. @var{list} should evaluate to a list; the body @var{forms} |
| 2062 | are executed with @var{var} bound to each element of the list in | 1689 | are executed with @var{var} bound to each element of the list in |
| @@ -2064,9 +1691,9 @@ turn. Finally, the @var{result} form (or @code{nil}) is evaluated | |||
| 2064 | with @var{var} bound to @code{nil} to produce the result returned by | 1691 | with @var{var} bound to @code{nil} to produce the result returned by |
| 2065 | the loop. Unlike with Emacs's built in @code{dolist}, the loop is | 1692 | the loop. Unlike with Emacs's built in @code{dolist}, the loop is |
| 2066 | surrounded by an implicit @code{nil} block. | 1693 | surrounded by an implicit @code{nil} block. |
| 2067 | @end defspec | 1694 | @end defmac |
| 2068 | 1695 | ||
| 2069 | @defspec dotimes (var count [result]) forms@dots{} | 1696 | @defmac cl-dotimes (var count [result]) forms@dots{} |
| 2070 | This is a more specialized loop which iterates a specified number | 1697 | This is a more specialized loop which iterates a specified number |
| 2071 | of times. The body is executed with @var{var} bound to the integers | 1698 | of times. The body is executed with @var{var} bound to the integers |
| 2072 | from zero (inclusive) to @var{count} (exclusive), in turn. Then | 1699 | from zero (inclusive) to @var{count} (exclusive), in turn. Then |
| @@ -2074,9 +1701,9 @@ the @code{result} form is evaluated with @var{var} bound to the total | |||
| 2074 | number of iterations that were done (i.e., @code{(max 0 @var{count})}) | 1701 | number of iterations that were done (i.e., @code{(max 0 @var{count})}) |
| 2075 | to get the return value for the loop form. Unlike with Emacs's built in | 1702 | to get the return value for the loop form. Unlike with Emacs's built in |
| 2076 | @code{dolist}, the loop is surrounded by an implicit @code{nil} block. | 1703 | @code{dolist}, the loop is surrounded by an implicit @code{nil} block. |
| 2077 | @end defspec | 1704 | @end defmac |
| 2078 | 1705 | ||
| 2079 | @defspec do-symbols (var [obarray [result]]) forms@dots{} | 1706 | @defmac cl-do-symbols (var [obarray [result]]) forms@dots{} |
| 2080 | This loop iterates over all interned symbols. If @var{obarray} | 1707 | This loop iterates over all interned symbols. If @var{obarray} |
| 2081 | is specified and is not @code{nil}, it loops over all symbols in | 1708 | is specified and is not @code{nil}, it loops over all symbols in |
| 2082 | that obarray. For each symbol, the body @var{forms} are evaluated | 1709 | that obarray. For each symbol, the body @var{forms} are evaluated |
| @@ -2084,12 +1711,12 @@ with @var{var} bound to that symbol. The symbols are visited in | |||
| 2084 | an unspecified order. Afterward the @var{result} form, if any, | 1711 | an unspecified order. Afterward the @var{result} form, if any, |
| 2085 | is evaluated (with @var{var} bound to @code{nil}) to get the return | 1712 | is evaluated (with @var{var} bound to @code{nil}) to get the return |
| 2086 | value. The loop is surrounded by an implicit @code{nil} block. | 1713 | value. The loop is surrounded by an implicit @code{nil} block. |
| 2087 | @end defspec | 1714 | @end defmac |
| 2088 | 1715 | ||
| 2089 | @defspec do-all-symbols (var [result]) forms@dots{} | 1716 | @defmac cl-do-all-symbols (var [result]) forms@dots{} |
| 2090 | This is identical to @code{do-symbols} except that the @var{obarray} | 1717 | This is identical to @code{cl-do-symbols} except that the @var{obarray} |
| 2091 | argument is omitted; it always iterates over the default obarray. | 1718 | argument is omitted; it always iterates over the default obarray. |
| 2092 | @end defspec | 1719 | @end defmac |
| 2093 | 1720 | ||
| 2094 | @xref{Mapping over Sequences}, for some more functions for | 1721 | @xref{Mapping over Sequences}, for some more functions for |
| 2095 | iterating over vectors or lists. | 1722 | iterating over vectors or lists. |
| @@ -2104,12 +1731,12 @@ that they are either too simple and limited, such as Common Lisp's | |||
| 2104 | obscure, like Common Lisp's @code{do} loop. | 1731 | obscure, like Common Lisp's @code{do} loop. |
| 2105 | 1732 | ||
| 2106 | To remedy this, recent versions of Common Lisp have added a new | 1733 | To remedy this, recent versions of Common Lisp have added a new |
| 2107 | construct called the ``Loop Facility'' or ``@code{loop} macro,'' | 1734 | construct called the ``Loop Facility'' or ``@code{loop} macro'', |
| 2108 | with an easy-to-use but very powerful and expressive syntax. | 1735 | with an easy-to-use but very powerful and expressive syntax. |
| 2109 | 1736 | ||
| 2110 | @menu | 1737 | @menu |
| 2111 | * Loop Basics:: @code{loop} macro, basic clause structure. | 1738 | * Loop Basics:: @code{cl-loop} macro, basic clause structure. |
| 2112 | * Loop Examples:: Working examples of @code{loop} macro. | 1739 | * Loop Examples:: Working examples of @code{cl-loop} macro. |
| 2113 | * For Clauses:: Clauses introduced by @code{for} or @code{as}. | 1740 | * For Clauses:: Clauses introduced by @code{for} or @code{as}. |
| 2114 | * Iteration Clauses:: @code{repeat}, @code{while}, @code{thereis}, etc. | 1741 | * Iteration Clauses:: @code{repeat}, @code{while}, @code{thereis}, etc. |
| 2115 | * Accumulation Clauses:: @code{collect}, @code{sum}, @code{maximize}, etc. | 1742 | * Accumulation Clauses:: @code{collect}, @code{sum}, @code{maximize}, etc. |
| @@ -2120,19 +1747,19 @@ with an easy-to-use but very powerful and expressive syntax. | |||
| 2120 | @subsection Loop Basics | 1747 | @subsection Loop Basics |
| 2121 | 1748 | ||
| 2122 | @noindent | 1749 | @noindent |
| 2123 | The @code{loop} macro essentially creates a mini-language within | 1750 | The @code{cl-loop} macro essentially creates a mini-language within |
| 2124 | Lisp that is specially tailored for describing loops. While this | 1751 | Lisp that is specially tailored for describing loops. While this |
| 2125 | language is a little strange-looking by the standards of regular Lisp, | 1752 | language is a little strange-looking by the standards of regular Lisp, |
| 2126 | it turns out to be very easy to learn and well-suited to its purpose. | 1753 | it turns out to be very easy to learn and well-suited to its purpose. |
| 2127 | 1754 | ||
| 2128 | Since @code{loop} is a macro, all parsing of the loop language | 1755 | Since @code{cl-loop} is a macro, all parsing of the loop language |
| 2129 | takes place at byte-compile time; compiled @code{loop}s are just | 1756 | takes place at byte-compile time; compiled @code{cl-loop}s are just |
| 2130 | as efficient as the equivalent @code{while} loops written longhand. | 1757 | as efficient as the equivalent @code{while} loops written longhand. |
| 2131 | 1758 | ||
| 2132 | @defspec loop clauses@dots{} | 1759 | @defmac cl-loop clauses@dots{} |
| 2133 | A loop construct consists of a series of @var{clause}s, each | 1760 | A loop construct consists of a series of @var{clause}s, each |
| 2134 | introduced by a symbol like @code{for} or @code{do}. Clauses | 1761 | introduced by a symbol like @code{for} or @code{do}. Clauses |
| 2135 | are simply strung together in the argument list of @code{loop}, | 1762 | are simply strung together in the argument list of @code{cl-loop}, |
| 2136 | with minimal extra parentheses. The various types of clauses | 1763 | with minimal extra parentheses. The various types of clauses |
| 2137 | specify initializations, such as the binding of temporary | 1764 | specify initializations, such as the binding of temporary |
| 2138 | variables, actions to be taken in the loop, stepping actions, | 1765 | variables, actions to be taken in the loop, stepping actions, |
| @@ -2142,9 +1769,9 @@ Common Lisp specifies a certain general order of clauses in a | |||
| 2142 | loop: | 1769 | loop: |
| 2143 | 1770 | ||
| 2144 | @example | 1771 | @example |
| 2145 | (loop @var{name-clause} | 1772 | (cl-loop @var{name-clause} |
| 2146 | @var{var-clauses}@dots{} | 1773 | @var{var-clauses}@dots{} |
| 2147 | @var{action-clauses}@dots{}) | 1774 | @var{action-clauses}@dots{}) |
| 2148 | @end example | 1775 | @end example |
| 2149 | 1776 | ||
| 2150 | The @var{name-clause} optionally gives a name to the implicit | 1777 | The @var{name-clause} optionally gives a name to the implicit |
| @@ -2155,7 +1782,7 @@ be modified or iterated throughout the course of the loop. The | |||
| 2155 | @var{action-clauses} are things to be done during the loop, such | 1782 | @var{action-clauses} are things to be done during the loop, such |
| 2156 | as computing, collecting, and returning values. | 1783 | as computing, collecting, and returning values. |
| 2157 | 1784 | ||
| 2158 | The Emacs version of the @code{loop} macro is less restrictive about | 1785 | The Emacs version of the @code{cl-loop} macro is less restrictive about |
| 2159 | the order of clauses, but things will behave most predictably if | 1786 | the order of clauses, but things will behave most predictably if |
| 2160 | you put the variable-binding clauses @code{with}, @code{for}, and | 1787 | you put the variable-binding clauses @code{with}, @code{for}, and |
| 2161 | @code{repeat} before the action clauses. As in Common Lisp, | 1788 | @code{repeat} before the action clauses. As in Common Lisp, |
| @@ -2166,9 +1793,9 @@ them to return a value by using an accumulation clause like | |||
| 2166 | @code{collect}, an end-test clause like @code{always}, or an | 1793 | @code{collect}, an end-test clause like @code{always}, or an |
| 2167 | explicit @code{return} clause to jump out of the implicit block. | 1794 | explicit @code{return} clause to jump out of the implicit block. |
| 2168 | (Because the loop body is enclosed in an implicit block, you can | 1795 | (Because the loop body is enclosed in an implicit block, you can |
| 2169 | also use regular Lisp @code{return} or @code{return-from} to | 1796 | also use regular Lisp @code{cl-return} or @code{cl-return-from} to |
| 2170 | break out of the loop.) | 1797 | break out of the loop.) |
| 2171 | @end defspec | 1798 | @end defmac |
| 2172 | 1799 | ||
| 2173 | The following sections give some examples of the Loop Macro in | 1800 | The following sections give some examples of the Loop Macro in |
| 2174 | action, and describe the particular loop clauses in great detail. | 1801 | action, and describe the particular loop clauses in great detail. |
| @@ -2180,25 +1807,25 @@ for additional discussion and examples of the @code{loop} macro. | |||
| 2180 | 1807 | ||
| 2181 | @noindent | 1808 | @noindent |
| 2182 | Before listing the full set of clauses that are allowed, let's | 1809 | Before listing the full set of clauses that are allowed, let's |
| 2183 | look at a few example loops just to get a feel for the @code{loop} | 1810 | look at a few example loops just to get a feel for the @code{cl-loop} |
| 2184 | language. | 1811 | language. |
| 2185 | 1812 | ||
| 2186 | @example | 1813 | @example |
| 2187 | (loop for buf in (buffer-list) | 1814 | (cl-loop for buf in (buffer-list) |
| 2188 | collect (buffer-file-name buf)) | 1815 | collect (buffer-file-name buf)) |
| 2189 | @end example | 1816 | @end example |
| 2190 | 1817 | ||
| 2191 | @noindent | 1818 | @noindent |
| 2192 | This loop iterates over all Emacs buffers, using the list | 1819 | This loop iterates over all Emacs buffers, using the list |
| 2193 | returned by @code{buffer-list}. For each buffer @code{buf}, | 1820 | returned by @code{buffer-list}. For each buffer @var{buf}, |
| 2194 | it calls @code{buffer-file-name} and collects the results into | 1821 | it calls @code{buffer-file-name} and collects the results into |
| 2195 | a list, which is then returned from the @code{loop} construct. | 1822 | a list, which is then returned from the @code{cl-loop} construct. |
| 2196 | The result is a list of the file names of all the buffers in | 1823 | The result is a list of the file names of all the buffers in |
| 2197 | Emacs's memory. The words @code{for}, @code{in}, and @code{collect} | 1824 | Emacs's memory. The words @code{for}, @code{in}, and @code{collect} |
| 2198 | are reserved words in the @code{loop} language. | 1825 | are reserved words in the @code{cl-loop} language. |
| 2199 | 1826 | ||
| 2200 | @example | 1827 | @example |
| 2201 | (loop repeat 20 do (insert "Yowsa\n")) | 1828 | (cl-loop repeat 20 do (insert "Yowsa\n")) |
| 2202 | @end example | 1829 | @end example |
| 2203 | 1830 | ||
| 2204 | @noindent | 1831 | @noindent |
| @@ -2206,7 +1833,7 @@ This loop inserts the phrase ``Yowsa'' twenty times in the | |||
| 2206 | current buffer. | 1833 | current buffer. |
| 2207 | 1834 | ||
| 2208 | @example | 1835 | @example |
| 2209 | (loop until (eobp) do (munch-line) (forward-line 1)) | 1836 | (cl-loop until (eobp) do (munch-line) (forward-line 1)) |
| 2210 | @end example | 1837 | @end example |
| 2211 | 1838 | ||
| 2212 | @noindent | 1839 | @noindent |
| @@ -2215,7 +1842,7 @@ of the buffer. If point is already at the end of the buffer, | |||
| 2215 | the loop exits immediately. | 1842 | the loop exits immediately. |
| 2216 | 1843 | ||
| 2217 | @example | 1844 | @example |
| 2218 | (loop do (munch-line) until (eobp) do (forward-line 1)) | 1845 | (cl-loop do (munch-line) until (eobp) do (forward-line 1)) |
| 2219 | @end example | 1846 | @end example |
| 2220 | 1847 | ||
| 2221 | @noindent | 1848 | @noindent |
| @@ -2223,10 +1850,10 @@ This loop is similar to the above one, except that @code{munch-line} | |||
| 2223 | is always called at least once. | 1850 | is always called at least once. |
| 2224 | 1851 | ||
| 2225 | @example | 1852 | @example |
| 2226 | (loop for x from 1 to 100 | 1853 | (cl-loop for x from 1 to 100 |
| 2227 | for y = (* x x) | 1854 | for y = (* x x) |
| 2228 | until (>= y 729) | 1855 | until (>= y 729) |
| 2229 | finally return (list x (= y 729))) | 1856 | finally return (list x (= y 729))) |
| 2230 | @end example | 1857 | @end example |
| 2231 | 1858 | ||
| 2232 | @noindent | 1859 | @noindent |
| @@ -2246,7 +1873,7 @@ Note that even though this loop contains three clauses (two | |||
| 2246 | @code{for}s and an @code{until}) that would have been enough to | 1873 | @code{for}s and an @code{until}) that would have been enough to |
| 2247 | define loops all by themselves, it still creates a single loop | 1874 | define loops all by themselves, it still creates a single loop |
| 2248 | rather than some sort of triple-nested loop. You must explicitly | 1875 | rather than some sort of triple-nested loop. You must explicitly |
| 2249 | nest your @code{loop} constructs if you want nested loops. | 1876 | nest your @code{cl-loop} constructs if you want nested loops. |
| 2250 | 1877 | ||
| 2251 | @node For Clauses | 1878 | @node For Clauses |
| 2252 | @subsection For Clauses | 1879 | @subsection For Clauses |
| @@ -2272,7 +1899,7 @@ The variable is bound around the loop as if by @code{let}: | |||
| 2272 | 1899 | ||
| 2273 | @example | 1900 | @example |
| 2274 | (setq i 'happy) | 1901 | (setq i 'happy) |
| 2275 | (loop for i from 1 to 10 do (do-something-with i)) | 1902 | (cl-loop for i from 1 to 10 do (do-something-with i)) |
| 2276 | i | 1903 | i |
| 2277 | @result{} happy | 1904 | @result{} happy |
| 2278 | @end example | 1905 | @end example |
| @@ -2302,10 +1929,10 @@ which are like @code{upto} and @code{downto} respectively except | |||
| 2302 | that they are exclusive rather than inclusive limits: | 1929 | that they are exclusive rather than inclusive limits: |
| 2303 | 1930 | ||
| 2304 | @example | 1931 | @example |
| 2305 | (loop for x to 10 collect x) | 1932 | (cl-loop for x to 10 collect x) |
| 2306 | @result{} (0 1 2 3 4 5 6 7 8 9 10) | 1933 | @result{} (0 1 2 3 4 5 6 7 8 9 10) |
| 2307 | (loop for x below 10 collect x) | 1934 | (cl-loop for x below 10 collect x) |
| 2308 | @result{} (0 1 2 3 4 5 6 7 8 9) | 1935 | @result{} (0 1 2 3 4 5 6 7 8 9) |
| 2309 | @end example | 1936 | @end example |
| 2310 | 1937 | ||
| 2311 | The @code{by} value is always positive, even for downward-counting | 1938 | The @code{by} value is always positive, even for downward-counting |
| @@ -2320,25 +1947,25 @@ is used to traverse the list instead of @code{cdr}; it must be a | |||
| 2320 | function taking one argument. For example: | 1947 | function taking one argument. For example: |
| 2321 | 1948 | ||
| 2322 | @example | 1949 | @example |
| 2323 | (loop for x in '(1 2 3 4 5 6) collect (* x x)) | 1950 | (cl-loop for x in '(1 2 3 4 5 6) collect (* x x)) |
| 2324 | @result{} (1 4 9 16 25 36) | 1951 | @result{} (1 4 9 16 25 36) |
| 2325 | (loop for x in '(1 2 3 4 5 6) by 'cddr collect (* x x)) | 1952 | (cl-loop for x in '(1 2 3 4 5 6) by 'cddr collect (* x x)) |
| 2326 | @result{} (1 9 25) | 1953 | @result{} (1 9 25) |
| 2327 | @end example | 1954 | @end example |
| 2328 | 1955 | ||
| 2329 | @item for @var{var} on @var{list} by @var{function} | 1956 | @item for @var{var} on @var{list} by @var{function} |
| 2330 | This clause iterates @var{var} over all the cons cells of @var{list}. | 1957 | This clause iterates @var{var} over all the cons cells of @var{list}. |
| 2331 | 1958 | ||
| 2332 | @example | 1959 | @example |
| 2333 | (loop for x on '(1 2 3 4) collect x) | 1960 | (cl-loop for x on '(1 2 3 4) collect x) |
| 2334 | @result{} ((1 2 3 4) (2 3 4) (3 4) (4)) | 1961 | @result{} ((1 2 3 4) (2 3 4) (3 4) (4)) |
| 2335 | @end example | 1962 | @end example |
| 2336 | 1963 | ||
| 2337 | With @code{by}, there is no real reason that the @code{on} expression | 1964 | With @code{by}, there is no real reason that the @code{on} expression |
| 2338 | must be a list. For example: | 1965 | must be a list. For example: |
| 2339 | 1966 | ||
| 2340 | @example | 1967 | @example |
| 2341 | (loop for x on first-animal by 'next-animal collect x) | 1968 | (cl-loop for x on first-animal by 'next-animal collect x) |
| 2342 | @end example | 1969 | @end example |
| 2343 | 1970 | ||
| 2344 | @noindent | 1971 | @noindent |
| @@ -2352,7 +1979,7 @@ a @code{setf}-able ``reference'' onto the elements of the list | |||
| 2352 | rather than just a temporary variable. For example, | 1979 | rather than just a temporary variable. For example, |
| 2353 | 1980 | ||
| 2354 | @example | 1981 | @example |
| 2355 | (loop for x in-ref my-list do (incf x)) | 1982 | (cl-loop for x in-ref my-list do (cl-incf x)) |
| 2356 | @end example | 1983 | @end example |
| 2357 | 1984 | ||
| 2358 | @noindent | 1985 | @noindent |
| @@ -2364,8 +1991,8 @@ This clause iterates @var{var} over all the elements of @var{array}, | |||
| 2364 | which may be a vector or a string. | 1991 | which may be a vector or a string. |
| 2365 | 1992 | ||
| 2366 | @example | 1993 | @example |
| 2367 | (loop for x across "aeiou" | 1994 | (cl-loop for x across "aeiou" |
| 2368 | do (use-vowel (char-to-string x))) | 1995 | do (use-vowel (char-to-string x))) |
| 2369 | @end example | 1996 | @end example |
| 2370 | 1997 | ||
| 2371 | @item for @var{var} across-ref @var{array} | 1998 | @item for @var{var} across-ref @var{array} |
| @@ -2397,10 +2024,10 @@ an unspecified order. | |||
| 2397 | As an example, | 2024 | As an example, |
| 2398 | 2025 | ||
| 2399 | @example | 2026 | @example |
| 2400 | (loop for sym being the symbols | 2027 | (cl-loop for sym being the symbols |
| 2401 | when (fboundp sym) | 2028 | when (fboundp sym) |
| 2402 | when (string-match "^map" (symbol-name sym)) | 2029 | when (string-match "^map" (symbol-name sym)) |
| 2403 | collect sym) | 2030 | collect sym) |
| 2404 | @end example | 2031 | @end example |
| 2405 | 2032 | ||
| 2406 | @noindent | 2033 | @noindent |
| @@ -2411,7 +2038,7 @@ are also recognized but are equivalent to @code{symbols} in Emacs Lisp. | |||
| 2411 | 2038 | ||
| 2412 | Due to a minor implementation restriction, it will not work to have | 2039 | Due to a minor implementation restriction, it will not work to have |
| 2413 | more than one @code{for} clause iterating over symbols, hash tables, | 2040 | more than one @code{for} clause iterating over symbols, hash tables, |
| 2414 | keymaps, overlays, or intervals in a given @code{loop}. Fortunately, | 2041 | keymaps, overlays, or intervals in a given @code{cl-loop}. Fortunately, |
| 2415 | it would rarely if ever be useful to do so. It @emph{is} valid to mix | 2042 | it would rarely if ever be useful to do so. It @emph{is} valid to mix |
| 2416 | one of these types of clauses with other clauses like @code{for ... to} | 2043 | one of these types of clauses with other clauses like @code{for ... to} |
| 2417 | or @code{while}. | 2044 | or @code{while}. |
| @@ -2423,10 +2050,10 @@ This clause iterates over the entries in @var{hash-table} with | |||
| 2423 | a second variable to the opposite part. | 2050 | a second variable to the opposite part. |
| 2424 | 2051 | ||
| 2425 | @example | 2052 | @example |
| 2426 | (loop for k being the hash-keys of h | 2053 | (cl-loop for k being the hash-keys of h |
| 2427 | using (hash-values v) | 2054 | using (hash-values v) |
| 2428 | do | 2055 | do |
| 2429 | (message "key %S -> value %S" k v)) | 2056 | (message "key %S -> value %S" k v)) |
| 2430 | @end example | 2057 | @end example |
| 2431 | 2058 | ||
| 2432 | @item for @var{var} being the key-codes of @var{keymap} | 2059 | @item for @var{var} being the key-codes of @var{keymap} |
| @@ -2438,10 +2065,10 @@ A @code{using} clause can access both the codes and the bindings | |||
| 2438 | together. | 2065 | together. |
| 2439 | 2066 | ||
| 2440 | @example | 2067 | @example |
| 2441 | (loop for c being the key-codes of (current-local-map) | 2068 | (cl-loop for c being the key-codes of (current-local-map) |
| 2442 | using (key-bindings b) | 2069 | using (key-bindings b) |
| 2443 | do | 2070 | do |
| 2444 | (message "key %S -> binding %S" c b)) | 2071 | (message "key %S -> binding %S" c b)) |
| 2445 | @end example | 2072 | @end example |
| 2446 | 2073 | ||
| 2447 | 2074 | ||
| @@ -2497,8 +2124,8 @@ and successive iterations it will be set by evaluating @var{expr2} | |||
| 2497 | these two loops are effectively the same: | 2124 | these two loops are effectively the same: |
| 2498 | 2125 | ||
| 2499 | @example | 2126 | @example |
| 2500 | (loop for x on my-list by 'cddr do ...) | 2127 | (cl-loop for x on my-list by 'cddr do ...) |
| 2501 | (loop for x = my-list then (cddr x) while x do ...) | 2128 | (cl-loop for x = my-list then (cddr x) while x do ...) |
| 2502 | @end example | 2129 | @end example |
| 2503 | 2130 | ||
| 2504 | Note that this type of @code{for} clause does not imply any sort | 2131 | Note that this type of @code{for} clause does not imply any sort |
| @@ -2509,7 +2136,7 @@ If you omit the @code{then} term, @var{expr1} is used both for | |||
| 2509 | the initial setting and for successive settings: | 2136 | the initial setting and for successive settings: |
| 2510 | 2137 | ||
| 2511 | @example | 2138 | @example |
| 2512 | (loop for x = (random) when (> x 0) return x) | 2139 | (cl-loop for x = (random) when (> x 0) return x) |
| 2513 | @end example | 2140 | @end example |
| 2514 | 2141 | ||
| 2515 | @noindent | 2142 | @noindent |
| @@ -2524,10 +2151,10 @@ in which case they are processed in parallel (as if by @code{let} | |||
| 2524 | and @code{cl-psetq}). | 2151 | and @code{cl-psetq}). |
| 2525 | 2152 | ||
| 2526 | @example | 2153 | @example |
| 2527 | (loop for x below 5 for y = nil then x collect (list x y)) | 2154 | (cl-loop for x below 5 for y = nil then x collect (list x y)) |
| 2528 | @result{} ((0 nil) (1 1) (2 2) (3 3) (4 4)) | 2155 | @result{} ((0 nil) (1 1) (2 2) (3 3) (4 4)) |
| 2529 | (loop for x below 5 and y = nil then x collect (list x y)) | 2156 | (cl-loop for x below 5 and y = nil then x collect (list x y)) |
| 2530 | @result{} ((0 nil) (1 0) (2 1) (3 2) (4 3)) | 2157 | @result{} ((0 nil) (1 0) (2 1) (3 2) (4 3)) |
| 2531 | @end example | 2158 | @end example |
| 2532 | 2159 | ||
| 2533 | @noindent | 2160 | @noindent |
| @@ -2537,7 +2164,7 @@ that was just set by the previous clause; in the second loop, | |||
| 2537 | based on the value of @code{x} left over from the previous time | 2164 | based on the value of @code{x} left over from the previous time |
| 2538 | through the loop. | 2165 | through the loop. |
| 2539 | 2166 | ||
| 2540 | Another feature of the @code{loop} macro is @dfn{destructuring}, | 2167 | Another feature of the @code{cl-loop} macro is @dfn{destructuring}, |
| 2541 | similar in concept to the destructuring provided by @code{defmacro}. | 2168 | similar in concept to the destructuring provided by @code{defmacro}. |
| 2542 | The @var{var} part of any @code{for} clause can be given as a list | 2169 | The @var{var} part of any @code{for} clause can be given as a list |
| 2543 | of variables instead of a single variable. The values produced | 2170 | of variables instead of a single variable. The values produced |
| @@ -2545,8 +2172,8 @@ during loop execution must be lists; the values in the lists are | |||
| 2545 | stored in the corresponding variables. | 2172 | stored in the corresponding variables. |
| 2546 | 2173 | ||
| 2547 | @example | 2174 | @example |
| 2548 | (loop for (x y) in '((2 3) (4 5) (6 7)) collect (+ x y)) | 2175 | (cl-loop for (x y) in '((2 3) (4 5) (6 7)) collect (+ x y)) |
| 2549 | @result{} (5 9 13) | 2176 | @result{} (5 9 13) |
| 2550 | @end example | 2177 | @end example |
| 2551 | 2178 | ||
| 2552 | In loop destructuring, if there are more values than variables | 2179 | In loop destructuring, if there are more values than variables |
| @@ -2558,9 +2185,9 @@ lists of variables like @code{(x . y)} are allowed, so for example | |||
| 2558 | to process an alist | 2185 | to process an alist |
| 2559 | 2186 | ||
| 2560 | @example | 2187 | @example |
| 2561 | (loop for (key . value) in '((a . 1) (b . 2)) | 2188 | (cl-loop for (key . value) in '((a . 1) (b . 2)) |
| 2562 | collect value) | 2189 | collect value) |
| 2563 | @result{} (1 2) | 2190 | @result{} (1 2) |
| 2564 | @end example | 2191 | @end example |
| 2565 | 2192 | ||
| 2566 | @node Iteration Clauses | 2193 | @node Iteration Clauses |
| @@ -2577,8 +2204,8 @@ This clause simply counts up to the specified number using an | |||
| 2577 | internal temporary variable. The loops | 2204 | internal temporary variable. The loops |
| 2578 | 2205 | ||
| 2579 | @example | 2206 | @example |
| 2580 | (loop repeat (1+ n) do ...) | 2207 | (cl-loop repeat (1+ n) do ...) |
| 2581 | (loop for temp to n do ...) | 2208 | (cl-loop for temp to n do ...) |
| 2582 | @end example | 2209 | @end example |
| 2583 | 2210 | ||
| 2584 | @noindent | 2211 | @noindent |
| @@ -2593,7 +2220,7 @@ that surrounds the second one: | |||
| 2593 | 2220 | ||
| 2594 | @example | 2221 | @example |
| 2595 | (while @var{cond} @var{forms}@dots{}) | 2222 | (while @var{cond} @var{forms}@dots{}) |
| 2596 | (loop while @var{cond} do @var{forms}@dots{}) | 2223 | (cl-loop while @var{cond} do @var{forms}@dots{}) |
| 2597 | @end example | 2224 | @end example |
| 2598 | 2225 | ||
| 2599 | @item until @var{condition} | 2226 | @item until @var{condition} |
| @@ -2607,7 +2234,7 @@ the @code{finally} clauses are not executed. If all the conditions | |||
| 2607 | were non-@code{nil}, the loop returns @code{t}: | 2234 | were non-@code{nil}, the loop returns @code{t}: |
| 2608 | 2235 | ||
| 2609 | @example | 2236 | @example |
| 2610 | (if (loop for size in size-list always (> size 10)) | 2237 | (if (cl-loop for size in size-list always (> size 10)) |
| 2611 | (some-big-sizes) | 2238 | (some-big-sizes) |
| 2612 | (no-big-sizes)) | 2239 | (no-big-sizes)) |
| 2613 | @end example | 2240 | @end example |
| @@ -2684,11 +2311,11 @@ It is valid for several accumulation clauses of the same type to | |||
| 2684 | accumulate into the same place. From Steele: | 2311 | accumulate into the same place. From Steele: |
| 2685 | 2312 | ||
| 2686 | @example | 2313 | @example |
| 2687 | (loop for name in '(fred sue alice joe june) | 2314 | (cl-loop for name in '(fred sue alice joe june) |
| 2688 | for kids in '((bob ken) () () (kris sunshine) ()) | 2315 | for kids in '((bob ken) () () (kris sunshine) ()) |
| 2689 | collect name | 2316 | collect name |
| 2690 | append kids) | 2317 | append kids) |
| 2691 | @result{} (fred bob ken sue alice joe kris sunshine june) | 2318 | @result{} (fred bob ken sue alice joe kris sunshine june) |
| 2692 | @end example | 2319 | @end example |
| 2693 | 2320 | ||
| 2694 | @node Other Clauses | 2321 | @node Other Clauses |
| @@ -2704,17 +2331,17 @@ otherwise leaves the variable alone during the loop. The following | |||
| 2704 | loops are basically equivalent: | 2331 | loops are basically equivalent: |
| 2705 | 2332 | ||
| 2706 | @example | 2333 | @example |
| 2707 | (loop with x = 17 do ...) | 2334 | (cl-loop with x = 17 do ...) |
| 2708 | (let ((x 17)) (loop do ...)) | 2335 | (let ((x 17)) (cl-loop do ...)) |
| 2709 | (loop for x = 17 then x do ...) | 2336 | (cl-loop for x = 17 then x do ...) |
| 2710 | @end example | 2337 | @end example |
| 2711 | 2338 | ||
| 2712 | Naturally, the variable @var{var} might be used for some purpose | 2339 | Naturally, the variable @var{var} might be used for some purpose |
| 2713 | in the rest of the loop. For example: | 2340 | in the rest of the loop. For example: |
| 2714 | 2341 | ||
| 2715 | @example | 2342 | @example |
| 2716 | (loop for x in my-list with res = nil do (push x res) | 2343 | (cl-loop for x in my-list with res = nil do (push x res) |
| 2717 | finally return res) | 2344 | finally return res) |
| 2718 | @end example | 2345 | @end example |
| 2719 | 2346 | ||
| 2720 | This loop inserts the elements of @code{my-list} at the front of | 2347 | This loop inserts the elements of @code{my-list} at the front of |
| @@ -2749,18 +2376,18 @@ by the name @code{it} in the ``then'' part. For example: | |||
| 2749 | @example | 2376 | @example |
| 2750 | (setq funny-numbers '(6 13 -1)) | 2377 | (setq funny-numbers '(6 13 -1)) |
| 2751 | @result{} (6 13 -1) | 2378 | @result{} (6 13 -1) |
| 2752 | (loop for x below 10 | 2379 | (cl-loop for x below 10 |
| 2753 | if (oddp x) | 2380 | if (oddp x) |
| 2754 | collect x into odds | 2381 | collect x into odds |
| 2755 | and if (memq x funny-numbers) return (cdr it) end | 2382 | and if (memq x funny-numbers) return (cdr it) end |
| 2756 | else | 2383 | else |
| 2757 | collect x into evens | 2384 | collect x into evens |
| 2758 | finally return (vector odds evens)) | 2385 | finally return (vector odds evens)) |
| 2759 | @result{} [(1 3 5 7 9) (0 2 4 6 8)] | 2386 | @result{} [(1 3 5 7 9) (0 2 4 6 8)] |
| 2760 | (setq funny-numbers '(6 7 13 -1)) | 2387 | (setq funny-numbers '(6 7 13 -1)) |
| 2761 | @result{} (6 7 13 -1) | 2388 | @result{} (6 7 13 -1) |
| 2762 | (loop <@r{same thing again}>) | 2389 | (cl-loop <@r{same thing again}>) |
| 2763 | @result{} (13 -1) | 2390 | @result{} (13 -1) |
| 2764 | @end example | 2391 | @end example |
| 2765 | 2392 | ||
| 2766 | Note the use of @code{and} to put two clauses into the ``then'' | 2393 | Note the use of @code{and} to put two clauses into the ``then'' |
| @@ -2823,20 +2450,20 @@ Of course, @code{return} is generally used inside an @code{if} or | |||
| 2823 | the loop would never get to ``loop'' more than once. | 2450 | the loop would never get to ``loop'' more than once. |
| 2824 | 2451 | ||
| 2825 | The clause @samp{return @var{form}} is equivalent to | 2452 | The clause @samp{return @var{form}} is equivalent to |
| 2453 | @c FIXME cl-do, cl-return? | ||
| 2826 | @samp{do (return @var{form})} (or @code{return-from} if the loop | 2454 | @samp{do (return @var{form})} (or @code{return-from} if the loop |
| 2827 | was named). The @code{return} clause is implemented a bit more | 2455 | was named). The @code{return} clause is implemented a bit more |
| 2828 | efficiently, though. | 2456 | efficiently, though. |
| 2829 | @end table | 2457 | @end table |
| 2830 | 2458 | ||
| 2831 | While there is no high-level way to add user extensions to @code{loop} | 2459 | While there is no high-level way to add user extensions to @code{cl-loop}, |
| 2832 | (comparable to @code{defsetf} for @code{setf}, say), this package | 2460 | this package does offer two properties called @code{cl-loop-handler} |
| 2833 | does offer two properties called @code{cl-loop-handler} and | 2461 | and @code{cl-loop-for-handler} which are functions to be called when a |
| 2834 | @code{cl-loop-for-handler} which are functions to be called when | 2462 | given symbol is encountered as a top-level loop clause or @code{for} |
| 2835 | a given symbol is encountered as a top-level loop clause or | 2463 | clause, respectively. Consult the source code in file |
| 2836 | @code{for} clause, respectively. Consult the source code in | 2464 | @file{cl-macs.el} for details. |
| 2837 | file @file{cl-macs.el} for details. | ||
| 2838 | 2465 | ||
| 2839 | This package's @code{loop} macro is compatible with that of Common | 2466 | This package's @code{cl-loop} macro is compatible with that of Common |
| 2840 | Lisp, except that a few features are not implemented: @code{loop-finish} | 2467 | Lisp, except that a few features are not implemented: @code{loop-finish} |
| 2841 | and data-type specifiers. Naturally, the @code{for} clauses which | 2468 | and data-type specifiers. Naturally, the @code{for} clauses which |
| 2842 | iterate over keymaps, overlays, intervals, frames, windows, and | 2469 | iterate over keymaps, overlays, intervals, frames, windows, and |
| @@ -2851,35 +2478,28 @@ functions, by contrast, always return exactly one result. This | |||
| 2851 | package makes no attempt to emulate Common Lisp multiple return | 2478 | package makes no attempt to emulate Common Lisp multiple return |
| 2852 | values; Emacs versions of Common Lisp functions that return more | 2479 | values; Emacs versions of Common Lisp functions that return more |
| 2853 | than one value either return just the first value (as in | 2480 | than one value either return just the first value (as in |
| 2854 | @code{compiler-macroexpand}) or return a list of values (as in | 2481 | @code{cl-compiler-macroexpand}) or return a list of values. |
| 2855 | @code{get-setf-method}). This package @emph{does} define placeholders | 2482 | This package @emph{does} define placeholders |
| 2856 | for the Common Lisp functions that work with multiple values, but | 2483 | for the Common Lisp functions that work with multiple values, but |
| 2857 | in Emacs Lisp these functions simply operate on lists instead. | 2484 | in Emacs Lisp these functions simply operate on lists instead. |
| 2858 | The @code{values} form, for example, is a synonym for @code{list} | 2485 | The @code{cl-values} form, for example, is a synonym for @code{list} |
| 2859 | in Emacs. | 2486 | in Emacs. |
| 2860 | 2487 | ||
| 2861 | @defspec multiple-value-bind (var@dots{}) values-form forms@dots{} | 2488 | @defmac cl-multiple-value-bind (var@dots{}) values-form forms@dots{} |
| 2862 | This form evaluates @var{values-form}, which must return a list of | 2489 | This form evaluates @var{values-form}, which must return a list of |
| 2863 | values. It then binds the @var{var}s to these respective values, | 2490 | values. It then binds the @var{var}s to these respective values, |
| 2864 | as if by @code{let}, and then executes the body @var{forms}. | 2491 | as if by @code{let}, and then executes the body @var{forms}. |
| 2865 | If there are more @var{var}s than values, the extra @var{var}s | 2492 | If there are more @var{var}s than values, the extra @var{var}s |
| 2866 | are bound to @code{nil}. If there are fewer @var{var}s than | 2493 | are bound to @code{nil}. If there are fewer @var{var}s than |
| 2867 | values, the excess values are ignored. | 2494 | values, the excess values are ignored. |
| 2868 | @end defspec | 2495 | @end defmac |
| 2869 | 2496 | ||
| 2870 | @defspec multiple-value-setq (var@dots{}) form | 2497 | @defmac cl-multiple-value-setq (var@dots{}) form |
| 2871 | This form evaluates @var{form}, which must return a list of values. | 2498 | This form evaluates @var{form}, which must return a list of values. |
| 2872 | It then sets the @var{var}s to these respective values, as if by | 2499 | It then sets the @var{var}s to these respective values, as if by |
| 2873 | @code{setq}. Extra @var{var}s or values are treated the same as | 2500 | @code{setq}. Extra @var{var}s or values are treated the same as |
| 2874 | in @code{multiple-value-bind}. | 2501 | in @code{cl-multiple-value-bind}. |
| 2875 | @end defspec | 2502 | @end defmac |
| 2876 | |||
| 2877 | The older Quiroz package attempted a more faithful (but still | ||
| 2878 | imperfect) emulation of Common Lisp multiple values. The old | ||
| 2879 | method ``usually'' simulated true multiple values quite well, | ||
| 2880 | but under certain circumstances would leave spurious return | ||
| 2881 | values in memory where a later, unrelated @code{multiple-value-bind} | ||
| 2882 | form would see them. | ||
| 2883 | 2503 | ||
| 2884 | Since a perfect emulation is not feasible in Emacs Lisp, this | 2504 | Since a perfect emulation is not feasible in Emacs Lisp, this |
| 2885 | package opts to keep it as simple and predictable as possible. | 2505 | package opts to keep it as simple and predictable as possible. |
| @@ -2897,7 +2517,7 @@ for @code{defmacro} due to technical difficulties. | |||
| 2897 | Destructuring is made available to the user by way of the | 2517 | Destructuring is made available to the user by way of the |
| 2898 | following macro: | 2518 | following macro: |
| 2899 | 2519 | ||
| 2900 | @defspec destructuring-bind arglist expr forms@dots{} | 2520 | @defmac cl-destructuring-bind arglist expr forms@dots{} |
| 2901 | This macro expands to code which executes @var{forms}, with | 2521 | This macro expands to code which executes @var{forms}, with |
| 2902 | the variables in @var{arglist} bound to the list of values | 2522 | the variables in @var{arglist} bound to the list of values |
| 2903 | returned by @var{expr}. The @var{arglist} can include all | 2523 | returned by @var{expr}. The @var{arglist} can include all |
| @@ -2906,13 +2526,13 @@ including destructuring. (The @code{&environment} keyword | |||
| 2906 | is not allowed.) The macro expansion will signal an error | 2526 | is not allowed.) The macro expansion will signal an error |
| 2907 | if @var{expr} returns a list of the wrong number of arguments | 2527 | if @var{expr} returns a list of the wrong number of arguments |
| 2908 | or with incorrect keyword arguments. | 2528 | or with incorrect keyword arguments. |
| 2909 | @end defspec | 2529 | @end defmac |
| 2910 | 2530 | ||
| 2911 | This package also includes the Common Lisp @code{define-compiler-macro} | 2531 | This package also includes the Common Lisp @code{cl-define-compiler-macro} |
| 2912 | facility, which allows you to define compile-time expansions and | 2532 | facility, which allows you to define compile-time expansions and |
| 2913 | optimizations for your functions. | 2533 | optimizations for your functions. |
| 2914 | 2534 | ||
| 2915 | @defspec define-compiler-macro name arglist forms@dots{} | 2535 | @defmac cl-define-compiler-macro name arglist forms@dots{} |
| 2916 | This form is similar to @code{defmacro}, except that it only expands | 2536 | This form is similar to @code{defmacro}, except that it only expands |
| 2917 | calls to @var{name} at compile-time; calls processed by the Lisp | 2537 | calls to @var{name} at compile-time; calls processed by the Lisp |
| 2918 | interpreter are not expanded, nor are they expanded by the | 2538 | interpreter are not expanded, nor are they expanded by the |
| @@ -2930,25 +2550,25 @@ For example, here is a simplified version of a definition that | |||
| 2930 | appears as a standard part of this package: | 2550 | appears as a standard part of this package: |
| 2931 | 2551 | ||
| 2932 | @example | 2552 | @example |
| 2933 | (define-compiler-macro member* (&whole form a list &rest keys) | 2553 | (cl-define-compiler-macro cl-member (&whole form a list &rest keys) |
| 2934 | (if (and (null keys) | 2554 | (if (and (null keys) |
| 2935 | (eq (car-safe a) 'quote) | 2555 | (eq (car-safe a) 'quote) |
| 2936 | (not (floatp-safe (cadr a)))) | 2556 | (not (floatp-safe (cadr a)))) |
| 2937 | (list 'memq a list) | 2557 | (list 'memq a list) |
| 2938 | form)) | 2558 | form)) |
| 2939 | @end example | 2559 | @end example |
| 2940 | 2560 | ||
| 2941 | @noindent | 2561 | @noindent |
| 2942 | This definition causes @code{(member* @var{a} @var{list})} to change | 2562 | This definition causes @code{(cl-member @var{a} @var{list})} to change |
| 2943 | to a call to the faster @code{memq} in the common case where @var{a} | 2563 | to a call to the faster @code{memq} in the common case where @var{a} |
| 2944 | is a non-floating-point constant; if @var{a} is anything else, or | 2564 | is a non-floating-point constant; if @var{a} is anything else, or |
| 2945 | if there are any keyword arguments in the call, then the original | 2565 | if there are any keyword arguments in the call, then the original |
| 2946 | @code{member*} call is left intact. (The actual compiler macro | 2566 | @code{cl-member} call is left intact. (The actual compiler macro |
| 2947 | for @code{member*} optimizes a number of other cases, including | 2567 | for @code{cl-member} optimizes a number of other cases, including |
| 2948 | common @code{:test} predicates.) | 2568 | common @code{:test} predicates.) |
| 2949 | @end defspec | 2569 | @end defmac |
| 2950 | 2570 | ||
| 2951 | @defun compiler-macroexpand form | 2571 | @defun cl-compiler-macroexpand form |
| 2952 | This function is analogous to @code{macroexpand}, except that it | 2572 | This function is analogous to @code{macroexpand}, except that it |
| 2953 | expands compiler macros rather than regular macros. It returns | 2573 | expands compiler macros rather than regular macros. It returns |
| 2954 | @var{form} unchanged if it is not a call to a function for which | 2574 | @var{form} unchanged if it is not a call to a function for which |
| @@ -2958,8 +2578,8 @@ decided to punt by returning its @code{&whole} argument. Like | |||
| 2958 | for which no further expansion is possible. | 2578 | for which no further expansion is possible. |
| 2959 | @end defun | 2579 | @end defun |
| 2960 | 2580 | ||
| 2961 | @xref{Macro Bindings}, for descriptions of the @code{macrolet} | 2581 | @xref{Macro Bindings}, for descriptions of the @code{cl-macrolet} |
| 2962 | and @code{symbol-macrolet} forms for making ``local'' macro | 2582 | and @code{cl-symbol-macrolet} forms for making ``local'' macro |
| 2963 | definitions. | 2583 | definitions. |
| 2964 | 2584 | ||
| 2965 | @node Declarations | 2585 | @node Declarations |
| @@ -2971,8 +2591,8 @@ mechanism that allows you to give the compiler special hints | |||
| 2971 | about the types of data that will be stored in particular variables, | 2591 | about the types of data that will be stored in particular variables, |
| 2972 | and about the ways those variables and functions will be used. This | 2592 | and about the ways those variables and functions will be used. This |
| 2973 | package defines versions of all the Common Lisp declaration forms: | 2593 | package defines versions of all the Common Lisp declaration forms: |
| 2974 | @code{declare}, @code{locally}, @code{proclaim}, @code{declaim}, | 2594 | @code{cl-declare}, @code{cl-locally}, @code{cl-proclaim}, @code{cl-declaim}, |
| 2975 | and @code{the}. | 2595 | and @code{cl-the}. |
| 2976 | 2596 | ||
| 2977 | Most of the Common Lisp declarations are not currently useful in | 2597 | Most of the Common Lisp declarations are not currently useful in |
| 2978 | Emacs Lisp, as the byte-code system provides little opportunity | 2598 | Emacs Lisp, as the byte-code system provides little opportunity |
| @@ -2982,53 +2602,53 @@ declarations are meaningful when the optimizing byte | |||
| 2982 | compiler is being used, however. Under the earlier non-optimizing | 2602 | compiler is being used, however. Under the earlier non-optimizing |
| 2983 | compiler, these declarations will effectively be ignored. | 2603 | compiler, these declarations will effectively be ignored. |
| 2984 | 2604 | ||
| 2985 | @defun proclaim decl-spec | 2605 | @defun cl-proclaim decl-spec |
| 2986 | This function records a ``global'' declaration specified by | 2606 | This function records a ``global'' declaration specified by |
| 2987 | @var{decl-spec}. Since @code{proclaim} is a function, @var{decl-spec} | 2607 | @var{decl-spec}. Since @code{cl-proclaim} is a function, @var{decl-spec} |
| 2988 | is evaluated and thus should normally be quoted. | 2608 | is evaluated and thus should normally be quoted. |
| 2989 | @end defun | 2609 | @end defun |
| 2990 | 2610 | ||
| 2991 | @defspec declaim decl-specs@dots{} | 2611 | @defmac cl-declaim decl-specs@dots{} |
| 2992 | This macro is like @code{proclaim}, except that it takes any number | 2612 | This macro is like @code{cl-proclaim}, except that it takes any number |
| 2993 | of @var{decl-spec} arguments, and the arguments are unevaluated and | 2613 | of @var{decl-spec} arguments, and the arguments are unevaluated and |
| 2994 | unquoted. The @code{declaim} macro also puts an @code{(eval-when | 2614 | unquoted. The @code{cl-declaim} macro also puts an @code{(cl-eval-when |
| 2995 | (compile load eval) ...)} around the declarations so that they will | 2615 | (compile load eval) ...)} around the declarations so that they will |
| 2996 | be registered at compile-time as well as at run-time. (This is vital, | 2616 | be registered at compile-time as well as at run-time. (This is vital, |
| 2997 | since normally the declarations are meant to influence the way the | 2617 | since normally the declarations are meant to influence the way the |
| 2998 | compiler treats the rest of the file that contains the @code{declaim} | 2618 | compiler treats the rest of the file that contains the @code{cl-declaim} |
| 2999 | form.) | 2619 | form.) |
| 3000 | @end defspec | 2620 | @end defmac |
| 3001 | 2621 | ||
| 3002 | @defspec declare decl-specs@dots{} | 2622 | @defmac cl-declare decl-specs@dots{} |
| 3003 | This macro is used to make declarations within functions and other | 2623 | This macro is used to make declarations within functions and other |
| 3004 | code. Common Lisp allows declarations in various locations, generally | 2624 | code. Common Lisp allows declarations in various locations, generally |
| 3005 | at the beginning of any of the many ``implicit @code{progn}s'' | 2625 | at the beginning of any of the many ``implicit @code{progn}s'' |
| 3006 | throughout Lisp syntax, such as function bodies, @code{let} bodies, | 2626 | throughout Lisp syntax, such as function bodies, @code{let} bodies, |
| 3007 | etc. Currently the only declaration understood by @code{declare} | 2627 | etc. Currently the only declaration understood by @code{cl-declare} |
| 3008 | is @code{special}. | 2628 | is @code{special}. |
| 3009 | @end defspec | 2629 | @end defmac |
| 3010 | 2630 | ||
| 3011 | @defspec locally declarations@dots{} forms@dots{} | 2631 | @defmac cl-locally declarations@dots{} forms@dots{} |
| 3012 | In this package, @code{locally} is no different from @code{progn}. | 2632 | In this package, @code{cl-locally} is no different from @code{progn}. |
| 3013 | @end defspec | 2633 | @end defmac |
| 3014 | 2634 | ||
| 3015 | @defspec the type form | 2635 | @defmac cl-the type form |
| 3016 | Type information provided by @code{the} is ignored in this package; | 2636 | Type information provided by @code{cl-the} is ignored in this package; |
| 3017 | in other words, @code{(the @var{type} @var{form})} is equivalent | 2637 | in other words, @code{(cl-the @var{type} @var{form})} is equivalent |
| 3018 | to @var{form}. Future versions of the optimizing byte-compiler may | 2638 | to @var{form}. Future versions of the optimizing byte-compiler may |
| 3019 | make use of this information. | 2639 | make use of this information. |
| 3020 | 2640 | ||
| 3021 | For example, @code{mapcar} can map over both lists and arrays. It is | 2641 | For example, @code{mapcar} can map over both lists and arrays. It is |
| 3022 | hard for the compiler to expand @code{mapcar} into an in-line loop | 2642 | hard for the compiler to expand @code{mapcar} into an in-line loop |
| 3023 | unless it knows whether the sequence will be a list or an array ahead | 2643 | unless it knows whether the sequence will be a list or an array ahead |
| 3024 | of time. With @code{(mapcar 'car (the vector foo))}, a future | 2644 | of time. With @code{(mapcar 'car (cl-the vector foo))}, a future |
| 3025 | compiler would have enough information to expand the loop in-line. | 2645 | compiler would have enough information to expand the loop in-line. |
| 3026 | For now, Emacs Lisp will treat the above code as exactly equivalent | 2646 | For now, Emacs Lisp will treat the above code as exactly equivalent |
| 3027 | to @code{(mapcar 'car foo)}. | 2647 | to @code{(mapcar 'car foo)}. |
| 3028 | @end defspec | 2648 | @end defmac |
| 3029 | 2649 | ||
| 3030 | Each @var{decl-spec} in a @code{proclaim}, @code{declaim}, or | 2650 | Each @var{decl-spec} in a @code{cl-proclaim}, @code{cl-declaim}, or |
| 3031 | @code{declare} should be a list beginning with a symbol that says | 2651 | @code{cl-declare} should be a list beginning with a symbol that says |
| 3032 | what kind of declaration it is. This package currently understands | 2652 | what kind of declaration it is. This package currently understands |
| 3033 | @code{special}, @code{inline}, @code{notinline}, @code{optimize}, | 2653 | @code{special}, @code{inline}, @code{notinline}, @code{optimize}, |
| 3034 | and @code{warn} declarations. (The @code{warn} declaration is an | 2654 | and @code{warn} declarations. (The @code{warn} declaration is an |
| @@ -3045,16 +2665,16 @@ bound in the body of the function. The compiler normally emits | |||
| 3045 | warnings for such references, since they could be typographical | 2665 | warnings for such references, since they could be typographical |
| 3046 | errors for references to local variables. | 2666 | errors for references to local variables. |
| 3047 | 2667 | ||
| 3048 | The declaration @code{(declare (special @var{var1} @var{var2}))} is | 2668 | The declaration @code{(cl-declare (special @var{var1} @var{var2}))} is |
| 3049 | equivalent to @code{(defvar @var{var1}) (defvar @var{var2})} in the | 2669 | equivalent to @code{(defvar @var{var1}) (defvar @var{var2})} in the |
| 3050 | optimizing compiler, or to nothing at all in older compilers (which | 2670 | optimizing compiler, or to nothing at all in older compilers (which |
| 3051 | do not warn for non-local references). | 2671 | do not warn for non-local references). |
| 3052 | 2672 | ||
| 3053 | In top-level contexts, it is generally better to write | 2673 | In top-level contexts, it is generally better to write |
| 3054 | @code{(defvar @var{var})} than @code{(declaim (special @var{var}))}, | 2674 | @code{(defvar @var{var})} than @code{(cl-declaim (special @var{var}))}, |
| 3055 | since @code{defvar} makes your intentions clearer. But the older | 2675 | since @code{defvar} makes your intentions clearer. But the older |
| 3056 | byte compilers can not handle @code{defvar}s appearing inside of | 2676 | byte compilers can not handle @code{defvar}s appearing inside of |
| 3057 | functions, while @code{(declare (special @var{var}))} takes care | 2677 | functions, while @code{(cl-declare (special @var{var}))} takes care |
| 3058 | to work correctly with all compilers. | 2678 | to work correctly with all compilers. |
| 3059 | 2679 | ||
| 3060 | @item inline | 2680 | @item inline |
| @@ -3072,8 +2692,9 @@ The following declarations are all equivalent. Note that the | |||
| 3072 | and declare it inline all at once. | 2692 | and declare it inline all at once. |
| 3073 | 2693 | ||
| 3074 | @example | 2694 | @example |
| 3075 | (declaim (inline foo bar)) | 2695 | (cl-declaim (inline foo bar)) |
| 3076 | (eval-when (compile load eval) (proclaim '(inline foo bar))) | 2696 | (cl-eval-when (compile load eval) |
| 2697 | (cl-proclaim '(inline foo bar))) | ||
| 3077 | (defsubst foo (...) ...) ; instead of defun | 2698 | (defsubst foo (...) ...) ; instead of defun |
| 3078 | @end example | 2699 | @end example |
| 3079 | 2700 | ||
| @@ -3083,10 +2704,10 @@ request that a function you have defined should be inlined, | |||
| 3083 | but it is impolite to use it to request inlining of an external | 2704 | but it is impolite to use it to request inlining of an external |
| 3084 | function. | 2705 | function. |
| 3085 | 2706 | ||
| 3086 | In Common Lisp, it is possible to use @code{(declare (inline @dots{}))} | 2707 | In Common Lisp, it is possible to use @code{(cl-declare (inline @dots{}))} |
| 3087 | before a particular call to a function to cause just that call to | 2708 | before a particular call to a function to cause just that call to |
| 3088 | be inlined; the current byte compilers provide no way to implement | 2709 | be inlined; the current byte compilers provide no way to implement |
| 3089 | this, so @code{(declare (inline @dots{}))} is currently ignored by | 2710 | this, so @code{(cl-declare (inline @dots{}))} is currently ignored by |
| 3090 | this package. | 2711 | this package. |
| 3091 | 2712 | ||
| 3092 | @item notinline | 2713 | @item notinline |
| @@ -3103,15 +2724,15 @@ The word @code{optimize} is followed by any number of lists like | |||
| 3103 | @code{(speed 3)} or @code{(safety 2)}. Common Lisp defines several | 2724 | @code{(speed 3)} or @code{(safety 2)}. Common Lisp defines several |
| 3104 | optimization ``qualities''; this package ignores all but @code{speed} | 2725 | optimization ``qualities''; this package ignores all but @code{speed} |
| 3105 | and @code{safety}. The value of a quality should be an integer from | 2726 | and @code{safety}. The value of a quality should be an integer from |
| 3106 | 0 to 3, with 0 meaning ``unimportant'' and 3 meaning ``very important.'' | 2727 | 0 to 3, with 0 meaning ``unimportant'' and 3 meaning ``very important''. |
| 3107 | The default level for both qualities is 1. | 2728 | The default level for both qualities is 1. |
| 3108 | 2729 | ||
| 3109 | In this package, with the optimizing compiler, the | 2730 | In this package, with the optimizing compiler, the |
| 3110 | @code{speed} quality is tied to the @code{byte-compile-optimize} | 2731 | @code{speed} quality is tied to the @code{byte-optimize} |
| 3111 | flag, which is set to @code{nil} for @code{(speed 0)} and to | 2732 | flag, which is set to @code{nil} for @code{(speed 0)} and to |
| 3112 | @code{t} for higher settings; and the @code{safety} quality is | 2733 | @code{t} for higher settings; and the @code{safety} quality is |
| 3113 | tied to the @code{byte-compile-delete-errors} flag, which is | 2734 | tied to the @code{byte-compile-delete-errors} flag, which is |
| 3114 | set to @code{t} for @code{(safety 3)} and to @code{nil} for all | 2735 | set to @code{nil} for @code{(safety 3)} and to @code{t} for all |
| 3115 | lower settings. (The latter flag controls whether the compiler | 2736 | lower settings. (The latter flag controls whether the compiler |
| 3116 | is allowed to optimize out code whose only side-effect could | 2737 | is allowed to optimize out code whose only side-effect could |
| 3117 | be to signal an error, e.g., rewriting @code{(progn foo bar)} to | 2738 | be to signal an error, e.g., rewriting @code{(progn foo bar)} to |
| @@ -3125,10 +2746,10 @@ Emacs itself, Emacs will not crash with a segmentation fault | |||
| 3125 | just because of an error in a fully-optimized Lisp program. | 2746 | just because of an error in a fully-optimized Lisp program. |
| 3126 | 2747 | ||
| 3127 | The @code{optimize} declaration is normally used in a top-level | 2748 | The @code{optimize} declaration is normally used in a top-level |
| 3128 | @code{proclaim} or @code{declaim} in a file; Common Lisp allows | 2749 | @code{cl-proclaim} or @code{cl-declaim} in a file; Common Lisp allows |
| 3129 | it to be used with @code{declare} to set the level of optimization | 2750 | it to be used with @code{cl-declare} to set the level of optimization |
| 3130 | locally for a given form, but this will not work correctly with the | 2751 | locally for a given form, but this will not work correctly with the |
| 3131 | current version of the optimizing compiler. (The @code{declare} | 2752 | current version of the optimizing compiler. (The @code{cl-declare} |
| 3132 | will set the new optimization level, but that level will not | 2753 | will set the new optimization level, but that level will not |
| 3133 | automatically be unset after the enclosing form is done.) | 2754 | automatically be unset after the enclosing form is done.) |
| 3134 | 2755 | ||
| @@ -3136,7 +2757,7 @@ automatically be unset after the enclosing form is done.) | |||
| 3136 | This declaration controls what sorts of warnings are generated | 2757 | This declaration controls what sorts of warnings are generated |
| 3137 | by the byte compiler. Again, only the optimizing compiler | 2758 | by the byte compiler. Again, only the optimizing compiler |
| 3138 | generates warnings. The word @code{warn} is followed by any | 2759 | generates warnings. The word @code{warn} is followed by any |
| 3139 | number of ``warning qualities,'' similar in form to optimization | 2760 | number of ``warning qualities'', similar in form to optimization |
| 3140 | qualities. The currently supported warning types are | 2761 | qualities. The currently supported warning types are |
| 3141 | @code{redefine}, @code{callargs}, @code{unresolved}, and | 2762 | @code{redefine}, @code{callargs}, @code{unresolved}, and |
| 3142 | @code{free-vars}; in the current system, a value of 0 will | 2763 | @code{free-vars}; in the current system, a value of 0 will |
| @@ -3152,8 +2773,8 @@ This package defines several symbol-related features that were | |||
| 3152 | missing from Emacs Lisp. | 2773 | missing from Emacs Lisp. |
| 3153 | 2774 | ||
| 3154 | @menu | 2775 | @menu |
| 3155 | * Property Lists:: @code{get*}, @code{remprop}, @code{getf}, @code{remf}. | 2776 | * Property Lists:: @code{cl-get}, @code{cl-remprop}, @code{cl-getf}, @code{cl-remf}. |
| 3156 | * Creating Symbols:: @code{gensym}, @code{gentemp}. | 2777 | * Creating Symbols:: @code{cl-gensym}, @code{cl-gentemp}. |
| 3157 | @end menu | 2778 | @end menu |
| 3158 | 2779 | ||
| 3159 | @node Property Lists | 2780 | @node Property Lists |
| @@ -3165,18 +2786,18 @@ and @code{put} for operating on properties attached to symbols. | |||
| 3165 | There are also functions for working with property lists as | 2786 | There are also functions for working with property lists as |
| 3166 | first-class data structures not attached to particular symbols. | 2787 | first-class data structures not attached to particular symbols. |
| 3167 | 2788 | ||
| 3168 | @defun get* symbol property &optional default | 2789 | @defun cl-get symbol property &optional default |
| 3169 | This function is like @code{get}, except that if the property is | 2790 | This function is like @code{get}, except that if the property is |
| 3170 | not found, the @var{default} argument provides the return value. | 2791 | not found, the @var{default} argument provides the return value. |
| 3171 | (The Emacs Lisp @code{get} function always uses @code{nil} as | 2792 | (The Emacs Lisp @code{get} function always uses @code{nil} as |
| 3172 | the default; this package's @code{get*} is equivalent to Common | 2793 | the default; this package's @code{cl-get} is equivalent to Common |
| 3173 | Lisp's @code{get}.) | 2794 | Lisp's @code{get}.) |
| 3174 | 2795 | ||
| 3175 | The @code{get*} function is @code{setf}-able; when used in this | 2796 | The @code{cl-get} function is @code{setf}-able; when used in this |
| 3176 | fashion, the @var{default} argument is allowed but ignored. | 2797 | fashion, the @var{default} argument is allowed but ignored. |
| 3177 | @end defun | 2798 | @end defun |
| 3178 | 2799 | ||
| 3179 | @defun remprop symbol property | 2800 | @defun cl-remprop symbol property |
| 3180 | This function removes the entry for @var{property} from the property | 2801 | This function removes the entry for @var{property} from the property |
| 3181 | list of @var{symbol}. It returns a true value if the property was | 2802 | list of @var{symbol}. It returns a true value if the property was |
| 3182 | indeed found and removed, or @code{nil} if there was no such property. | 2803 | indeed found and removed, or @code{nil} if there was no such property. |
| @@ -3184,10 +2805,10 @@ indeed found and removed, or @code{nil} if there was no such property. | |||
| 3184 | since @code{get} did not allow a @var{default}, it was very difficult | 2805 | since @code{get} did not allow a @var{default}, it was very difficult |
| 3185 | to distinguish between a missing property and a property whose value | 2806 | to distinguish between a missing property and a property whose value |
| 3186 | was @code{nil}; thus, setting a property to @code{nil} was close | 2807 | was @code{nil}; thus, setting a property to @code{nil} was close |
| 3187 | enough to @code{remprop} for most purposes.) | 2808 | enough to @code{cl-remprop} for most purposes.) |
| 3188 | @end defun | 2809 | @end defun |
| 3189 | 2810 | ||
| 3190 | @defun getf place property &optional default | 2811 | @defun cl-getf place property &optional default |
| 3191 | This function scans the list @var{place} as if it were a property | 2812 | This function scans the list @var{place} as if it were a property |
| 3192 | list, i.e., a list of alternating property names and values. If | 2813 | list, i.e., a list of alternating property names and values. If |
| 3193 | an even-numbered element of @var{place} is found which is @code{eq} | 2814 | an even-numbered element of @var{place} is found which is @code{eq} |
| @@ -3198,10 +2819,10 @@ is given). | |||
| 3198 | In particular, | 2819 | In particular, |
| 3199 | 2820 | ||
| 3200 | @example | 2821 | @example |
| 3201 | (get sym prop) @equiv{} (getf (symbol-plist sym) prop) | 2822 | (get sym prop) @equiv{} (cl-getf (symbol-plist sym) prop) |
| 3202 | @end example | 2823 | @end example |
| 3203 | 2824 | ||
| 3204 | It is valid to use @code{getf} as a @code{setf} place, in which case | 2825 | It is valid to use @code{cl-getf} as a @code{setf} place, in which case |
| 3205 | its @var{place} argument must itself be a valid @code{setf} place. | 2826 | its @var{place} argument must itself be a valid @code{setf} place. |
| 3206 | The @var{default} argument, if any, is ignored in this context. | 2827 | The @var{default} argument, if any, is ignored in this context. |
| 3207 | The effect is to change (via @code{setcar}) the value cell in the | 2828 | The effect is to change (via @code{setcar}) the value cell in the |
| @@ -3209,25 +2830,25 @@ list that corresponds to @var{property}, or to cons a new property-value | |||
| 3209 | pair onto the list if the property is not yet present. | 2830 | pair onto the list if the property is not yet present. |
| 3210 | 2831 | ||
| 3211 | @example | 2832 | @example |
| 3212 | (put sym prop val) @equiv{} (setf (getf (symbol-plist sym) prop) val) | 2833 | (put sym prop val) @equiv{} (setf (cl-getf (symbol-plist sym) prop) val) |
| 3213 | @end example | 2834 | @end example |
| 3214 | 2835 | ||
| 3215 | The @code{get} and @code{get*} functions are also @code{setf}-able. | 2836 | The @code{get} and @code{cl-get} functions are also @code{setf}-able. |
| 3216 | The fact that @code{default} is ignored can sometimes be useful: | 2837 | The fact that @code{default} is ignored can sometimes be useful: |
| 3217 | 2838 | ||
| 3218 | @example | 2839 | @example |
| 3219 | (incf (get* 'foo 'usage-count 0)) | 2840 | (cl-incf (cl-get 'foo 'usage-count 0)) |
| 3220 | @end example | 2841 | @end example |
| 3221 | 2842 | ||
| 3222 | Here, symbol @code{foo}'s @code{usage-count} property is incremented | 2843 | Here, symbol @code{foo}'s @code{usage-count} property is incremented |
| 3223 | if it exists, or set to 1 (an incremented 0) otherwise. | 2844 | if it exists, or set to 1 (an incremented 0) otherwise. |
| 3224 | 2845 | ||
| 3225 | When not used as a @code{setf} form, @code{getf} is just a regular | 2846 | When not used as a @code{setf} form, @code{cl-getf} is just a regular |
| 3226 | function and its @var{place} argument can actually be any Lisp | 2847 | function and its @var{place} argument can actually be any Lisp |
| 3227 | expression. | 2848 | expression. |
| 3228 | @end defun | 2849 | @end defun |
| 3229 | 2850 | ||
| 3230 | @defspec remf place property | 2851 | @defmac cl-remf place property |
| 3231 | This macro removes the property-value pair for @var{property} from | 2852 | This macro removes the property-value pair for @var{property} from |
| 3232 | the property list stored at @var{place}, which is any @code{setf}-able | 2853 | the property list stored at @var{place}, which is any @code{setf}-able |
| 3233 | place expression. It returns true if the property was found. Note | 2854 | place expression. It returns true if the property was found. Note |
| @@ -3235,11 +2856,7 @@ that if @var{property} happens to be first on the list, this will | |||
| 3235 | effectively do a @code{(setf @var{place} (cddr @var{place}))}, | 2856 | effectively do a @code{(setf @var{place} (cddr @var{place}))}, |
| 3236 | whereas if it occurs later, this simply uses @code{setcdr} to splice | 2857 | whereas if it occurs later, this simply uses @code{setcdr} to splice |
| 3237 | out the property and value cells. | 2858 | out the property and value cells. |
| 3238 | @end defspec | 2859 | @end defmac |
| 3239 | |||
| 3240 | @iftex | ||
| 3241 | @secno=2 | ||
| 3242 | @end iftex | ||
| 3243 | 2860 | ||
| 3244 | @node Creating Symbols | 2861 | @node Creating Symbols |
| 3245 | @section Creating Symbols | 2862 | @section Creating Symbols |
| @@ -3248,7 +2865,7 @@ out the property and value cells. | |||
| 3248 | These functions create unique symbols, typically for use as | 2865 | These functions create unique symbols, typically for use as |
| 3249 | temporary variables. | 2866 | temporary variables. |
| 3250 | 2867 | ||
| 3251 | @defun gensym &optional x | 2868 | @defun cl-gensym &optional x |
| 3252 | This function creates a new, uninterned symbol (using @code{make-symbol}) | 2869 | This function creates a new, uninterned symbol (using @code{make-symbol}) |
| 3253 | with a unique name. (The name of an uninterned symbol is relevant | 2870 | with a unique name. (The name of an uninterned symbol is relevant |
| 3254 | only if the symbol is printed.) By default, the name is generated | 2871 | only if the symbol is printed.) By default, the name is generated |
| @@ -3260,31 +2877,30 @@ their names will not conflict with ``real'' variables in the user's | |||
| 3260 | code. | 2877 | code. |
| 3261 | @end defun | 2878 | @end defun |
| 3262 | 2879 | ||
| 3263 | @defvar *gensym-counter* | 2880 | @defvar cl--gensym-counter |
| 3264 | This variable holds the counter used to generate @code{gensym} names. | 2881 | This variable holds the counter used to generate @code{cl-gensym} names. |
| 3265 | It is incremented after each use by @code{gensym}. In Common Lisp | 2882 | It is incremented after each use by @code{cl-gensym}. In Common Lisp |
| 3266 | this is initialized with 0, but this package initializes it with a | 2883 | this is initialized with 0, but this package initializes it with a |
| 3267 | random (time-dependent) value to avoid trouble when two files that | 2884 | random (time-dependent) value to avoid trouble when two files that |
| 3268 | each used @code{gensym} in their compilation are loaded together. | 2885 | each used @code{cl-gensym} in their compilation are loaded together. |
| 3269 | (Uninterned symbols become interned when the compiler writes them | 2886 | (Uninterned symbols become interned when the compiler writes them |
| 3270 | out to a file and the Emacs loader loads them, so their names have to | 2887 | out to a file and the Emacs loader loads them, so their names have to |
| 3271 | be treated a bit more carefully than in Common Lisp where uninterned | 2888 | be treated a bit more carefully than in Common Lisp where uninterned |
| 3272 | symbols remain uninterned after loading.) | 2889 | symbols remain uninterned after loading.) |
| 3273 | @end defvar | 2890 | @end defvar |
| 3274 | 2891 | ||
| 3275 | @defun gentemp &optional x | 2892 | @defun cl-gentemp &optional x |
| 3276 | This function is like @code{gensym}, except that it produces a new | 2893 | This function is like @code{cl-gensym}, except that it produces a new |
| 3277 | @emph{interned} symbol. If the symbol that is generated already | 2894 | @emph{interned} symbol. If the symbol that is generated already |
| 3278 | exists, the function keeps incrementing the counter and trying | 2895 | exists, the function keeps incrementing the counter and trying |
| 3279 | again until a new symbol is generated. | 2896 | again until a new symbol is generated. |
| 3280 | @end defun | 2897 | @end defun |
| 3281 | 2898 | ||
| 3282 | The Quiroz @file{cl.el} package also defined a @code{defkeyword} | 2899 | This package automatically creates all keywords that are called for by |
| 3283 | form for creating self-quoting keyword symbols. This package | 2900 | @code{&key} argument specifiers, and discourages the use of keywords |
| 3284 | automatically creates all keywords that are called for by | 2901 | as data unrelated to keyword arguments, so the related function |
| 3285 | @code{&key} argument specifiers, and discourages the use of | 2902 | @code{defkeyword} (to create self-quoting keyword symbols) is not |
| 3286 | keywords as data unrelated to keyword arguments, so the | 2903 | provided. |
| 3287 | @code{defkeyword} form has been discontinued. | ||
| 3288 | 2904 | ||
| 3289 | @node Numbers | 2905 | @node Numbers |
| 3290 | @chapter Numbers | 2906 | @chapter Numbers |
| @@ -3294,16 +2910,12 @@ This section defines a few simple Common Lisp operations on numbers | |||
| 3294 | which were left out of Emacs Lisp. | 2910 | which were left out of Emacs Lisp. |
| 3295 | 2911 | ||
| 3296 | @menu | 2912 | @menu |
| 3297 | * Predicates on Numbers:: @code{plusp}, @code{oddp}, @code{floatp-safe}, etc. | 2913 | * Predicates on Numbers:: @code{cl-plusp}, @code{cl-oddp}, @code{cl-floatp-safe}, etc. |
| 3298 | * Numerical Functions:: @code{abs}, @code{floor*}, etc. | 2914 | * Numerical Functions:: @code{abs}, @code{cl-floor}, etc. |
| 3299 | * Random Numbers:: @code{random*}, @code{make-random-state}. | 2915 | * Random Numbers:: @code{cl-random}, @code{cl-make-random-state}. |
| 3300 | * Implementation Parameters:: @code{most-positive-float}. | 2916 | * Implementation Parameters:: @code{cl-most-positive-float}. |
| 3301 | @end menu | 2917 | @end menu |
| 3302 | 2918 | ||
| 3303 | @iftex | ||
| 3304 | @secno=1 | ||
| 3305 | @end iftex | ||
| 3306 | |||
| 3307 | @node Predicates on Numbers | 2919 | @node Predicates on Numbers |
| 3308 | @section Predicates on Numbers | 2920 | @section Predicates on Numbers |
| 3309 | 2921 | ||
| @@ -3311,66 +2923,58 @@ which were left out of Emacs Lisp. | |||
| 3311 | These functions return @code{t} if the specified condition is | 2923 | These functions return @code{t} if the specified condition is |
| 3312 | true of the numerical argument, or @code{nil} otherwise. | 2924 | true of the numerical argument, or @code{nil} otherwise. |
| 3313 | 2925 | ||
| 3314 | @defun plusp number | 2926 | @defun cl-plusp number |
| 3315 | This predicate tests whether @var{number} is positive. It is an | 2927 | This predicate tests whether @var{number} is positive. It is an |
| 3316 | error if the argument is not a number. | 2928 | error if the argument is not a number. |
| 3317 | @end defun | 2929 | @end defun |
| 3318 | 2930 | ||
| 3319 | @defun minusp number | 2931 | @defun cl-minusp number |
| 3320 | This predicate tests whether @var{number} is negative. It is an | 2932 | This predicate tests whether @var{number} is negative. It is an |
| 3321 | error if the argument is not a number. | 2933 | error if the argument is not a number. |
| 3322 | @end defun | 2934 | @end defun |
| 3323 | 2935 | ||
| 3324 | @defun oddp integer | 2936 | @defun cl-oddp integer |
| 3325 | This predicate tests whether @var{integer} is odd. It is an | 2937 | This predicate tests whether @var{integer} is odd. It is an |
| 3326 | error if the argument is not an integer. | 2938 | error if the argument is not an integer. |
| 3327 | @end defun | 2939 | @end defun |
| 3328 | 2940 | ||
| 3329 | @defun evenp integer | 2941 | @defun cl-evenp integer |
| 3330 | This predicate tests whether @var{integer} is even. It is an | 2942 | This predicate tests whether @var{integer} is even. It is an |
| 3331 | error if the argument is not an integer. | 2943 | error if the argument is not an integer. |
| 3332 | @end defun | 2944 | @end defun |
| 3333 | 2945 | ||
| 3334 | @defun floatp-safe object | 2946 | @defun cl-floatp-safe object |
| 3335 | This predicate tests whether @var{object} is a floating-point | 2947 | This predicate tests whether @var{object} is a floating-point |
| 3336 | number. On systems that support floating-point, this is equivalent | 2948 | number. On systems that support floating-point, this is equivalent |
| 3337 | to @code{floatp}. On other systems, this always returns @code{nil}. | 2949 | to @code{floatp}. On other systems, this always returns @code{nil}. |
| 3338 | @end defun | 2950 | @end defun |
| 3339 | 2951 | ||
| 3340 | @iftex | ||
| 3341 | @secno=3 | ||
| 3342 | @end iftex | ||
| 3343 | |||
| 3344 | @node Numerical Functions | 2952 | @node Numerical Functions |
| 3345 | @section Numerical Functions | 2953 | @section Numerical Functions |
| 3346 | 2954 | ||
| 3347 | @noindent | 2955 | @noindent |
| 3348 | These functions perform various arithmetic operations on numbers. | 2956 | These functions perform various arithmetic operations on numbers. |
| 3349 | 2957 | ||
| 3350 | @defun gcd &rest integers | 2958 | @defun cl-gcd &rest integers |
| 3351 | This function returns the Greatest Common Divisor of the arguments. | 2959 | This function returns the Greatest Common Divisor of the arguments. |
| 3352 | For one argument, it returns the absolute value of that argument. | 2960 | For one argument, it returns the absolute value of that argument. |
| 3353 | For zero arguments, it returns zero. | 2961 | For zero arguments, it returns zero. |
| 3354 | @end defun | 2962 | @end defun |
| 3355 | 2963 | ||
| 3356 | @defun lcm &rest integers | 2964 | @defun cl-lcm &rest integers |
| 3357 | This function returns the Least Common Multiple of the arguments. | 2965 | This function returns the Least Common Multiple of the arguments. |
| 3358 | For one argument, it returns the absolute value of that argument. | 2966 | For one argument, it returns the absolute value of that argument. |
| 3359 | For zero arguments, it returns one. | 2967 | For zero arguments, it returns one. |
| 3360 | @end defun | 2968 | @end defun |
| 3361 | 2969 | ||
| 3362 | @defun isqrt integer | 2970 | @defun cl-isqrt integer |
| 3363 | This function computes the ``integer square root'' of its integer | 2971 | This function computes the ``integer square root'' of its integer |
| 3364 | argument, i.e., the greatest integer less than or equal to the true | 2972 | argument, i.e., the greatest integer less than or equal to the true |
| 3365 | square root of the argument. | 2973 | square root of the argument. |
| 3366 | @end defun | 2974 | @end defun |
| 3367 | 2975 | ||
| 3368 | @defun floor* number &optional divisor | 2976 | @defun cl-floor number &optional divisor |
| 3369 | This function implements the Common Lisp @code{floor} function. | 2977 | With one argument, @code{cl-floor} returns a list of two numbers: |
| 3370 | It is called @code{floor*} to avoid name conflicts with the | ||
| 3371 | simpler @code{floor} function built-in to Emacs. | ||
| 3372 | |||
| 3373 | With one argument, @code{floor*} returns a list of two numbers: | ||
| 3374 | The argument rounded down (toward minus infinity) to an integer, | 2978 | The argument rounded down (toward minus infinity) to an integer, |
| 3375 | and the ``remainder'' which would have to be added back to the | 2979 | and the ``remainder'' which would have to be added back to the |
| 3376 | first return value to yield the argument again. If the argument | 2980 | first return value to yield the argument again. If the argument |
| @@ -3379,37 +2983,37 @@ If the argument is a floating-point number, the first | |||
| 3379 | result is a Lisp integer and the second is a Lisp float between | 2983 | result is a Lisp integer and the second is a Lisp float between |
| 3380 | 0 (inclusive) and 1 (exclusive). | 2984 | 0 (inclusive) and 1 (exclusive). |
| 3381 | 2985 | ||
| 3382 | With two arguments, @code{floor*} divides @var{number} by | 2986 | With two arguments, @code{cl-floor} divides @var{number} by |
| 3383 | @var{divisor}, and returns the floor of the quotient and the | 2987 | @var{divisor}, and returns the floor of the quotient and the |
| 3384 | corresponding remainder as a list of two numbers. If | 2988 | corresponding remainder as a list of two numbers. If |
| 3385 | @code{(floor* @var{x} @var{y})} returns @code{(@var{q} @var{r})}, | 2989 | @code{(cl-floor @var{x} @var{y})} returns @code{(@var{q} @var{r})}, |
| 3386 | then @code{@var{q}*@var{y} + @var{r} = @var{x}}, with @var{r} | 2990 | then @code{@var{q}*@var{y} + @var{r} = @var{x}}, with @var{r} |
| 3387 | between 0 (inclusive) and @var{r} (exclusive). Also, note | 2991 | between 0 (inclusive) and @var{r} (exclusive). Also, note |
| 3388 | that @code{(floor* @var{x})} is exactly equivalent to | 2992 | that @code{(cl-floor @var{x})} is exactly equivalent to |
| 3389 | @code{(floor* @var{x} 1)}. | 2993 | @code{(cl-floor @var{x} 1)}. |
| 3390 | 2994 | ||
| 3391 | This function is entirely compatible with Common Lisp's @code{floor} | 2995 | This function is entirely compatible with Common Lisp's @code{floor} |
| 3392 | function, except that it returns the two results in a list since | 2996 | function, except that it returns the two results in a list since |
| 3393 | Emacs Lisp does not support multiple-valued functions. | 2997 | Emacs Lisp does not support multiple-valued functions. |
| 3394 | @end defun | 2998 | @end defun |
| 3395 | 2999 | ||
| 3396 | @defun ceiling* number &optional divisor | 3000 | @defun cl-ceiling number &optional divisor |
| 3397 | This function implements the Common Lisp @code{ceiling} function, | 3001 | This function implements the Common Lisp @code{ceiling} function, |
| 3398 | which is analogous to @code{floor} except that it rounds the | 3002 | which is analogous to @code{floor} except that it rounds the |
| 3399 | argument or quotient of the arguments up toward plus infinity. | 3003 | argument or quotient of the arguments up toward plus infinity. |
| 3400 | The remainder will be between 0 and minus @var{r}. | 3004 | The remainder will be between 0 and minus @var{r}. |
| 3401 | @end defun | 3005 | @end defun |
| 3402 | 3006 | ||
| 3403 | @defun truncate* number &optional divisor | 3007 | @defun cl-truncate number &optional divisor |
| 3404 | This function implements the Common Lisp @code{truncate} function, | 3008 | This function implements the Common Lisp @code{truncate} function, |
| 3405 | which is analogous to @code{floor} except that it rounds the | 3009 | which is analogous to @code{floor} except that it rounds the |
| 3406 | argument or quotient of the arguments toward zero. Thus it is | 3010 | argument or quotient of the arguments toward zero. Thus it is |
| 3407 | equivalent to @code{floor*} if the argument or quotient is | 3011 | equivalent to @code{cl-floor} if the argument or quotient is |
| 3408 | positive, or to @code{ceiling*} otherwise. The remainder has | 3012 | positive, or to @code{cl-ceiling} otherwise. The remainder has |
| 3409 | the same sign as @var{number}. | 3013 | the same sign as @var{number}. |
| 3410 | @end defun | 3014 | @end defun |
| 3411 | 3015 | ||
| 3412 | @defun round* number &optional divisor | 3016 | @defun cl-round number &optional divisor |
| 3413 | This function implements the Common Lisp @code{round} function, | 3017 | This function implements the Common Lisp @code{round} function, |
| 3414 | which is analogous to @code{floor} except that it rounds the | 3018 | which is analogous to @code{floor} except that it rounds the |
| 3415 | argument or quotient of the arguments to the nearest integer. | 3019 | argument or quotient of the arguments to the nearest integer. |
| @@ -3417,26 +3021,16 @@ In the case of a tie (the argument or quotient is exactly | |||
| 3417 | halfway between two integers), it rounds to the even integer. | 3021 | halfway between two integers), it rounds to the even integer. |
| 3418 | @end defun | 3022 | @end defun |
| 3419 | 3023 | ||
| 3420 | @defun mod* number divisor | 3024 | @defun cl-mod number divisor |
| 3421 | This function returns the same value as the second return value | 3025 | This function returns the same value as the second return value |
| 3422 | of @code{floor}. | 3026 | of @code{cl-floor}. |
| 3423 | @end defun | 3027 | @end defun |
| 3424 | 3028 | ||
| 3425 | @defun rem* number divisor | 3029 | @defun cl-rem number divisor |
| 3426 | This function returns the same value as the second return value | 3030 | This function returns the same value as the second return value |
| 3427 | of @code{truncate}. | 3031 | of @code{cl-truncate}. |
| 3428 | @end defun | 3032 | @end defun |
| 3429 | 3033 | ||
| 3430 | These definitions are compatible with those in the Quiroz | ||
| 3431 | @file{cl.el} package, except that this package appends @samp{*} | ||
| 3432 | to certain function names to avoid conflicts with existing | ||
| 3433 | Emacs functions, and that the mechanism for returning | ||
| 3434 | multiple values is different. | ||
| 3435 | |||
| 3436 | @iftex | ||
| 3437 | @secno=8 | ||
| 3438 | @end iftex | ||
| 3439 | |||
| 3440 | @node Random Numbers | 3034 | @node Random Numbers |
| 3441 | @section Random Numbers | 3035 | @section Random Numbers |
| 3442 | 3036 | ||
| @@ -3447,32 +3041,32 @@ algorithm, which is much more likely to give statistically clean | |||
| 3447 | random numbers than the simple generators supplied by many | 3041 | random numbers than the simple generators supplied by many |
| 3448 | operating systems. | 3042 | operating systems. |
| 3449 | 3043 | ||
| 3450 | @defun random* number &optional state | 3044 | @defun cl-random number &optional state |
| 3451 | This function returns a random nonnegative number less than | 3045 | This function returns a random nonnegative number less than |
| 3452 | @var{number}, and of the same type (either integer or floating-point). | 3046 | @var{number}, and of the same type (either integer or floating-point). |
| 3453 | The @var{state} argument should be a @code{random-state} object | 3047 | The @var{state} argument should be a @code{random-state} object |
| 3454 | which holds the state of the random number generator. The | 3048 | which holds the state of the random number generator. The |
| 3455 | function modifies this state object as a side effect. If | 3049 | function modifies this state object as a side effect. If |
| 3456 | @var{state} is omitted, it defaults to the variable | 3050 | @var{state} is omitted, it defaults to the variable |
| 3457 | @code{*random-state*}, which contains a pre-initialized | 3051 | @code{cl--random-state}, which contains a pre-initialized |
| 3458 | @code{random-state} object. | 3052 | @code{random-state} object. |
| 3459 | @end defun | 3053 | @end defun |
| 3460 | 3054 | ||
| 3461 | @defvar *random-state* | 3055 | @defvar cl--random-state |
| 3462 | This variable contains the system ``default'' @code{random-state} | 3056 | This variable contains the system ``default'' @code{random-state} |
| 3463 | object, used for calls to @code{random*} that do not specify an | 3057 | object, used for calls to @code{cl-random} that do not specify an |
| 3464 | alternative state object. Since any number of programs in the | 3058 | alternative state object. Since any number of programs in the |
| 3465 | Emacs process may be accessing @code{*random-state*} in interleaved | 3059 | Emacs process may be accessing @code{cl--random-state} in interleaved |
| 3466 | fashion, the sequence generated from this variable will be | 3060 | fashion, the sequence generated from this variable will be |
| 3467 | irreproducible for all intents and purposes. | 3061 | irreproducible for all intents and purposes. |
| 3468 | @end defvar | 3062 | @end defvar |
| 3469 | 3063 | ||
| 3470 | @defun make-random-state &optional state | 3064 | @defun cl-make-random-state &optional state |
| 3471 | This function creates or copies a @code{random-state} object. | 3065 | This function creates or copies a @code{random-state} object. |
| 3472 | If @var{state} is omitted or @code{nil}, it returns a new copy of | 3066 | If @var{state} is omitted or @code{nil}, it returns a new copy of |
| 3473 | @code{*random-state*}. This is a copy in the sense that future | 3067 | @code{cl--random-state}. This is a copy in the sense that future |
| 3474 | sequences of calls to @code{(random* @var{n})} and | 3068 | sequences of calls to @code{(cl-random @var{n})} and |
| 3475 | @code{(random* @var{n} @var{s})} (where @var{s} is the new | 3069 | @code{(cl-random @var{n} @var{s})} (where @var{s} is the new |
| 3476 | random-state object) will return identical sequences of random | 3070 | random-state object) will return identical sequences of random |
| 3477 | numbers. | 3071 | numbers. |
| 3478 | 3072 | ||
| @@ -3487,13 +3081,13 @@ different sequence of random numbers. | |||
| 3487 | It is valid to print a @code{random-state} object to a buffer or | 3081 | It is valid to print a @code{random-state} object to a buffer or |
| 3488 | file and later read it back with @code{read}. If a program wishes | 3082 | file and later read it back with @code{read}. If a program wishes |
| 3489 | to use a sequence of pseudo-random numbers which can be reproduced | 3083 | to use a sequence of pseudo-random numbers which can be reproduced |
| 3490 | later for debugging, it can call @code{(make-random-state t)} to | 3084 | later for debugging, it can call @code{(cl-make-random-state t)} to |
| 3491 | get a new sequence, then print this sequence to a file. When the | 3085 | get a new sequence, then print this sequence to a file. When the |
| 3492 | program is later rerun, it can read the original run's random-state | 3086 | program is later rerun, it can read the original run's random-state |
| 3493 | from the file. | 3087 | from the file. |
| 3494 | @end defun | 3088 | @end defun |
| 3495 | 3089 | ||
| 3496 | @defun random-state-p object | 3090 | @defun cl-random-state-p object |
| 3497 | This predicate returns @code{t} if @var{object} is a | 3091 | This predicate returns @code{t} if @var{object} is a |
| 3498 | @code{random-state} object, or @code{nil} otherwise. | 3092 | @code{random-state} object, or @code{nil} otherwise. |
| 3499 | @end defun | 3093 | @end defun |
| @@ -3512,7 +3106,7 @@ function that must be called before the parameters can be used. | |||
| 3512 | 3106 | ||
| 3513 | @defun cl-float-limits | 3107 | @defun cl-float-limits |
| 3514 | This function makes sure that the Common Lisp floating-point parameters | 3108 | This function makes sure that the Common Lisp floating-point parameters |
| 3515 | like @code{most-positive-float} have been initialized. Until it is | 3109 | like @code{cl-most-positive-float} have been initialized. Until it is |
| 3516 | called, these parameters will be @code{nil}. If this version of Emacs | 3110 | called, these parameters will be @code{nil}. If this version of Emacs |
| 3517 | does not support floats, the parameters will remain @code{nil}. If the | 3111 | does not support floats, the parameters will remain @code{nil}. If the |
| 3518 | parameters have already been initialized, the function returns | 3112 | parameters have already been initialized, the function returns |
| @@ -3530,50 +3124,50 @@ precisions, it has families of constants like | |||
| 3530 | floating-point precision, so this package omits the precision word | 3124 | floating-point precision, so this package omits the precision word |
| 3531 | from the constants' names. | 3125 | from the constants' names. |
| 3532 | 3126 | ||
| 3533 | @defvar most-positive-float | 3127 | @defvar cl-most-positive-float |
| 3534 | This constant equals the largest value a Lisp float can hold. | 3128 | This constant equals the largest value a Lisp float can hold. |
| 3535 | For those systems whose arithmetic supports infinities, this is | 3129 | For those systems whose arithmetic supports infinities, this is |
| 3536 | the largest @emph{finite} value. For IEEE machines, the value | 3130 | the largest @emph{finite} value. For IEEE machines, the value |
| 3537 | is approximately @code{1.79e+308}. | 3131 | is approximately @code{1.79e+308}. |
| 3538 | @end defvar | 3132 | @end defvar |
| 3539 | 3133 | ||
| 3540 | @defvar most-negative-float | 3134 | @defvar cl-most-negative-float |
| 3541 | This constant equals the most-negative value a Lisp float can hold. | 3135 | This constant equals the most-negative value a Lisp float can hold. |
| 3542 | (It is assumed to be equal to @code{(- most-positive-float)}.) | 3136 | (It is assumed to be equal to @code{(- cl-most-positive-float)}.) |
| 3543 | @end defvar | 3137 | @end defvar |
| 3544 | 3138 | ||
| 3545 | @defvar least-positive-float | 3139 | @defvar cl-least-positive-float |
| 3546 | This constant equals the smallest Lisp float value greater than zero. | 3140 | This constant equals the smallest Lisp float value greater than zero. |
| 3547 | For IEEE machines, it is about @code{4.94e-324} if denormals are | 3141 | For IEEE machines, it is about @code{4.94e-324} if denormals are |
| 3548 | supported or @code{2.22e-308} if not. | 3142 | supported or @code{2.22e-308} if not. |
| 3549 | @end defvar | 3143 | @end defvar |
| 3550 | 3144 | ||
| 3551 | @defvar least-positive-normalized-float | 3145 | @defvar cl-least-positive-normalized-float |
| 3552 | This constant equals the smallest @emph{normalized} Lisp float greater | 3146 | This constant equals the smallest @emph{normalized} Lisp float greater |
| 3553 | than zero, i.e., the smallest value for which IEEE denormalization | 3147 | than zero, i.e., the smallest value for which IEEE denormalization |
| 3554 | will not result in a loss of precision. For IEEE machines, this | 3148 | will not result in a loss of precision. For IEEE machines, this |
| 3555 | value is about @code{2.22e-308}. For machines that do not support | 3149 | value is about @code{2.22e-308}. For machines that do not support |
| 3556 | the concept of denormalization and gradual underflow, this constant | 3150 | the concept of denormalization and gradual underflow, this constant |
| 3557 | will always equal @code{least-positive-float}. | 3151 | will always equal @code{cl-least-positive-float}. |
| 3558 | @end defvar | 3152 | @end defvar |
| 3559 | 3153 | ||
| 3560 | @defvar least-negative-float | 3154 | @defvar cl-least-negative-float |
| 3561 | This constant is the negative counterpart of @code{least-positive-float}. | 3155 | This constant is the negative counterpart of @code{cl-least-positive-float}. |
| 3562 | @end defvar | 3156 | @end defvar |
| 3563 | 3157 | ||
| 3564 | @defvar least-negative-normalized-float | 3158 | @defvar cl-least-negative-normalized-float |
| 3565 | This constant is the negative counterpart of | 3159 | This constant is the negative counterpart of |
| 3566 | @code{least-positive-normalized-float}. | 3160 | @code{cl-least-positive-normalized-float}. |
| 3567 | @end defvar | 3161 | @end defvar |
| 3568 | 3162 | ||
| 3569 | @defvar float-epsilon | 3163 | @defvar cl-float-epsilon |
| 3570 | This constant is the smallest positive Lisp float that can be added | 3164 | This constant is the smallest positive Lisp float that can be added |
| 3571 | to 1.0 to produce a distinct value. Adding a smaller number to 1.0 | 3165 | to 1.0 to produce a distinct value. Adding a smaller number to 1.0 |
| 3572 | will yield 1.0 again due to roundoff. For IEEE machines, epsilon | 3166 | will yield 1.0 again due to roundoff. For IEEE machines, epsilon |
| 3573 | is about @code{2.22e-16}. | 3167 | is about @code{2.22e-16}. |
| 3574 | @end defvar | 3168 | @end defvar |
| 3575 | 3169 | ||
| 3576 | @defvar float-negative-epsilon | 3170 | @defvar cl-float-negative-epsilon |
| 3577 | This is the smallest positive value that can be subtracted from | 3171 | This is the smallest positive value that can be subtracted from |
| 3578 | 1.0 to produce a distinct value. For IEEE machines, it is about | 3172 | 1.0 to produce a distinct value. For IEEE machines, it is about |
| 3579 | @code{1.11e-16}. | 3173 | @code{1.11e-16}. |
| @@ -3590,10 +3184,10 @@ Emacs Lisp includes a few of these, notably @code{elt} and | |||
| 3590 | 3184 | ||
| 3591 | @menu | 3185 | @menu |
| 3592 | * Sequence Basics:: Arguments shared by all sequence functions. | 3186 | * Sequence Basics:: Arguments shared by all sequence functions. |
| 3593 | * Mapping over Sequences:: @code{mapcar*}, @code{mapcan}, @code{map}, @code{every}, etc. | 3187 | * Mapping over Sequences:: @code{cl-mapcar}, @code{cl-mapcan}, @code{cl-map}, @code{cl-every}, etc. |
| 3594 | * Sequence Functions:: @code{subseq}, @code{remove*}, @code{substitute}, etc. | 3188 | * Sequence Functions:: @code{cl-subseq}, @code{cl-remove}, @code{cl-substitute}, etc. |
| 3595 | * Searching Sequences:: @code{find}, @code{position}, @code{count}, @code{search}, etc. | 3189 | * Searching Sequences:: @code{cl-find}, @code{cl-position}, @code{cl-count}, @code{cl-search}, etc. |
| 3596 | * Sorting Sequences:: @code{sort*}, @code{stable-sort}, @code{merge}. | 3190 | * Sorting Sequences:: @code{cl-sort}, @code{cl-stable-sort}, @code{cl-merge}. |
| 3597 | @end menu | 3191 | @end menu |
| 3598 | 3192 | ||
| 3599 | @node Sequence Basics | 3193 | @node Sequence Basics |
| @@ -3607,7 +3201,7 @@ may appear in any order. | |||
| 3607 | The @code{:key} argument should be passed either @code{nil}, or a | 3201 | The @code{:key} argument should be passed either @code{nil}, or a |
| 3608 | function of one argument. This key function is used as a filter | 3202 | function of one argument. This key function is used as a filter |
| 3609 | through which the elements of the sequence are seen; for example, | 3203 | through which the elements of the sequence are seen; for example, |
| 3610 | @code{(find x y :key 'car)} is similar to @code{(assoc* x y)}: | 3204 | @code{(cl-find x y :key 'car)} is similar to @code{(cl-assoc x y)}: |
| 3611 | It searches for an element of the list whose @code{car} equals | 3205 | It searches for an element of the list whose @code{car} equals |
| 3612 | @code{x}, rather than for an element which equals @code{x} itself. | 3206 | @code{x}, rather than for an element which equals @code{x} itself. |
| 3613 | If @code{:key} is omitted or @code{nil}, the filter is effectively | 3207 | If @code{:key} is omitted or @code{nil}, the filter is effectively |
| @@ -3632,7 +3226,7 @@ and sequence elements match if the predicate returns true on them | |||
| 3632 | (or false in the case of @code{-if-not}). For example: | 3226 | (or false in the case of @code{-if-not}). For example: |
| 3633 | 3227 | ||
| 3634 | @example | 3228 | @example |
| 3635 | (remove* 0 seq :test '=) @equiv{} (remove-if 'zerop seq) | 3229 | (cl-remove 0 seq :test '=) @equiv{} (cl-remove-if 'zerop seq) |
| 3636 | @end example | 3230 | @end example |
| 3637 | 3231 | ||
| 3638 | @noindent | 3232 | @noindent |
| @@ -3662,14 +3256,14 @@ are called on various elements. Therefore, it is a bad idea to depend | |||
| 3662 | on side effects of these functions. For example, @code{:from-end} | 3256 | on side effects of these functions. For example, @code{:from-end} |
| 3663 | may cause the sequence to be scanned actually in reverse, or it may | 3257 | may cause the sequence to be scanned actually in reverse, or it may |
| 3664 | be scanned forwards but computing a result ``as if'' it were scanned | 3258 | be scanned forwards but computing a result ``as if'' it were scanned |
| 3665 | backwards. (Some functions, like @code{mapcar*} and @code{every}, | 3259 | backwards. (Some functions, like @code{cl-mapcar} and @code{cl-every}, |
| 3666 | @emph{do} specify exactly the order in which the function is called | 3260 | @emph{do} specify exactly the order in which the function is called |
| 3667 | so side effects are perfectly acceptable in those cases.) | 3261 | so side effects are perfectly acceptable in those cases.) |
| 3668 | 3262 | ||
| 3669 | Strings may contain ``text properties'' as well | 3263 | Strings may contain ``text properties'' as well |
| 3670 | as character data. Except as noted, it is undefined whether or | 3264 | as character data. Except as noted, it is undefined whether or |
| 3671 | not text properties are preserved by sequence functions. For | 3265 | not text properties are preserved by sequence functions. For |
| 3672 | example, @code{(remove* ?A @var{str})} may or may not preserve | 3266 | example, @code{(cl-remove ?A @var{str})} may or may not preserve |
| 3673 | the properties of the characters copied from @var{str} into the | 3267 | the properties of the characters copied from @var{str} into the |
| 3674 | result. | 3268 | result. |
| 3675 | 3269 | ||
| @@ -3681,7 +3275,7 @@ These functions ``map'' the function you specify over the elements | |||
| 3681 | of lists or arrays. They are all variations on the theme of the | 3275 | of lists or arrays. They are all variations on the theme of the |
| 3682 | built-in function @code{mapcar}. | 3276 | built-in function @code{mapcar}. |
| 3683 | 3277 | ||
| 3684 | @defun mapcar* function seq &rest more-seqs | 3278 | @defun cl-mapcar function seq &rest more-seqs |
| 3685 | This function calls @var{function} on successive parallel sets of | 3279 | This function calls @var{function} on successive parallel sets of |
| 3686 | elements from its argument sequences. Given a single @var{seq} | 3280 | elements from its argument sequences. Given a single @var{seq} |
| 3687 | argument it is equivalent to @code{mapcar}; given @var{n} sequences, | 3281 | argument it is equivalent to @code{mapcar}; given @var{n} sequences, |
| @@ -3694,86 +3288,89 @@ is always a list. | |||
| 3694 | 3288 | ||
| 3695 | Common Lisp's @code{mapcar} accepts multiple arguments but works | 3289 | Common Lisp's @code{mapcar} accepts multiple arguments but works |
| 3696 | only on lists; Emacs Lisp's @code{mapcar} accepts a single sequence | 3290 | only on lists; Emacs Lisp's @code{mapcar} accepts a single sequence |
| 3697 | argument. This package's @code{mapcar*} works as a compatible | 3291 | argument. This package's @code{cl-mapcar} works as a compatible |
| 3698 | superset of both. | 3292 | superset of both. |
| 3699 | @end defun | 3293 | @end defun |
| 3700 | 3294 | ||
| 3701 | @defun map result-type function seq &rest more-seqs | 3295 | @defun cl-map result-type function seq &rest more-seqs |
| 3702 | This function maps @var{function} over the argument sequences, | 3296 | This function maps @var{function} over the argument sequences, |
| 3703 | just like @code{mapcar*}, but it returns a sequence of type | 3297 | just like @code{cl-mapcar}, but it returns a sequence of type |
| 3704 | @var{result-type} rather than a list. @var{result-type} must | 3298 | @var{result-type} rather than a list. @var{result-type} must |
| 3705 | be one of the following symbols: @code{vector}, @code{string}, | 3299 | be one of the following symbols: @code{vector}, @code{string}, |
| 3706 | @code{list} (in which case the effect is the same as for | 3300 | @code{list} (in which case the effect is the same as for |
| 3707 | @code{mapcar*}), or @code{nil} (in which case the results are | 3301 | @code{cl-mapcar}), or @code{nil} (in which case the results are |
| 3708 | thrown away and @code{map} returns @code{nil}). | 3302 | thrown away and @code{cl-map} returns @code{nil}). |
| 3709 | @end defun | 3303 | @end defun |
| 3710 | 3304 | ||
| 3711 | @defun maplist function list &rest more-lists | 3305 | @defun cl-maplist function list &rest more-lists |
| 3712 | This function calls @var{function} on each of its argument lists, | 3306 | This function calls @var{function} on each of its argument lists, |
| 3713 | then on the @code{cdr}s of those lists, and so on, until the | 3307 | then on the @code{cdr}s of those lists, and so on, until the |
| 3714 | shortest list runs out. The results are returned in the form | 3308 | shortest list runs out. The results are returned in the form |
| 3715 | of a list. Thus, @code{maplist} is like @code{mapcar*} except | 3309 | of a list. Thus, @code{cl-maplist} is like @code{cl-mapcar} except |
| 3716 | that it passes in the list pointers themselves rather than the | 3310 | that it passes in the list pointers themselves rather than the |
| 3717 | @code{car}s of the advancing pointers. | 3311 | @code{car}s of the advancing pointers. |
| 3718 | @end defun | 3312 | @end defun |
| 3719 | 3313 | ||
| 3720 | @defun cl-mapc function seq &rest more-seqs | 3314 | @defun cl-mapc function seq &rest more-seqs |
| 3721 | This function is like @code{mapcar*}, except that the values returned | 3315 | This function is like @code{cl-mapcar}, except that the values returned |
| 3722 | by @var{function} are ignored and thrown away rather than being | 3316 | by @var{function} are ignored and thrown away rather than being |
| 3723 | collected into a list. The return value of @code{cl-mapc} is @var{seq}, | 3317 | collected into a list. The return value of @code{cl-mapc} is @var{seq}, |
| 3724 | the first sequence. This function is more general than the Emacs | 3318 | the first sequence. This function is more general than the Emacs |
| 3725 | primitive @code{mapc}. | 3319 | primitive @code{mapc}. (Note that this function is called |
| 3320 | @code{cl-mapc} even in @file{cl.el}, rather than @code{map*} as you | ||
| 3321 | might expect.) | ||
| 3322 | @c http://debbugs.gnu.org/6575 | ||
| 3726 | @end defun | 3323 | @end defun |
| 3727 | 3324 | ||
| 3728 | @defun mapl function list &rest more-lists | 3325 | @defun cl-mapl function list &rest more-lists |
| 3729 | This function is like @code{maplist}, except that it throws away | 3326 | This function is like @code{cl-maplist}, except that it throws away |
| 3730 | the values returned by @var{function}. | 3327 | the values returned by @var{function}. |
| 3731 | @end defun | 3328 | @end defun |
| 3732 | 3329 | ||
| 3733 | @defun mapcan function seq &rest more-seqs | 3330 | @defun cl-mapcan function seq &rest more-seqs |
| 3734 | This function is like @code{mapcar*}, except that it concatenates | 3331 | This function is like @code{cl-mapcar}, except that it concatenates |
| 3735 | the return values (which must be lists) using @code{nconc}, | 3332 | the return values (which must be lists) using @code{nconc}, |
| 3736 | rather than simply collecting them into a list. | 3333 | rather than simply collecting them into a list. |
| 3737 | @end defun | 3334 | @end defun |
| 3738 | 3335 | ||
| 3739 | @defun mapcon function list &rest more-lists | 3336 | @defun cl-mapcon function list &rest more-lists |
| 3740 | This function is like @code{maplist}, except that it concatenates | 3337 | This function is like @code{cl-maplist}, except that it concatenates |
| 3741 | the return values using @code{nconc}. | 3338 | the return values using @code{nconc}. |
| 3742 | @end defun | 3339 | @end defun |
| 3743 | 3340 | ||
| 3744 | @defun some predicate seq &rest more-seqs | 3341 | @defun cl-some predicate seq &rest more-seqs |
| 3745 | This function calls @var{predicate} on each element of @var{seq} | 3342 | This function calls @var{predicate} on each element of @var{seq} |
| 3746 | in turn; if @var{predicate} returns a non-@code{nil} value, | 3343 | in turn; if @var{predicate} returns a non-@code{nil} value, |
| 3747 | @code{some} returns that value, otherwise it returns @code{nil}. | 3344 | @code{some} returns that value, otherwise it returns @code{nil}. |
| 3748 | Given several sequence arguments, it steps through the sequences | 3345 | Given several sequence arguments, it steps through the sequences |
| 3749 | in parallel until the shortest one runs out, just as in | 3346 | in parallel until the shortest one runs out, just as in |
| 3750 | @code{mapcar*}. You can rely on the left-to-right order in which | 3347 | @code{cl-mapcar}. You can rely on the left-to-right order in which |
| 3751 | the elements are visited, and on the fact that mapping stops | 3348 | the elements are visited, and on the fact that mapping stops |
| 3752 | immediately as soon as @var{predicate} returns non-@code{nil}. | 3349 | immediately as soon as @var{predicate} returns non-@code{nil}. |
| 3753 | @end defun | 3350 | @end defun |
| 3754 | 3351 | ||
| 3755 | @defun every predicate seq &rest more-seqs | 3352 | @defun cl-every predicate seq &rest more-seqs |
| 3756 | This function calls @var{predicate} on each element of the sequence(s) | 3353 | This function calls @var{predicate} on each element of the sequence(s) |
| 3757 | in turn; it returns @code{nil} as soon as @var{predicate} returns | 3354 | in turn; it returns @code{nil} as soon as @var{predicate} returns |
| 3758 | @code{nil} for any element, or @code{t} if the predicate was true | 3355 | @code{nil} for any element, or @code{t} if the predicate was true |
| 3759 | for all elements. | 3356 | for all elements. |
| 3760 | @end defun | 3357 | @end defun |
| 3761 | 3358 | ||
| 3762 | @defun notany predicate seq &rest more-seqs | 3359 | @defun cl-notany predicate seq &rest more-seqs |
| 3763 | This function calls @var{predicate} on each element of the sequence(s) | 3360 | This function calls @var{predicate} on each element of the sequence(s) |
| 3764 | in turn; it returns @code{nil} as soon as @var{predicate} returns | 3361 | in turn; it returns @code{nil} as soon as @var{predicate} returns |
| 3765 | a non-@code{nil} value for any element, or @code{t} if the predicate | 3362 | a non-@code{nil} value for any element, or @code{t} if the predicate |
| 3766 | was @code{nil} for all elements. | 3363 | was @code{nil} for all elements. |
| 3767 | @end defun | 3364 | @end defun |
| 3768 | 3365 | ||
| 3769 | @defun notevery predicate seq &rest more-seqs | 3366 | @defun cl-notevery predicate seq &rest more-seqs |
| 3770 | This function calls @var{predicate} on each element of the sequence(s) | 3367 | This function calls @var{predicate} on each element of the sequence(s) |
| 3771 | in turn; it returns a non-@code{nil} value as soon as @var{predicate} | 3368 | in turn; it returns a non-@code{nil} value as soon as @var{predicate} |
| 3772 | returns @code{nil} for any element, or @code{t} if the predicate was | 3369 | returns @code{nil} for any element, or @code{t} if the predicate was |
| 3773 | true for all elements. | 3370 | true for all elements. |
| 3774 | @end defun | 3371 | @end defun |
| 3775 | 3372 | ||
| 3776 | @defun reduce function seq @t{&key :from-end :start :end :initial-value :key} | 3373 | @defun cl-reduce function seq @t{&key :from-end :start :end :initial-value :key} |
| 3777 | This function combines the elements of @var{seq} using an associative | 3374 | This function combines the elements of @var{seq} using an associative |
| 3778 | binary operation. Suppose @var{function} is @code{*} and @var{seq} is | 3375 | binary operation. Suppose @var{function} is @code{*} and @var{seq} is |
| 3779 | the list @code{(2 3 4 5)}. The first two elements of the list are | 3376 | the list @code{(2 3 4 5)}. The first two elements of the list are |
| @@ -3781,16 +3378,16 @@ combined with @code{(* 2 3) = 6}; this is combined with the next | |||
| 3781 | element, @code{(* 6 4) = 24}, and that is combined with the final | 3378 | element, @code{(* 6 4) = 24}, and that is combined with the final |
| 3782 | element: @code{(* 24 5) = 120}. Note that the @code{*} function happens | 3379 | element: @code{(* 24 5) = 120}. Note that the @code{*} function happens |
| 3783 | to be self-reducing, so that @code{(* 2 3 4 5)} has the same effect as | 3380 | to be self-reducing, so that @code{(* 2 3 4 5)} has the same effect as |
| 3784 | an explicit call to @code{reduce}. | 3381 | an explicit call to @code{cl-reduce}. |
| 3785 | 3382 | ||
| 3786 | If @code{:from-end} is true, the reduction is right-associative instead | 3383 | If @code{:from-end} is true, the reduction is right-associative instead |
| 3787 | of left-associative: | 3384 | of left-associative: |
| 3788 | 3385 | ||
| 3789 | @example | 3386 | @example |
| 3790 | (reduce '- '(1 2 3 4)) | 3387 | (cl-reduce '- '(1 2 3 4)) |
| 3791 | @equiv{} (- (- (- 1 2) 3) 4) @result{} -8 | 3388 | @equiv{} (- (- (- 1 2) 3) 4) @result{} -8 |
| 3792 | (reduce '- '(1 2 3 4) :from-end t) | 3389 | (cl-reduce '- '(1 2 3 4) :from-end t) |
| 3793 | @equiv{} (- 1 (- 2 (- 3 4))) @result{} -2 | 3390 | @equiv{} (- 1 (- 2 (- 3 4))) @result{} -2 |
| 3794 | @end example | 3391 | @end example |
| 3795 | 3392 | ||
| 3796 | If @code{:key} is specified, it is a function of one argument which | 3393 | If @code{:key} is specified, it is a function of one argument which |
| @@ -3807,7 +3404,7 @@ If the sequence is empty (and there is no initial value), then | |||
| 3807 | @end defun | 3404 | @end defun |
| 3808 | 3405 | ||
| 3809 | All of these mapping operations can be expressed conveniently in | 3406 | All of these mapping operations can be expressed conveniently in |
| 3810 | terms of the @code{loop} macro. In compiled code, @code{loop} will | 3407 | terms of the @code{cl-loop} macro. In compiled code, @code{cl-loop} will |
| 3811 | be faster since it generates the loop as in-line code with no | 3408 | be faster since it generates the loop as in-line code with no |
| 3812 | function calls. | 3409 | function calls. |
| 3813 | 3410 | ||
| @@ -3818,7 +3415,7 @@ function calls. | |||
| 3818 | This section describes a number of Common Lisp functions for | 3415 | This section describes a number of Common Lisp functions for |
| 3819 | operating on sequences. | 3416 | operating on sequences. |
| 3820 | 3417 | ||
| 3821 | @defun subseq sequence start &optional end | 3418 | @defun cl-subseq sequence start &optional end |
| 3822 | This function returns a given subsequence of the argument | 3419 | This function returns a given subsequence of the argument |
| 3823 | @var{sequence}, which may be a list, string, or vector. | 3420 | @var{sequence}, which may be a list, string, or vector. |
| 3824 | The indices @var{start} and @var{end} must be in range, and | 3421 | The indices @var{start} and @var{end} must be in range, and |
| @@ -3830,30 +3427,30 @@ with @var{sequence}. | |||
| 3830 | As an extension to Common Lisp, @var{start} and/or @var{end} | 3427 | As an extension to Common Lisp, @var{start} and/or @var{end} |
| 3831 | may be negative, in which case they represent a distance back | 3428 | may be negative, in which case they represent a distance back |
| 3832 | from the end of the sequence. This is for compatibility with | 3429 | from the end of the sequence. This is for compatibility with |
| 3833 | Emacs's @code{substring} function. Note that @code{subseq} is | 3430 | Emacs's @code{substring} function. Note that @code{cl-subseq} is |
| 3834 | the @emph{only} sequence function that allows negative | 3431 | the @emph{only} sequence function that allows negative |
| 3835 | @var{start} and @var{end}. | 3432 | @var{start} and @var{end}. |
| 3836 | 3433 | ||
| 3837 | You can use @code{setf} on a @code{subseq} form to replace a | 3434 | You can use @code{setf} on a @code{cl-subseq} form to replace a |
| 3838 | specified range of elements with elements from another sequence. | 3435 | specified range of elements with elements from another sequence. |
| 3839 | The replacement is done as if by @code{replace}, described below. | 3436 | The replacement is done as if by @code{cl-replace}, described below. |
| 3840 | @end defun | 3437 | @end defun |
| 3841 | 3438 | ||
| 3842 | @defun concatenate result-type &rest seqs | 3439 | @defun cl-concatenate result-type &rest seqs |
| 3843 | This function concatenates the argument sequences together to | 3440 | This function concatenates the argument sequences together to |
| 3844 | form a result sequence of type @var{result-type}, one of the | 3441 | form a result sequence of type @var{result-type}, one of the |
| 3845 | symbols @code{vector}, @code{string}, or @code{list}. The | 3442 | symbols @code{vector}, @code{string}, or @code{list}. The |
| 3846 | arguments are always copied, even in cases such as | 3443 | arguments are always copied, even in cases such as |
| 3847 | @code{(concatenate 'list '(1 2 3))} where the result is | 3444 | @code{(cl-concatenate 'list '(1 2 3))} where the result is |
| 3848 | identical to an argument. | 3445 | identical to an argument. |
| 3849 | @end defun | 3446 | @end defun |
| 3850 | 3447 | ||
| 3851 | @defun fill seq item @t{&key :start :end} | 3448 | @defun cl-fill seq item @t{&key :start :end} |
| 3852 | This function fills the elements of the sequence (or the specified | 3449 | This function fills the elements of the sequence (or the specified |
| 3853 | part of the sequence) with the value @var{item}. | 3450 | part of the sequence) with the value @var{item}. |
| 3854 | @end defun | 3451 | @end defun |
| 3855 | 3452 | ||
| 3856 | @defun replace seq1 seq2 @t{&key :start1 :end1 :start2 :end2} | 3453 | @defun cl-replace seq1 seq2 @t{&key :start1 :end1 :start2 :end2} |
| 3857 | This function copies part of @var{seq2} into part of @var{seq1}. | 3454 | This function copies part of @var{seq2} into part of @var{seq1}. |
| 3858 | The sequence @var{seq1} is not stretched or resized; the amount | 3455 | The sequence @var{seq1} is not stretched or resized; the amount |
| 3859 | of data copied is simply the shorter of the source and destination | 3456 | of data copied is simply the shorter of the source and destination |
| @@ -3867,7 +3464,7 @@ start and end arguments specify overlapping regions, the effect | |||
| 3867 | is undefined. | 3464 | is undefined. |
| 3868 | @end defun | 3465 | @end defun |
| 3869 | 3466 | ||
| 3870 | @defun remove* item seq @t{&key :test :test-not :key :count :start :end :from-end} | 3467 | @defun cl-remove item seq @t{&key :test :test-not :key :count :start :end :from-end} |
| 3871 | This returns a copy of @var{seq} with all elements matching | 3468 | This returns a copy of @var{seq} with all elements matching |
| 3872 | @var{item} removed. The result may share storage with or be | 3469 | @var{item} removed. The result may share storage with or be |
| 3873 | @code{eq} to @var{seq} in some circumstances, but the original | 3470 | @code{eq} to @var{seq} in some circumstances, but the original |
| @@ -3884,25 +3481,25 @@ end of the sequence rather than the beginning (this matters only | |||
| 3884 | if @var{count} was also specified). | 3481 | if @var{count} was also specified). |
| 3885 | @end defun | 3482 | @end defun |
| 3886 | 3483 | ||
| 3887 | @defun delete* item seq @t{&key :test :test-not :key :count :start :end :from-end} | 3484 | @defun cl-delete item seq @t{&key :test :test-not :key :count :start :end :from-end} |
| 3888 | This deletes all elements of @var{seq} which match @var{item}. | 3485 | This deletes all elements of @var{seq} which match @var{item}. |
| 3889 | It is a destructive operation. Since Emacs Lisp does not support | 3486 | It is a destructive operation. Since Emacs Lisp does not support |
| 3890 | stretchable strings or vectors, this is the same as @code{remove*} | 3487 | stretchable strings or vectors, this is the same as @code{cl-remove} |
| 3891 | for those sequence types. On lists, @code{remove*} will copy the | 3488 | for those sequence types. On lists, @code{cl-remove} will copy the |
| 3892 | list if necessary to preserve the original list, whereas | 3489 | list if necessary to preserve the original list, whereas |
| 3893 | @code{delete*} will splice out parts of the argument list. | 3490 | @code{cl-delete} will splice out parts of the argument list. |
| 3894 | Compare @code{append} and @code{nconc}, which are analogous | 3491 | Compare @code{append} and @code{nconc}, which are analogous |
| 3895 | non-destructive and destructive list operations in Emacs Lisp. | 3492 | non-destructive and destructive list operations in Emacs Lisp. |
| 3896 | @end defun | 3493 | @end defun |
| 3897 | 3494 | ||
| 3898 | @findex remove-if | 3495 | @findex cl-remove-if |
| 3899 | @findex remove-if-not | 3496 | @findex cl-remove-if-not |
| 3900 | @findex delete-if | 3497 | @findex cl-delete-if |
| 3901 | @findex delete-if-not | 3498 | @findex cl-delete-if-not |
| 3902 | The predicate-oriented functions @code{remove-if}, @code{remove-if-not}, | 3499 | The predicate-oriented functions @code{cl-remove-if}, @code{cl-remove-if-not}, |
| 3903 | @code{delete-if}, and @code{delete-if-not} are defined similarly. | 3500 | @code{cl-delete-if}, and @code{cl-delete-if-not} are defined similarly. |
| 3904 | 3501 | ||
| 3905 | @defun remove-duplicates seq @t{&key :test :test-not :key :start :end :from-end} | 3502 | @defun cl-remove-duplicates seq @t{&key :test :test-not :key :start :end :from-end} |
| 3906 | This function returns a copy of @var{seq} with duplicate elements | 3503 | This function returns a copy of @var{seq} with duplicate elements |
| 3907 | removed. Specifically, if two elements from the sequence match | 3504 | removed. Specifically, if two elements from the sequence match |
| 3908 | according to the @code{:test}, @code{:test-not}, and @code{:key} | 3505 | according to the @code{:test}, @code{:test-not}, and @code{:key} |
| @@ -3912,40 +3509,41 @@ is true, the leftmost one is retained instead. If @code{:start} or | |||
| 3912 | examined or removed. | 3509 | examined or removed. |
| 3913 | @end defun | 3510 | @end defun |
| 3914 | 3511 | ||
| 3915 | @defun delete-duplicates seq @t{&key :test :test-not :key :start :end :from-end} | 3512 | @defun cl-delete-duplicates seq @t{&key :test :test-not :key :start :end :from-end} |
| 3916 | This function deletes duplicate elements from @var{seq}. It is | 3513 | This function deletes duplicate elements from @var{seq}. It is |
| 3917 | a destructive version of @code{remove-duplicates}. | 3514 | a destructive version of @code{cl-remove-duplicates}. |
| 3918 | @end defun | 3515 | @end defun |
| 3919 | 3516 | ||
| 3920 | @defun substitute new old seq @t{&key :test :test-not :key :count :start :end :from-end} | 3517 | @defun cl-substitute new old seq @t{&key :test :test-not :key :count :start :end :from-end} |
| 3921 | This function returns a copy of @var{seq}, with all elements | 3518 | This function returns a copy of @var{seq}, with all elements |
| 3922 | matching @var{old} replaced with @var{new}. The @code{:count}, | 3519 | matching @var{old} replaced with @var{new}. The @code{:count}, |
| 3923 | @code{:start}, @code{:end}, and @code{:from-end} arguments may be | 3520 | @code{:start}, @code{:end}, and @code{:from-end} arguments may be |
| 3924 | used to limit the number of substitutions made. | 3521 | used to limit the number of substitutions made. |
| 3925 | @end defun | 3522 | @end defun |
| 3926 | 3523 | ||
| 3927 | @defun nsubstitute new old seq @t{&key :test :test-not :key :count :start :end :from-end} | 3524 | @defun cl-nsubstitute new old seq @t{&key :test :test-not :key :count :start :end :from-end} |
| 3928 | This is a destructive version of @code{substitute}; it performs | 3525 | This is a destructive version of @code{cl-substitute}; it performs |
| 3929 | the substitution using @code{setcar} or @code{aset} rather than | 3526 | the substitution using @code{setcar} or @code{aset} rather than |
| 3930 | by returning a changed copy of the sequence. | 3527 | by returning a changed copy of the sequence. |
| 3931 | @end defun | 3528 | @end defun |
| 3932 | 3529 | ||
| 3933 | @findex substitute-if | 3530 | @findex cl-substitute-if |
| 3934 | @findex substitute-if-not | 3531 | @findex cl-substitute-if-not |
| 3935 | @findex nsubstitute-if | 3532 | @findex cl-nsubstitute-if |
| 3936 | @findex nsubstitute-if-not | 3533 | @findex cl-nsubstitute-if-not |
| 3937 | The @code{substitute-if}, @code{substitute-if-not}, @code{nsubstitute-if}, | 3534 | The functions @code{cl-substitute-if}, @code{cl-substitute-if-not}, |
| 3938 | and @code{nsubstitute-if-not} functions are defined similarly. For | 3535 | @code{cl-nsubstitute-if}, and @code{cl-nsubstitute-if-not} are defined |
| 3939 | these, a @var{predicate} is given in place of the @var{old} argument. | 3536 | similarly. For these, a @var{predicate} is given in place of the |
| 3537 | @var{old} argument. | ||
| 3940 | 3538 | ||
| 3941 | @node Searching Sequences | 3539 | @node Searching Sequences |
| 3942 | @section Searching Sequences | 3540 | @section Searching Sequences |
| 3943 | 3541 | ||
| 3944 | @noindent | 3542 | @noindent |
| 3945 | These functions search for elements or subsequences in a sequence. | 3543 | These functions search for elements or subsequences in a sequence. |
| 3946 | (See also @code{member*} and @code{assoc*}; @pxref{Lists}.) | 3544 | (See also @code{cl-member} and @code{cl-assoc}; @pxref{Lists}.) |
| 3947 | 3545 | ||
| 3948 | @defun find item seq @t{&key :test :test-not :key :start :end :from-end} | 3546 | @defun cl-find item seq @t{&key :test :test-not :key :start :end :from-end} |
| 3949 | This function searches @var{seq} for an element matching @var{item}. | 3547 | This function searches @var{seq} for an element matching @var{item}. |
| 3950 | If it finds a match, it returns the matching element. Otherwise, | 3548 | If it finds a match, it returns the matching element. Otherwise, |
| 3951 | it returns @code{nil}. It returns the leftmost match, unless | 3549 | it returns @code{nil}. It returns the leftmost match, unless |
| @@ -3954,30 +3552,30 @@ match. The @code{:start} and @code{:end} arguments may be used to | |||
| 3954 | limit the range of elements that are searched. | 3552 | limit the range of elements that are searched. |
| 3955 | @end defun | 3553 | @end defun |
| 3956 | 3554 | ||
| 3957 | @defun position item seq @t{&key :test :test-not :key :start :end :from-end} | 3555 | @defun cl-position item seq @t{&key :test :test-not :key :start :end :from-end} |
| 3958 | This function is like @code{find}, except that it returns the | 3556 | This function is like @code{cl-find}, except that it returns the |
| 3959 | integer position in the sequence of the matching item rather than | 3557 | integer position in the sequence of the matching item rather than |
| 3960 | the item itself. The position is relative to the start of the | 3558 | the item itself. The position is relative to the start of the |
| 3961 | sequence as a whole, even if @code{:start} is non-zero. The function | 3559 | sequence as a whole, even if @code{:start} is non-zero. The function |
| 3962 | returns @code{nil} if no matching element was found. | 3560 | returns @code{nil} if no matching element was found. |
| 3963 | @end defun | 3561 | @end defun |
| 3964 | 3562 | ||
| 3965 | @defun count item seq @t{&key :test :test-not :key :start :end} | 3563 | @defun cl-count item seq @t{&key :test :test-not :key :start :end} |
| 3966 | This function returns the number of elements of @var{seq} which | 3564 | This function returns the number of elements of @var{seq} which |
| 3967 | match @var{item}. The result is always a nonnegative integer. | 3565 | match @var{item}. The result is always a nonnegative integer. |
| 3968 | @end defun | 3566 | @end defun |
| 3969 | 3567 | ||
| 3970 | @findex find-if | 3568 | @findex cl-find-if |
| 3971 | @findex find-if-not | 3569 | @findex cl-find-if-not |
| 3972 | @findex position-if | 3570 | @findex cl-position-if |
| 3973 | @findex position-if-not | 3571 | @findex cl-position-if-not |
| 3974 | @findex count-if | 3572 | @findex cl-count-if |
| 3975 | @findex count-if-not | 3573 | @findex cl-count-if-not |
| 3976 | The @code{find-if}, @code{find-if-not}, @code{position-if}, | 3574 | The @code{cl-find-if}, @code{cl-find-if-not}, @code{cl-position-if}, |
| 3977 | @code{position-if-not}, @code{count-if}, and @code{count-if-not} | 3575 | @code{cl-position-if-not}, @code{cl-count-if}, and @code{cl-count-if-not} |
| 3978 | functions are defined similarly. | 3576 | functions are defined similarly. |
| 3979 | 3577 | ||
| 3980 | @defun mismatch seq1 seq2 @t{&key :test :test-not :key :start1 :end1 :start2 :end2 :from-end} | 3578 | @defun cl-mismatch seq1 seq2 @t{&key :test :test-not :key :start1 :end1 :start2 :end2 :from-end} |
| 3981 | This function compares the specified parts of @var{seq1} and | 3579 | This function compares the specified parts of @var{seq1} and |
| 3982 | @var{seq2}. If they are the same length and the corresponding | 3580 | @var{seq2}. If they are the same length and the corresponding |
| 3983 | elements match (according to @code{:test}, @code{:test-not}, | 3581 | elements match (according to @code{:test}, @code{:test-not}, |
| @@ -3992,11 +3590,11 @@ to left starting at @code{(1- @var{end1})} and @code{(1- @var{end2})}. | |||
| 3992 | If the sequences differ, then one plus the index of the rightmost | 3590 | If the sequences differ, then one plus the index of the rightmost |
| 3993 | difference (relative to @var{seq1}) is returned. | 3591 | difference (relative to @var{seq1}) is returned. |
| 3994 | 3592 | ||
| 3995 | An interesting example is @code{(mismatch str1 str2 :key 'upcase)}, | 3593 | An interesting example is @code{(cl-mismatch str1 str2 :key 'upcase)}, |
| 3996 | which compares two strings case-insensitively. | 3594 | which compares two strings case-insensitively. |
| 3997 | @end defun | 3595 | @end defun |
| 3998 | 3596 | ||
| 3999 | @defun search seq1 seq2 @t{&key :test :test-not :key :from-end :start1 :end1 :start2 :end2} | 3597 | @defun cl-search seq1 seq2 @t{&key :test :test-not :key :from-end :start1 :end1 :start2 :end2} |
| 4000 | This function searches @var{seq2} for a subsequence that matches | 3598 | This function searches @var{seq2} for a subsequence that matches |
| 4001 | @var{seq1} (or part of it specified by @code{:start1} and | 3599 | @var{seq1} (or part of it specified by @code{:start1} and |
| 4002 | @code{:end1}.) Only matches which fall entirely within the region | 3600 | @code{:end1}.) Only matches which fall entirely within the region |
| @@ -4010,7 +3608,7 @@ function finds the @emph{rightmost} matching subsequence. | |||
| 4010 | @node Sorting Sequences | 3608 | @node Sorting Sequences |
| 4011 | @section Sorting Sequences | 3609 | @section Sorting Sequences |
| 4012 | 3610 | ||
| 4013 | @defun sort* seq predicate @t{&key :key} | 3611 | @defun clsort seq predicate @t{&key :key} |
| 4014 | This function sorts @var{seq} into increasing order as determined | 3612 | This function sorts @var{seq} into increasing order as determined |
| 4015 | by using @var{predicate} to compare pairs of elements. @var{predicate} | 3613 | by using @var{predicate} to compare pairs of elements. @var{predicate} |
| 4016 | should return true (non-@code{nil}) if and only if its first argument | 3614 | should return true (non-@code{nil}) if and only if its first argument |
| @@ -4025,7 +3623,7 @@ accepts a @code{:key} argument which is used to preprocess data | |||
| 4025 | fed to the @var{predicate} function. For example, | 3623 | fed to the @var{predicate} function. For example, |
| 4026 | 3624 | ||
| 4027 | @example | 3625 | @example |
| 4028 | (setq data (sort* data 'string-lessp :key 'downcase)) | 3626 | (setq data (cl-sort data 'string-lessp :key 'downcase)) |
| 4029 | @end example | 3627 | @end example |
| 4030 | 3628 | ||
| 4031 | @noindent | 3629 | @noindent |
| @@ -4035,25 +3633,25 @@ would be useful for sorting association lists. It should only be a | |||
| 4035 | simple accessor though, it's used heavily in the current | 3633 | simple accessor though, it's used heavily in the current |
| 4036 | implementation. | 3634 | implementation. |
| 4037 | 3635 | ||
| 4038 | The @code{sort*} function is destructive; it sorts lists by actually | 3636 | The @code{cl-sort} function is destructive; it sorts lists by actually |
| 4039 | rearranging the @code{cdr} pointers in suitable fashion. | 3637 | rearranging the @code{cdr} pointers in suitable fashion. |
| 4040 | @end defun | 3638 | @end defun |
| 4041 | 3639 | ||
| 4042 | @defun stable-sort seq predicate @t{&key :key} | 3640 | @defun cl-stable-sort seq predicate @t{&key :key} |
| 4043 | This function sorts @var{seq} @dfn{stably}, meaning two elements | 3641 | This function sorts @var{seq} @dfn{stably}, meaning two elements |
| 4044 | which are equal in terms of @var{predicate} are guaranteed not to | 3642 | which are equal in terms of @var{predicate} are guaranteed not to |
| 4045 | be rearranged out of their original order by the sort. | 3643 | be rearranged out of their original order by the sort. |
| 4046 | 3644 | ||
| 4047 | In practice, @code{sort*} and @code{stable-sort} are equivalent | 3645 | In practice, @code{cl-sort} and @code{cl-stable-sort} are equivalent |
| 4048 | in Emacs Lisp because the underlying @code{sort} function is | 3646 | in Emacs Lisp because the underlying @code{sort} function is |
| 4049 | stable by default. However, this package reserves the right to | 3647 | stable by default. However, this package reserves the right to |
| 4050 | use non-stable methods for @code{sort*} in the future. | 3648 | use non-stable methods for @code{cl-sort} in the future. |
| 4051 | @end defun | 3649 | @end defun |
| 4052 | 3650 | ||
| 4053 | @defun merge type seq1 seq2 predicate @t{&key :key} | 3651 | @defun cl-merge type seq1 seq2 predicate @t{&key :key} |
| 4054 | This function merges two sequences @var{seq1} and @var{seq2} by | 3652 | This function merges two sequences @var{seq1} and @var{seq2} by |
| 4055 | interleaving their elements. The result sequence, of type @var{type} | 3653 | interleaving their elements. The result sequence, of type @var{type} |
| 4056 | (in the sense of @code{concatenate}), has length equal to the sum | 3654 | (in the sense of @code{cl-concatenate}), has length equal to the sum |
| 4057 | of the lengths of the two input sequences. The sequences may be | 3655 | of the lengths of the two input sequences. The sequences may be |
| 4058 | modified destructively. Order of elements within @var{seq1} and | 3656 | modified destructively. Order of elements within @var{seq1} and |
| 4059 | @var{seq2} is preserved in the interleaving; elements of the two | 3657 | @var{seq2} is preserved in the interleaving; elements of the two |
| @@ -4073,10 +3671,10 @@ a merged sequence which is (stably) sorted according to | |||
| 4073 | The functions described here operate on lists. | 3671 | The functions described here operate on lists. |
| 4074 | 3672 | ||
| 4075 | @menu | 3673 | @menu |
| 4076 | * List Functions:: @code{caddr}, @code{first}, @code{list*}, etc. | 3674 | * List Functions:: @code{cl-caddr}, @code{cl-first}, @code{cl-list*}, etc. |
| 4077 | * Substitution of Expressions:: @code{subst}, @code{sublis}, etc. | 3675 | * Substitution of Expressions:: @code{cl-subst}, @code{cl-sublis}, etc. |
| 4078 | * Lists as Sets:: @code{member*}, @code{adjoin}, @code{union}, etc. | 3676 | * Lists as Sets:: @code{cl-member}, @code{cl-adjoin}, @code{cl-union}, etc. |
| 4079 | * Association Lists:: @code{assoc*}, @code{rassoc*}, @code{acons}, @code{pairlis}. | 3677 | * Association Lists:: @code{cl-assoc}, @code{cl-rassoc}, @code{cl-acons}, @code{cl-pairlis}. |
| 4080 | @end menu | 3678 | @end menu |
| 4081 | 3679 | ||
| 4082 | @node List Functions | 3680 | @node List Functions |
| @@ -4086,7 +3684,7 @@ The functions described here operate on lists. | |||
| 4086 | This section describes a number of simple operations on lists, | 3684 | This section describes a number of simple operations on lists, |
| 4087 | i.e., chains of cons cells. | 3685 | i.e., chains of cons cells. |
| 4088 | 3686 | ||
| 4089 | @defun caddr x | 3687 | @defun cl-caddr x |
| 4090 | This function is equivalent to @code{(car (cdr (cdr @var{x})))}. | 3688 | This function is equivalent to @code{(car (cdr (cdr @var{x})))}. |
| 4091 | Likewise, this package defines all 28 @code{c@var{xxx}r} functions | 3689 | Likewise, this package defines all 28 @code{c@var{xxx}r} functions |
| 4092 | where @var{xxx} is up to four @samp{a}s and/or @samp{d}s. | 3690 | where @var{xxx} is up to four @samp{a}s and/or @samp{d}s. |
| @@ -4094,24 +3692,24 @@ All of these functions are @code{setf}-able, and calls to them | |||
| 4094 | are expanded inline by the byte-compiler for maximum efficiency. | 3692 | are expanded inline by the byte-compiler for maximum efficiency. |
| 4095 | @end defun | 3693 | @end defun |
| 4096 | 3694 | ||
| 4097 | @defun first x | 3695 | @defun cl-first x |
| 4098 | This function is a synonym for @code{(car @var{x})}. Likewise, | 3696 | This function is a synonym for @code{(car @var{x})}. Likewise, |
| 4099 | the functions @code{second}, @code{third}, @dots{}, through | 3697 | the functions @code{cl-second}, @code{cl-third}, @dots{}, through |
| 4100 | @code{tenth} return the given element of the list @var{x}. | 3698 | @code{cl-tenth} return the given element of the list @var{x}. |
| 4101 | @end defun | 3699 | @end defun |
| 4102 | 3700 | ||
| 4103 | @defun rest x | 3701 | @defun cl-rest x |
| 4104 | This function is a synonym for @code{(cdr @var{x})}. | 3702 | This function is a synonym for @code{(cdr @var{x})}. |
| 4105 | @end defun | 3703 | @end defun |
| 4106 | 3704 | ||
| 4107 | @defun endp x | 3705 | @defun cl-endp x |
| 4108 | Common Lisp defines this function to act like @code{null}, but | 3706 | Common Lisp defines this function to act like @code{null}, but |
| 4109 | signaling an error if @code{x} is neither a @code{nil} nor a | 3707 | signaling an error if @code{x} is neither a @code{nil} nor a |
| 4110 | cons cell. This package simply defines @code{endp} as a synonym | 3708 | cons cell. This package simply defines @code{cl-endp} as a synonym |
| 4111 | for @code{null}. | 3709 | for @code{null}. |
| 4112 | @end defun | 3710 | @end defun |
| 4113 | 3711 | ||
| 4114 | @defun list-length x | 3712 | @defun cl-list-length x |
| 4115 | This function returns the length of list @var{x}, exactly like | 3713 | This function returns the length of list @var{x}, exactly like |
| 4116 | @code{(length @var{x})}, except that if @var{x} is a circular | 3714 | @code{(length @var{x})}, except that if @var{x} is a circular |
| 4117 | list (where the cdr-chain forms a loop rather than terminating | 3715 | list (where the cdr-chain forms a loop rather than terminating |
| @@ -4119,38 +3717,35 @@ with @code{nil}), this function returns @code{nil}. (The regular | |||
| 4119 | @code{length} function would get stuck if given a circular list.) | 3717 | @code{length} function would get stuck if given a circular list.) |
| 4120 | @end defun | 3718 | @end defun |
| 4121 | 3719 | ||
| 4122 | @defun list* arg &rest others | 3720 | @defun cl-list* arg &rest others |
| 4123 | This function constructs a list of its arguments. The final | 3721 | This function constructs a list of its arguments. The final |
| 4124 | argument becomes the @code{cdr} of the last cell constructed. | 3722 | argument becomes the @code{cdr} of the last cell constructed. |
| 4125 | Thus, @code{(list* @var{a} @var{b} @var{c})} is equivalent to | 3723 | Thus, @code{(cl-list* @var{a} @var{b} @var{c})} is equivalent to |
| 4126 | @code{(cons @var{a} (cons @var{b} @var{c}))}, and | 3724 | @code{(cons @var{a} (cons @var{b} @var{c}))}, and |
| 4127 | @code{(list* @var{a} @var{b} nil)} is equivalent to | 3725 | @code{(cl-list* @var{a} @var{b} nil)} is equivalent to |
| 4128 | @code{(list @var{a} @var{b})}. | 3726 | @code{(list @var{a} @var{b})}. |
| 4129 | |||
| 4130 | (Note that this function really is called @code{list*} in Common | ||
| 4131 | Lisp; it is not a name invented for this package like @code{member*} | ||
| 4132 | or @code{defun*}.) | ||
| 4133 | @end defun | 3727 | @end defun |
| 4134 | 3728 | ||
| 4135 | @defun ldiff list sublist | 3729 | @defun cl-ldiff list sublist |
| 4136 | If @var{sublist} is a sublist of @var{list}, i.e., is @code{eq} to | 3730 | If @var{sublist} is a sublist of @var{list}, i.e., is @code{eq} to |
| 4137 | one of the cons cells of @var{list}, then this function returns | 3731 | one of the cons cells of @var{list}, then this function returns |
| 4138 | a copy of the part of @var{list} up to but not including | 3732 | a copy of the part of @var{list} up to but not including |
| 4139 | @var{sublist}. For example, @code{(ldiff x (cddr x))} returns | 3733 | @var{sublist}. For example, @code{(cl-ldiff x (cddr x))} returns |
| 4140 | the first two elements of the list @code{x}. The result is a | 3734 | the first two elements of the list @code{x}. The result is a |
| 4141 | copy; the original @var{list} is not modified. If @var{sublist} | 3735 | copy; the original @var{list} is not modified. If @var{sublist} |
| 4142 | is not a sublist of @var{list}, a copy of the entire @var{list} | 3736 | is not a sublist of @var{list}, a copy of the entire @var{list} |
| 4143 | is returned. | 3737 | is returned. |
| 4144 | @end defun | 3738 | @end defun |
| 4145 | 3739 | ||
| 4146 | @defun copy-list list | 3740 | @defun cl-copy-list list |
| 4147 | This function returns a copy of the list @var{list}. It copies | 3741 | This function returns a copy of the list @var{list}. It copies |
| 4148 | dotted lists like @code{(1 2 . 3)} correctly. | 3742 | dotted lists like @code{(1 2 . 3)} correctly. |
| 4149 | @end defun | 3743 | @end defun |
| 4150 | 3744 | ||
| 4151 | @defun copy-tree x &optional vecp | 3745 | @defun copy-tree x &optional vecp |
| 4152 | This function returns a copy of the tree of cons cells @var{x}. | 3746 | This function returns a copy of the tree of cons cells @var{x}. |
| 4153 | Unlike @code{copy-sequence} (and its alias @code{copy-list}), | 3747 | @c FIXME? cl-copy-list is not an alias of copy-sequence. |
| 3748 | Unlike @code{copy-sequence} (and its alias @code{cl-copy-list}), | ||
| 4154 | which copies only along the @code{cdr} direction, this function | 3749 | which copies only along the @code{cdr} direction, this function |
| 4155 | copies (recursively) along both the @code{car} and the @code{cdr} | 3750 | copies (recursively) along both the @code{car} and the @code{cdr} |
| 4156 | directions. If @var{x} is not a cons cell, the function simply | 3751 | directions. If @var{x} is not a cons cell, the function simply |
| @@ -4159,7 +3754,7 @@ is true, this function copies vectors (recursively) as well as | |||
| 4159 | cons cells. | 3754 | cons cells. |
| 4160 | @end defun | 3755 | @end defun |
| 4161 | 3756 | ||
| 4162 | @defun tree-equal x y @t{&key :test :test-not :key} | 3757 | @defun cl-tree-equal x y @t{&key :test :test-not :key} |
| 4163 | This function compares two trees of cons cells. If @var{x} and | 3758 | This function compares two trees of cons cells. If @var{x} and |
| 4164 | @var{y} are both cons cells, their @code{car}s and @code{cdr}s are | 3759 | @var{y} are both cons cells, their @code{car}s and @code{cdr}s are |
| 4165 | compared recursively. If neither @var{x} nor @var{y} is a cons | 3760 | compared recursively. If neither @var{x} nor @var{y} is a cons |
| @@ -4168,19 +3763,15 @@ specified test. The @code{:key} function, if specified, is | |||
| 4168 | applied to the elements of both trees. @xref{Sequences}. | 3763 | applied to the elements of both trees. @xref{Sequences}. |
| 4169 | @end defun | 3764 | @end defun |
| 4170 | 3765 | ||
| 4171 | @iftex | ||
| 4172 | @secno=3 | ||
| 4173 | @end iftex | ||
| 4174 | |||
| 4175 | @node Substitution of Expressions | 3766 | @node Substitution of Expressions |
| 4176 | @section Substitution of Expressions | 3767 | @section Substitution of Expressions |
| 4177 | 3768 | ||
| 4178 | @noindent | 3769 | @noindent |
| 4179 | These functions substitute elements throughout a tree of cons | 3770 | These functions substitute elements throughout a tree of cons |
| 4180 | cells. (@xref{Sequence Functions}, for the @code{substitute} | 3771 | cells. (@xref{Sequence Functions}, for the @code{cl-substitute} |
| 4181 | function, which works on just the top-level elements of a list.) | 3772 | function, which works on just the top-level elements of a list.) |
| 4182 | 3773 | ||
| 4183 | @defun subst new old tree @t{&key :test :test-not :key} | 3774 | @defun cl-subst new old tree @t{&key :test :test-not :key} |
| 4184 | This function substitutes occurrences of @var{old} with @var{new} | 3775 | This function substitutes occurrences of @var{old} with @var{new} |
| 4185 | in @var{tree}, a tree of cons cells. It returns a substituted | 3776 | in @var{tree}, a tree of cons cells. It returns a substituted |
| 4186 | tree, which will be a copy except that it may share storage with | 3777 | tree, which will be a copy except that it may share storage with |
| @@ -4195,21 +3786,21 @@ The @code{:key} function is applied to the elements of the tree | |||
| 4195 | but not to @var{old}. | 3786 | but not to @var{old}. |
| 4196 | @end defun | 3787 | @end defun |
| 4197 | 3788 | ||
| 4198 | @defun nsubst new old tree @t{&key :test :test-not :key} | 3789 | @defun cl-nsubst new old tree @t{&key :test :test-not :key} |
| 4199 | This function is like @code{subst}, except that it works by | 3790 | This function is like @code{cl-subst}, except that it works by |
| 4200 | destructive modification (by @code{setcar} or @code{setcdr}) | 3791 | destructive modification (by @code{setcar} or @code{setcdr}) |
| 4201 | rather than copying. | 3792 | rather than copying. |
| 4202 | @end defun | 3793 | @end defun |
| 4203 | 3794 | ||
| 4204 | @findex subst-if | 3795 | @findex cl-subst-if |
| 4205 | @findex subst-if-not | 3796 | @findex cl-subst-if-not |
| 4206 | @findex nsubst-if | 3797 | @findex cl-nsubst-if |
| 4207 | @findex nsubst-if-not | 3798 | @findex cl-nsubst-if-not |
| 4208 | The @code{subst-if}, @code{subst-if-not}, @code{nsubst-if}, and | 3799 | The @code{cl-subst-if}, @code{cl-subst-if-not}, @code{cl-nsubst-if}, and |
| 4209 | @code{nsubst-if-not} functions are defined similarly. | 3800 | @code{cl-nsubst-if-not} functions are defined similarly. |
| 4210 | 3801 | ||
| 4211 | @defun sublis alist tree @t{&key :test :test-not :key} | 3802 | @defun cl-sublis alist tree @t{&key :test :test-not :key} |
| 4212 | This function is like @code{subst}, except that it takes an | 3803 | This function is like @code{cl-subst}, except that it takes an |
| 4213 | association list @var{alist} of @var{old}-@var{new} pairs. | 3804 | association list @var{alist} of @var{old}-@var{new} pairs. |
| 4214 | Each element of the tree (after applying the @code{:key} | 3805 | Each element of the tree (after applying the @code{:key} |
| 4215 | function, if any), is compared with the @code{car}s of | 3806 | function, if any), is compared with the @code{car}s of |
| @@ -4217,8 +3808,8 @@ function, if any), is compared with the @code{car}s of | |||
| 4217 | @code{cdr}. | 3808 | @code{cdr}. |
| 4218 | @end defun | 3809 | @end defun |
| 4219 | 3810 | ||
| 4220 | @defun nsublis alist tree @t{&key :test :test-not :key} | 3811 | @defun cl-nsublis alist tree @t{&key :test :test-not :key} |
| 4221 | This is a destructive version of @code{sublis}. | 3812 | This is a destructive version of @code{cl-sublis}. |
| 4222 | @end defun | 3813 | @end defun |
| 4223 | 3814 | ||
| 4224 | @node Lists as Sets | 3815 | @node Lists as Sets |
| @@ -4228,7 +3819,7 @@ This is a destructive version of @code{sublis}. | |||
| 4228 | These functions perform operations on lists which represent sets | 3819 | These functions perform operations on lists which represent sets |
| 4229 | of elements. | 3820 | of elements. |
| 4230 | 3821 | ||
| 4231 | @defun member* item list @t{&key :test :test-not :key} | 3822 | @defun cl-member item list @t{&key :test :test-not :key} |
| 4232 | This function searches @var{list} for an element matching @var{item}. | 3823 | This function searches @var{list} for an element matching @var{item}. |
| 4233 | If a match is found, it returns the cons cell whose @code{car} was | 3824 | If a match is found, it returns the cons cell whose @code{car} was |
| 4234 | the matching element. Otherwise, it returns @code{nil}. Elements | 3825 | the matching element. Otherwise, it returns @code{nil}. Elements |
| @@ -4236,34 +3827,33 @@ are compared by @code{eql} by default; you can use the @code{:test}, | |||
| 4236 | @code{:test-not}, and @code{:key} arguments to modify this behavior. | 3827 | @code{:test-not}, and @code{:key} arguments to modify this behavior. |
| 4237 | @xref{Sequences}. | 3828 | @xref{Sequences}. |
| 4238 | 3829 | ||
| 4239 | Note that this function's name is suffixed by @samp{*} to avoid | 3830 | The standard Emacs lisp function @code{member} uses @code{equal} for |
| 4240 | the incompatible @code{member} function defined in Emacs. | 3831 | comparisons; it is equivalent to @code{(cl-member @var{item} @var{list} |
| 4241 | (That function uses @code{equal} for comparisons; it is equivalent | 3832 | :test 'equal)}. |
| 4242 | to @code{(member* @var{item} @var{list} :test 'equal)}.) | ||
| 4243 | @end defun | 3833 | @end defun |
| 4244 | 3834 | ||
| 4245 | @findex member-if | 3835 | @findex cl-member-if |
| 4246 | @findex member-if-not | 3836 | @findex cl-member-if-not |
| 4247 | The @code{member-if} and @code{member-if-not} functions | 3837 | The @code{cl-member-if} and @code{cl-member-if-not} functions |
| 4248 | analogously search for elements which satisfy a given predicate. | 3838 | analogously search for elements which satisfy a given predicate. |
| 4249 | 3839 | ||
| 4250 | @defun tailp sublist list | 3840 | @defun cl-tailp sublist list |
| 4251 | This function returns @code{t} if @var{sublist} is a sublist of | 3841 | This function returns @code{t} if @var{sublist} is a sublist of |
| 4252 | @var{list}, i.e., if @var{sublist} is @code{eql} to @var{list} or to | 3842 | @var{list}, i.e., if @var{sublist} is @code{eql} to @var{list} or to |
| 4253 | any of its @code{cdr}s. | 3843 | any of its @code{cdr}s. |
| 4254 | @end defun | 3844 | @end defun |
| 4255 | 3845 | ||
| 4256 | @defun adjoin item list @t{&key :test :test-not :key} | 3846 | @defun cl-adjoin item list @t{&key :test :test-not :key} |
| 4257 | This function conses @var{item} onto the front of @var{list}, | 3847 | This function conses @var{item} onto the front of @var{list}, |
| 4258 | like @code{(cons @var{item} @var{list})}, but only if @var{item} | 3848 | like @code{(cons @var{item} @var{list})}, but only if @var{item} |
| 4259 | is not already present on the list (as determined by @code{member*}). | 3849 | is not already present on the list (as determined by @code{cl-member}). |
| 4260 | If a @code{:key} argument is specified, it is applied to | 3850 | If a @code{:key} argument is specified, it is applied to |
| 4261 | @var{item} as well as to the elements of @var{list} during | 3851 | @var{item} as well as to the elements of @var{list} during |
| 4262 | the search, on the reasoning that @var{item} is ``about'' to | 3852 | the search, on the reasoning that @var{item} is ``about'' to |
| 4263 | become part of the list. | 3853 | become part of the list. |
| 4264 | @end defun | 3854 | @end defun |
| 4265 | 3855 | ||
| 4266 | @defun union list1 list2 @t{&key :test :test-not :key} | 3856 | @defun cl-union list1 list2 @t{&key :test :test-not :key} |
| 4267 | This function combines two lists which represent sets of items, | 3857 | This function combines two lists which represent sets of items, |
| 4268 | returning a list that represents the union of those two sets. | 3858 | returning a list that represents the union of those two sets. |
| 4269 | The result list will contain all items which appear in @var{list1} | 3859 | The result list will contain all items which appear in @var{list1} |
| @@ -4275,46 +3865,46 @@ result list. The order of elements in the result list is also | |||
| 4275 | undefined. | 3865 | undefined. |
| 4276 | @end defun | 3866 | @end defun |
| 4277 | 3867 | ||
| 4278 | @defun nunion list1 list2 @t{&key :test :test-not :key} | 3868 | @defun cl-nunion list1 list2 @t{&key :test :test-not :key} |
| 4279 | This is a destructive version of @code{union}; rather than copying, | 3869 | This is a destructive version of @code{cl-union}; rather than copying, |
| 4280 | it tries to reuse the storage of the argument lists if possible. | 3870 | it tries to reuse the storage of the argument lists if possible. |
| 4281 | @end defun | 3871 | @end defun |
| 4282 | 3872 | ||
| 4283 | @defun intersection list1 list2 @t{&key :test :test-not :key} | 3873 | @defun cl-intersection list1 list2 @t{&key :test :test-not :key} |
| 4284 | This function computes the intersection of the sets represented | 3874 | This function computes the intersection of the sets represented |
| 4285 | by @var{list1} and @var{list2}. It returns the list of items | 3875 | by @var{list1} and @var{list2}. It returns the list of items |
| 4286 | which appear in both @var{list1} and @var{list2}. | 3876 | which appear in both @var{list1} and @var{list2}. |
| 4287 | @end defun | 3877 | @end defun |
| 4288 | 3878 | ||
| 4289 | @defun nintersection list1 list2 @t{&key :test :test-not :key} | 3879 | @defun cl-nintersection list1 list2 @t{&key :test :test-not :key} |
| 4290 | This is a destructive version of @code{intersection}. It | 3880 | This is a destructive version of @code{cl-intersection}. It |
| 4291 | tries to reuse storage of @var{list1} rather than copying. | 3881 | tries to reuse storage of @var{list1} rather than copying. |
| 4292 | It does @emph{not} reuse the storage of @var{list2}. | 3882 | It does @emph{not} reuse the storage of @var{list2}. |
| 4293 | @end defun | 3883 | @end defun |
| 4294 | 3884 | ||
| 4295 | @defun set-difference list1 list2 @t{&key :test :test-not :key} | 3885 | @defun cl-set-difference list1 list2 @t{&key :test :test-not :key} |
| 4296 | This function computes the ``set difference'' of @var{list1} | 3886 | This function computes the ``set difference'' of @var{list1} |
| 4297 | and @var{list2}, i.e., the set of elements that appear in | 3887 | and @var{list2}, i.e., the set of elements that appear in |
| 4298 | @var{list1} but @emph{not} in @var{list2}. | 3888 | @var{list1} but @emph{not} in @var{list2}. |
| 4299 | @end defun | 3889 | @end defun |
| 4300 | 3890 | ||
| 4301 | @defun nset-difference list1 list2 @t{&key :test :test-not :key} | 3891 | @defun cl-nset-difference list1 list2 @t{&key :test :test-not :key} |
| 4302 | This is a destructive @code{set-difference}, which will try | 3892 | This is a destructive @code{cl-set-difference}, which will try |
| 4303 | to reuse @var{list1} if possible. | 3893 | to reuse @var{list1} if possible. |
| 4304 | @end defun | 3894 | @end defun |
| 4305 | 3895 | ||
| 4306 | @defun set-exclusive-or list1 list2 @t{&key :test :test-not :key} | 3896 | @defun cl-set-exclusive-or list1 list2 @t{&key :test :test-not :key} |
| 4307 | This function computes the ``set exclusive or'' of @var{list1} | 3897 | This function computes the ``set exclusive or'' of @var{list1} |
| 4308 | and @var{list2}, i.e., the set of elements that appear in | 3898 | and @var{list2}, i.e., the set of elements that appear in |
| 4309 | exactly one of @var{list1} and @var{list2}. | 3899 | exactly one of @var{list1} and @var{list2}. |
| 4310 | @end defun | 3900 | @end defun |
| 4311 | 3901 | ||
| 4312 | @defun nset-exclusive-or list1 list2 @t{&key :test :test-not :key} | 3902 | @defun cl-nset-exclusive-or list1 list2 @t{&key :test :test-not :key} |
| 4313 | This is a destructive @code{set-exclusive-or}, which will try | 3903 | This is a destructive @code{cl-set-exclusive-or}, which will try |
| 4314 | to reuse @var{list1} and @var{list2} if possible. | 3904 | to reuse @var{list1} and @var{list2} if possible. |
| 4315 | @end defun | 3905 | @end defun |
| 4316 | 3906 | ||
| 4317 | @defun subsetp list1 list2 @t{&key :test :test-not :key} | 3907 | @defun cl-subsetp list1 list2 @t{&key :test :test-not :key} |
| 4318 | This function checks whether @var{list1} represents a subset | 3908 | This function checks whether @var{list1} represents a subset |
| 4319 | of @var{list2}, i.e., whether every element of @var{list1} | 3909 | of @var{list2}, i.e., whether every element of @var{list1} |
| 4320 | also appears in @var{list2}. | 3910 | also appears in @var{list2}. |
| @@ -4328,7 +3918,7 @@ An @dfn{association list} is a list representing a mapping from | |||
| 4328 | one set of values to another; any list whose elements are cons | 3918 | one set of values to another; any list whose elements are cons |
| 4329 | cells is an association list. | 3919 | cells is an association list. |
| 4330 | 3920 | ||
| 4331 | @defun assoc* item a-list @t{&key :test :test-not :key} | 3921 | @defun cl-assoc item a-list @t{&key :test :test-not :key} |
| 4332 | This function searches the association list @var{a-list} for an | 3922 | This function searches the association list @var{a-list} for an |
| 4333 | element whose @code{car} matches (in the sense of @code{:test}, | 3923 | element whose @code{car} matches (in the sense of @code{:test}, |
| 4334 | @code{:test-not}, and @code{:key}, or by comparison with @code{eql}) | 3924 | @code{:test-not}, and @code{:key}, or by comparison with @code{eql}) |
| @@ -4340,27 +3930,27 @@ are not cons cells. (This corresponds to the behavior of | |||
| 4340 | elements of @var{a-list} to be an error.) | 3930 | elements of @var{a-list} to be an error.) |
| 4341 | @end defun | 3931 | @end defun |
| 4342 | 3932 | ||
| 4343 | @defun rassoc* item a-list @t{&key :test :test-not :key} | 3933 | @defun cl-rassoc item a-list @t{&key :test :test-not :key} |
| 4344 | This function searches for an element whose @code{cdr} matches | 3934 | This function searches for an element whose @code{cdr} matches |
| 4345 | @var{item}. If @var{a-list} represents a mapping, this applies | 3935 | @var{item}. If @var{a-list} represents a mapping, this applies |
| 4346 | the inverse of the mapping to @var{item}. | 3936 | the inverse of the mapping to @var{item}. |
| 4347 | @end defun | 3937 | @end defun |
| 4348 | 3938 | ||
| 4349 | @findex assoc-if | 3939 | @findex cl-assoc-if |
| 4350 | @findex assoc-if-not | 3940 | @findex cl-assoc-if-not |
| 4351 | @findex rassoc-if | 3941 | @findex cl-rassoc-if |
| 4352 | @findex rassoc-if-not | 3942 | @findex cl-rassoc-if-not |
| 4353 | The @code{assoc-if}, @code{assoc-if-not}, @code{rassoc-if}, | 3943 | The @code{cl-assoc-if}, @code{cl-assoc-if-not}, @code{cl-rassoc-if}, |
| 4354 | and @code{rassoc-if-not} functions are defined similarly. | 3944 | and @code{cl-rassoc-if-not} functions are defined similarly. |
| 4355 | 3945 | ||
| 4356 | Two simple functions for constructing association lists are: | 3946 | Two simple functions for constructing association lists are: |
| 4357 | 3947 | ||
| 4358 | @defun acons key value alist | 3948 | @defun cl-acons key value alist |
| 4359 | This is equivalent to @code{(cons (cons @var{key} @var{value}) @var{alist})}. | 3949 | This is equivalent to @code{(cons (cons @var{key} @var{value}) @var{alist})}. |
| 4360 | @end defun | 3950 | @end defun |
| 4361 | 3951 | ||
| 4362 | @defun pairlis keys values &optional alist | 3952 | @defun cl-pairlis keys values &optional alist |
| 4363 | This is equivalent to @code{(nconc (mapcar* 'cons @var{keys} @var{values}) | 3953 | This is equivalent to @code{(nconc (cl-mapcar 'cons @var{keys} @var{values}) |
| 4364 | @var{alist})}. | 3954 | @var{alist})}. |
| 4365 | @end defun | 3955 | @end defun |
| 4366 | 3956 | ||
| @@ -4382,15 +3972,15 @@ system provides no way to create new distinct types, this package | |||
| 4382 | implements structures as vectors (or lists upon request) with a | 3972 | implements structures as vectors (or lists upon request) with a |
| 4383 | special ``tag'' symbol to identify them. | 3973 | special ``tag'' symbol to identify them. |
| 4384 | 3974 | ||
| 4385 | @defspec defstruct name slots@dots{} | 3975 | @defmac cl-defstruct name slots@dots{} |
| 4386 | The @code{defstruct} form defines a new structure type called | 3976 | The @code{cl-defstruct} form defines a new structure type called |
| 4387 | @var{name}, with the specified @var{slots}. (The @var{slots} | 3977 | @var{name}, with the specified @var{slots}. (The @var{slots} |
| 4388 | may begin with a string which documents the structure type.) | 3978 | may begin with a string which documents the structure type.) |
| 4389 | In the simplest case, @var{name} and each of the @var{slots} | 3979 | In the simplest case, @var{name} and each of the @var{slots} |
| 4390 | are symbols. For example, | 3980 | are symbols. For example, |
| 4391 | 3981 | ||
| 4392 | @example | 3982 | @example |
| 4393 | (defstruct person name age sex) | 3983 | (cl-defstruct person name age sex) |
| 4394 | @end example | 3984 | @end example |
| 4395 | 3985 | ||
| 4396 | @noindent | 3986 | @noindent |
| @@ -4401,14 +3991,14 @@ and @code{(person-sex @var{p})}. You can also change these slots by | |||
| 4401 | using @code{setf} on any of these place forms: | 3991 | using @code{setf} on any of these place forms: |
| 4402 | 3992 | ||
| 4403 | @example | 3993 | @example |
| 4404 | (incf (person-age birthday-boy)) | 3994 | (cl-incf (person-age birthday-boy)) |
| 4405 | @end example | 3995 | @end example |
| 4406 | 3996 | ||
| 4407 | You can create a new @code{person} by calling @code{make-person}, | 3997 | You can create a new @code{person} by calling @code{make-person}, |
| 4408 | which takes keyword arguments @code{:name}, @code{:age}, and | 3998 | which takes keyword arguments @code{:name}, @code{:age}, and |
| 4409 | @code{:sex} to specify the initial values of these slots in the | 3999 | @code{:sex} to specify the initial values of these slots in the |
| 4410 | new object. (Omitting any of these arguments leaves the corresponding | 4000 | new object. (Omitting any of these arguments leaves the corresponding |
| 4411 | slot ``undefined,'' according to the Common Lisp standard; in Emacs | 4001 | slot ``undefined'', according to the Common Lisp standard; in Emacs |
| 4412 | Lisp, such uninitialized slots are filled with @code{nil}.) | 4002 | Lisp, such uninitialized slots are filled with @code{nil}.) |
| 4413 | 4003 | ||
| 4414 | Given a @code{person}, @code{(copy-person @var{p})} makes a new | 4004 | Given a @code{person}, @code{(copy-person @var{p})} makes a new |
| @@ -4465,10 +4055,10 @@ the slot's value is determined when the object is created and does | |||
| 4465 | not change afterward. | 4055 | not change afterward. |
| 4466 | 4056 | ||
| 4467 | @example | 4057 | @example |
| 4468 | (defstruct person | 4058 | (cl-defstruct person |
| 4469 | (name nil :read-only t) | 4059 | (name nil :read-only t) |
| 4470 | age | 4060 | age |
| 4471 | (sex 'unknown)) | 4061 | (sex 'unknown)) |
| 4472 | @end example | 4062 | @end example |
| 4473 | 4063 | ||
| 4474 | Any slot options other than @code{:read-only} are ignored. | 4064 | Any slot options other than @code{:read-only} are ignored. |
| @@ -4480,19 +4070,15 @@ by arguments. (By contrast, slot options are key-value pairs not | |||
| 4480 | enclosed in lists.) | 4070 | enclosed in lists.) |
| 4481 | 4071 | ||
| 4482 | @example | 4072 | @example |
| 4483 | (defstruct (person (:constructor create-person) | 4073 | (cl-defstruct (person (:constructor create-person) |
| 4484 | (:type list) | 4074 | (:type list) |
| 4485 | :named) | 4075 | :named) |
| 4486 | name age sex) | 4076 | name age sex) |
| 4487 | @end example | 4077 | @end example |
| 4488 | 4078 | ||
| 4489 | The following structure options are recognized. | 4079 | The following structure options are recognized. |
| 4490 | 4080 | ||
| 4491 | @table @code | 4081 | @table @code |
| 4492 | @iftex | ||
| 4493 | @itemmax=0 in | ||
| 4494 | @advance@leftskip-.5@tableindent | ||
| 4495 | @end iftex | ||
| 4496 | @item :conc-name | 4082 | @item :conc-name |
| 4497 | The argument is a symbol whose print name is used as the prefix for | 4083 | The argument is a symbol whose print name is used as the prefix for |
| 4498 | the names of slot accessor functions. The default is the name of | 4084 | the names of slot accessor functions. The default is the name of |
| @@ -4529,21 +4115,22 @@ as well unless you disable it with a simple-format @code{:constructor} | |||
| 4529 | option. | 4115 | option. |
| 4530 | 4116 | ||
| 4531 | @example | 4117 | @example |
| 4532 | (defstruct | 4118 | (cl-defstruct |
| 4533 | (person | 4119 | (person |
| 4534 | (:constructor nil) ; no default constructor | 4120 | (:constructor nil) ; no default constructor |
| 4535 | (:constructor new-person (name sex &optional (age 0))) | 4121 | (:constructor new-person |
| 4536 | (:constructor new-hound (&key (name "Rover") | 4122 | (name sex &optional (age 0))) |
| 4537 | (dog-years 0) | 4123 | (:constructor new-hound (&key (name "Rover") |
| 4538 | &aux (age (* 7 dog-years)) | 4124 | (dog-years 0) |
| 4539 | (sex 'canine)))) | 4125 | &aux (age (* 7 dog-years)) |
| 4540 | name age sex) | 4126 | (sex 'canine)))) |
| 4127 | name age sex) | ||
| 4541 | @end example | 4128 | @end example |
| 4542 | 4129 | ||
| 4543 | The first constructor here takes its arguments positionally rather | 4130 | The first constructor here takes its arguments positionally rather |
| 4544 | than by keyword. (In official Common Lisp terminology, constructors | 4131 | than by keyword. (In official Common Lisp terminology, constructors |
| 4545 | that work By Order of Arguments instead of by keyword are called | 4132 | that work By Order of Arguments instead of by keyword are called |
| 4546 | ``BOA constructors.'' No, I'm not making this up.) For example, | 4133 | ``BOA constructors''. No, I'm not making this up.) For example, |
| 4547 | @code{(new-person "Jane" 'female)} generates a person whose slots | 4134 | @code{(new-person "Jane" 'female)} generates a person whose slots |
| 4548 | are @code{"Jane"}, 0, and @code{female}, respectively. | 4135 | are @code{"Jane"}, 0, and @code{female}, respectively. |
| 4549 | 4136 | ||
| @@ -4569,14 +4156,14 @@ ever generated.) | |||
| 4569 | 4156 | ||
| 4570 | In true Common Lisp, @code{typep} is always able to recognize a | 4157 | In true Common Lisp, @code{typep} is always able to recognize a |
| 4571 | structure object even if @code{:predicate} was used. In this | 4158 | structure object even if @code{:predicate} was used. In this |
| 4572 | package, @code{typep} simply looks for a function called | 4159 | package, @code{cl-typep} simply looks for a function called |
| 4573 | @code{@var{typename}-p}, so it will work for structure types | 4160 | @code{@var{typename}-p}, so it will work for structure types |
| 4574 | only if they used the default predicate name. | 4161 | only if they used the default predicate name. |
| 4575 | 4162 | ||
| 4576 | @item :include | 4163 | @item :include |
| 4577 | This option implements a very limited form of C++-style inheritance. | 4164 | This option implements a very limited form of C++-style inheritance. |
| 4578 | The argument is the name of another structure type previously | 4165 | The argument is the name of another structure type previously |
| 4579 | created with @code{defstruct}. The effect is to cause the new | 4166 | created with @code{cl-defstruct}. The effect is to cause the new |
| 4580 | structure type to inherit all of the included structure's slots | 4167 | structure type to inherit all of the included structure's slots |
| 4581 | (plus, of course, any new slots described by this struct's slot | 4168 | (plus, of course, any new slots described by this struct's slot |
| 4582 | descriptors). The new structure is considered a ``specialization'' | 4169 | descriptors). The new structure is considered a ``specialization'' |
| @@ -4589,12 +4176,12 @@ slot descriptors for slots in the included structure, possibly with | |||
| 4589 | modified default values. Borrowing an example from Steele: | 4176 | modified default values. Borrowing an example from Steele: |
| 4590 | 4177 | ||
| 4591 | @example | 4178 | @example |
| 4592 | (defstruct person name (age 0) sex) | 4179 | (cl-defstruct person name (age 0) sex) |
| 4593 | @result{} person | 4180 | @result{} person |
| 4594 | (defstruct (astronaut (:include person (age 45))) | 4181 | (cl-defstruct (astronaut (:include person (age 45))) |
| 4595 | helmet-size | 4182 | helmet-size |
| 4596 | (favorite-beverage 'tang)) | 4183 | (favorite-beverage 'tang)) |
| 4597 | @result{} astronaut | 4184 | @result{} astronaut |
| 4598 | 4185 | ||
| 4599 | (setq joe (make-person :name "Joe")) | 4186 | (setq joe (make-person :name "Joe")) |
| 4600 | @result{} [cl-struct-person "Joe" 0 nil] | 4187 | @result{} [cl-struct-person "Joe" 0 nil] |
| @@ -4650,9 +4237,9 @@ use named vectors. Therefore, @code{:named} is only useful in | |||
| 4650 | conjunction with @code{:type}. | 4237 | conjunction with @code{:type}. |
| 4651 | 4238 | ||
| 4652 | @example | 4239 | @example |
| 4653 | (defstruct (person1) name age sex) | 4240 | (cl-defstruct (person1) name age sex) |
| 4654 | (defstruct (person2 (:type list) :named) name age sex) | 4241 | (cl-defstruct (person2 (:type list) :named) name age sex) |
| 4655 | (defstruct (person3 (:type list)) name age sex) | 4242 | (cl-defstruct (person3 (:type list)) name age sex) |
| 4656 | 4243 | ||
| 4657 | (setq p1 (make-person1)) | 4244 | (setq p1 (make-person1)) |
| 4658 | @result{} [cl-struct-person1 nil nil nil] | 4245 | @result{} [cl-struct-person1 nil nil nil] |
| @@ -4669,7 +4256,7 @@ conjunction with @code{:type}. | |||
| 4669 | @result{} error: function person3-p undefined | 4256 | @result{} error: function person3-p undefined |
| 4670 | @end example | 4257 | @end example |
| 4671 | 4258 | ||
| 4672 | Since unnamed structures don't have tags, @code{defstruct} is not | 4259 | Since unnamed structures don't have tags, @code{cl-defstruct} is not |
| 4673 | able to make a useful predicate for recognizing them. Also, | 4260 | able to make a useful predicate for recognizing them. Also, |
| 4674 | accessors like @code{person3-name} will be generated but they | 4261 | accessors like @code{person3-name} will be generated but they |
| 4675 | will not be able to do any type checking. The @code{person3-name} | 4262 | will not be able to do any type checking. The @code{person3-name} |
| @@ -4689,9 +4276,9 @@ the type @code{:include}s another type, then @code{:initial-offset} | |||
| 4689 | specifies a number of slots to be skipped between the last slot | 4276 | specifies a number of slots to be skipped between the last slot |
| 4690 | of the included type and the first new slot. | 4277 | of the included type and the first new slot. |
| 4691 | @end table | 4278 | @end table |
| 4692 | @end defspec | 4279 | @end defmac |
| 4693 | 4280 | ||
| 4694 | Except as noted, the @code{defstruct} facility of this package is | 4281 | Except as noted, the @code{cl-defstruct} facility of this package is |
| 4695 | entirely compatible with that of Common Lisp. | 4282 | entirely compatible with that of Common Lisp. |
| 4696 | 4283 | ||
| 4697 | @node Assertions | 4284 | @node Assertions |
| @@ -4708,10 +4295,10 @@ If the optimization property @code{speed} has been set to 3, and | |||
| 4708 | away the following assertions. Because assertions might be optimized | 4295 | away the following assertions. Because assertions might be optimized |
| 4709 | away, it is a bad idea for them to include side-effects. | 4296 | away, it is a bad idea for them to include side-effects. |
| 4710 | 4297 | ||
| 4711 | @defspec assert test-form [show-args string args@dots{}] | 4298 | @defmac cl-assert test-form [show-args string args@dots{}] |
| 4712 | This form verifies that @var{test-form} is true (i.e., evaluates to | 4299 | This form verifies that @var{test-form} is true (i.e., evaluates to |
| 4713 | a non-@code{nil} value). If so, it returns @code{nil}. If the test | 4300 | a non-@code{nil} value). If so, it returns @code{nil}. If the test |
| 4714 | is not satisfied, @code{assert} signals an error. | 4301 | is not satisfied, @code{cl-assert} signals an error. |
| 4715 | 4302 | ||
| 4716 | A default error message will be supplied which includes @var{test-form}. | 4303 | A default error message will be supplied which includes @var{test-form}. |
| 4717 | You can specify a different error message by including a @var{string} | 4304 | You can specify a different error message by including a @var{string} |
| @@ -4724,7 +4311,7 @@ will also include all non-constant arguments of the top-level | |||
| 4724 | @var{form}. For example: | 4311 | @var{form}. For example: |
| 4725 | 4312 | ||
| 4726 | @example | 4313 | @example |
| 4727 | (assert (> x 10) t "x is too small: %d") | 4314 | (cl-assert (> x 10) t "x is too small: %d") |
| 4728 | @end example | 4315 | @end example |
| 4729 | 4316 | ||
| 4730 | This usage of @var{show-args} is an extension to Common Lisp. In | 4317 | This usage of @var{show-args} is an extension to Common Lisp. In |
| @@ -4732,18 +4319,18 @@ true Common Lisp, the second argument gives a list of @var{places} | |||
| 4732 | which can be @code{setf}'d by the user before continuing from the | 4319 | which can be @code{setf}'d by the user before continuing from the |
| 4733 | error. Since Emacs Lisp does not support continuable errors, it | 4320 | error. Since Emacs Lisp does not support continuable errors, it |
| 4734 | makes no sense to specify @var{places}. | 4321 | makes no sense to specify @var{places}. |
| 4735 | @end defspec | 4322 | @end defmac |
| 4736 | 4323 | ||
| 4737 | @defspec check-type form type [string] | 4324 | @defmac cl-check-type form type [string] |
| 4738 | This form verifies that @var{form} evaluates to a value of type | 4325 | This form verifies that @var{form} evaluates to a value of type |
| 4739 | @var{type}. If so, it returns @code{nil}. If not, @code{check-type} | 4326 | @var{type}. If so, it returns @code{nil}. If not, @code{cl-check-type} |
| 4740 | signals a @code{wrong-type-argument} error. The default error message | 4327 | signals a @code{wrong-type-argument} error. The default error message |
| 4741 | lists the erroneous value along with @var{type} and @var{form} | 4328 | lists the erroneous value along with @var{type} and @var{form} |
| 4742 | themselves. If @var{string} is specified, it is included in the | 4329 | themselves. If @var{string} is specified, it is included in the |
| 4743 | error message in place of @var{type}. For example: | 4330 | error message in place of @var{type}. For example: |
| 4744 | 4331 | ||
| 4745 | @example | 4332 | @example |
| 4746 | (check-type x (integer 1 *) "a positive integer") | 4333 | (cl-check-type x (integer 1 *) "a positive integer") |
| 4747 | @end example | 4334 | @end example |
| 4748 | 4335 | ||
| 4749 | @xref{Type Predicates}, for a description of the type specifiers | 4336 | @xref{Type Predicates}, for a description of the type specifiers |
| @@ -4753,18 +4340,7 @@ Note that in Common Lisp, the first argument to @code{check-type} | |||
| 4753 | must be a @var{place} suitable for use by @code{setf}, because | 4340 | must be a @var{place} suitable for use by @code{setf}, because |
| 4754 | @code{check-type} signals a continuable error that allows the | 4341 | @code{check-type} signals a continuable error that allows the |
| 4755 | user to modify @var{place}. | 4342 | user to modify @var{place}. |
| 4756 | @end defspec | 4343 | @end defmac |
| 4757 | |||
| 4758 | The following error-related macro is also defined: | ||
| 4759 | |||
| 4760 | @defspec ignore-errors forms@dots{} | ||
| 4761 | This executes @var{forms} exactly like a @code{progn}, except that | ||
| 4762 | errors are ignored during the @var{forms}. More precisely, if | ||
| 4763 | an error is signaled then @code{ignore-errors} immediately | ||
| 4764 | aborts execution of the @var{forms} and returns @code{nil}. | ||
| 4765 | If the @var{forms} complete successfully, @code{ignore-errors} | ||
| 4766 | returns the result of the last @var{form}. | ||
| 4767 | @end defspec | ||
| 4768 | 4344 | ||
| 4769 | @node Efficiency Concerns | 4345 | @node Efficiency Concerns |
| 4770 | @appendix Efficiency Concerns | 4346 | @appendix Efficiency Concerns |
| @@ -4772,38 +4348,35 @@ returns the result of the last @var{form}. | |||
| 4772 | @appendixsec Macros | 4348 | @appendixsec Macros |
| 4773 | 4349 | ||
| 4774 | @noindent | 4350 | @noindent |
| 4775 | Many of the advanced features of this package, such as @code{defun*}, | 4351 | Many of the advanced features of this package, such as @code{cl-defun}, |
| 4776 | @code{loop}, and @code{setf}, are implemented as Lisp macros. In | 4352 | @code{cl-loop}, etc., are implemented as Lisp macros. In |
| 4777 | byte-compiled code, these complex notations will be expanded into | 4353 | byte-compiled code, these complex notations will be expanded into |
| 4778 | equivalent Lisp code which is simple and efficient. For example, | 4354 | equivalent Lisp code which is simple and efficient. For example, |
| 4779 | the forms | 4355 | the form |
| 4780 | 4356 | ||
| 4781 | @example | 4357 | @example |
| 4782 | (incf i n) | 4358 | (cl-incf i n) |
| 4783 | (push x (car p)) | ||
| 4784 | @end example | 4359 | @end example |
| 4785 | 4360 | ||
| 4786 | @noindent | 4361 | @noindent |
| 4787 | are expanded at compile-time to the Lisp forms | 4362 | is expanded at compile-time to the Lisp form |
| 4788 | 4363 | ||
| 4789 | @example | 4364 | @example |
| 4790 | (setq i (+ i n)) | 4365 | (setq i (+ i n)) |
| 4791 | (setcar p (cons x (car p))) | ||
| 4792 | @end example | 4366 | @end example |
| 4793 | 4367 | ||
| 4794 | @noindent | 4368 | @noindent |
| 4795 | which are the most efficient ways of doing these respective operations | 4369 | which is the most efficient ways of doing this operation |
| 4796 | in Lisp. Thus, there is no performance penalty for using the more | 4370 | in Lisp. Thus, there is no performance penalty for using the more |
| 4797 | readable @code{incf} and @code{push} forms in your compiled code. | 4371 | readable @code{cl-incf} form in your compiled code. |
| 4798 | 4372 | ||
| 4799 | @emph{Interpreted} code, on the other hand, must expand these macros | 4373 | @emph{Interpreted} code, on the other hand, must expand these macros |
| 4800 | every time they are executed. For this reason it is strongly | 4374 | every time they are executed. For this reason it is strongly |
| 4801 | recommended that code making heavy use of macros be compiled. | 4375 | recommended that code making heavy use of macros be compiled. |
| 4802 | (The features labeled ``Special Form'' instead of ``Function'' in | 4376 | A loop using @code{cl-incf} a hundred times will execute considerably |
| 4803 | this manual are macros.) A loop using @code{incf} a hundred times | 4377 | faster if compiled, and will also garbage-collect less because the |
| 4804 | will execute considerably faster if compiled, and will also | 4378 | macro expansion will not have to be generated, used, and thrown away a |
| 4805 | garbage-collect less because the macro expansion will not have | 4379 | hundred times. |
| 4806 | to be generated, used, and thrown away a hundred times. | ||
| 4807 | 4380 | ||
| 4808 | You can find out how a macro expands by using the | 4381 | You can find out how a macro expands by using the |
| 4809 | @code{cl-prettyexpand} function. | 4382 | @code{cl-prettyexpand} function. |
| @@ -4813,10 +4386,10 @@ This function takes a single Lisp form as an argument and inserts | |||
| 4813 | a nicely formatted copy of it in the current buffer (which must be | 4386 | a nicely formatted copy of it in the current buffer (which must be |
| 4814 | in Lisp mode so that indentation works properly). It also expands | 4387 | in Lisp mode so that indentation works properly). It also expands |
| 4815 | all Lisp macros which appear in the form. The easiest way to use | 4388 | all Lisp macros which appear in the form. The easiest way to use |
| 4816 | this function is to go to the @code{*scratch*} buffer and type, say, | 4389 | this function is to go to the @file{*scratch*} buffer and type, say, |
| 4817 | 4390 | ||
| 4818 | @example | 4391 | @example |
| 4819 | (cl-prettyexpand '(loop for x below 10 collect x)) | 4392 | (cl-prettyexpand '(cl-loop for x below 10 collect x)) |
| 4820 | @end example | 4393 | @end example |
| 4821 | 4394 | ||
| 4822 | @noindent | 4395 | @noindent |
| @@ -4824,36 +4397,36 @@ and type @kbd{C-x C-e} immediately after the closing parenthesis; | |||
| 4824 | the expansion | 4397 | the expansion |
| 4825 | 4398 | ||
| 4826 | @example | 4399 | @example |
| 4827 | (block nil | 4400 | (cl-block nil |
| 4828 | (let* ((x 0) | 4401 | (let* ((x 0) |
| 4829 | (G1004 nil)) | 4402 | (G1004 nil)) |
| 4830 | (while (< x 10) | 4403 | (while (< x 10) |
| 4831 | (setq G1004 (cons x G1004)) | 4404 | (setq G1004 (cons x G1004)) |
| 4832 | (setq x (+ x 1))) | 4405 | (setq x (+ x 1))) |
| 4833 | (nreverse G1004))) | 4406 | (nreverse G1004))) |
| 4834 | @end example | 4407 | @end example |
| 4835 | 4408 | ||
| 4836 | @noindent | 4409 | @noindent |
| 4837 | will be inserted into the buffer. (The @code{block} macro is | 4410 | will be inserted into the buffer. (The @code{cl-block} macro is |
| 4838 | expanded differently in the interpreter and compiler, so | 4411 | expanded differently in the interpreter and compiler, so |
| 4839 | @code{cl-prettyexpand} just leaves it alone. The temporary | 4412 | @code{cl-prettyexpand} just leaves it alone. The temporary |
| 4840 | variable @code{G1004} was created by @code{gensym}.) | 4413 | variable @code{G1004} was created by @code{cl-gensym}.) |
| 4841 | 4414 | ||
| 4842 | If the optional argument @var{full} is true, then @emph{all} | 4415 | If the optional argument @var{full} is true, then @emph{all} |
| 4843 | macros are expanded, including @code{block}, @code{eval-when}, | 4416 | macros are expanded, including @code{cl-block}, @code{cl-eval-when}, |
| 4844 | and compiler macros. Expansion is done as if @var{form} were | 4417 | and compiler macros. Expansion is done as if @var{form} were |
| 4845 | a top-level form in a file being compiled. For example, | 4418 | a top-level form in a file being compiled. For example, |
| 4846 | 4419 | ||
| 4847 | @example | 4420 | @example |
| 4848 | (cl-prettyexpand '(pushnew 'x list)) | 4421 | (cl-prettyexpand '(cl-pushnew 'x list)) |
| 4849 | @print{} (setq list (adjoin 'x list)) | 4422 | @print{} (setq list (cl-adjoin 'x list)) |
| 4850 | (cl-prettyexpand '(pushnew 'x list) t) | 4423 | (cl-prettyexpand '(cl-pushnew 'x list) t) |
| 4851 | @print{} (setq list (if (memq 'x list) list (cons 'x list))) | 4424 | @print{} (setq list (if (memq 'x list) list (cons 'x list))) |
| 4852 | (cl-prettyexpand '(caddr (member* 'a list)) t) | 4425 | (cl-prettyexpand '(caddr (cl-member 'a list)) t) |
| 4853 | @print{} (car (cdr (cdr (memq 'a list)))) | 4426 | @print{} (car (cdr (cdr (memq 'a list)))) |
| 4854 | @end example | 4427 | @end example |
| 4855 | 4428 | ||
| 4856 | Note that @code{adjoin}, @code{caddr}, and @code{member*} all | 4429 | Note that @code{cl-adjoin}, @code{cl-caddr}, and @code{cl-member} all |
| 4857 | have built-in compiler macros to optimize them in common cases. | 4430 | have built-in compiler macros to optimize them in common cases. |
| 4858 | @end defun | 4431 | @end defun |
| 4859 | 4432 | ||
| @@ -4875,22 +4448,22 @@ phrase ``it is an error if'' to indicate a situation which is not | |||
| 4875 | supposed to arise in complying programs; implementations are strongly | 4448 | supposed to arise in complying programs; implementations are strongly |
| 4876 | encouraged but not required to signal an error in these situations. | 4449 | encouraged but not required to signal an error in these situations. |
| 4877 | This package sometimes omits such error checking in the interest of | 4450 | This package sometimes omits such error checking in the interest of |
| 4878 | compactness and efficiency. For example, @code{do} variable | 4451 | compactness and efficiency. For example, @code{cl-do} variable |
| 4879 | specifiers are supposed to be lists of one, two, or three forms; | 4452 | specifiers are supposed to be lists of one, two, or three forms; |
| 4880 | extra forms are ignored by this package rather than signaling a | 4453 | extra forms are ignored by this package rather than signaling a |
| 4881 | syntax error. The @code{endp} function is simply a synonym for | 4454 | syntax error. The @code{cl-endp} function is simply a synonym for |
| 4882 | @code{null} in this package. Functions taking keyword arguments | 4455 | @code{null} in this package. Functions taking keyword arguments |
| 4883 | will accept an odd number of arguments, treating the trailing | 4456 | will accept an odd number of arguments, treating the trailing |
| 4884 | keyword as if it were followed by the value @code{nil}. | 4457 | keyword as if it were followed by the value @code{nil}. |
| 4885 | 4458 | ||
| 4886 | Argument lists (as processed by @code{defun*} and friends) | 4459 | Argument lists (as processed by @code{cl-defun} and friends) |
| 4887 | @emph{are} checked rigorously except for the minor point just | 4460 | @emph{are} checked rigorously except for the minor point just |
| 4888 | mentioned; in particular, keyword arguments are checked for | 4461 | mentioned; in particular, keyword arguments are checked for |
| 4889 | validity, and @code{&allow-other-keys} and @code{:allow-other-keys} | 4462 | validity, and @code{&allow-other-keys} and @code{:allow-other-keys} |
| 4890 | are fully implemented. Keyword validity checking is slightly | 4463 | are fully implemented. Keyword validity checking is slightly |
| 4891 | time consuming (though not too bad in byte-compiled code); | 4464 | time consuming (though not too bad in byte-compiled code); |
| 4892 | you can use @code{&allow-other-keys} to omit this check. Functions | 4465 | you can use @code{&allow-other-keys} to omit this check. Functions |
| 4893 | defined in this package such as @code{find} and @code{member*} | 4466 | defined in this package such as @code{cl-find} and @code{cl-member} |
| 4894 | do check their keyword arguments for validity. | 4467 | do check their keyword arguments for validity. |
| 4895 | 4468 | ||
| 4896 | @ifinfo | 4469 | @ifinfo |
| @@ -4904,10 +4477,10 @@ do check their keyword arguments for validity. | |||
| 4904 | Use of the optimizing Emacs compiler is highly recommended; many of the Common | 4477 | Use of the optimizing Emacs compiler is highly recommended; many of the Common |
| 4905 | Lisp macros emit | 4478 | Lisp macros emit |
| 4906 | code which can be improved by optimization. In particular, | 4479 | code which can be improved by optimization. In particular, |
| 4907 | @code{block}s (whether explicit or implicit in constructs like | 4480 | @code{cl-block}s (whether explicit or implicit in constructs like |
| 4908 | @code{defun*} and @code{loop}) carry a fair run-time penalty; the | 4481 | @code{cl-defun} and @code{cl-loop}) carry a fair run-time penalty; the |
| 4909 | optimizing compiler removes @code{block}s which are not actually | 4482 | optimizing compiler removes @code{cl-block}s which are not actually |
| 4910 | referenced by @code{return} or @code{return-from} inside the block. | 4483 | referenced by @code{cl-return} or @code{cl-return-from} inside the block. |
| 4911 | 4484 | ||
| 4912 | @node Common Lisp Compatibility | 4485 | @node Common Lisp Compatibility |
| 4913 | @appendix Common Lisp Compatibility | 4486 | @appendix Common Lisp Compatibility |
| @@ -4916,42 +4489,38 @@ referenced by @code{return} or @code{return-from} inside the block. | |||
| 4916 | Following is a list of all known incompatibilities between this | 4489 | Following is a list of all known incompatibilities between this |
| 4917 | package and Common Lisp as documented in Steele (2nd edition). | 4490 | package and Common Lisp as documented in Steele (2nd edition). |
| 4918 | 4491 | ||
| 4919 | Certain function names, such as @code{member}, @code{assoc}, and | 4492 | The word @code{cl-defun} is required instead of @code{defun} in order |
| 4920 | @code{floor}, were already taken by (incompatible) Emacs Lisp | ||
| 4921 | functions; this package appends @samp{*} to the names of its | ||
| 4922 | Common Lisp versions of these functions. | ||
| 4923 | |||
| 4924 | The word @code{defun*} is required instead of @code{defun} in order | ||
| 4925 | to use extended Common Lisp argument lists in a function. Likewise, | 4493 | to use extended Common Lisp argument lists in a function. Likewise, |
| 4926 | @code{defmacro*} and @code{function*} are versions of those forms | 4494 | @code{cl-defmacro} and @code{cl-function} are versions of those forms |
| 4927 | which understand full-featured argument lists. The @code{&whole} | 4495 | which understand full-featured argument lists. The @code{&whole} |
| 4928 | keyword does not work in @code{defmacro} argument lists (except | 4496 | keyword does not work in @code{defmacro} argument lists (except |
| 4929 | inside recursive argument lists). | 4497 | inside recursive argument lists). |
| 4930 | 4498 | ||
| 4931 | The @code{equal} predicate does not distinguish | 4499 | The @code{equal} predicate does not distinguish |
| 4932 | between IEEE floating-point plus and minus zero. The @code{equalp} | 4500 | between IEEE floating-point plus and minus zero. The @code{cl-equalp} |
| 4933 | predicate has several differences with Common Lisp; @pxref{Predicates}. | 4501 | predicate has several differences with Common Lisp; @pxref{Predicates}. |
| 4934 | 4502 | ||
| 4503 | @c FIXME no longer provided by cl. | ||
| 4935 | The @code{setf} mechanism is entirely compatible, except that | 4504 | The @code{setf} mechanism is entirely compatible, except that |
| 4936 | setf-methods return a list of five values rather than five | 4505 | setf-methods return a list of five values rather than five |
| 4937 | values directly. Also, the new ``@code{setf} function'' concept | 4506 | values directly. Also, the new ``@code{setf} function'' concept |
| 4938 | (typified by @code{(defun (setf foo) @dots{})}) is not implemented. | 4507 | (typified by @code{(defun (setf foo) @dots{})}) is not implemented. |
| 4939 | 4508 | ||
| 4940 | The @code{do-all-symbols} form is the same as @code{do-symbols} | 4509 | The @code{cl-do-all-symbols} form is the same as @code{cl-do-symbols} |
| 4941 | with no @var{obarray} argument. In Common Lisp, this form would | 4510 | with no @var{obarray} argument. In Common Lisp, this form would |
| 4942 | iterate over all symbols in all packages. Since Emacs obarrays | 4511 | iterate over all symbols in all packages. Since Emacs obarrays |
| 4943 | are not a first-class package mechanism, there is no way for | 4512 | are not a first-class package mechanism, there is no way for |
| 4944 | @code{do-all-symbols} to locate any but the default obarray. | 4513 | @code{cl-do-all-symbols} to locate any but the default obarray. |
| 4945 | 4514 | ||
| 4946 | The @code{loop} macro is complete except that @code{loop-finish} | 4515 | The @code{cl-loop} macro is complete except that @code{loop-finish} |
| 4947 | and type specifiers are unimplemented. | 4516 | and type specifiers are unimplemented. |
| 4948 | 4517 | ||
| 4949 | The multiple-value return facility treats lists as multiple | 4518 | The multiple-value return facility treats lists as multiple |
| 4950 | values, since Emacs Lisp cannot support multiple return values | 4519 | values, since Emacs Lisp cannot support multiple return values |
| 4951 | directly. The macros will be compatible with Common Lisp if | 4520 | directly. The macros will be compatible with Common Lisp if |
| 4952 | @code{values} or @code{values-list} is always used to return to | 4521 | @code{cl-values} or @code{cl-values-list} is always used to return to |
| 4953 | a @code{multiple-value-bind} or other multiple-value receiver; | 4522 | a @code{cl-multiple-value-bind} or other multiple-value receiver; |
| 4954 | if @code{values} is used without @code{multiple-value-@dots{}} | 4523 | if @code{cl-values} is used without @code{cl-multiple-value-@dots{}} |
| 4955 | or vice-versa the effect will be different from Common Lisp. | 4524 | or vice-versa the effect will be different from Common Lisp. |
| 4956 | 4525 | ||
| 4957 | Many Common Lisp declarations are ignored, and others match | 4526 | Many Common Lisp declarations are ignored, and others match |
| @@ -4960,117 +4529,16 @@ example, local @code{special} declarations, which are purely | |||
| 4960 | advisory in Emacs Lisp, do not rigorously obey the scoping rules | 4529 | advisory in Emacs Lisp, do not rigorously obey the scoping rules |
| 4961 | set down in Steele's book. | 4530 | set down in Steele's book. |
| 4962 | 4531 | ||
| 4963 | The variable @code{*gensym-counter*} starts out with a pseudo-random | 4532 | The variable @code{cl--gensym-counter} starts out with a pseudo-random |
| 4964 | value rather than with zero. This is to cope with the fact that | 4533 | value rather than with zero. This is to cope with the fact that |
| 4965 | generated symbols become interned when they are written to and | 4534 | generated symbols become interned when they are written to and |
| 4966 | loaded back from a file. | 4535 | loaded back from a file. |
| 4967 | 4536 | ||
| 4968 | The @code{defstruct} facility is compatible, except that structures | 4537 | The @code{cl-defstruct} facility is compatible, except that structures |
| 4969 | are of type @code{:type vector :named} by default rather than some | 4538 | are of type @code{:type vector :named} by default rather than some |
| 4970 | special, distinct type. Also, the @code{:type} slot option is ignored. | 4539 | special, distinct type. Also, the @code{:type} slot option is ignored. |
| 4971 | 4540 | ||
| 4972 | The second argument of @code{check-type} is treated differently. | 4541 | The second argument of @code{cl-check-type} is treated differently. |
| 4973 | |||
| 4974 | @node Old CL Compatibility | ||
| 4975 | @appendix Old CL Compatibility | ||
| 4976 | |||
| 4977 | @noindent | ||
| 4978 | Following is a list of all known incompatibilities between this package | ||
| 4979 | and the older Quiroz @file{cl.el} package. | ||
| 4980 | |||
| 4981 | This package's emulation of multiple return values in functions is | ||
| 4982 | incompatible with that of the older package. That package attempted | ||
| 4983 | to come as close as possible to true Common Lisp multiple return | ||
| 4984 | values; unfortunately, it could not be 100% reliable and so was prone | ||
| 4985 | to occasional surprises if used freely. This package uses a simpler | ||
| 4986 | method, namely replacing multiple values with lists of values, which | ||
| 4987 | is more predictable though more noticeably different from Common Lisp. | ||
| 4988 | |||
| 4989 | The @code{defkeyword} form and @code{keywordp} function are not | ||
| 4990 | implemented in this package. | ||
| 4991 | |||
| 4992 | The @code{member}, @code{floor}, @code{ceiling}, @code{truncate}, | ||
| 4993 | @code{round}, @code{mod}, and @code{rem} functions are suffixed | ||
| 4994 | by @samp{*} in this package to avoid collision with existing | ||
| 4995 | functions in Emacs. The older package simply | ||
| 4996 | redefined these functions, overwriting the built-in meanings and | ||
| 4997 | causing serious portability problems. (Some more | ||
| 4998 | recent versions of the Quiroz package changed the names to | ||
| 4999 | @code{cl-member}, etc.; this package defines the latter names as | ||
| 5000 | aliases for @code{member*}, etc.) | ||
| 5001 | |||
| 5002 | Certain functions in the old package which were buggy or inconsistent | ||
| 5003 | with the Common Lisp standard are incompatible with the conforming | ||
| 5004 | versions in this package. For example, @code{eql} and @code{member} | ||
| 5005 | were synonyms for @code{eq} and @code{memq} in that package, @code{setf} | ||
| 5006 | failed to preserve correct order of evaluation of its arguments, etc. | ||
| 5007 | |||
| 5008 | Finally, unlike the older package, this package is careful to | ||
| 5009 | prefix all of its internal names with @code{cl-}. Except for a | ||
| 5010 | few functions which are explicitly defined as additional features | ||
| 5011 | (such as @code{floatp-safe} and @code{letf}), this package does not | ||
| 5012 | export any non-@samp{cl-} symbols which are not also part of Common | ||
| 5013 | Lisp. | ||
| 5014 | |||
| 5015 | @ifinfo | ||
| 5016 | @example | ||
| 5017 | |||
| 5018 | @end example | ||
| 5019 | @end ifinfo | ||
| 5020 | @appendixsec The @code{cl-compat} package | ||
| 5021 | |||
| 5022 | @noindent | ||
| 5023 | The @code{CL} package includes emulations of some features of the | ||
| 5024 | old @file{cl.el}, in the form of a compatibility package | ||
| 5025 | @code{cl-compat}. This file is obsolete and may be removed in future, | ||
| 5026 | so it should not be used in new code. | ||
| 5027 | |||
| 5028 | The old package defined a number of internal routines without | ||
| 5029 | @code{cl-} prefixes or other annotations. Call to these routines | ||
| 5030 | may have crept into existing Lisp code. @code{cl-compat} | ||
| 5031 | provides emulations of the following internal routines: | ||
| 5032 | @code{pair-with-newsyms}, @code{zip-lists}, @code{unzip-lists}, | ||
| 5033 | @code{reassemble-arglists}, @code{duplicate-symbols-p}, | ||
| 5034 | @code{safe-idiv}. | ||
| 5035 | |||
| 5036 | Some @code{setf} forms translated into calls to internal | ||
| 5037 | functions that user code might call directly. The functions | ||
| 5038 | @code{setnth}, @code{setnthcdr}, and @code{setelt} fall in | ||
| 5039 | this category; they are defined by @code{cl-compat}, but the | ||
| 5040 | best fix is to change to use @code{setf} properly. | ||
| 5041 | |||
| 5042 | The @code{cl-compat} file defines the keyword functions | ||
| 5043 | @code{keywordp}, @code{keyword-of}, and @code{defkeyword}, | ||
| 5044 | which are not defined by the new @code{CL} package because the | ||
| 5045 | use of keywords as data is discouraged. | ||
| 5046 | |||
| 5047 | The @code{build-klist} mechanism for parsing keyword arguments | ||
| 5048 | is emulated by @code{cl-compat}; the @code{with-keyword-args} | ||
| 5049 | macro is not, however, and in any case it's best to change to | ||
| 5050 | use the more natural keyword argument processing offered by | ||
| 5051 | @code{defun*}. | ||
| 5052 | |||
| 5053 | Multiple return values are treated differently by the two | ||
| 5054 | Common Lisp packages. The old package's method was more | ||
| 5055 | compatible with true Common Lisp, though it used heuristics | ||
| 5056 | that caused it to report spurious multiple return values in | ||
| 5057 | certain cases. The @code{cl-compat} package defines a set | ||
| 5058 | of multiple-value macros that are compatible with the old | ||
| 5059 | CL package; again, they are heuristic in nature, but they | ||
| 5060 | are guaranteed to work in any case where the old package's | ||
| 5061 | macros worked. To avoid name collision with the ``official'' | ||
| 5062 | multiple-value facilities, the ones in @code{cl-compat} have | ||
| 5063 | capitalized names: @code{Values}, @code{Values-list}, | ||
| 5064 | @code{Multiple-value-bind}, etc. | ||
| 5065 | |||
| 5066 | The functions @code{cl-floor}, @code{cl-ceiling}, @code{cl-truncate}, | ||
| 5067 | and @code{cl-round} are defined by @code{cl-compat} to use the | ||
| 5068 | old-style multiple-value mechanism, just as they did in the old | ||
| 5069 | package. The newer @code{floor*} and friends return their two | ||
| 5070 | results in a list rather than as multiple values. Note that | ||
| 5071 | older versions of the old package used the unadorned names | ||
| 5072 | @code{floor}, @code{ceiling}, etc.; @code{cl-compat} cannot use | ||
| 5073 | these names because they conflict with Emacs built-ins. | ||
| 5074 | 4542 | ||
| 5075 | @node Porting Common Lisp | 4543 | @node Porting Common Lisp |
| 5076 | @appendix Porting Common Lisp | 4544 | @appendix Porting Common Lisp |
| @@ -5100,19 +4568,17 @@ this convention, calls to Lisp builtins like @code{if} and | |||
| 5100 | 4568 | ||
| 5101 | @item | 4569 | @item |
| 5102 | Lexical scoping. In Common Lisp, function arguments and @code{let} | 4570 | Lexical scoping. In Common Lisp, function arguments and @code{let} |
| 5103 | bindings apply only to references physically within their bodies | 4571 | bindings apply only to references physically within their bodies (or |
| 5104 | (or within macro expansions in their bodies). Emacs Lisp, by | 4572 | within macro expansions in their bodies). Traditionally, Emacs Lisp |
| 5105 | contrast, uses @dfn{dynamic scoping} wherein a binding to a | 4573 | uses @dfn{dynamic scoping} wherein a binding to a variable is visible |
| 5106 | variable is visible even inside functions called from the body. | 4574 | even inside functions called from the body. |
| 5107 | 4575 | @xref{Dynamic Binding,,,elisp,GNU Emacs Lisp Reference Manual}. | |
| 5108 | Variables in Common Lisp can be made dynamically scoped by | 4576 | Lexical binding is available since Emacs 24.1, so be sure to set |
| 5109 | declaring them @code{special} or using @code{defvar}. In Emacs | 4577 | @code{lexical-binding} to @code{t} if you need to emulate this aspect |
| 5110 | Lisp it is as if all variables were declared @code{special}. | 4578 | of Common Lisp. @xref{Lexical Binding,,,elisp,GNU Emacs Lisp Reference Manual}. |
| 5111 | 4579 | ||
| 5112 | Often you can use code that was written for lexical scoping | 4580 | Here is an example of a Common Lisp code fragment that would fail in |
| 5113 | even in a dynamically scoped Lisp, but not always. Here is | 4581 | Emacs Lisp if @code{lexical-binding} were set to @code{nil}: |
| 5114 | an example of a Common Lisp code fragment that would fail in | ||
| 5115 | Emacs Lisp: | ||
| 5116 | 4582 | ||
| 5117 | @example | 4583 | @example |
| 5118 | (defun map-odd-elements (func list) | 4584 | (defun map-odd-elements (func list) |
| @@ -5125,20 +4591,16 @@ Emacs Lisp: | |||
| 5125 | @end example | 4591 | @end example |
| 5126 | 4592 | ||
| 5127 | @noindent | 4593 | @noindent |
| 5128 | In Common Lisp, the two functions' usages of @code{x} are completely | 4594 | With lexical binding, the two functions' usages of @code{x} are |
| 5129 | independent. In Emacs Lisp, the binding to @code{x} made by | 4595 | completely independent. With dynamic binding, the binding to @code{x} |
| 5130 | @code{add-odd-elements} will have been hidden by the binding | 4596 | made by @code{add-odd-elements} will have been hidden by the binding |
| 5131 | in @code{map-odd-elements} by the time the @code{(+ a x)} function | 4597 | in @code{map-odd-elements} by the time the @code{(+ a x)} function is |
| 5132 | is called. | 4598 | called. |
| 5133 | |||
| 5134 | (This package avoids such problems in its own mapping functions | ||
| 5135 | by using names like @code{cl-x} instead of @code{x} internally; | ||
| 5136 | as long as you don't use the @code{cl-} prefix for your own | ||
| 5137 | variables no collision can occur.) | ||
| 5138 | 4599 | ||
| 5139 | @xref{Lexical Bindings}, for a description of the @code{lexical-let} | 4600 | Internally, this package uses lexical binding so that such problems do |
| 5140 | form which establishes a Common Lisp-style lexical binding, and some | 4601 | not occur. @xref{Lexical Bindings}, for a description of the obsolete |
| 5141 | examples of how it differs from Emacs's regular @code{let}. | 4602 | @code{lexical-let} form that emulates a Common Lisp-style lexical |
| 4603 | binding when dynamic binding is in use. | ||
| 5142 | 4604 | ||
| 5143 | @item | 4605 | @item |
| 5144 | Reader macros. Common Lisp includes a second type of macro that | 4606 | Reader macros. Common Lisp includes a second type of macro that |
| @@ -5178,7 +4640,7 @@ Lisp, they are totally distinct in Emacs Lisp. Common Lisp | |||
| 5178 | programs which refer to a symbol by the full name sometimes | 4640 | programs which refer to a symbol by the full name sometimes |
| 5179 | and the short name other times will not port cleanly to Emacs. | 4641 | and the short name other times will not port cleanly to Emacs. |
| 5180 | 4642 | ||
| 5181 | Emacs Lisp does have a concept of ``obarrays,'' which are | 4643 | Emacs Lisp does have a concept of ``obarrays'', which are |
| 5182 | package-like collections of symbols, but this feature is not | 4644 | package-like collections of symbols, but this feature is not |
| 5183 | strong enough to be used as a true package mechanism. | 4645 | strong enough to be used as a true package mechanism. |
| 5184 | 4646 | ||
| @@ -5198,10 +4660,10 @@ codes provide such features as paragraph filling, case | |||
| 5198 | conversion, and even loops and conditionals. | 4660 | conversion, and even loops and conditionals. |
| 5199 | 4661 | ||
| 5200 | While it would have been possible to implement most of Common | 4662 | While it would have been possible to implement most of Common |
| 5201 | Lisp @code{format} in this package (under the name @code{format*}, | 4663 | Lisp @code{format} in this package (under the name @code{cl-format}, |
| 5202 | of course), it was not deemed worthwhile. It would have required | 4664 | of course), it was not deemed worthwhile. It would have required |
| 5203 | a huge amount of code to implement even a decent subset of | 4665 | a huge amount of code to implement even a decent subset of |
| 5204 | @code{format*}, yet the functionality it would provide over | 4666 | @code{cl-format}, yet the functionality it would provide over |
| 5205 | Emacs Lisp's @code{format} would rarely be useful. | 4667 | Emacs Lisp's @code{format} would rarely be useful. |
| 5206 | 4668 | ||
| 5207 | @item | 4669 | @item |
| @@ -5267,8 +4729,8 @@ where a more iteratively-minded programmer might write one of | |||
| 5267 | these forms: | 4729 | these forms: |
| 5268 | 4730 | ||
| 5269 | @example | 4731 | @example |
| 5270 | (let ((total 0)) (dolist (x my-list) (incf total x)) total) | 4732 | (let ((total 0)) (dolist (x my-list) (cl-incf total x)) total) |
| 5271 | (loop for x in my-list sum x) | 4733 | (cl-loop for x in my-list sum x) |
| 5272 | @end example | 4734 | @end example |
| 5273 | 4735 | ||
| 5274 | While this would be mainly a stylistic choice in most Common Lisps, | 4736 | While this would be mainly a stylistic choice in most Common Lisps, |
| @@ -5278,6 +4740,373 @@ note that the current Emacs Lisp compiler does not optimize tail | |||
| 5278 | recursion. | 4740 | recursion. |
| 5279 | @end itemize | 4741 | @end itemize |
| 5280 | 4742 | ||
| 4743 | @node Obsolete Features | ||
| 4744 | @appendix Obsolete Features | ||
| 4745 | |||
| 4746 | This section describes some features of the package that are obsolete | ||
| 4747 | and should not be used in new code. They are either only provided by | ||
| 4748 | the old @file{cl.el} entry point, not by the newer @file{cl-lib.el}; | ||
| 4749 | or where versions with a @samp{cl-} prefix do exist they do not behave | ||
| 4750 | in exactly the same way. | ||
| 4751 | |||
| 4752 | @menu | ||
| 4753 | * Lexical Bindings:: An approximation of lexical binding. | ||
| 4754 | * Obsolete Lexical Macros:: Obsolete macros using lexical-let. | ||
| 4755 | * Obsolete Setf Customization:: Obsolete ways to customize setf. | ||
| 4756 | @end menu | ||
| 4757 | |||
| 4758 | @node Lexical Bindings | ||
| 4759 | @appendixsec Lexical Bindings | ||
| 4760 | |||
| 4761 | The following macros are extensions to Common Lisp, where all bindings | ||
| 4762 | are lexical unless declared otherwise. These features are likewise | ||
| 4763 | obsolete since the introduction of true lexical binding in Emacs 24.1. | ||
| 4764 | |||
| 4765 | @defmac lexical-let (bindings@dots{}) forms@dots{} | ||
| 4766 | This form is exactly like @code{let} except that the bindings it | ||
| 4767 | establishes are purely lexical. | ||
| 4768 | @end defmac | ||
| 4769 | |||
| 4770 | @c FIXME remove this and refer to elisp manual. | ||
| 4771 | @c Maybe merge some stuff from here to there? | ||
| 4772 | @noindent | ||
| 4773 | Lexical bindings are similar to local variables in a language like C: | ||
| 4774 | Only the code physically within the body of the @code{lexical-let} | ||
| 4775 | (after macro expansion) may refer to the bound variables. | ||
| 4776 | |||
| 4777 | @example | ||
| 4778 | (setq a 5) | ||
| 4779 | (defun foo (b) (+ a b)) | ||
| 4780 | (let ((a 2)) (foo a)) | ||
| 4781 | @result{} 4 | ||
| 4782 | (lexical-let ((a 2)) (foo a)) | ||
| 4783 | @result{} 7 | ||
| 4784 | @end example | ||
| 4785 | |||
| 4786 | @noindent | ||
| 4787 | In this example, a regular @code{let} binding of @code{a} actually | ||
| 4788 | makes a temporary change to the global variable @code{a}, so @code{foo} | ||
| 4789 | is able to see the binding of @code{a} to 2. But @code{lexical-let} | ||
| 4790 | actually creates a distinct local variable @code{a} for use within its | ||
| 4791 | body, without any effect on the global variable of the same name. | ||
| 4792 | |||
| 4793 | The most important use of lexical bindings is to create @dfn{closures}. | ||
| 4794 | A closure is a function object that refers to an outside lexical | ||
| 4795 | variable (@pxref{Closures,,,elisp,GNU Emacs Lisp Reference Manual}). | ||
| 4796 | For example: | ||
| 4797 | |||
| 4798 | @example | ||
| 4799 | (defun make-adder (n) | ||
| 4800 | (lexical-let ((n n)) | ||
| 4801 | (function (lambda (m) (+ n m))))) | ||
| 4802 | (setq add17 (make-adder 17)) | ||
| 4803 | (funcall add17 4) | ||
| 4804 | @result{} 21 | ||
| 4805 | @end example | ||
| 4806 | |||
| 4807 | @noindent | ||
| 4808 | The call @code{(make-adder 17)} returns a function object which adds | ||
| 4809 | 17 to its argument. If @code{let} had been used instead of | ||
| 4810 | @code{lexical-let}, the function object would have referred to the | ||
| 4811 | global @code{n}, which would have been bound to 17 only during the | ||
| 4812 | call to @code{make-adder} itself. | ||
| 4813 | |||
| 4814 | @example | ||
| 4815 | (defun make-counter () | ||
| 4816 | (lexical-let ((n 0)) | ||
| 4817 | (cl-function (lambda (&optional (m 1)) (cl-incf n m))))) | ||
| 4818 | (setq count-1 (make-counter)) | ||
| 4819 | (funcall count-1 3) | ||
| 4820 | @result{} 3 | ||
| 4821 | (funcall count-1 14) | ||
| 4822 | @result{} 17 | ||
| 4823 | (setq count-2 (make-counter)) | ||
| 4824 | (funcall count-2 5) | ||
| 4825 | @result{} 5 | ||
| 4826 | (funcall count-1 2) | ||
| 4827 | @result{} 19 | ||
| 4828 | (funcall count-2) | ||
| 4829 | @result{} 6 | ||
| 4830 | @end example | ||
| 4831 | |||
| 4832 | @noindent | ||
| 4833 | Here we see that each call to @code{make-counter} creates a distinct | ||
| 4834 | local variable @code{n}, which serves as a private counter for the | ||
| 4835 | function object that is returned. | ||
| 4836 | |||
| 4837 | Closed-over lexical variables persist until the last reference to | ||
| 4838 | them goes away, just like all other Lisp objects. For example, | ||
| 4839 | @code{count-2} refers to a function object which refers to an | ||
| 4840 | instance of the variable @code{n}; this is the only reference | ||
| 4841 | to that variable, so after @code{(setq count-2 nil)} the garbage | ||
| 4842 | collector would be able to delete this instance of @code{n}. | ||
| 4843 | Of course, if a @code{lexical-let} does not actually create any | ||
| 4844 | closures, then the lexical variables are free as soon as the | ||
| 4845 | @code{lexical-let} returns. | ||
| 4846 | |||
| 4847 | Many closures are used only during the extent of the bindings they | ||
| 4848 | refer to; these are known as ``downward funargs'' in Lisp parlance. | ||
| 4849 | When a closure is used in this way, regular Emacs Lisp dynamic | ||
| 4850 | bindings suffice and will be more efficient than @code{lexical-let} | ||
| 4851 | closures: | ||
| 4852 | |||
| 4853 | @example | ||
| 4854 | (defun add-to-list (x list) | ||
| 4855 | (mapcar (lambda (y) (+ x y))) list) | ||
| 4856 | (add-to-list 7 '(1 2 5)) | ||
| 4857 | @result{} (8 9 12) | ||
| 4858 | @end example | ||
| 4859 | |||
| 4860 | @noindent | ||
| 4861 | Since this lambda is only used while @code{x} is still bound, | ||
| 4862 | it is not necessary to make a true closure out of it. | ||
| 4863 | |||
| 4864 | You can use @code{defun} or @code{flet} inside a @code{lexical-let} | ||
| 4865 | to create a named closure. If several closures are created in the | ||
| 4866 | body of a single @code{lexical-let}, they all close over the same | ||
| 4867 | instance of the lexical variable. | ||
| 4868 | |||
| 4869 | @defmac lexical-let* (bindings@dots{}) forms@dots{} | ||
| 4870 | This form is just like @code{lexical-let}, except that the bindings | ||
| 4871 | are made sequentially in the manner of @code{let*}. | ||
| 4872 | @end defmac | ||
| 4873 | |||
| 4874 | @node Obsolete Lexical Macros | ||
| 4875 | @appendixsec Macros Defined Using Lexical-Let | ||
| 4876 | |||
| 4877 | The following macros are defined using @code{lexical-let}. | ||
| 4878 | They are replaced by versions with a @samp{cl-} prefix that use true | ||
| 4879 | lexical binding (and hence rely on @code{lexical-binding} being set to | ||
| 4880 | @code{t} in code using them). | ||
| 4881 | |||
| 4882 | @defmac flet (bindings@dots{}) forms@dots{} | ||
| 4883 | Replaced by @code{cl-flet} (@pxref{Function Bindings}) | ||
| 4884 | or @code{cl-letf} (@pxref{Modify Macros}). | ||
| 4885 | @end defmac | ||
| 4886 | |||
| 4887 | @defmac labels (bindings@dots{}) forms@dots{} | ||
| 4888 | Replaced by @code{cl-labels} (@pxref{Function Bindings}). | ||
| 4889 | @end defmac | ||
| 4890 | |||
| 4891 | @defmac letf (bindings@dots{}) forms@dots{} | ||
| 4892 | This macro is almost exactly the same as @code{cl-letf}, which | ||
| 4893 | replaces it (@pxref{Modify Macros}). The only difference is in | ||
| 4894 | details that relate to some deprecated usage of @code{symbol-function} | ||
| 4895 | in place forms. | ||
| 4896 | @end defmac | ||
| 4897 | |||
| 4898 | @node Obsolete Setf Customization | ||
| 4899 | @appendixsec Obsolete Ways to Customize Setf | ||
| 4900 | |||
| 4901 | Common Lisp defines three macros, @code{define-modify-macro}, | ||
| 4902 | @code{defsetf}, and @code{define-setf-method}, that allow the | ||
| 4903 | user to extend generalized variables in various ways. | ||
| 4904 | In Emacs, these are obsolete, replaced by various features of | ||
| 4905 | @file{gv.el} in Emacs 24.3. | ||
| 4906 | @c FIXME details. | ||
| 4907 | |||
| 4908 | @defmac define-modify-macro name arglist function [doc-string] | ||
| 4909 | This macro defines a ``read-modify-write'' macro similar to | ||
| 4910 | @code{cl-incf} and @code{cl-decf}. The macro @var{name} is defined | ||
| 4911 | to take a @var{place} argument followed by additional arguments | ||
| 4912 | described by @var{arglist}. The call | ||
| 4913 | |||
| 4914 | @example | ||
| 4915 | (@var{name} @var{place} @var{args}...) | ||
| 4916 | @end example | ||
| 4917 | |||
| 4918 | @noindent | ||
| 4919 | will be expanded to | ||
| 4920 | |||
| 4921 | @example | ||
| 4922 | (cl-callf @var{func} @var{place} @var{args}...) | ||
| 4923 | @end example | ||
| 4924 | |||
| 4925 | @noindent | ||
| 4926 | which in turn is roughly equivalent to | ||
| 4927 | |||
| 4928 | @example | ||
| 4929 | (setf @var{place} (@var{func} @var{place} @var{args}...)) | ||
| 4930 | @end example | ||
| 4931 | |||
| 4932 | For example: | ||
| 4933 | |||
| 4934 | @example | ||
| 4935 | (define-modify-macro cl-incf (&optional (n 1)) +) | ||
| 4936 | (define-modify-macro cl-concatf (&rest args) concat) | ||
| 4937 | @end example | ||
| 4938 | |||
| 4939 | Note that @code{&key} is not allowed in @var{arglist}, but | ||
| 4940 | @code{&rest} is sufficient to pass keywords on to the function. | ||
| 4941 | |||
| 4942 | Most of the modify macros defined by Common Lisp do not exactly | ||
| 4943 | follow the pattern of @code{define-modify-macro}. For example, | ||
| 4944 | @code{push} takes its arguments in the wrong order, and @code{pop} | ||
| 4945 | is completely irregular. You can define these macros ``by hand'' | ||
| 4946 | using @code{get-setf-method}, or consult the source | ||
| 4947 | to see how to use the internal @code{setf} building blocks. | ||
| 4948 | @end defmac | ||
| 4949 | |||
| 4950 | @defmac defsetf access-fn update-fn | ||
| 4951 | This is the simpler of two @code{defsetf} forms. Where | ||
| 4952 | @var{access-fn} is the name of a function which accesses a place, | ||
| 4953 | this declares @var{update-fn} to be the corresponding store | ||
| 4954 | function. From now on, | ||
| 4955 | |||
| 4956 | @example | ||
| 4957 | (setf (@var{access-fn} @var{arg1} @var{arg2} @var{arg3}) @var{value}) | ||
| 4958 | @end example | ||
| 4959 | |||
| 4960 | @noindent | ||
| 4961 | will be expanded to | ||
| 4962 | |||
| 4963 | @example | ||
| 4964 | (@var{update-fn} @var{arg1} @var{arg2} @var{arg3} @var{value}) | ||
| 4965 | @end example | ||
| 4966 | |||
| 4967 | @noindent | ||
| 4968 | The @var{update-fn} is required to be either a true function, or | ||
| 4969 | a macro which evaluates its arguments in a function-like way. Also, | ||
| 4970 | the @var{update-fn} is expected to return @var{value} as its result. | ||
| 4971 | Otherwise, the above expansion would not obey the rules for the way | ||
| 4972 | @code{setf} is supposed to behave. | ||
| 4973 | |||
| 4974 | As a special (non-Common-Lisp) extension, a third argument of @code{t} | ||
| 4975 | to @code{defsetf} says that the @code{update-fn}'s return value is | ||
| 4976 | not suitable, so that the above @code{setf} should be expanded to | ||
| 4977 | something more like | ||
| 4978 | |||
| 4979 | @example | ||
| 4980 | (let ((temp @var{value})) | ||
| 4981 | (@var{update-fn} @var{arg1} @var{arg2} @var{arg3} temp) | ||
| 4982 | temp) | ||
| 4983 | @end example | ||
| 4984 | |||
| 4985 | Some examples of the use of @code{defsetf}, drawn from the standard | ||
| 4986 | suite of setf methods, are: | ||
| 4987 | |||
| 4988 | @example | ||
| 4989 | (defsetf car setcar) | ||
| 4990 | (defsetf symbol-value set) | ||
| 4991 | (defsetf buffer-name rename-buffer t) | ||
| 4992 | @end example | ||
| 4993 | @end defmac | ||
| 4994 | |||
| 4995 | @defmac defsetf access-fn arglist (store-var) forms@dots{} | ||
| 4996 | This is the second, more complex, form of @code{defsetf}. It is | ||
| 4997 | rather like @code{defmacro} except for the additional @var{store-var} | ||
| 4998 | argument. The @var{forms} should return a Lisp form which stores | ||
| 4999 | the value of @var{store-var} into the generalized variable formed | ||
| 5000 | by a call to @var{access-fn} with arguments described by @var{arglist}. | ||
| 5001 | The @var{forms} may begin with a string which documents the @code{setf} | ||
| 5002 | method (analogous to the doc string that appears at the front of a | ||
| 5003 | function). | ||
| 5004 | |||
| 5005 | For example, the simple form of @code{defsetf} is shorthand for | ||
| 5006 | |||
| 5007 | @example | ||
| 5008 | (defsetf @var{access-fn} (&rest args) (store) | ||
| 5009 | (append '(@var{update-fn}) args (list store))) | ||
| 5010 | @end example | ||
| 5011 | |||
| 5012 | The Lisp form that is returned can access the arguments from | ||
| 5013 | @var{arglist} and @var{store-var} in an unrestricted fashion; | ||
| 5014 | macros like @code{setf} and @code{cl-incf} which invoke this | ||
| 5015 | setf-method will insert temporary variables as needed to make | ||
| 5016 | sure the apparent order of evaluation is preserved. | ||
| 5017 | |||
| 5018 | Another example drawn from the standard package: | ||
| 5019 | |||
| 5020 | @example | ||
| 5021 | (defsetf nth (n x) (store) | ||
| 5022 | (list 'setcar (list 'nthcdr n x) store)) | ||
| 5023 | @end example | ||
| 5024 | @end defmac | ||
| 5025 | |||
| 5026 | @defmac define-setf-method access-fn arglist forms@dots{} | ||
| 5027 | This is the most general way to create new place forms. When | ||
| 5028 | a @code{setf} to @var{access-fn} with arguments described by | ||
| 5029 | @var{arglist} is expanded, the @var{forms} are evaluated and | ||
| 5030 | must return a list of five items: | ||
| 5031 | |||
| 5032 | @enumerate | ||
| 5033 | @item | ||
| 5034 | A list of @dfn{temporary variables}. | ||
| 5035 | |||
| 5036 | @item | ||
| 5037 | A list of @dfn{value forms} corresponding to the temporary variables | ||
| 5038 | above. The temporary variables will be bound to these value forms | ||
| 5039 | as the first step of any operation on the generalized variable. | ||
| 5040 | |||
| 5041 | @item | ||
| 5042 | A list of exactly one @dfn{store variable} (generally obtained | ||
| 5043 | from a call to @code{gensym}). | ||
| 5044 | |||
| 5045 | @item | ||
| 5046 | A Lisp form which stores the contents of the store variable into | ||
| 5047 | the generalized variable, assuming the temporaries have been | ||
| 5048 | bound as described above. | ||
| 5049 | |||
| 5050 | @item | ||
| 5051 | A Lisp form which accesses the contents of the generalized variable, | ||
| 5052 | assuming the temporaries have been bound. | ||
| 5053 | @end enumerate | ||
| 5054 | |||
| 5055 | This is exactly like the Common Lisp macro of the same name, | ||
| 5056 | except that the method returns a list of five values rather | ||
| 5057 | than the five values themselves, since Emacs Lisp does not | ||
| 5058 | support Common Lisp's notion of multiple return values. | ||
| 5059 | |||
| 5060 | Once again, the @var{forms} may begin with a documentation string. | ||
| 5061 | |||
| 5062 | A setf-method should be maximally conservative with regard to | ||
| 5063 | temporary variables. In the setf-methods generated by | ||
| 5064 | @code{defsetf}, the second return value is simply the list of | ||
| 5065 | arguments in the place form, and the first return value is a | ||
| 5066 | list of a corresponding number of temporary variables generated | ||
| 5067 | by @code{cl-gensym}. Macros like @code{setf} and @code{cl-incf} which | ||
| 5068 | use this setf-method will optimize away most temporaries that | ||
| 5069 | turn out to be unnecessary, so there is little reason for the | ||
| 5070 | setf-method itself to optimize. | ||
| 5071 | @end defmac | ||
| 5072 | |||
| 5073 | @defun get-setf-method place &optional env | ||
| 5074 | This function returns the setf-method for @var{place}, by | ||
| 5075 | invoking the definition previously recorded by @code{defsetf} | ||
| 5076 | or @code{define-setf-method}. The result is a list of five | ||
| 5077 | values as described above. You can use this function to build | ||
| 5078 | your own @code{cl-incf}-like modify macros. (Actually, it is | ||
| 5079 | @c FIXME? | ||
| 5080 | better to use the internal functions @code{cl-setf-do-modify} | ||
| 5081 | and @code{cl-setf-do-store}, which are a bit easier to use and | ||
| 5082 | which also do a number of optimizations; consult the source | ||
| 5083 | code for the @code{cl-incf} function for a simple example.) | ||
| 5084 | |||
| 5085 | The argument @var{env} specifies the ``environment'' to be | ||
| 5086 | passed on to @code{macroexpand} if @code{get-setf-method} should | ||
| 5087 | need to expand a macro in @var{place}. It should come from | ||
| 5088 | an @code{&environment} argument to the macro or setf-method | ||
| 5089 | that called @code{get-setf-method}. | ||
| 5090 | |||
| 5091 | See also the source code for the setf-method for | ||
| 5092 | @c Also @code{apply}, but that is commented out. | ||
| 5093 | @code{substring}, which works by calling @code{get-setf-method} on a | ||
| 5094 | simpler case, then massaging the result. | ||
| 5095 | @end defun | ||
| 5096 | |||
| 5097 | Modern Common Lisp defines a second, independent way to specify | ||
| 5098 | the @code{setf} behavior of a function, namely ``@code{setf} | ||
| 5099 | functions'' whose names are lists @code{(setf @var{name})} | ||
| 5100 | rather than symbols. For example, @code{(defun (setf foo) @dots{})} | ||
| 5101 | defines the function that is used when @code{setf} is applied to | ||
| 5102 | @code{foo}. This package does not currently support @code{setf} | ||
| 5103 | functions. In particular, it is a compile-time error to use | ||
| 5104 | @code{setf} on a form which has not already been @code{defsetf}'d | ||
| 5105 | or otherwise declared; in newer Common Lisps, this would not be | ||
| 5106 | an error since the function @code{(setf @var{func})} might be | ||
| 5107 | defined later. | ||
| 5108 | |||
| 5109 | |||
| 5281 | @node GNU Free Documentation License | 5110 | @node GNU Free Documentation License |
| 5282 | @appendix GNU Free Documentation License | 5111 | @appendix GNU Free Documentation License |
| 5283 | @include doclicense.texi | 5112 | @include doclicense.texi |
diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi index 896eba2f1bb..e57fcc8adf1 100644 --- a/doc/misc/emacs-mime.texi +++ b/doc/misc/emacs-mime.texi | |||
| @@ -1516,16 +1516,16 @@ Here's a bunch of time/date/second/day examples: | |||
| 1516 | @result{} 905595714.0 | 1516 | @result{} 905595714.0 |
| 1517 | 1517 | ||
| 1518 | (seconds-to-time 905595714.0) | 1518 | (seconds-to-time 905595714.0) |
| 1519 | @result{} (13818 19266 0) | 1519 | @result{} (13818 19266 0 0) |
| 1520 | 1520 | ||
| 1521 | (time-to-days '(13818 19266)) | 1521 | (time-to-days '(13818 19266)) |
| 1522 | @result{} 729644 | 1522 | @result{} 729644 |
| 1523 | 1523 | ||
| 1524 | (days-to-time 729644) | 1524 | (days-to-time 729644) |
| 1525 | @result{} (961933 65536) | 1525 | @result{} (961933 512) |
| 1526 | 1526 | ||
| 1527 | (time-since '(13818 19266)) | 1527 | (time-since '(13818 19266)) |
| 1528 | @result{} (0 430) | 1528 | @result{} (6797 9607 984839 247000) |
| 1529 | 1529 | ||
| 1530 | (time-less-p '(13818 19266) '(13818 19145)) | 1530 | (time-less-p '(13818 19266) '(13818 19145)) |
| 1531 | @result{} nil | 1531 | @result{} nil |
| @@ -1546,7 +1546,7 @@ Here's a bunch of time/date/second/day examples: | |||
| 1546 | (time-to-number-of-days | 1546 | (time-to-number-of-days |
| 1547 | (time-since | 1547 | (time-since |
| 1548 | (date-to-time "Mon, 01 Jan 2001 02:22:26 GMT"))) | 1548 | (date-to-time "Mon, 01 Jan 2001 02:22:26 GMT"))) |
| 1549 | @result{} 4.146122685185185 | 1549 | @result{} 4314.095589286675 |
| 1550 | @end example | 1550 | @end example |
| 1551 | 1551 | ||
| 1552 | And finally, we have @code{safe-date-to-time}, which does the same as | 1552 | And finally, we have @code{safe-date-to-time}, which does the same as |
| @@ -1561,7 +1561,7 @@ An RFC822 (or similar) date string. For instance: @code{"Sat Sep 12 | |||
| 1561 | 12:21:54 1998 +0200"}. | 1561 | 12:21:54 1998 +0200"}. |
| 1562 | 1562 | ||
| 1563 | @item time | 1563 | @item time |
| 1564 | An internal Emacs time. For instance: @code{(13818 26466)}. | 1564 | An internal Emacs time. For instance: @code{(13818 26466 0 0)}. |
| 1565 | 1565 | ||
| 1566 | @item seconds | 1566 | @item seconds |
| 1567 | A floating point representation of the internal Emacs time. For | 1567 | A floating point representation of the internal Emacs time. For |
diff --git a/doc/misc/org.texi b/doc/misc/org.texi index 89c99018460..a69dc0fd81f 100644 --- a/doc/misc/org.texi +++ b/doc/misc/org.texi | |||
| @@ -857,7 +857,7 @@ Theory Ltd.} | |||
| 857 | @b{Important:} @i{If you the version of Org that comes with Emacs or as a | 857 | @b{Important:} @i{If you the version of Org that comes with Emacs or as a |
| 858 | XEmacs package, please skip this section and go directly to @ref{Activation}. | 858 | XEmacs package, please skip this section and go directly to @ref{Activation}. |
| 859 | If you downloaded Org as an ELPA package, please read the instructions on the | 859 | If you downloaded Org as an ELPA package, please read the instructions on the |
| 860 | @uref{http://orgmode.org/elpa/, Org ELPA page}. To see what version of Org | 860 | @uref{http://orgmode.org/elpa.html, Org ELPA page}. To see what version of Org |
| 861 | (if any) is part of your Emacs distribution, type @kbd{M-x org-version} (if | 861 | (if any) is part of your Emacs distribution, type @kbd{M-x org-version} (if |
| 862 | your Emacs distribution does not come with Org, this function will not be | 862 | your Emacs distribution does not come with Org, this function will not be |
| 863 | defined).} | 863 | defined).} |
| @@ -964,13 +964,6 @@ on your system). | |||
| 964 | make install-info | 964 | make install-info |
| 965 | @end example | 965 | @end example |
| 966 | 966 | ||
| 967 | Then add the following line to @file{.emacs}. It is needed so that | ||
| 968 | Emacs can autoload functions that are located in files not immediately loaded | ||
| 969 | when Org mode starts. | ||
| 970 | @lisp | ||
| 971 | (require 'org-install) | ||
| 972 | @end lisp | ||
| 973 | |||
| 974 | Do not forget to activate Org as described in the following section. | 967 | Do not forget to activate Org as described in the following section. |
| 975 | @page | 968 | @page |
| 976 | 969 | ||
| @@ -1092,9 +1085,6 @@ shown below. | |||
| 1092 | ;; add latest org-mode to load path | 1085 | ;; add latest org-mode to load path |
| 1093 | (add-to-list 'load-path (expand-file-name "/path/to/org-mode/lisp")) | 1086 | (add-to-list 'load-path (expand-file-name "/path/to/org-mode/lisp")) |
| 1094 | (add-to-list 'load-path (expand-file-name "/path/to/org-mode/contrib/lisp" t)) | 1087 | (add-to-list 'load-path (expand-file-name "/path/to/org-mode/contrib/lisp" t)) |
| 1095 | |||
| 1096 | ;; activate org | ||
| 1097 | (require 'org-install) | ||
| 1098 | @end example | 1088 | @end example |
| 1099 | 1089 | ||
| 1100 | If an error occurs, a backtrace can be very useful (see below on how to | 1090 | If an error occurs, a backtrace can be very useful (see below on how to |
| @@ -3785,7 +3775,7 @@ mostly if more than two TODO states are possible (@pxref{TODO | |||
| 3785 | extensions}). See also @ref{Conflicts}, for a discussion of the interaction | 3775 | extensions}). See also @ref{Conflicts}, for a discussion of the interaction |
| 3786 | with @code{shift-selection-mode}. See also the variable | 3776 | with @code{shift-selection-mode}. See also the variable |
| 3787 | @code{org-treat-S-cursor-todo-selection-as-state-change}. | 3777 | @code{org-treat-S-cursor-todo-selection-as-state-change}. |
| 3788 | @orgcmd{C-c / t,org-show-todo-key} | 3778 | @orgcmd{C-c / t,org-show-todo-tree} |
| 3789 | @cindex sparse tree, for TODO | 3779 | @cindex sparse tree, for TODO |
| 3790 | @vindex org-todo-keywords | 3780 | @vindex org-todo-keywords |
| 3791 | View TODO items in a @emph{sparse tree} (@pxref{Sparse trees}). Folds the | 3781 | View TODO items in a @emph{sparse tree} (@pxref{Sparse trees}). Folds the |
| @@ -9386,16 +9376,16 @@ so often, shortcuts are provided using the Easy Templates facility | |||
| 9386 | @item C-c ' | 9376 | @item C-c ' |
| 9387 | Edit the source code example at point in its native mode. This works by | 9377 | Edit the source code example at point in its native mode. This works by |
| 9388 | switching to a temporary buffer with the source code. You need to exit by | 9378 | switching to a temporary buffer with the source code. You need to exit by |
| 9389 | pressing @kbd{C-c '} again@footnote{Upon exit, lines starting with @samp{*} | 9379 | pressing @kbd{C-c '} again@footnote{Upon exit, lines starting with @samp{*}, |
| 9390 | or @samp{#} will get a comma prepended, to keep them from being interpreted | 9380 | @samp{,*}, @samp{#+} and @samp{,#+} will get a comma prepended, to keep them |
| 9391 | by Org as outline nodes or special comments. These commas will be stripped | 9381 | from being interpreted by Org as outline nodes or special syntax. These |
| 9392 | for editing with @kbd{C-c '}, and also for export.}. The edited version will | 9382 | commas will be stripped for editing with @kbd{C-c '}, and also for export.}. |
| 9393 | then replace the old version in the Org buffer. Fixed-width regions | 9383 | The edited version will then replace the old version in the Org buffer. |
| 9394 | (where each line starts with a colon followed by a space) will be edited | 9384 | Fixed-width regions (where each line starts with a colon followed by a space) |
| 9395 | using @code{artist-mode}@footnote{You may select a different-mode with the | 9385 | will be edited using @code{artist-mode}@footnote{You may select |
| 9396 | variable @code{org-edit-fixed-width-region-mode}.} to allow creating ASCII | 9386 | a different-mode with the variable @code{org-edit-fixed-width-region-mode}.} |
| 9397 | drawings easily. Using this command in an empty line will create a new | 9387 | to allow creating ASCII drawings easily. Using this command in an empty line |
| 9398 | fixed-width region. | 9388 | will create a new fixed-width region. |
| 9399 | @kindex C-c l | 9389 | @kindex C-c l |
| 9400 | @item C-c l | 9390 | @item C-c l |
| 9401 | Calling @code{org-store-link} while editing a source code example in a | 9391 | Calling @code{org-store-link} while editing a source code example in a |
| @@ -14523,14 +14513,13 @@ Be sure to adjust the paths to fit your system. | |||
| 14523 | # | 14513 | # |
| 14524 | DIR=`pwd` | 14514 | DIR=`pwd` |
| 14525 | FILES="" | 14515 | FILES="" |
| 14526 | ORGINSTALL="~/src/org/lisp/org-install.el" | ||
| 14527 | 14516 | ||
| 14528 | # wrap each argument in the code required to call tangle on it | 14517 | # wrap each argument in the code required to call tangle on it |
| 14529 | for i in $@@; do | 14518 | for i in $@@; do |
| 14530 | FILES="$FILES \"$i\"" | 14519 | FILES="$FILES \"$i\"" |
| 14531 | done | 14520 | done |
| 14532 | 14521 | ||
| 14533 | emacs -Q --batch -l $ORGINSTALL \ | 14522 | emacs -Q --batch \ |
| 14534 | --eval "(progn | 14523 | --eval "(progn |
| 14535 | (add-to-list 'load-path (expand-file-name \"~/src/org/lisp/\")) | 14524 | (add-to-list 'load-path (expand-file-name \"~/src/org/lisp/\")) |
| 14536 | (add-to-list 'load-path (expand-file-name \"~/src/org/contrib/lisp/\" t)) | 14525 | (add-to-list 'load-path (expand-file-name \"~/src/org/contrib/lisp/\" t)) |
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 46f99acbb87..a983f76ffd3 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi | |||
| @@ -2918,7 +2918,8 @@ information about remote hosts is kept in the file specified in | |||
| 2918 | @code{tramp-persistency-file-name}. Keep this file. If you are | 2918 | @code{tramp-persistency-file-name}. Keep this file. If you are |
| 2919 | confident that files on remote hosts are not changed out of | 2919 | confident that files on remote hosts are not changed out of |
| 2920 | @value{emacsname}' control, set @code{remote-file-name-inhibit-cache} | 2920 | @value{emacsname}' control, set @code{remote-file-name-inhibit-cache} |
| 2921 | to @code{nil}. | 2921 | to @code{nil}. Set also @code{tramp-completion-reread-directory-timeout} |
| 2922 | to @code{nil}, @ref{Filename completion}. | ||
| 2922 | 2923 | ||
| 2923 | Disable version control. If you access remote files which are not | 2924 | Disable version control. If you access remote files which are not |
| 2924 | under version control, a lot of check operations can be avoided by | 2925 | under version control, a lot of check operations can be avoided by |