diff options
| author | Chong Yidong | 2012-02-05 14:44:47 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-02-05 14:44:47 +0800 |
| commit | 03988c98dfbb4506ada95f52e4a34071627c3b49 (patch) | |
| tree | a4c4d5fcbf9fa063519f5b688de89c2c1e3cadda /doc | |
| parent | 98366438c7163579bfc47b0d2eabe875081d51b6 (diff) | |
| download | emacs-03988c98dfbb4506ada95f52e4a34071627c3b49.tar.gz emacs-03988c98dfbb4506ada95f52e4a34071627c3b49.zip | |
Updates to Macros and Customization chapters of Lisp manual.
* doc/lispref/customize.texi (Common Keywords): Minor clarifications.
Document custom-unlispify-remove-prefixes.
(Variable Definitions): Backquotes in defcustom seem to work fine
now. Various other copyedits.
* doc/lispref/macros.texi (Expansion): Minor clarification.
(Backquote): Move node to eval.texi.
(Defining Macros): Move an example from Backquote node.
(Argument Evaluation): No need to mention Pascal.
(Indenting Macros): Add xref to Defining Macros.
* doc/lispref/eval.texi (Backquote): Move from macros.texi.
* lisp/custom.el (defcustom): Doc fix.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/ChangeLog | 15 | ||||
| -rw-r--r-- | doc/lispref/customize.texi | 123 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 2 | ||||
| -rw-r--r-- | doc/lispref/eval.texi | 91 | ||||
| -rw-r--r-- | doc/lispref/macros.texi | 142 | ||||
| -rw-r--r-- | doc/lispref/vol1.texi | 2 | ||||
| -rw-r--r-- | doc/lispref/vol2.texi | 2 |
7 files changed, 194 insertions, 183 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 65740feeee5..bd7b27bbe60 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2012-02-05 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * customize.texi (Common Keywords): Minor clarifications. | ||
| 4 | Document custom-unlispify-remove-prefixes. | ||
| 5 | (Variable Definitions): Backquotes in defcustom seem to work fine | ||
| 6 | now. Various other copyedits. | ||
| 7 | |||
| 8 | * eval.texi (Backquote): Move from macros.texi. | ||
| 9 | |||
| 10 | * macros.texi (Expansion): Minor clarification. | ||
| 11 | (Backquote): Move node to eval.texi. | ||
| 12 | (Defining Macros): Move an example from Backquote node. | ||
| 13 | (Argument Evaluation): No need to mention Pascal. | ||
| 14 | (Indenting Macros): Add xref to Defining Macros. | ||
| 15 | |||
| 1 | 2012-02-05 Glenn Morris <rgm@gnu.org> | 16 | 2012-02-05 Glenn Morris <rgm@gnu.org> |
| 2 | 17 | ||
| 3 | * debugging.texi (Error Debugging): Mention debug-on-event default. | 18 | * debugging.texi (Error Debugging): Mention debug-on-event default. |
diff --git a/doc/lispref/customize.texi b/doc/lispref/customize.texi index 6d6c5df10ed..b8c30fff8ae 100644 --- a/doc/lispref/customize.texi +++ b/doc/lispref/customize.texi | |||
| @@ -24,9 +24,10 @@ definitions---as well as face definitions (@pxref{Defining Faces}). | |||
| 24 | @section Common Item Keywords | 24 | @section Common Item Keywords |
| 25 | 25 | ||
| 26 | @cindex customization keywords | 26 | @cindex customization keywords |
| 27 | All kinds of customization declarations (for variables and groups, and | 27 | The customization declarations that we will describe in the next few |
| 28 | for faces) accept keyword arguments for specifying various information. | 28 | sections (@code{defcustom}, @code{defgroup}, etc.) all accept keyword |
| 29 | This section describes some keywords that apply to all kinds. | 29 | arguments for specifying various information. This section describes |
| 30 | keywords that apply to all types of customization declarations. | ||
| 30 | 31 | ||
| 31 | All of these keywords, except @code{:tag}, can be used more than once | 32 | All of these keywords, except @code{:tag}, can be used more than once |
| 32 | in a given item. Each use of the keyword has an independent effect. | 33 | in a given item. Each use of the keyword has an independent effect. |
| @@ -108,8 +109,7 @@ You can specify the text to use in the customization buffer by adding | |||
| 108 | for example, @code{(info-link :tag "foo" "(emacs)Top")} makes a link to | 109 | for example, @code{(info-link :tag "foo" "(emacs)Top")} makes a link to |
| 109 | the Emacs manual which appears in the buffer as @samp{foo}. | 110 | the Emacs manual which appears in the buffer as @samp{foo}. |
| 110 | 111 | ||
| 111 | An item can have more than one external link; however, most items have | 112 | You can use this keyword more than once, to add multiple links. |
| 112 | none at all. | ||
| 113 | 113 | ||
| 114 | @item :load @var{file} | 114 | @item :load @var{file} |
| 115 | @kindex load@r{, customization keyword} | 115 | @kindex load@r{, customization keyword} |
| @@ -136,14 +136,13 @@ version. The value @var{version} must be a string. | |||
| 136 | @kindex package-version@r{, customization keyword} | 136 | @kindex package-version@r{, customization keyword} |
| 137 | This keyword specifies that the item was first introduced in | 137 | This keyword specifies that the item was first introduced in |
| 138 | @var{package} version @var{version}, or that its meaning or default | 138 | @var{package} version @var{version}, or that its meaning or default |
| 139 | value was changed in that version. The value of @var{package} is a | 139 | value was changed in that version. This keyword takes priority over |
| 140 | symbol and @var{version} is a string. | 140 | @code{:version}. |
| 141 | 141 | ||
| 142 | This keyword takes priority over @code{:version}. | 142 | @var{package} should be the official name of the package, as a symbol |
| 143 | 143 | (e.g.@: @code{MH-E}). @var{version} should be a string. If the | |
| 144 | @var{package} should be the official name of the package, such as MH-E | 144 | package @var{package} is released as part of Emacs, @var{package} and |
| 145 | or Gnus. If the package @var{package} is released as part of Emacs, | 145 | @var{version} should appear in the value of |
| 146 | @var{package} and @var{version} should appear in the value of | ||
| 147 | @code{customize-package-emacs-version-alist}. | 146 | @code{customize-package-emacs-version-alist}. |
| 148 | @end table | 147 | @end table |
| 149 | 148 | ||
| @@ -226,41 +225,31 @@ also use this keyword in @code{defgroup}: | |||
| 226 | @table @code | 225 | @table @code |
| 227 | @item :prefix @var{prefix} | 226 | @item :prefix @var{prefix} |
| 228 | @kindex prefix@r{, @code{defgroup} keyword} | 227 | @kindex prefix@r{, @code{defgroup} keyword} |
| 229 | If the name of an item in the group starts with @var{prefix}, then the | 228 | If the name of an item in the group starts with @var{prefix}, and the |
| 230 | tag for that item is constructed (by default) by omitting @var{prefix}. | 229 | customizable variable @code{custom-unlispify-remove-prefixes} is |
| 231 | 230 | non-@code{nil}, the item's tag will omit @var{prefix}. A group can | |
| 232 | One group can have any number of prefixes. | 231 | have any number of prefixes. |
| 233 | @end table | 232 | @end table |
| 234 | @end defmac | 233 | @end defmac |
| 235 | 234 | ||
| 236 | The prefix-discarding feature is currently turned off, which means | 235 | @defopt custom-unlispify-remove-prefixes |
| 237 | that @code{:prefix} currently has no effect. We did this because we | 236 | If this variable is non-@code{nil}, the prefixes specified by a |
| 238 | found that discarding the specified prefixes often led to confusing | 237 | group's @code{:prefix} keyword are omitted from tag names, whenever |
| 239 | names for options. This happened because the people who wrote the | 238 | the user customizes the group. |
| 240 | @code{defgroup} definitions for various groups added @code{:prefix} | ||
| 241 | keywords whenever they make logical sense---that is, whenever the | ||
| 242 | variables in the library have a common prefix. | ||
| 243 | |||
| 244 | In order to obtain good results with @code{:prefix}, it would be | ||
| 245 | necessary to check the specific effects of discarding a particular | ||
| 246 | prefix, given the specific items in a group and their names and | ||
| 247 | documentation. If the resulting text is not clear, then @code{:prefix} | ||
| 248 | should not be used in that case. | ||
| 249 | 239 | ||
| 250 | It should be possible to recheck all the customization groups, delete | 240 | The default value is @code{nil}, i.e.@: the prefix-discarding feature |
| 251 | the @code{:prefix} specifications which give unclear results, and then | 241 | is disabled. This is because discarding prefixes often leads to |
| 252 | turn this feature back on, if someone would like to do the work. | 242 | confusing names for options and faces. |
| 243 | @end defopt | ||
| 253 | 244 | ||
| 254 | @node Variable Definitions | 245 | @node Variable Definitions |
| 255 | @section Defining Customization Variables | 246 | @section Defining Customization Variables |
| 256 | @cindex define customization options | 247 | @cindex define customization options |
| 257 | @cindex customization variables, how to define | 248 | @cindex customization variables, how to define |
| 258 | 249 | ||
| 259 | Use @code{defcustom} to declare user-customizable variables. | ||
| 260 | |||
| 261 | @defmac defcustom option standard doc [keyword value]@dots{} | 250 | @defmac defcustom option standard doc [keyword value]@dots{} |
| 262 | This macro declares @var{option} as a customizable @dfn{user option}. | 251 | This macro declares @var{option} as a user option (i.e.@: a |
| 263 | You should not quote @var{option}. | 252 | customizable variable). You should not quote @var{option}. |
| 264 | 253 | ||
| 265 | The argument @var{standard} is an expression that specifies the | 254 | The argument @var{standard} is an expression that specifies the |
| 266 | standard value for @var{option}. Evaluating the @code{defcustom} form | 255 | standard value for @var{option}. Evaluating the @code{defcustom} form |
| @@ -275,31 +264,25 @@ cases applies, @code{defcustom} installs the result of evaluating | |||
| 275 | The expression @var{standard} can be evaluated at various other times, | 264 | The expression @var{standard} can be evaluated at various other times, |
| 276 | too---whenever the customization facility needs to know @var{option}'s | 265 | too---whenever the customization facility needs to know @var{option}'s |
| 277 | standard value. So be sure to use an expression which is harmless to | 266 | standard value. So be sure to use an expression which is harmless to |
| 278 | evaluate at any time. We recommend avoiding backquotes in | 267 | evaluate at any time. |
| 279 | @var{standard}, because they are not expanded when editing the value, | ||
| 280 | so list values will appear to have the wrong structure. | ||
| 281 | 268 | ||
| 282 | The argument @var{doc} specifies the documentation string for the | 269 | The argument @var{doc} specifies the documentation string for the |
| 283 | variable. | 270 | variable. |
| 284 | 271 | ||
| 285 | Every @code{defcustom} should specify @code{:group} at least once. | 272 | Every @code{defcustom} should specify @code{:group} at least once. |
| 286 | 273 | ||
| 287 | If you specify the @code{:set} keyword, to make the variable take other | ||
| 288 | special actions when set through the customization buffer, the | ||
| 289 | variable's documentation string should tell the user specifically how | ||
| 290 | to do the same job in hand-written Lisp code. | ||
| 291 | |||
| 292 | When you evaluate a @code{defcustom} form with @kbd{C-M-x} in Emacs Lisp | 274 | When you evaluate a @code{defcustom} form with @kbd{C-M-x} in Emacs Lisp |
| 293 | mode (@code{eval-defun}), a special feature of @code{eval-defun} | 275 | mode (@code{eval-defun}), a special feature of @code{eval-defun} |
| 294 | arranges to set the variable unconditionally, without testing whether | 276 | arranges to set the variable unconditionally, without testing whether |
| 295 | its value is void. (The same feature applies to @code{defvar}.) | 277 | its value is void. (The same feature applies to @code{defvar}.) |
| 296 | @xref{Defining Variables}. | 278 | @xref{Defining Variables}. |
| 297 | 279 | ||
| 298 | If you put a @code{defcustom} in a file that is preloaded at dump time | 280 | If you put a @code{defcustom} in a pre-loaded Emacs Lisp file |
| 299 | (@pxref{Building Emacs}), and the standard value installed for the | 281 | (@pxref{Building Emacs}), the standard value installed at dump time |
| 300 | variable at that time might not be correct, use | 282 | might be incorrect, e.g.@: because another variable that it depends on |
| 283 | has not been assigned the right value yet. In that case, use | ||
| 301 | @code{custom-reevaluate-setting}, described below, to re-evaluate the | 284 | @code{custom-reevaluate-setting}, described below, to re-evaluate the |
| 302 | standard value during or after Emacs startup. | 285 | standard value after Emacs starts up. |
| 303 | @end defmac | 286 | @end defmac |
| 304 | 287 | ||
| 305 | @code{defcustom} accepts the following additional keywords: | 288 | @code{defcustom} accepts the following additional keywords: |
| @@ -330,6 +313,9 @@ the value properly for this option (which may not mean simply setting | |||
| 330 | the option as a Lisp variable). The default for @var{setfunction} is | 313 | the option as a Lisp variable). The default for @var{setfunction} is |
| 331 | @code{set-default}. | 314 | @code{set-default}. |
| 332 | 315 | ||
| 316 | If you specify this keyword, the variable's documentation string | ||
| 317 | should describe how to do the same job in hand-written Lisp code. | ||
| 318 | |||
| 333 | @item :get @var{getfunction} | 319 | @item :get @var{getfunction} |
| 334 | @kindex get@r{, @code{defcustom} keyword} | 320 | @kindex get@r{, @code{defcustom} keyword} |
| 335 | Specify @var{getfunction} as the way to extract the value of this | 321 | Specify @var{getfunction} as the way to extract the value of this |
| @@ -341,7 +327,7 @@ value). The default is @code{default-value}. | |||
| 341 | You have to really understand the workings of Custom to use | 327 | You have to really understand the workings of Custom to use |
| 342 | @code{:get} correctly. It is meant for values that are treated in | 328 | @code{:get} correctly. It is meant for values that are treated in |
| 343 | Custom as variables but are not actually stored in Lisp variables. It | 329 | Custom as variables but are not actually stored in Lisp variables. It |
| 344 | is almost surely a mistake to specify @code{getfunction} for a value | 330 | is almost surely a mistake to specify @var{getfunction} for a value |
| 345 | that really is stored in a Lisp variable. | 331 | that really is stored in a Lisp variable. |
| 346 | 332 | ||
| 347 | @item :initialize @var{function} | 333 | @item :initialize @var{function} |
| @@ -380,16 +366,15 @@ already set or has been customized; otherwise, just use | |||
| 380 | These functions behave like @code{custom-initialize-set} | 366 | These functions behave like @code{custom-initialize-set} |
| 381 | (@code{custom-initialize-default}, respectively), but catch errors. | 367 | (@code{custom-initialize-default}, respectively), but catch errors. |
| 382 | If an error occurs during initialization, they set the variable to | 368 | If an error occurs during initialization, they set the variable to |
| 383 | @code{nil} using @code{set-default}, and throw no error. | 369 | @code{nil} using @code{set-default}, and signal no error. |
| 384 | 370 | ||
| 385 | These two functions are only meant for options defined in pre-loaded | 371 | These functions are meant for options defined in pre-loaded files, |
| 386 | files, where some variables or functions used to compute the option's | 372 | where the @var{standard} expression may signal an error because some |
| 387 | value may not yet be defined. The option normally gets updated in | 373 | required variable or function is not yet defined. The value normally |
| 388 | @file{startup.el}, ignoring the previously computed value. Because of | 374 | gets updated in @file{startup.el}, ignoring the value computed by |
| 389 | this typical usage, the value which these two functions compute | 375 | @code{defcustom}. After startup, if one unsets the value and |
| 390 | normally only matters when, after startup, one unsets the option's | 376 | reevaluates the @code{defcustom}, the @var{standard} expression can be |
| 391 | value and then reevaluates the defcustom. By that time, the necessary | 377 | evaluated without error. |
| 392 | variables and functions will be defined, so there will not be an error. | ||
| 393 | @end table | 378 | @end table |
| 394 | 379 | ||
| 395 | @item :risky @var{value} | 380 | @item :risky @var{value} |
| @@ -457,18 +442,16 @@ is an expression that evaluates to the value. | |||
| 457 | 442 | ||
| 458 | @defun custom-reevaluate-setting symbol | 443 | @defun custom-reevaluate-setting symbol |
| 459 | This function re-evaluates the standard value of @var{symbol}, which | 444 | This function re-evaluates the standard value of @var{symbol}, which |
| 460 | should be a user option declared via @code{defcustom}. (If the | 445 | should be a user option declared via @code{defcustom}. If the |
| 461 | variable was customized, this function re-evaluates the saved value | 446 | variable was customized, this function re-evaluates the saved value |
| 462 | instead.) This is useful for customizable options that are defined | 447 | instead. Then it sets the user option to that value (using the |
| 463 | before their value could be computed correctly, such as variables | 448 | option's @code{:set} property if that is defined). |
| 464 | defined in packages that are loaded at dump time, but depend on the | 449 | |
| 465 | run-time information. For example, the value could be a file whose | 450 | This is useful for customizable options that are defined before their |
| 466 | precise name depends on the hierarchy of files when Emacs runs, or a | 451 | value could be computed correctly. For example, during startup Emacs |
| 467 | name of a program that needs to be searched at run time. | 452 | calls this function for some user options that were defined in |
| 468 | 453 | pre-loaded Emacs Lisp files, but whose initial values depend on | |
| 469 | A good place to put calls to this function is in the function | 454 | information available only at run-time. |
| 470 | @code{command-line} that is run during startup (@pxref{Startup Summary}) | ||
| 471 | or in the various hooks it calls. | ||
| 472 | @end defun | 455 | @end defun |
| 473 | 456 | ||
| 474 | @defun custom-variable-p arg | 457 | @defun custom-variable-p arg |
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index b4692cd33ce..f69823101d0 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -374,6 +374,7 @@ Evaluation | |||
| 374 | * Forms:: How various sorts of objects are evaluated. | 374 | * Forms:: How various sorts of objects are evaluated. |
| 375 | * Quoting:: Avoiding evaluation (to put constants in | 375 | * Quoting:: Avoiding evaluation (to put constants in |
| 376 | the program). | 376 | the program). |
| 377 | * Backquote:: Easier construction of list structure. | ||
| 377 | * Eval:: How to invoke the Lisp interpreter explicitly. | 378 | * Eval:: How to invoke the Lisp interpreter explicitly. |
| 378 | 379 | ||
| 379 | Kinds of Forms | 380 | Kinds of Forms |
| @@ -482,7 +483,6 @@ Macros | |||
| 482 | * Expansion:: How, when and why macros are expanded. | 483 | * Expansion:: How, when and why macros are expanded. |
| 483 | * Compiling Macros:: How macros are expanded by the compiler. | 484 | * Compiling Macros:: How macros are expanded by the compiler. |
| 484 | * Defining Macros:: How to write a macro definition. | 485 | * Defining Macros:: How to write a macro definition. |
| 485 | * Backquote:: Easier construction of list structure. | ||
| 486 | * Problems with Macros:: Don't evaluate the macro arguments too many times. | 486 | * Problems with Macros:: Don't evaluate the macro arguments too many times. |
| 487 | Don't hide the user's variables. | 487 | Don't hide the user's variables. |
| 488 | * Indenting Macros:: Specifying how to indent macro calls. | 488 | * Indenting Macros:: Specifying how to indent macro calls. |
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi index e81efd10892..cb3a4c54fac 100644 --- a/doc/lispref/eval.texi +++ b/doc/lispref/eval.texi | |||
| @@ -23,6 +23,7 @@ function @code{eval}. | |||
| 23 | * Intro Eval:: Evaluation in the scheme of things. | 23 | * Intro Eval:: Evaluation in the scheme of things. |
| 24 | * Forms:: How various sorts of objects are evaluated. | 24 | * Forms:: How various sorts of objects are evaluated. |
| 25 | * Quoting:: Avoiding evaluation (to put constants in the program). | 25 | * Quoting:: Avoiding evaluation (to put constants in the program). |
| 26 | * Backquote:: Easier construction of list structure. | ||
| 26 | * Eval:: How to invoke the Lisp interpreter explicitly. | 27 | * Eval:: How to invoke the Lisp interpreter explicitly. |
| 27 | @end menu | 28 | @end menu |
| 28 | 29 | ||
| @@ -579,6 +580,96 @@ Functions}), which causes an anonymous lambda expression written in Lisp | |||
| 579 | to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote | 580 | to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote |
| 580 | only part of a list, while computing and substituting other parts. | 581 | only part of a list, while computing and substituting other parts. |
| 581 | 582 | ||
| 583 | @node Backquote | ||
| 584 | @section Backquote | ||
| 585 | @cindex backquote (list substitution) | ||
| 586 | @cindex ` (list substitution) | ||
| 587 | @findex ` | ||
| 588 | |||
| 589 | @dfn{Backquote constructs} allow you to quote a list, but | ||
| 590 | selectively evaluate elements of that list. In the simplest case, it | ||
| 591 | is identical to the special form @code{quote} | ||
| 592 | @iftex | ||
| 593 | @end iftex | ||
| 594 | @ifnottex | ||
| 595 | (described in the previous section; @pxref{Quoting}). | ||
| 596 | @end ifnottex | ||
| 597 | For example, these two forms yield identical results: | ||
| 598 | |||
| 599 | @example | ||
| 600 | @group | ||
| 601 | `(a list of (+ 2 3) elements) | ||
| 602 | @result{} (a list of (+ 2 3) elements) | ||
| 603 | @end group | ||
| 604 | @group | ||
| 605 | '(a list of (+ 2 3) elements) | ||
| 606 | @result{} (a list of (+ 2 3) elements) | ||
| 607 | @end group | ||
| 608 | @end example | ||
| 609 | |||
| 610 | @findex , @r{(with backquote)} | ||
| 611 | The special marker @samp{,} inside of the argument to backquote | ||
| 612 | indicates a value that isn't constant. The Emacs Lisp evaluator | ||
| 613 | evaluates the argument of @samp{,}, and puts the value in the list | ||
| 614 | structure: | ||
| 615 | |||
| 616 | @example | ||
| 617 | @group | ||
| 618 | `(a list of ,(+ 2 3) elements) | ||
| 619 | @result{} (a list of 5 elements) | ||
| 620 | @end group | ||
| 621 | @end example | ||
| 622 | |||
| 623 | @noindent | ||
| 624 | Substitution with @samp{,} is allowed at deeper levels of the list | ||
| 625 | structure also. For example: | ||
| 626 | |||
| 627 | @example | ||
| 628 | @group | ||
| 629 | `(1 2 (3 ,(+ 4 5))) | ||
| 630 | @result{} (1 2 (3 9)) | ||
| 631 | @end group | ||
| 632 | @end example | ||
| 633 | |||
| 634 | @findex ,@@ @r{(with backquote)} | ||
| 635 | @cindex splicing (with backquote) | ||
| 636 | You can also @dfn{splice} an evaluated value into the resulting list, | ||
| 637 | using the special marker @samp{,@@}. The elements of the spliced list | ||
| 638 | become elements at the same level as the other elements of the resulting | ||
| 639 | list. The equivalent code without using @samp{`} is often unreadable. | ||
| 640 | Here are some examples: | ||
| 641 | |||
| 642 | @example | ||
| 643 | @group | ||
| 644 | (setq some-list '(2 3)) | ||
| 645 | @result{} (2 3) | ||
| 646 | @end group | ||
| 647 | @group | ||
| 648 | (cons 1 (append some-list '(4) some-list)) | ||
| 649 | @result{} (1 2 3 4 2 3) | ||
| 650 | @end group | ||
| 651 | @group | ||
| 652 | `(1 ,@@some-list 4 ,@@some-list) | ||
| 653 | @result{} (1 2 3 4 2 3) | ||
| 654 | @end group | ||
| 655 | |||
| 656 | @group | ||
| 657 | (setq list '(hack foo bar)) | ||
| 658 | @result{} (hack foo bar) | ||
| 659 | @end group | ||
| 660 | @group | ||
| 661 | (cons 'use | ||
| 662 | (cons 'the | ||
| 663 | (cons 'words (append (cdr list) '(as elements))))) | ||
| 664 | @result{} (use the words foo bar as elements) | ||
| 665 | @end group | ||
| 666 | @group | ||
| 667 | `(use the words ,@@(cdr list) as elements) | ||
| 668 | @result{} (use the words foo bar as elements) | ||
| 669 | @end group | ||
| 670 | @end example | ||
| 671 | |||
| 672 | |||
| 582 | @node Eval | 673 | @node Eval |
| 583 | @section Eval | 674 | @section Eval |
| 584 | 675 | ||
diff --git a/doc/lispref/macros.texi b/doc/lispref/macros.texi index 3804d963108..dca88d2b7c7 100644 --- a/doc/lispref/macros.texi +++ b/doc/lispref/macros.texi | |||
| @@ -27,7 +27,6 @@ instead. @xref{Inline Functions}. | |||
| 27 | * Expansion:: How, when and why macros are expanded. | 27 | * Expansion:: How, when and why macros are expanded. |
| 28 | * Compiling Macros:: How macros are expanded by the compiler. | 28 | * Compiling Macros:: How macros are expanded by the compiler. |
| 29 | * Defining Macros:: How to write a macro definition. | 29 | * Defining Macros:: How to write a macro definition. |
| 30 | * Backquote:: Easier construction of list structure. | ||
| 31 | * Problems with Macros:: Don't evaluate the macro arguments too many times. | 30 | * Problems with Macros:: Don't evaluate the macro arguments too many times. |
| 32 | Don't hide the user's variables. | 31 | Don't hide the user's variables. |
| 33 | * Indenting Macros:: Specifying how to indent macro calls. | 32 | * Indenting Macros:: Specifying how to indent macro calls. |
| @@ -78,10 +77,9 @@ to the argument values from the macro call, or to a list of them in the | |||
| 78 | case of a @code{&rest} argument. And the macro body executes and | 77 | case of a @code{&rest} argument. And the macro body executes and |
| 79 | returns its value just as a function body does. | 78 | returns its value just as a function body does. |
| 80 | 79 | ||
| 81 | The second crucial difference between macros and functions is that the | 80 | The second crucial difference between macros and functions is that |
| 82 | value returned by the macro body is not the value of the macro call. | 81 | the value returned by the macro body is an alternate Lisp expression, |
| 83 | Instead, it is an alternate expression for computing that value, also | 82 | also known as the @dfn{expansion} of the macro. The Lisp interpreter |
| 84 | known as the @dfn{expansion} of the macro. The Lisp interpreter | ||
| 85 | proceeds to evaluate the expansion as soon as it comes back from the | 83 | proceeds to evaluate the expansion as soon as it comes back from the |
| 86 | macro. | 84 | macro. |
| 87 | 85 | ||
| @@ -221,7 +219,26 @@ any @code{interactive} declaration is ignored since macros cannot be | |||
| 221 | called interactively. | 219 | called interactively. |
| 222 | @end defspec | 220 | @end defspec |
| 223 | 221 | ||
| 224 | The body of the macro definition can include a @code{declare} form, | 222 | Macros often need to construct large list structures from a mixture |
| 223 | of constants and nonconstant parts. To make this easier, use the | ||
| 224 | @samp{`} syntax (@pxref{Backquote}). For example: | ||
| 225 | |||
| 226 | @example | ||
| 227 | @example | ||
| 228 | @group | ||
| 229 | (defmacro t-becomes-nil (variable) | ||
| 230 | `(if (eq ,variable t) | ||
| 231 | (setq ,variable nil))) | ||
| 232 | @end group | ||
| 233 | |||
| 234 | @group | ||
| 235 | (t-becomes-nil foo) | ||
| 236 | @equiv{} (if (eq foo t) (setq foo nil)) | ||
| 237 | @end group | ||
| 238 | @end example | ||
| 239 | @end example | ||
| 240 | |||
| 241 | The body of a macro definition can include a @code{declare} form, | ||
| 225 | which can specify how @key{TAB} should indent macro calls, and how to | 242 | which can specify how @key{TAB} should indent macro calls, and how to |
| 226 | step through them for Edebug. | 243 | step through them for Edebug. |
| 227 | 244 | ||
| @@ -259,107 +276,11 @@ without evaluating any @var{specs}. | |||
| 259 | has no effect on how the macro expands, on what the macro means in the | 276 | has no effect on how the macro expands, on what the macro means in the |
| 260 | program. It only affects the secondary features listed above. | 277 | program. It only affects the secondary features listed above. |
| 261 | 278 | ||
| 262 | @node Backquote | ||
| 263 | @section Backquote | ||
| 264 | @cindex backquote (list substitution) | ||
| 265 | @cindex ` (list substitution) | ||
| 266 | @findex ` | ||
| 267 | |||
| 268 | Macros often need to construct large list structures from a mixture of | ||
| 269 | constants and nonconstant parts. To make this easier, use the @samp{`} | ||
| 270 | syntax (usually called @dfn{backquote}). | ||
| 271 | |||
| 272 | Backquote allows you to quote a list, but selectively evaluate | ||
| 273 | elements of that list. In the simplest case, it is identical to the | ||
| 274 | special form @code{quote} (@pxref{Quoting}). For example, these | ||
| 275 | two forms yield identical results: | ||
| 276 | |||
| 277 | @example | ||
| 278 | @group | ||
| 279 | `(a list of (+ 2 3) elements) | ||
| 280 | @result{} (a list of (+ 2 3) elements) | ||
| 281 | @end group | ||
| 282 | @group | ||
| 283 | '(a list of (+ 2 3) elements) | ||
| 284 | @result{} (a list of (+ 2 3) elements) | ||
| 285 | @end group | ||
| 286 | @end example | ||
| 287 | |||
| 288 | @findex , @r{(with backquote)} | ||
| 289 | The special marker @samp{,} inside of the argument to backquote | ||
| 290 | indicates a value that isn't constant. Backquote evaluates the | ||
| 291 | argument of @samp{,} and puts the value in the list structure: | ||
| 292 | |||
| 293 | @example | ||
| 294 | @group | ||
| 295 | (list 'a 'list 'of (+ 2 3) 'elements) | ||
| 296 | @result{} (a list of 5 elements) | ||
| 297 | @end group | ||
| 298 | @group | ||
| 299 | `(a list of ,(+ 2 3) elements) | ||
| 300 | @result{} (a list of 5 elements) | ||
| 301 | @end group | ||
| 302 | @end example | ||
| 303 | |||
| 304 | Substitution with @samp{,} is allowed at deeper levels of the list | ||
| 305 | structure also. For example: | ||
| 306 | |||
| 307 | @example | ||
| 308 | @group | ||
| 309 | (defmacro t-becomes-nil (variable) | ||
| 310 | `(if (eq ,variable t) | ||
| 311 | (setq ,variable nil))) | ||
| 312 | @end group | ||
| 313 | |||
| 314 | @group | ||
| 315 | (t-becomes-nil foo) | ||
| 316 | @equiv{} (if (eq foo t) (setq foo nil)) | ||
| 317 | @end group | ||
| 318 | @end example | ||
| 319 | |||
| 320 | @findex ,@@ @r{(with backquote)} | ||
| 321 | @cindex splicing (with backquote) | ||
| 322 | You can also @dfn{splice} an evaluated value into the resulting list, | ||
| 323 | using the special marker @samp{,@@}. The elements of the spliced list | ||
| 324 | become elements at the same level as the other elements of the resulting | ||
| 325 | list. The equivalent code without using @samp{`} is often unreadable. | ||
| 326 | Here are some examples: | ||
| 327 | |||
| 328 | @example | ||
| 329 | @group | ||
| 330 | (setq some-list '(2 3)) | ||
| 331 | @result{} (2 3) | ||
| 332 | @end group | ||
| 333 | @group | ||
| 334 | (cons 1 (append some-list '(4) some-list)) | ||
| 335 | @result{} (1 2 3 4 2 3) | ||
| 336 | @end group | ||
| 337 | @group | ||
| 338 | `(1 ,@@some-list 4 ,@@some-list) | ||
| 339 | @result{} (1 2 3 4 2 3) | ||
| 340 | @end group | ||
| 341 | |||
| 342 | @group | ||
| 343 | (setq list '(hack foo bar)) | ||
| 344 | @result{} (hack foo bar) | ||
| 345 | @end group | ||
| 346 | @group | ||
| 347 | (cons 'use | ||
| 348 | (cons 'the | ||
| 349 | (cons 'words (append (cdr list) '(as elements))))) | ||
| 350 | @result{} (use the words foo bar as elements) | ||
| 351 | @end group | ||
| 352 | @group | ||
| 353 | `(use the words ,@@(cdr list) as elements) | ||
| 354 | @result{} (use the words foo bar as elements) | ||
| 355 | @end group | ||
| 356 | @end example | ||
| 357 | |||
| 358 | @node Problems with Macros | 279 | @node Problems with Macros |
| 359 | @section Common Problems Using Macros | 280 | @section Common Problems Using Macros |
| 360 | 281 | ||
| 361 | The basic facts of macro expansion have counterintuitive consequences. | 282 | Macro expansion can have counterintuitive consequences. This |
| 362 | This section describes some important consequences that can lead to | 283 | section describes some important consequences that can lead to |
| 363 | trouble, and rules to follow to avoid trouble. | 284 | trouble, and rules to follow to avoid trouble. |
| 364 | 285 | ||
| 365 | @menu | 286 | @menu |
| @@ -407,9 +328,8 @@ program is actually run. | |||
| 407 | 328 | ||
| 408 | When defining a macro you must pay attention to the number of times | 329 | When defining a macro you must pay attention to the number of times |
| 409 | the arguments will be evaluated when the expansion is executed. The | 330 | the arguments will be evaluated when the expansion is executed. The |
| 410 | following macro (used to facilitate iteration) illustrates the problem. | 331 | following macro (used to facilitate iteration) illustrates the |
| 411 | This macro allows us to write a simple ``for'' loop such as one might | 332 | problem. This macro allows us to write a ``for'' loop construct. |
| 412 | find in Pascal. | ||
| 413 | 333 | ||
| 414 | @findex for | 334 | @findex for |
| 415 | @smallexample | 335 | @smallexample |
| @@ -683,9 +603,9 @@ either. | |||
| 683 | @node Indenting Macros | 603 | @node Indenting Macros |
| 684 | @section Indenting Macros | 604 | @section Indenting Macros |
| 685 | 605 | ||
| 686 | You can use the @code{declare} form in the macro definition to | 606 | Within a macro definition, you can use the @code{declare} form |
| 687 | specify how to @key{TAB} should indent calls to the macro. You | 607 | (@pxref{Defining Macros}) to specify how to @key{TAB} should indent |
| 688 | write it like this: | 608 | calls to the macro. An indentation specifiction is written like this: |
| 689 | 609 | ||
| 690 | @example | 610 | @example |
| 691 | (declare (indent @var{indent-spec})) | 611 | (declare (indent @var{indent-spec})) |
| @@ -715,6 +635,7 @@ the line uses the standard pattern. | |||
| 715 | @var{symbol} should be a function name; that function is called to | 635 | @var{symbol} should be a function name; that function is called to |
| 716 | calculate the indentation of a line within this expression. The | 636 | calculate the indentation of a line within this expression. The |
| 717 | function receives two arguments: | 637 | function receives two arguments: |
| 638 | |||
| 718 | @table @asis | 639 | @table @asis |
| 719 | @item @var{state} | 640 | @item @var{state} |
| 720 | The value returned by @code{parse-partial-sexp} (a Lisp primitive for | 641 | The value returned by @code{parse-partial-sexp} (a Lisp primitive for |
| @@ -723,6 +644,7 @@ beginning of this line. | |||
| 723 | @item @var{pos} | 644 | @item @var{pos} |
| 724 | The position at which the line being indented begins. | 645 | The position at which the line being indented begins. |
| 725 | @end table | 646 | @end table |
| 647 | |||
| 726 | @noindent | 648 | @noindent |
| 727 | It should return either a number, which is the number of columns of | 649 | It should return either a number, which is the number of columns of |
| 728 | indentation for that line, or a list whose car is such a number. The | 650 | indentation for that line, or a list whose car is such a number. The |
diff --git a/doc/lispref/vol1.texi b/doc/lispref/vol1.texi index 4a48536f5f3..0f4a4447ed3 100644 --- a/doc/lispref/vol1.texi +++ b/doc/lispref/vol1.texi | |||
| @@ -390,6 +390,7 @@ Evaluation | |||
| 390 | * Forms:: How various sorts of objects are evaluated. | 390 | * Forms:: How various sorts of objects are evaluated. |
| 391 | * Quoting:: Avoiding evaluation (to put constants in | 391 | * Quoting:: Avoiding evaluation (to put constants in |
| 392 | the program). | 392 | the program). |
| 393 | * Backquote:: Easier construction of list structure. | ||
| 393 | * Eval:: How to invoke the Lisp interpreter explicitly. | 394 | * Eval:: How to invoke the Lisp interpreter explicitly. |
| 394 | 395 | ||
| 395 | Kinds of Forms | 396 | Kinds of Forms |
| @@ -501,7 +502,6 @@ Macros | |||
| 501 | * Expansion:: How, when and why macros are expanded. | 502 | * Expansion:: How, when and why macros are expanded. |
| 502 | * Compiling Macros:: How macros are expanded by the compiler. | 503 | * Compiling Macros:: How macros are expanded by the compiler. |
| 503 | * Defining Macros:: How to write a macro definition. | 504 | * Defining Macros:: How to write a macro definition. |
| 504 | * Backquote:: Easier construction of list structure. | ||
| 505 | * Problems with Macros:: Don't evaluate the macro arguments too many times. | 505 | * Problems with Macros:: Don't evaluate the macro arguments too many times. |
| 506 | Don't hide the user's variables. | 506 | Don't hide the user's variables. |
| 507 | * Indenting Macros:: Specifying how to indent macro calls. | 507 | * Indenting Macros:: Specifying how to indent macro calls. |
diff --git a/doc/lispref/vol2.texi b/doc/lispref/vol2.texi index 961b3225823..241728fd1d2 100644 --- a/doc/lispref/vol2.texi +++ b/doc/lispref/vol2.texi | |||
| @@ -389,6 +389,7 @@ Evaluation | |||
| 389 | * Forms:: How various sorts of objects are evaluated. | 389 | * Forms:: How various sorts of objects are evaluated. |
| 390 | * Quoting:: Avoiding evaluation (to put constants in | 390 | * Quoting:: Avoiding evaluation (to put constants in |
| 391 | the program). | 391 | the program). |
| 392 | * Backquote:: Easier construction of list structure. | ||
| 392 | * Eval:: How to invoke the Lisp interpreter explicitly. | 393 | * Eval:: How to invoke the Lisp interpreter explicitly. |
| 393 | 394 | ||
| 394 | Kinds of Forms | 395 | Kinds of Forms |
| @@ -500,7 +501,6 @@ Macros | |||
| 500 | * Expansion:: How, when and why macros are expanded. | 501 | * Expansion:: How, when and why macros are expanded. |
| 501 | * Compiling Macros:: How macros are expanded by the compiler. | 502 | * Compiling Macros:: How macros are expanded by the compiler. |
| 502 | * Defining Macros:: How to write a macro definition. | 503 | * Defining Macros:: How to write a macro definition. |
| 503 | * Backquote:: Easier construction of list structure. | ||
| 504 | * Problems with Macros:: Don't evaluate the macro arguments too many times. | 504 | * Problems with Macros:: Don't evaluate the macro arguments too many times. |
| 505 | Don't hide the user's variables. | 505 | Don't hide the user's variables. |
| 506 | * Indenting Macros:: Specifying how to indent macro calls. | 506 | * Indenting Macros:: Specifying how to indent macro calls. |