aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorChong Yidong2012-02-05 14:44:47 +0800
committerChong Yidong2012-02-05 14:44:47 +0800
commit03988c98dfbb4506ada95f52e4a34071627c3b49 (patch)
treea4c4d5fcbf9fa063519f5b688de89c2c1e3cadda /doc
parent98366438c7163579bfc47b0d2eabe875081d51b6 (diff)
downloademacs-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/ChangeLog15
-rw-r--r--doc/lispref/customize.texi123
-rw-r--r--doc/lispref/elisp.texi2
-rw-r--r--doc/lispref/eval.texi91
-rw-r--r--doc/lispref/macros.texi142
-rw-r--r--doc/lispref/vol1.texi2
-rw-r--r--doc/lispref/vol2.texi2
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 @@
12012-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
12012-02-05 Glenn Morris <rgm@gnu.org> 162012-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
28for faces) accept keyword arguments for specifying various information. 28sections (@code{defcustom}, @code{defgroup}, etc.) all accept keyword
29This section describes some keywords that apply to all kinds. 29arguments for specifying various information. This section describes
30keywords 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
32in a given item. Each use of the keyword has an independent effect. 33in 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
108for example, @code{(info-link :tag "foo" "(emacs)Top")} makes a link to 109for example, @code{(info-link :tag "foo" "(emacs)Top")} makes a link to
109the Emacs manual which appears in the buffer as @samp{foo}. 110the Emacs manual which appears in the buffer as @samp{foo}.
110 111
111An item can have more than one external link; however, most items have 112You can use this keyword more than once, to add multiple links.
112none 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}
137This keyword specifies that the item was first introduced in 137This 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
139value was changed in that version. The value of @var{package} is a 139value was changed in that version. This keyword takes priority over
140symbol and @var{version} is a string. 140@code{:version}.
141 141
142This 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 144package @var{package} is released as part of Emacs, @var{package} and
145or 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}
229If the name of an item in the group starts with @var{prefix}, then the 228If the name of an item in the group starts with @var{prefix}, and the
230tag for that item is constructed (by default) by omitting @var{prefix}. 229customizable variable @code{custom-unlispify-remove-prefixes} is
231 230non-@code{nil}, the item's tag will omit @var{prefix}. A group can
232One group can have any number of prefixes. 231have 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
237that @code{:prefix} currently has no effect. We did this because we 236If this variable is non-@code{nil}, the prefixes specified by a
238found that discarding the specified prefixes often led to confusing 237group's @code{:prefix} keyword are omitted from tag names, whenever
239names for options. This happened because the people who wrote the 238the user customizes the group.
240@code{defgroup} definitions for various groups added @code{:prefix}
241keywords whenever they make logical sense---that is, whenever the
242variables in the library have a common prefix.
243
244 In order to obtain good results with @code{:prefix}, it would be
245necessary to check the specific effects of discarding a particular
246prefix, given the specific items in a group and their names and
247documentation. If the resulting text is not clear, then @code{:prefix}
248should not be used in that case.
249 239
250 It should be possible to recheck all the customization groups, delete 240The default value is @code{nil}, i.e.@: the prefix-discarding feature
251the @code{:prefix} specifications which give unclear results, and then 241is disabled. This is because discarding prefixes often leads to
252turn this feature back on, if someone would like to do the work. 242confusing 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{}
262This macro declares @var{option} as a customizable @dfn{user option}. 251This macro declares @var{option} as a user option (i.e.@: a
263You should not quote @var{option}. 252customizable variable). You should not quote @var{option}.
264 253
265The argument @var{standard} is an expression that specifies the 254The argument @var{standard} is an expression that specifies the
266standard value for @var{option}. Evaluating the @code{defcustom} form 255standard value for @var{option}. Evaluating the @code{defcustom} form
@@ -275,31 +264,25 @@ cases applies, @code{defcustom} installs the result of evaluating
275The expression @var{standard} can be evaluated at various other times, 264The expression @var{standard} can be evaluated at various other times,
276too---whenever the customization facility needs to know @var{option}'s 265too---whenever the customization facility needs to know @var{option}'s
277standard value. So be sure to use an expression which is harmless to 266standard value. So be sure to use an expression which is harmless to
278evaluate at any time. We recommend avoiding backquotes in 267evaluate at any time.
279@var{standard}, because they are not expanded when editing the value,
280so list values will appear to have the wrong structure.
281 268
282The argument @var{doc} specifies the documentation string for the 269The argument @var{doc} specifies the documentation string for the
283variable. 270variable.
284 271
285Every @code{defcustom} should specify @code{:group} at least once. 272Every @code{defcustom} should specify @code{:group} at least once.
286 273
287If you specify the @code{:set} keyword, to make the variable take other
288special actions when set through the customization buffer, the
289variable's documentation string should tell the user specifically how
290to do the same job in hand-written Lisp code.
291
292When you evaluate a @code{defcustom} form with @kbd{C-M-x} in Emacs Lisp 274When you evaluate a @code{defcustom} form with @kbd{C-M-x} in Emacs Lisp
293mode (@code{eval-defun}), a special feature of @code{eval-defun} 275mode (@code{eval-defun}), a special feature of @code{eval-defun}
294arranges to set the variable unconditionally, without testing whether 276arranges to set the variable unconditionally, without testing whether
295its value is void. (The same feature applies to @code{defvar}.) 277its value is void. (The same feature applies to @code{defvar}.)
296@xref{Defining Variables}. 278@xref{Defining Variables}.
297 279
298If you put a @code{defcustom} in a file that is preloaded at dump time 280If 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
300variable at that time might not be correct, use 282might be incorrect, e.g.@: because another variable that it depends on
283has 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
302standard value during or after Emacs startup. 285standard 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
330the option as a Lisp variable). The default for @var{setfunction} is 313the option as a Lisp variable). The default for @var{setfunction} is
331@code{set-default}. 314@code{set-default}.
332 315
316If you specify this keyword, the variable's documentation string
317should 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}
335Specify @var{getfunction} as the way to extract the value of this 321Specify @var{getfunction} as the way to extract the value of this
@@ -341,7 +327,7 @@ value). The default is @code{default-value}.
341You have to really understand the workings of Custom to use 327You 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
343Custom as variables but are not actually stored in Lisp variables. It 329Custom as variables but are not actually stored in Lisp variables. It
344is almost surely a mistake to specify @code{getfunction} for a value 330is almost surely a mistake to specify @var{getfunction} for a value
345that really is stored in a Lisp variable. 331that 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
380These functions behave like @code{custom-initialize-set} 366These 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.
382If an error occurs during initialization, they set the variable to 368If 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
385These two functions are only meant for options defined in pre-loaded 371These functions are meant for options defined in pre-loaded files,
386files, where some variables or functions used to compute the option's 372where the @var{standard} expression may signal an error because some
387value may not yet be defined. The option normally gets updated in 373required variable or function is not yet defined. The value normally
388@file{startup.el}, ignoring the previously computed value. Because of 374gets updated in @file{startup.el}, ignoring the value computed by
389this typical usage, the value which these two functions compute 375@code{defcustom}. After startup, if one unsets the value and
390normally only matters when, after startup, one unsets the option's 376reevaluates the @code{defcustom}, the @var{standard} expression can be
391value and then reevaluates the defcustom. By that time, the necessary 377evaluated without error.
392variables 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
459This function re-evaluates the standard value of @var{symbol}, which 444This function re-evaluates the standard value of @var{symbol}, which
460should be a user option declared via @code{defcustom}. (If the 445should be a user option declared via @code{defcustom}. If the
461variable was customized, this function re-evaluates the saved value 446variable was customized, this function re-evaluates the saved value
462instead.) This is useful for customizable options that are defined 447instead. Then it sets the user option to that value (using the
463before their value could be computed correctly, such as variables 448option's @code{:set} property if that is defined).
464defined in packages that are loaded at dump time, but depend on the 449
465run-time information. For example, the value could be a file whose 450This is useful for customizable options that are defined before their
466precise name depends on the hierarchy of files when Emacs runs, or a 451value could be computed correctly. For example, during startup Emacs
467name of a program that needs to be searched at run time. 452calls this function for some user options that were defined in
468 453pre-loaded Emacs Lisp files, but whose initial values depend on
469A good place to put calls to this function is in the function 454information available only at run-time.
470@code{command-line} that is run during startup (@pxref{Startup Summary})
471or 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
379Kinds of Forms 380Kinds 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
579to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote 580to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote
580only part of a list, while computing and substituting other parts. 581only 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
590selectively evaluate elements of that list. In the simplest case, it
591is 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
597For 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
612indicates a value that isn't constant. The Emacs Lisp evaluator
613evaluates the argument of @samp{,}, and puts the value in the list
614structure:
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
624Substitution with @samp{,} is allowed at deeper levels of the list
625structure 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,
637using the special marker @samp{,@@}. The elements of the spliced list
638become elements at the same level as the other elements of the resulting
639list. The equivalent code without using @samp{`} is often unreadable.
640Here 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
78case of a @code{&rest} argument. And the macro body executes and 77case of a @code{&rest} argument. And the macro body executes and
79returns its value just as a function body does. 78returns 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
82value returned by the macro body is not the value of the macro call. 81the value returned by the macro body is an alternate Lisp expression,
83Instead, it is an alternate expression for computing that value, also 82also known as the @dfn{expansion} of the macro. The Lisp interpreter
84known as the @dfn{expansion} of the macro. The Lisp interpreter
85proceeds to evaluate the expansion as soon as it comes back from the 83proceeds to evaluate the expansion as soon as it comes back from the
86macro. 84macro.
87 85
@@ -221,7 +219,26 @@ any @code{interactive} declaration is ignored since macros cannot be
221called interactively. 219called 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
223of 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,
225which can specify how @key{TAB} should indent macro calls, and how to 242which can specify how @key{TAB} should indent macro calls, and how to
226step through them for Edebug. 243step through them for Edebug.
227 244
@@ -259,107 +276,11 @@ without evaluating any @var{specs}.
259has no effect on how the macro expands, on what the macro means in the 276has no effect on how the macro expands, on what the macro means in the
260program. It only affects the secondary features listed above. 277program. 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
269constants and nonconstant parts. To make this easier, use the @samp{`}
270syntax (usually called @dfn{backquote}).
271
272 Backquote allows you to quote a list, but selectively evaluate
273elements of that list. In the simplest case, it is identical to the
274special form @code{quote} (@pxref{Quoting}). For example, these
275two 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)}
289The special marker @samp{,} inside of the argument to backquote
290indicates a value that isn't constant. Backquote evaluates the
291argument 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
305structure 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,
323using the special marker @samp{,@@}. The elements of the spliced list
324become elements at the same level as the other elements of the resulting
325list. The equivalent code without using @samp{`} is often unreadable.
326Here 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
362This section describes some important consequences that can lead to 283section describes some important consequences that can lead to
363trouble, and rules to follow to avoid trouble. 284trouble, 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
409the arguments will be evaluated when the expansion is executed. The 330the arguments will be evaluated when the expansion is executed. The
410following macro (used to facilitate iteration) illustrates the problem. 331following macro (used to facilitate iteration) illustrates the
411This macro allows us to write a simple ``for'' loop such as one might 332problem. This macro allows us to write a ``for'' loop construct.
412find 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
687specify how to @key{TAB} should indent calls to the macro. You 607(@pxref{Defining Macros}) to specify how to @key{TAB} should indent
688write it like this: 608calls 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
716calculate the indentation of a line within this expression. The 636calculate the indentation of a line within this expression. The
717function receives two arguments: 637function receives two arguments:
638
718@table @asis 639@table @asis
719@item @var{state} 640@item @var{state}
720The value returned by @code{parse-partial-sexp} (a Lisp primitive for 641The 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}
724The position at which the line being indented begins. 645The position at which the line being indented begins.
725@end table 646@end table
647
726@noindent 648@noindent
727It should return either a number, which is the number of columns of 649It should return either a number, which is the number of columns of
728indentation for that line, or a list whose car is such a number. The 650indentation 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
395Kinds of Forms 396Kinds 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
394Kinds of Forms 395Kinds 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.