aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorJoakim Verona2012-02-05 14:40:28 +0100
committerJoakim Verona2012-02-05 14:40:28 +0100
commit8c5c7f5afa968d06efb6788cf680d5463c389d85 (patch)
treea70876b87a7dbdcb936524880492f8fdc661fab0 /doc
parentfbdce5fed745bc78911980466d9374d1101487fc (diff)
parent1ff980ae49715eb372acff8a193e36497a7665c4 (diff)
downloademacs-8c5c7f5afa968d06efb6788cf680d5463c389d85.tar.gz
emacs-8c5c7f5afa968d06efb6788cf680d5463c389d85.zip
ustream
Diffstat (limited to 'doc')
-rw-r--r--doc/emacs/ChangeLog22
-rw-r--r--doc/emacs/display.texi18
-rw-r--r--doc/emacs/files.texi10
-rw-r--r--doc/emacs/frames.texi1
-rw-r--r--doc/emacs/macos.texi12
-rw-r--r--doc/emacs/maintaining.texi5
-rw-r--r--doc/emacs/trouble.texi6
-rw-r--r--doc/emacs/windows.texi13
-rw-r--r--doc/lispintro/ChangeLog2
-rw-r--r--doc/lispref/ChangeLog106
-rw-r--r--doc/lispref/backups.texi3
-rw-r--r--doc/lispref/commands.texi12
-rw-r--r--doc/lispref/customize.texi123
-rw-r--r--doc/lispref/debugging.texi9
-rw-r--r--doc/lispref/display.texi82
-rw-r--r--doc/lispref/elisp.texi4
-rw-r--r--doc/lispref/eval.texi118
-rw-r--r--doc/lispref/functions.texi671
-rw-r--r--doc/lispref/help.texi11
-rw-r--r--doc/lispref/hooks.texi9
-rw-r--r--doc/lispref/macros.texi142
-rw-r--r--doc/lispref/minibuf.texi12
-rw-r--r--doc/lispref/modes.texi95
-rw-r--r--doc/lispref/numbers.texi2
-rw-r--r--doc/lispref/processes.texi3
-rw-r--r--doc/lispref/syntax.texi16
-rw-r--r--doc/lispref/text.texi57
-rw-r--r--doc/lispref/variables.texi137
-rw-r--r--doc/lispref/vol1.texi4
-rw-r--r--doc/lispref/vol2.texi4
-rw-r--r--doc/misc/ChangeLog5
-rw-r--r--doc/misc/gnus.texi5
32 files changed, 968 insertions, 751 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index 871422f9bfe..ab4161c75b8 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,23 @@
12012-02-05 Glenn Morris <rgm@gnu.org>
2
3 * trouble.texi (Checklist): Mention debug-on-event.
4
5 * maintaining.texi (Maintaining): Add cross-ref to ERT.
6
72012-02-04 Glenn Morris <rgm@gnu.org>
8
9 * macos.texi (Customization options specific to Mac OS / GNUstep):
10 New subsection.
11
12 * display.texi (Colors): Mention list-colors-sort.
13
14 * files.texi (File Conveniences): Mention image animation.
15
162012-01-31 Chong Yidong <cyd@gnu.org>
17
18 * windows.texi (Split Window): C-mouse-2 doesn't work on GTK+
19 scroll bars (Bug#10666).
20
12012-01-28 Chong Yidong <cyd@gnu.org> 212012-01-28 Chong Yidong <cyd@gnu.org>
2 22
3 * files.texi (Filesets): Fix typos. 23 * files.texi (Filesets): Fix typos.
@@ -8,7 +28,7 @@
8 28
9 * buffers.texi (Select Buffer): Clarify explanation of switching 29 * buffers.texi (Select Buffer): Clarify explanation of switching
10 to new buffers. Fix description of next-buffer and 30 to new buffers. Fix description of next-buffer and
11 previous-buffer (Bug#10334). 31 previous-buffer (Bug#10334).
12 (Misc Buffer): Add xref to View Mode. 32 (Misc Buffer): Add xref to View Mode.
13 33
14 * text.texi (Fill Commands): Fix description of 34 * text.texi (Fill Commands): Fix description of
diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index 6e69b723204..8159b8cc6aa 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -524,16 +524,18 @@ specify a color for a face---for instance, when customizing the face
524or an @dfn{RGB triplet}. 524or an @dfn{RGB triplet}.
525 525
526@findex list-colors-display 526@findex list-colors-display
527@vindex list-colors-sort
527 A color name is a pre-defined name, such as @samp{dark orange} or 528 A color name is a pre-defined name, such as @samp{dark orange} or
528@samp{medium sea green}. To view a list of color names, type @kbd{M-x 529@samp{medium sea green}. To view a list of color names, type @kbd{M-x
529list-colors-display}. If you run this command on a graphical display, 530list-colors-display}. To control the order in which colors are shown,
530it shows the full range of color names known to Emacs (these are the 531customize @code{list-colors-sort}. If you run this command on a
531standard X11 color names, defined in X's @file{rgb.txt} file). If you 532graphical display, it shows the full range of color names known to Emacs
532run the command on a text-only terminal, it shows only a small subset 533(these are the standard X11 color names, defined in X's @file{rgb.txt}
533of colors that can be safely displayed on such terminals. However, 534file). If you run the command on a text-only terminal, it shows only a
534Emacs understands X11 color names even on text-only terminals; if a 535small subset of colors that can be safely displayed on such terminals.
535face is given a color specified by an X11 color name, it is displayed 536However, Emacs understands X11 color names even on text-only terminals;
536using the closest-matching terminal color. 537if a face is given a color specified by an X11 color name, it is
538displayed using the closest-matching terminal color.
537 539
538 An RGB triplet is a string of the form @samp{#RRGGBB}. Each of the 540 An RGB triplet is a string of the form @samp{#RRGGBB}. Each of the
539R, G, and B components is a hexadecimal number specifying the 541R, G, and B components is a hexadecimal number specifying the
diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index 081614aa3b9..b2eb68d2812 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -1907,7 +1907,10 @@ point. Partial Completion mode offers other features extending
1907 1907
1908@findex image-mode 1908@findex image-mode
1909@findex image-toggle-display 1909@findex image-toggle-display
1910@findex image-toggle-animation
1910@cindex images, viewing 1911@cindex images, viewing
1912@cindex image animation
1913@cindex animated images
1911 Visiting image files automatically selects Image mode. This major 1914 Visiting image files automatically selects Image mode. This major
1912mode allows you to toggle between displaying the file as an image in 1915mode allows you to toggle between displaying the file as an image in
1913the Emacs buffer, and displaying its underlying text representation, 1916the Emacs buffer, and displaying its underlying text representation,
@@ -1915,7 +1918,12 @@ using the command @kbd{C-c C-c} (@code{image-toggle-display}). This
1915works only when Emacs can display the specific image type. If the 1918works only when Emacs can display the specific image type. If the
1916displayed image is wider or taller than the frame, the usual point 1919displayed image is wider or taller than the frame, the usual point
1917motion keys (@kbd{C-f}, @kbd{C-p}, and so forth) cause different parts 1920motion keys (@kbd{C-f}, @kbd{C-p}, and so forth) cause different parts
1918of the image to be displayed. 1921of the image to be displayed. If the image can be animated, then
1922the command @kbd{RET} (@code{image-toggle-animation}), will start (or
1923stop) animating it. Animation plays once, unless the option
1924@code{image-animate-loop} is non-@code{nil}. Currently, Emacs only
1925supports animated GIF files (@pxref{Animated Images,,, elisp, The Emacs
1926Lisp Reference Manual}).
1919 1927
1920@findex thumbs-mode 1928@findex thumbs-mode
1921@findex mode, thumbs 1929@findex mode, thumbs
diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi
index 1adeee480a6..38ee620dbd5 100644
--- a/doc/emacs/frames.texi
+++ b/doc/emacs/frames.texi
@@ -370,7 +370,6 @@ side-by-side windows with the boundary running through the click
370position (@pxref{Split Window}). 370position (@pxref{Split Window}).
371@end table 371@end table
372 372
373@kindex C-Mouse-2 @r{(scroll bar)}
374@kindex Mouse-1 @r{(scroll bar)} 373@kindex Mouse-1 @r{(scroll bar)}
375 Furthermore, by clicking and dragging @kbd{Mouse-1} on the divider 374 Furthermore, by clicking and dragging @kbd{Mouse-1} on the divider
376between two side-by-side mode lines, you can move the vertical 375between two side-by-side mode lines, you can move the vertical
diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi
index a36dc0cbcc5..e6d936e8e9f 100644
--- a/doc/emacs/macos.texi
+++ b/doc/emacs/macos.texi
@@ -130,6 +130,18 @@ open the dragged files in the current frame use the following line:
130@end lisp 130@end lisp
131 131
132 132
133@subsection Customization options specific to Mac OS / GNUstep
134
135The following customization options are specific to the Nextstep port.
136
137@table @code
138@item ns-auto-hide-menu-bar
139Non-nil means the menu-bar is hidden by default, but appears if you
140move the mouse pointer over it. (Requires OS X 10.6 or later.)
141
142@end table
143
144
133@node Mac / GNUstep Events, GNUstep Support, Mac / GNUstep Customization, Mac OS / GNUstep 145@node Mac / GNUstep Events, GNUstep Support, Mac / GNUstep Customization, Mac OS / GNUstep
134@section Windowing System Events under Mac OS / GNUstep 146@section Windowing System Events under Mac OS / GNUstep
135 147
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index 2ec477031ca..d2f92bf0da5 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -6,7 +6,10 @@
6@chapter Maintaining Large Programs 6@chapter Maintaining Large Programs
7 7
8 This chapter describes Emacs features for maintaining large 8 This chapter describes Emacs features for maintaining large
9programs. 9programs. If you are maintaining a large Lisp program, then in
10addition to the features described here, you may find
11the @file{ERT} (``Emacs Lisp Regression Testing'') library useful
12(@pxref{Top,,ERT,ert, Emacs Lisp Regression Testing}).
10 13
11@menu 14@menu
12* Version Control:: Using version control systems. 15* Version Control:: Using version control systems.
diff --git a/doc/emacs/trouble.texi b/doc/emacs/trouble.texi
index 8cb5ab44a2e..6c6dbea9525 100644
--- a/doc/emacs/trouble.texi
+++ b/doc/emacs/trouble.texi
@@ -784,6 +784,12 @@ non-@code{nil} will start the Lisp debugger and show a backtrace.
784This backtrace is useful for debugging such long loops, so if you can 784This backtrace is useful for debugging such long loops, so if you can
785produce it, copy it into the bug report. 785produce it, copy it into the bug report.
786 786
787@vindex debug-on-event
788If you cannot get Emacs to respond to @kbd{C-g} (e.g., because
789@code{inhibit-quit} is set), then you can try sending the signal
790specified by @code{debug-on-event} (default SIGUSR2) from outside
791Emacs to cause it to enter the debugger.
792
787@item 793@item
788Check whether any programs you have loaded into the Lisp world, 794Check whether any programs you have loaded into the Lisp world,
789including your initialization file, set any variables that may affect 795including your initialization file, set any variables that may affect
diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi
index 76ab79361e4..3733eed3eca 100644
--- a/doc/emacs/windows.texi
+++ b/doc/emacs/windows.texi
@@ -72,7 +72,7 @@ Split the selected window into two windows, one above the other
72Split the selected window into two windows, positioned side by side 72Split the selected window into two windows, positioned side by side
73(@code{split-window-right}). 73(@code{split-window-right}).
74@item C-Mouse-2 74@item C-Mouse-2
75In the mode line or scroll bar of a window, split that window. 75In the mode line of a window, split that window.
76@end table 76@end table
77 77
78@kindex C-x 2 78@kindex C-x 2
@@ -125,11 +125,14 @@ lines in every partial-width window regardless of its width.
125 On text terminals, side-by-side windows are separated by a vertical 125 On text terminals, side-by-side windows are separated by a vertical
126divider which is drawn using the @code{vertical-border} face. 126divider which is drawn using the @code{vertical-border} face.
127 127
128@kindex C-Mouse-2 @r{(mode line)}
128@kindex C-Mouse-2 @r{(scroll bar)} 129@kindex C-Mouse-2 @r{(scroll bar)}
129 You can also split a window horizontally or vertically by clicking 130 If you click @kbd{C-Mouse-2} in the mode line of a window, that
130@kbd{C-Mouse-2} in the mode line or the scroll bar. If you click on 131splits the window, putting a vertical divider where you click.
131the mode line, that puts the vertical divider where you click; if you 132Depending on how Emacs is compiled, you can also split a window by
132click in the scroll bar, that puts the new mode-line where you click. 133clicking @kbd{C-Mouse-2} in the scroll bar, which puts a horizontal
134divider where you click (this feature does not work when Emacs uses
135GTK+ scroll bars).
133 136
134@node Other Window 137@node Other Window
135@section Using Other Windows 138@section Using Other Windows
diff --git a/doc/lispintro/ChangeLog b/doc/lispintro/ChangeLog
index 66f9d3cace4..bf08571f6fb 100644
--- a/doc/lispintro/ChangeLog
+++ b/doc/lispintro/ChangeLog
@@ -1,7 +1,7 @@
12012-01-28 Andreas Schwab <schwab@linux-m68k.org> 12012-01-28 Andreas Schwab <schwab@linux-m68k.org>
2 2
3 * emacs-lisp-intro.texi (Top): Move setting of COUNT-WORDS outside 3 * emacs-lisp-intro.texi (Top): Move setting of COUNT-WORDS outside
4 of @menu. (Bug#10628) 4 of @menu. (Bug#10628)
5 5
62012-01-19 Juanma Barranquero <lekktu@gmail.com> 62012-01-19 Juanma Barranquero <lekktu@gmail.com>
7 7
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 8f949eb24dd..bd7b27bbe60 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,109 @@
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
162012-02-05 Glenn Morris <rgm@gnu.org>
17
18 * debugging.texi (Error Debugging): Mention debug-on-event default.
19
202012-02-04 Glenn Morris <rgm@gnu.org>
21
22 * backups.texi (Reverting): Mention revert-buffer-in-progress-p.
23
24 * debugging.texi (Error Debugging): Mention debug-on-event.
25 * commands.texi (Misc Events): Mention sigusr1,2 and debugging.
26
27 * modes.texi (Running Hooks): Try to clarify with-wrapper-hook.
28
29 * text.texi (Buffer Contents):
30 Update filter-buffer-substring description.
31
322012-02-04 Chong Yidong <cyd@gnu.org>
33
34 * functions.texi (What Is a Function): Add closures. Mention
35 "return value" terminology. Add xref for command-execute. Remove
36 unused "keystroke command" terminology.
37 (Lambda Expressions): Give a different example than in the
38 following subsection. Add xref to Anonymous Functions.
39 (Function Documentation): Remove gratuitous markup.
40 (Function Names): Move introductory text to `What Is a Function'.
41 (Defining Functions): Fix defun argument spec.
42 (Anonymous Functions): Document lambda macro explicitly. Mention
43 effects on lexical binding.
44 (Function Cells): Downplay direct usage of fset.
45 (Closures): New node.
46 (Inline Functions): Remove "open-code" terminology.
47 (Declaring Functions): Minor tweak; .m is not C code.
48
49 * variables.texi (Variables): Don't refer to "global value".
50 (Local Variables, Void Variables): Copyedits.
51 (Lexical Binding): Minor clarification of example.
52 (File Local Variables): Mention :safe and :risky defcustom args.
53 (Lexical Binding): Add xref to Closures node.
54
552012-02-04 Glenn Morris <rgm@gnu.org>
56
57 * minibuf.texi (High-Level Completion): Updates for read-color.
58
592012-02-03 Glenn Morris <rgm@gnu.org>
60
61 * display.texi (GIF Images): Mention animation.
62 Remove commented-out old example of animation.
63 (Animated Images): New subsection.
64 * elisp.texi (Top):
65 * vol1.texi (Top):
66 * vol2.texi (Top): Add Animated Images menu entry.
67
68 * display.texi (Image Formats): Remove oddly specific information
69 on versions of image libraries.
70 (GIF Images, TIFF Images): Minor rephrasing.
71
722012-02-02 Glenn Morris <rgm@gnu.org>
73
74 * processes.texi (Synchronous Processes):
75 Mention call-process's :file gets overwritten.
76
77 * commands.texi (Reading One Event):
78 * help.texi (Help Functions): Document read-char-choice.
79
80 * hooks.texi (Standard Hooks):
81 * modes.texi (Keymaps and Minor Modes):
82 * text.texi (Commands for Insertion): Document post-self-insert-hook.
83
84 * hooks.texi (Standard Hooks): Add prog-mode-hook.
85
86 * hooks.texi (Standard Hooks):
87 * modes.texi (Major Mode Conventions, Mode Hooks):
88 Document change-major-mode-after-body-hook.
89
902012-02-01 Glenn Morris <rgm@gnu.org>
91
92 * modes.texi (Defining Minor Modes):
93 Mention disabling global minor modes on a per-major-mode basis.
94
952012-01-31 Chong Yidong <cyd@gnu.org>
96
97 * syntax.texi (Parsing Expressions): Clarify intro (Bug#10657).
98 (Parser State): Remove unnecessary statement (Bug#10661).
99
100 * eval.texi (Intro Eval): Add footnote about "sexp" terminology.
101
1022012-01-31 Glenn Morris <rgm@gnu.org>
103
104 * modes.texi (Defining Minor Modes):
105 Document define-minor-mode's new :variable keyword.
106
12012-01-29 Chong Yidong <cyd@gnu.org> 1072012-01-29 Chong Yidong <cyd@gnu.org>
2 108
3 * syntax.texi (Syntax Class Table): Tweak description of newline 109 * syntax.texi (Syntax Class Table): Tweak description of newline
diff --git a/doc/lispref/backups.texi b/doc/lispref/backups.texi
index 969220845d0..a4b3a0b9bef 100644
--- a/doc/lispref/backups.texi
+++ b/doc/lispref/backups.texi
@@ -696,6 +696,9 @@ operation, reverting preserves all the markers. If they are not
696identical, reverting does change the buffer; in that case, it preserves 696identical, reverting does change the buffer; in that case, it preserves
697the markers in the unchanged text (if any) at the beginning and end of 697the markers in the unchanged text (if any) at the beginning and end of
698the buffer. Preserving any additional markers would be problematical. 698the buffer. Preserving any additional markers would be problematical.
699
700This command binds @code{revert-buffer-in-progress-p} to a
701non-@code{nil} value while it operates.
699@end deffn 702@end deffn
700 703
701You can customize how @code{revert-buffer} does its work by setting 704You can customize how @code{revert-buffer} does its work by setting
diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi
index 3d2b813b592..91e224a439f 100644
--- a/doc/lispref/commands.texi
+++ b/doc/lispref/commands.texi
@@ -1696,6 +1696,7 @@ parameters are used to display the help-echo text are described in
1696These events are generated when the Emacs process receives 1696These events are generated when the Emacs process receives
1697the signals @code{SIGUSR1} and @code{SIGUSR2}. They contain no 1697the signals @code{SIGUSR1} and @code{SIGUSR2}. They contain no
1698additional data because signals do not carry additional information. 1698additional data because signals do not carry additional information.
1699They can be useful for debugging (@pxref{Error Debugging}).
1699 1700
1700To catch a user signal, bind the corresponding event to an interactive 1701To catch a user signal, bind the corresponding event to an interactive
1701command in the @code{special-event-map} (@pxref{Active Keymaps}). 1702command in the @code{special-event-map} (@pxref{Active Keymaps}).
@@ -2472,6 +2473,17 @@ The argument @var{prompt} is either a string to be displayed in the
2472echo area as a prompt, or @code{nil}, meaning not to display a prompt. 2473echo area as a prompt, or @code{nil}, meaning not to display a prompt.
2473@end defun 2474@end defun
2474 2475
2476@defun read-char-choice prompt chars &optional inhibit-quit
2477This function uses @code{read-key} to read and return a single
2478character. It ignores any input that is not a member of @var{chars},
2479a list of accepted characters. Optionally, it will also ignore
2480keyboard-quit events while it is waiting for valid input. If you bind
2481@code{help-form} (@pxref{Help Functions}) to a non-@code{nil} value
2482while calling @code{read-char-choice}, then pressing @code{help-char}
2483causes it to evaluate @code{help-form} and display the result. It
2484then continues to wait for a valid input character, or keyboard-quit.
2485@end defun
2486
2475@node Event Mod 2487@node Event Mod
2476@subsection Modifying and Translating Input Events 2488@subsection Modifying and Translating Input Events
2477 2489
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/debugging.texi b/doc/lispref/debugging.texi
index 9466f21a563..cc92fc225f9 100644
--- a/doc/lispref/debugging.texi
+++ b/doc/lispref/debugging.texi
@@ -148,6 +148,15 @@ enter the debugger.
148@code{debug-on-error} is @code{nil}. 148@code{debug-on-error} is @code{nil}.
149@end defopt 149@end defopt
150 150
151@defopt debug-on-event
152If you set @code{debug-on-event} to a special event (@pxref{Special
153Events}), Emacs will try to enter the debugger as soon as it receives
154this event, bypassing @code{special-event-map}. At present, the only
155supported values correspond to the signals @code{SIGUSR1} and
156@code{SIGUSR2} (this is the default). This can be helpful when
157@code{inhibit-quit} is set and Emacs is not otherwise responding.
158@end defopt
159
151 To debug an error that happens during loading of the init 160 To debug an error that happens during loading of the init
152file, use the option @samp{--debug-init}. This binds 161file, use the option @samp{--debug-init}. This binds
153@code{debug-on-error} to @code{t} while loading the init file, and 162@code{debug-on-error} to @code{t} while loading the init file, and
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index a351dbfb407..e97e6c264a3 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -4134,6 +4134,7 @@ displayed (@pxref{Display Feature Testing}).
4134* Other Image Types:: Various other formats are supported. 4134* Other Image Types:: Various other formats are supported.
4135* Defining Images:: Convenient ways to define an image for later use. 4135* Defining Images:: Convenient ways to define an image for later use.
4136* Showing Images:: Convenient ways to display an image once it is defined. 4136* Showing Images:: Convenient ways to display an image once it is defined.
4137* Animated Images:: Some image formats can be animated.
4137* Image Cache:: Internal mechanisms of image display. 4138* Image Cache:: Internal mechanisms of image display.
4138@end menu 4139@end menu
4139 4140
@@ -4151,12 +4152,10 @@ names for these dynamic libraries (though it is not possible to add
4151new image formats). Note that image types @code{pbm} and @code{xbm} 4152new image formats). Note that image types @code{pbm} and @code{xbm}
4152do not depend on external libraries and are always available in Emacs. 4153do not depend on external libraries and are always available in Emacs.
4153 4154
4154 The supported image formats include XBM, XPM (this requires the 4155 The supported image formats (and the necessary library files)
4155libraries @code{libXpm} version 3.4k and @code{libz}), GIF (requiring 4156include XBM, XPM (@code{libXpm} and @code{libz}), GIF (@code{libgif}
4156@code{libungif} 4.1.0), PostScript, PBM, JPEG (requiring the 4157or @code{libungif}), PostScript, PBM, JPEG (@code{libjpeg}), TIFF
4157@code{libjpeg} library version v6a), TIFF (requiring @code{libtiff} 4158(@code{libtiff}), PNG (@code{libpng}), and SVG (@code{librsvg}).
4158v3.4), PNG (requiring @code{libpng} 1.0.2), and SVG (requiring
4159@code{librsvg} 2.0.0).
4160 4159
4161 You specify one of these formats with an image type symbol. The image 4160 You specify one of these formats with an image type symbol. The image
4162type symbols are @code{xbm}, @code{xpm}, @code{gif}, @code{postscript}, 4161type symbols are @code{xbm}, @code{xpm}, @code{gif}, @code{postscript},
@@ -4471,33 +4470,13 @@ specifies the actual color to use for displaying that name.
4471 4470
4472@table @code 4471@table @code
4473@item :index @var{index} 4472@item :index @var{index}
4474You can use @code{:index} to specify one image from a GIF file that 4473You can use @code{:index} to specify image number @var{index} from a
4475contains more than one image. This property specifies use of image 4474GIF file that contains more than one image. If the GIF file doesn't
4476number @var{index} from the file. If the GIF file doesn't contain an 4475contain an image with the specified index, the image displays as a
4477image with index @var{index}, the image displays as a hollow box. 4476hollow box. GIF files with more than one image can be animated,
4477@pxref{Animated Images}.
4478@end table 4478@end table
4479 4479
4480@ignore
4481This could be used to implement limited support for animated GIFs.
4482For example, the following function displays a multi-image GIF file
4483at point-min in the current buffer, switching between sub-images
4484every 0.1 seconds.
4485
4486(defun show-anim (file max)
4487 "Display multi-image GIF file FILE which contains MAX subimages."
4488 (display-anim (current-buffer) file 0 max t))
4489
4490(defun display-anim (buffer file idx max first-time)
4491 (when (= idx max)
4492 (setq idx 0))
4493 (let ((img (create-image file nil :image idx)))
4494 (with-current-buffer buffer
4495 (goto-char (point-min))
4496 (unless first-time (delete-char 1))
4497 (insert-image img))
4498 (run-with-timer 0.1 nil 'display-anim buffer file (1+ idx) max nil)))
4499@end ignore
4500
4501@node TIFF Images 4480@node TIFF Images
4502@subsection TIFF Images 4481@subsection TIFF Images
4503@cindex TIFF 4482@cindex TIFF
@@ -4506,10 +4485,10 @@ every 0.1 seconds.
4506 4485
4507@table @code 4486@table @code
4508@item :index @var{index} 4487@item :index @var{index}
4509You can use @code{:index} to specify one image from a TIFF file that 4488You can use @code{:index} to specify image number @var{index} from a
4510contains more than one image. This property specifies use of image 4489TIFF file that contains more than one image. If the TIFF file doesn't
4511number @var{index} from the file. If the TIFF file doesn't contain an 4490contain an image with the specified index, the image displays as a
4512image with index @var{index}, the image displays as a hollow box. 4491hollow box.
4513@end table 4492@end table
4514 4493
4515@node PostScript Images 4494@node PostScript Images
@@ -4857,6 +4836,39 @@ cache, it can always be displayed, even if the value of
4857@var{max-image-size} is subsequently changed (@pxref{Image Cache}). 4836@var{max-image-size} is subsequently changed (@pxref{Image Cache}).
4858@end defvar 4837@end defvar
4859 4838
4839@node Animated Images
4840@subsection Animated Images
4841
4842@cindex animation
4843@cindex image animation
4844Some image files can contain more than one image. This can be used to
4845create animation. Currently, Emacs only supports animated GIF files.
4846The following functions related to animated images are available.
4847
4848@defun image-animated-p image
4849This function returns non-nil if @var{image} can be animated.
4850The actual return value is a cons @code{(@var{nimages} . @var{delay})},
4851where @var{nimages} is the number of frames and @var{delay} is the
4852delay in seconds between them.
4853@end defun
4854
4855@defun image-animate image &optional index limit
4856This function animates @var{image}. The optional integer @var{index}
4857specifies the frame from which to start (default 0). The optional
4858argument @var{limit} controls the length of the animation. If omitted
4859or @code{nil}, the image animates once only; if @code{t} it loops
4860forever; if a number animation stops after that many seconds.
4861@end defun
4862
4863@noindent Animation operates by means of a timer. Note that Emacs imposes a
4864minimum frame delay of 0.01 seconds.
4865
4866@defun image-animate-timer image
4867This function returns the timer responsible for animating @var{image},
4868if there is one.
4869@end defun
4870
4871
4860@node Image Cache 4872@node Image Cache
4861@subsection Image Cache 4873@subsection Image Cache
4862@cindex image cache 4874@cindex image cache
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 31e887ea68b..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
@@ -459,6 +460,7 @@ Functions
459* Anonymous Functions:: Lambda expressions are functions with no names. 460* Anonymous Functions:: Lambda expressions are functions with no names.
460* Function Cells:: Accessing or setting the function definition 461* Function Cells:: Accessing or setting the function definition
461 of a symbol. 462 of a symbol.
463* Closures:: Functions that enclose a lexical environment.
462* Obsolete Functions:: Declaring functions obsolete. 464* Obsolete Functions:: Declaring functions obsolete.
463* Inline Functions:: Defining functions that the compiler 465* Inline Functions:: Defining functions that the compiler
464 will open code. 466 will open code.
@@ -481,7 +483,6 @@ Macros
481* Expansion:: How, when and why macros are expanded. 483* Expansion:: How, when and why macros are expanded.
482* Compiling Macros:: How macros are expanded by the compiler. 484* Compiling Macros:: How macros are expanded by the compiler.
483* Defining Macros:: How to write a macro definition. 485* Defining Macros:: How to write a macro definition.
484* Backquote:: Easier construction of list structure.
485* 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.
486 Don't hide the user's variables. 487 Don't hide the user's variables.
487* Indenting Macros:: Specifying how to indent macro calls. 488* Indenting Macros:: Specifying how to indent macro calls.
@@ -1351,6 +1352,7 @@ Images
1351* Defining Images:: Convenient ways to define an image for later use. 1352* Defining Images:: Convenient ways to define an image for later use.
1352* Showing Images:: Convenient ways to display an image once 1353* Showing Images:: Convenient ways to display an image once
1353 it is defined. 1354 it is defined.
1355* Animated Images:: Some image formats can be animated.
1354* Image Cache:: Internal mechanisms of image display. 1356* Image Cache:: Internal mechanisms of image display.
1355 1357
1356Buttons 1358Buttons
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi
index fc18e503543..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
@@ -39,12 +40,15 @@ interpreter.
39 40
40@cindex form 41@cindex form
41@cindex expression 42@cindex expression
42 A Lisp object that is intended for evaluation is called an 43@cindex S-expression
43@dfn{expression} or a @dfn{form}. The fact that forms are data 44 A Lisp object that is intended for evaluation is called a @dfn{form}
44objects and not merely text is one of the fundamental differences 45or @dfn{expression}@footnote{It is sometimes also referred to as an
45between Lisp-like languages and typical programming languages. Any 46@dfn{S-expression} or @dfn{sexp}, but we generally do not use this
46object can be evaluated, but in practice only numbers, symbols, lists 47terminology in this manual.}. The fact that forms are data objects
47and strings are evaluated very often. 48and not merely text is one of the fundamental differences between
49Lisp-like languages and typical programming languages. Any object can
50be evaluated, but in practice only numbers, symbols, lists and strings
51are evaluated very often.
48 52
49 In subsequent sections, we will describe the details of what 53 In subsequent sections, we will describe the details of what
50evaluation means for each kind of form. 54evaluation means for each kind of form.
@@ -96,12 +100,12 @@ interpretation. @xref{Command Loop}.
96@node Forms 100@node Forms
97@section Kinds of Forms 101@section Kinds of Forms
98 102
99 A Lisp object that is intended to be evaluated is called a @dfn{form}. 103 A Lisp object that is intended to be evaluated is called a
100How Emacs evaluates a form depends on its data type. Emacs has three 104@dfn{form} (or an @dfn{expression}). How Emacs evaluates a form
101different kinds of form that are evaluated differently: symbols, lists, 105depends on its data type. Emacs has three different kinds of form
102and ``all other types.'' This section describes all three kinds, one by 106that are evaluated differently: symbols, lists, and ``all other
103one, starting with the ``all other types'' which are self-evaluating 107types.'' This section describes all three kinds, one by one, starting
104forms. 108with the ``all other types'' which are self-evaluating forms.
105 109
106@menu 110@menu
107* Self-Evaluating Forms:: Forms that evaluate to themselves. 111* Self-Evaluating Forms:: Forms that evaluate to themselves.
@@ -576,6 +580,96 @@ Functions}), which causes an anonymous lambda expression written in Lisp
576to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote 580to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote
577only part of a list, while computing and substituting other parts. 581only part of a list, while computing and substituting other parts.
578 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
579@node Eval 673@node Eval
580@section Eval 674@section Eval
581 675
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index ada00867bd0..9ee94557066 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -21,8 +21,9 @@ define them.
21* Anonymous Functions:: Lambda expressions are functions with no names. 21* Anonymous Functions:: Lambda expressions are functions with no names.
22* Function Cells:: Accessing or setting the function definition 22* Function Cells:: Accessing or setting the function definition
23 of a symbol. 23 of a symbol.
24* Closures:: Functions that enclose a lexical environment.
24* Obsolete Functions:: Declaring functions obsolete. 25* Obsolete Functions:: Declaring functions obsolete.
25* Inline Functions:: Defining functions that the compiler will open code. 26* Inline Functions:: Functions that the compiler will expand inline.
26* Declaring Functions:: Telling the compiler that a function is defined. 27* Declaring Functions:: Telling the compiler that a function is defined.
27* Function Safety:: Determining whether a function is safe to call. 28* Function Safety:: Determining whether a function is safe to call.
28* Related Topics:: Cross-references to specific Lisp primitives 29* Related Topics:: Cross-references to specific Lisp primitives
@@ -32,104 +33,117 @@ define them.
32@node What Is a Function 33@node What Is a Function
33@section What Is a Function? 34@section What Is a Function?
34 35
35 In a general sense, a function is a rule for carrying on a computation 36@cindex return value
36given several values called @dfn{arguments}. The result of the 37@cindex value of function
37computation is called the value of the function. The computation can 38@cindex argument
38also have side effects: lasting changes in the values of variables or 39 In a general sense, a function is a rule for carrying out a
39the contents of data structures. 40computation given input values called @dfn{arguments}. The result of
40 41the computation is called the @dfn{value} or @dfn{return value} of the
41 Here are important terms for functions in Emacs Lisp and for other 42function. The computation can also have side effects, such as lasting
42function-like objects. 43changes in the values of variables or the contents of data structures.
44
45 In most computer languages, every function has a name. But in Lisp,
46a function in the strictest sense has no name: it is an object which
47can @emph{optionally} be associated with a symbol (e.g.@: @code{car})
48that serves as the function name. @xref{Function Names}. When a
49function has been given a name, we usually also refer to that symbol
50as a ``function'' (e.g.@: we refer to ``the function @code{car}'').
51In this manual, the distinction between a function name and the
52function object itself is usually unimportant, but we will take note
53wherever it is relevant.
54
55 Certain function-like objects, called @dfn{special forms} and
56@dfn{macros}, also accept arguments to carry out computations.
57However, as explained below, these are not considered functions in
58Emacs Lisp.
59
60 Here are important terms for functions and function-like objects:
43 61
44@table @dfn 62@table @dfn
45@item function 63@item lambda expression
46@cindex function 64A function (in the strict sense, i.e.@: a function object) which is
47In Emacs Lisp, a @dfn{function} is anything that can be applied to 65written in Lisp. These are described in the following section.
48arguments in a Lisp program. In some cases, we use it more 66@ifnottex
49specifically to mean a function written in Lisp. Special forms and 67@xref{Lambda Expressions}.
50macros are not functions. 68@end ifnottex
51 69
52@item primitive 70@item primitive
53@cindex primitive 71@cindex primitive
54@cindex subr 72@cindex subr
55@cindex built-in function 73@cindex built-in function
56A @dfn{primitive} is a function callable from Lisp that is written in C, 74A function which is callable from Lisp but is actually written in C.
57such as @code{car} or @code{append}. These functions are also called 75Primitives are also called @dfn{built-in functions}, or @dfn{subrs}.
58@dfn{built-in functions}, or @dfn{subrs}. (Special forms are also 76Examples include functions like @code{car} and @code{append}. In
59considered primitives.) 77addition, all special forms (see below) are also considered
60 78primitives.
61Usually the reason we implement a function as a primitive is either 79
62because it is fundamental, because it provides a low-level interface 80Usually, a function is implemented as a primitive because it is a
63to operating system services, or because it needs to run fast. 81fundamental part of Lisp (e.g.@: @code{car}), or because it provides a
64Primitives can be modified or added only by changing the C sources and 82low-level interface to operating system services, or because it needs
65recompiling the editor. See @ref{Writing Emacs Primitives}. 83to run fast. Unlike functions defined in Lisp, primitives can be
66 84modified or added only by changing the C sources and recompiling
67@item lambda expression 85Emacs. See @ref{Writing Emacs Primitives}.
68A @dfn{lambda expression} is a function written in Lisp.
69These are described in the following section.
70@ifnottex
71@xref{Lambda Expressions}.
72@end ifnottex
73 86
74@item special form 87@item special form
75A @dfn{special form} is a primitive that is like a function but does not 88A primitive that is like a function but does not evaluate all of its
76evaluate all of its arguments in the usual way. It may evaluate only 89arguments in the usual way. It may evaluate only some of the
77some of the arguments, or may evaluate them in an unusual order, or 90arguments, or may evaluate them in an unusual order, or several times.
78several times. Many special forms are described in @ref{Control 91Examples include @code{if}, @code{and}, and @code{while}.
79Structures}. 92@xref{Special Forms}.
80 93
81@item macro 94@item macro
82@cindex macro 95@cindex macro
83A @dfn{macro} is a construct defined in Lisp by the programmer. It 96A construct defined in Lisp, which differs from a function in that it
84differs from a function in that it translates a Lisp expression that you 97translates a Lisp expression into another expression which is to be
85write into an equivalent expression to be evaluated instead of the 98evaluated instead of the original expression. Macros enable Lisp
86original expression. Macros enable Lisp programmers to do the sorts of 99programmers to do the sorts of things that special forms can do.
87things that special forms can do. @xref{Macros}, for how to define and 100@xref{Macros}.
88use macros.
89 101
90@item command 102@item command
91@cindex command 103@cindex command
92A @dfn{command} is an object that @code{command-execute} can invoke; it 104An object which can be invoked via the @code{command-execute}
93is a possible definition for a key sequence. Some functions are 105primitive, usually due to the user typing in a key sequence
94commands; a function written in Lisp is a command if it contains an 106@dfn{bound} to that command. @xref{Interactive Call}. A command is
95interactive declaration (@pxref{Defining Commands}). Such a function 107usually a function; if the function is written in Lisp, it is made
96can be called from Lisp expressions like other functions; in this case, 108into a command by an @code{interactive} form in the function
97the fact that the function is a command makes no difference. 109definition (@pxref{Defining Commands}). Commands that are functions
110can also be called from Lisp expressions, just like other functions.
98 111
99Keyboard macros (strings and vectors) are commands also, even though 112Keyboard macros (strings and vectors) are commands also, even though
100they are not functions. A symbol is a command if its function 113they are not functions. @xref{Keyboard Macros}. We say that a symbol
101definition is a command; such symbols can be invoked with @kbd{M-x}. 114is a command if its function cell contains a command (@pxref{Symbol
102The symbol is a function as well if the definition is a function. 115Components}); such a @dfn{named command} can be invoked with
103@xref{Interactive Call}. 116@kbd{M-x}.
104 117
105@item keystroke command 118@item closure
106@cindex keystroke command 119A function object that is much like a lambda expression, except that
107A @dfn{keystroke command} is a command that is bound to a key sequence 120it also encloses an ``environment'' of lexical variable bindings.
108(typically one to three keystrokes). The distinction is made here 121@xref{Closures}.
109merely to avoid confusion with the meaning of ``command'' in non-Emacs
110editors; for Lisp programs, the distinction is normally unimportant.
111 122
112@item byte-code function 123@item byte-code function
113A @dfn{byte-code function} is a function that has been compiled by the 124A function that has been compiled by the byte compiler.
114byte compiler. @xref{Byte-Code Type}. 125@xref{Byte-Code Type}.
115 126
116@item autoload object 127@item autoload object
117@cindex autoload object 128@cindex autoload object
118An @dfn{autoload object} is a place-holder for a real function. If 129A place-holder for a real function. If the autoload object is called,
119the autoload object is called, it will make Emacs load the file 130Emacs loads the file containing the definition of the real function,
120containing the definition of the real function, and then call the real 131and then calls the real function. @xref{Autoload}.
121function instead.
122@end table 132@end table
123 133
134 You can use the function @code{functionp} to test if an object is a
135function:
136
124@defun functionp object 137@defun functionp object
125This function returns @code{t} if @var{object} is any kind of 138This function returns @code{t} if @var{object} is any kind of
126function, i.e.@: can be passed to @code{funcall}. Note that 139function, i.e.@: can be passed to @code{funcall}. Note that
127@code{functionp} returns @code{nil} for special forms (@pxref{Special 140@code{functionp} returns @code{t} for symbols that are function names,
128Forms}). 141and returns @code{nil} for special forms.
129@end defun 142@end defun
130 143
131Unlike @code{functionp}, the next three functions do @emph{not} 144@noindent
132treat a symbol as its function definition. 145Unlike @code{functionp}, the next three functions do @emph{not} treat
146a symbol as its function definition.
133 147
134@defun subrp object 148@defun subrp object
135This function returns @code{t} if @var{object} is a built-in function 149This function returns @code{t} if @var{object} is a built-in function
@@ -172,21 +186,26 @@ function with @code{&rest} arguments, or the symbol @code{unevalled} if
172@section Lambda Expressions 186@section Lambda Expressions
173@cindex lambda expression 187@cindex lambda expression
174 188
175 A function written in Lisp is a list that looks like this: 189 A lambda expression is a function object written in Lisp. Here is
190an example:
176 191
177@example 192@example
178(lambda (@var{arg-variables}@dots{}) 193(lambda (x)
179 @r{[}@var{documentation-string}@r{]} 194 "Return the hyperbolic cosine of X."
180 @r{[}@var{interactive-declaration}@r{]} 195 (* 0.5 (+ (exp x) (exp (- x)))))
181 @var{body-forms}@dots{})
182@end example 196@end example
183 197
184@noindent 198@noindent
185Such a list is called a @dfn{lambda expression}. In Emacs Lisp, it 199In Emacs Lisp, such a list is valid as an expression---it evaluates to
186actually is valid as an expression---it evaluates to itself. In some 200itself. But its main use is not to be evaluated as an expression, but
187other Lisp dialects, a lambda expression is not a valid expression at 201to be called as a function.
188all. In either case, its main use is not to be evaluated as an 202
189expression, but to be called as a function. 203 A lambda expression, by itself, has no name; it is an @dfn{anonymous
204function}. Although lambda expressions can be used this way
205(@pxref{Anonymous Functions}), they are more commonly associated with
206symbols to make @dfn{named functions} (@pxref{Function Names}).
207Before going into these details, the following subsections describe
208the components of a lambda expression and what they do.
190 209
191@menu 210@menu
192* Lambda Components:: The parts of a lambda expression. 211* Lambda Components:: The parts of a lambda expression.
@@ -198,10 +217,7 @@ expression, but to be called as a function.
198@node Lambda Components 217@node Lambda Components
199@subsection Components of a Lambda Expression 218@subsection Components of a Lambda Expression
200 219
201@ifnottex 220 A lambda expression is a list that looks like this:
202
203 A function written in Lisp (a ``lambda expression'') is a list that
204looks like this:
205 221
206@example 222@example
207(lambda (@var{arg-variables}@dots{}) 223(lambda (@var{arg-variables}@dots{})
@@ -209,7 +225,6 @@ looks like this:
209 [@var{interactive-declaration}] 225 [@var{interactive-declaration}]
210 @var{body-forms}@dots{}) 226 @var{body-forms}@dots{})
211@end example 227@end example
212@end ifnottex
213 228
214@cindex lambda list 229@cindex lambda list
215 The first element of a lambda expression is always the symbol 230 The first element of a lambda expression is always the symbol
@@ -243,9 +258,9 @@ code to do the work of the function (or, as a Lisp programmer would say,
243function is the value returned by the last element of the body. 258function is the value returned by the last element of the body.
244 259
245@node Simple Lambda 260@node Simple Lambda
246@subsection A Simple Lambda-Expression Example 261@subsection A Simple Lambda Expression Example
247 262
248 Consider for example the following function: 263 Consider the following example:
249 264
250@example 265@example
251(lambda (a b c) (+ a b c)) 266(lambda (a b c) (+ a b c))
@@ -283,18 +298,15 @@ This evaluates the arguments @code{1}, @code{(* 2 3)}, and @code{(- 5
2834)} from left to right. Then it applies the lambda expression to the 2984)} from left to right. Then it applies the lambda expression to the
284argument values 1, 6 and 1 to produce the value 8. 299argument values 1, 6 and 1 to produce the value 8.
285 300
286 It is not often useful to write a lambda expression as the @sc{car} of 301 As these examples show, you can use a form with a lambda expression
287a form in this way. You can get the same result, of making local 302as its @sc{car} to make local variables and give them values. In the
288variables and giving them values, using the special form @code{let} 303old days of Lisp, this technique was the only way to bind and
289(@pxref{Local Variables}). And @code{let} is clearer and easier to use. 304initialize local variables. But nowadays, it is clearer to use the
290In practice, lambda expressions are either stored as the function 305special form @code{let} for this purpose (@pxref{Local Variables}).
291definitions of symbols, to produce named functions, or passed as 306Lambda expressions are mainly used as anonymous functions for passing
292arguments to other functions (@pxref{Anonymous Functions}). 307as arguments to other functions (@pxref{Anonymous Functions}), or
293 308stored as symbol function definitions to produce named functions
294 However, calls to explicit lambda expressions were very useful in the 309(@pxref{Function Names}).
295old days of Lisp, before the special form @code{let} was invented. At
296that time, they were the only way to bind and initialize local
297variables.
298 310
299@node Argument List 311@node Argument List
300@subsection Other Features of Argument Lists 312@subsection Other Features of Argument Lists
@@ -405,12 +417,12 @@ after a @code{&rest} argument.
405@subsection Documentation Strings of Functions 417@subsection Documentation Strings of Functions
406@cindex documentation of function 418@cindex documentation of function
407 419
408 A lambda expression may optionally have a @dfn{documentation string} just 420 A lambda expression may optionally have a @dfn{documentation string}
409after the lambda list. This string does not affect execution of the 421just after the lambda list. This string does not affect execution of
410function; it is a kind of comment, but a systematized comment which 422the function; it is a kind of comment, but a systematized comment
411actually appears inside the Lisp world and can be used by the Emacs help 423which actually appears inside the Lisp world and can be used by the
412facilities. @xref{Documentation}, for how the @var{documentation-string} is 424Emacs help facilities. @xref{Documentation}, for how the
413accessed. 425documentation string is accessed.
414 426
415 It is a good idea to provide documentation strings for all the 427 It is a good idea to provide documentation strings for all the
416functions in your program, even those that are called only from within 428functions in your program, even those that are called only from within
@@ -463,55 +475,45 @@ way users think of the parts of the macro call.
463@cindex named function 475@cindex named function
464@cindex function name 476@cindex function name
465 477
466 In most computer languages, every function has a name; the idea of a 478 A symbol can serve as the name of a function. This happens when the
467function without a name is nonsensical. In Lisp, a function in the 479symbol's @dfn{function cell} (@pxref{Symbol Components}) contains a
468strictest sense has no name. It is simply a list whose first element is 480function object (e.g.@: a lambda expression). Then the symbol itself
469@code{lambda}, a byte-code function object, or a primitive subr-object. 481becomes a valid, callable function, equivalent to the function object
470 482in its function cell.
471 However, a symbol can serve as the name of a function. This happens 483
472when you put the function in the symbol's @dfn{function cell} 484 The contents of the function cell are also called the symbol's
473(@pxref{Symbol Components}). Then the symbol itself becomes a valid, 485@dfn{function definition}. The procedure of using a symbol's function
474callable function, equivalent to the list or subr-object that its 486definition in place of the symbol is called @dfn{symbol function
475function cell refers to. The contents of the function cell are also 487indirection}; see @ref{Function Indirection}. If you have not given a
476called the symbol's @dfn{function definition}. The procedure of using a 488symbol a function definition, its function cell is said to be
477symbol's function definition in place of the symbol is called 489@dfn{void}, and it cannot be used as a function.
478@dfn{symbol function indirection}; see @ref{Function Indirection}. 490
479 491 In practice, nearly all functions have names, and are referred to by
480 In practice, nearly all functions are given names in this way and 492their names. You can create a named Lisp function by defining a
481referred to through their names. For example, the symbol @code{car} works 493lambda expression and putting it in a function cell (@pxref{Function
482as a function and does what it does because the primitive subr-object 494Cells}). However, it is more common to use the @code{defun} special
483@code{#<subr car>} is stored in its function cell. 495form, described in the next section.
496@ifnottex
497@xref{Defining Functions}.
498@end ifnottex
484 499
485 We give functions names because it is convenient to refer to them by 500 We give functions names because it is convenient to refer to them by
486their names in Lisp expressions. For primitive subr-objects such as 501their names in Lisp expressions. Also, a named Lisp function can
487@code{#<subr car>}, names are the only way you can refer to them: there 502easily refer to itself---it can be recursive. Furthermore, primitives
488is no read syntax for such objects. For functions written in Lisp, the 503can only be referred to textually by their names, since primitive
489name is more convenient to use in a call than an explicit lambda 504function objects (@pxref{Primitive Function Type}) have no read
490expression. Also, a function with a name can refer to itself---it can 505syntax.
491be recursive. Writing the function's name in its own definition is much 506
492more convenient than making the function definition point to itself 507 A function need not have a unique name. A given function object
493(something that is not impossible but that has various disadvantages in 508@emph{usually} appears in the function cell of only one symbol, but
494practice). 509this is just a convention. It is easy to store it in several symbols
495 510using @code{fset}; then each of the symbols is a valid name for the
496 We often identify functions with the symbols used to name them. For 511same function.
497example, we often speak of ``the function @code{car},'' not 512
498distinguishing between the symbol @code{car} and the primitive 513 Note that a symbol used as a function name may also be used as a
499subr-object that is its function definition. For most purposes, the 514variable; these two uses of a symbol are independent and do not
500distinction is not important. 515conflict. (This is not the case in some dialects of Lisp, like
501 516Scheme.)
502 Even so, keep in mind that a function need not have a unique name. While
503a given function object @emph{usually} appears in the function cell of only
504one symbol, this is just a matter of convenience. It is easy to store
505it in several symbols using @code{fset}; then each of the symbols is
506equally well a name for the same function.
507
508 A symbol used as a function name may also be used as a variable; these
509two uses of a symbol are independent and do not conflict. (Some Lisp
510dialects, such as Scheme, do not distinguish between a symbol's value
511and its function definition; a symbol's value as a variable is also its
512function definition.) If you have not given a symbol a function
513definition, you cannot use it as a function; whether the symbol has a
514value as a variable makes no difference to this.
515 517
516@node Defining Functions 518@node Defining Functions
517@section Defining Functions 519@section Defining Functions
@@ -521,7 +523,7 @@ value as a variable makes no difference to this.
521is called @dfn{defining a function}, and it is done with the 523is called @dfn{defining a function}, and it is done with the
522@code{defun} special form. 524@code{defun} special form.
523 525
524@defspec defun name argument-list body-forms 526@defspec defun name argument-list body-forms...
525@code{defun} is the usual way to define new Lisp functions. It 527@code{defun} is the usual way to define new Lisp functions. It
526defines the symbol @var{name} as a function that looks like this: 528defines the symbol @var{name} as a function that looks like this:
527 529
@@ -534,14 +536,9 @@ defines the symbol @var{name} as a function that looks like this:
534value. 536value.
535 537
536As described previously, @var{argument-list} is a list of argument 538As described previously, @var{argument-list} is a list of argument
537names and may include the keywords @code{&optional} and @code{&rest} 539names and may include the keywords @code{&optional} and @code{&rest}.
538(@pxref{Lambda Expressions}). Also, the first two of the 540Also, the first two of the @var{body-forms} may be a documentation
539@var{body-forms} may be a documentation string and an interactive 541string and an interactive declaration. @xref{Lambda Components}.
540declaration.
541
542There is no conflict if the same symbol @var{name} is also used as a
543variable, since the symbol's value cell is independent of the function
544cell. @xref{Symbol Components}.
545 542
546Here are some examples: 543Here are some examples:
547 544
@@ -575,7 +572,7 @@ Here are some examples:
575 572
576@group 573@group
577(defun capitalize-backwards () 574(defun capitalize-backwards ()
578 "Upcase the last letter of a word." 575 "Upcase the last letter of the word at point."
579 (interactive) 576 (interactive)
580 (backward-word 1) 577 (backward-word 1)
581 (forward-word 1) 578 (forward-word 1)
@@ -587,9 +584,10 @@ Here are some examples:
587 584
588Be careful not to redefine existing functions unintentionally. 585Be careful not to redefine existing functions unintentionally.
589@code{defun} redefines even primitive functions such as @code{car} 586@code{defun} redefines even primitive functions such as @code{car}
590without any hesitation or notification. Redefining a function already 587without any hesitation or notification. Emacs does not prevent you
591defined is often done deliberately, and there is no way to distinguish 588from doing this, because redefining a function is sometimes done
592deliberate redefinition from unintentional redefinition. 589deliberately, and there is no way to distinguish deliberate
590redefinition from unintentional redefinition.
593@end defspec 591@end defspec
594 592
595@cindex function aliases 593@cindex function aliases
@@ -626,7 +624,8 @@ call the primitive's C definition directly, so changing the symbol's
626definition will have no effect on them. 624definition will have no effect on them.
627 625
628 See also @code{defsubst}, which defines a function like @code{defun} 626 See also @code{defsubst}, which defines a function like @code{defun}
629and tells the Lisp compiler to open-code it. @xref{Inline Functions}. 627and tells the Lisp compiler to perform inline expansion on it.
628@xref{Inline Functions}.
630 629
631@node Calling Functions 630@node Calling Functions
632@section Calling Functions 631@section Calling Functions
@@ -790,11 +789,10 @@ This function returns @var{arg} and has no side effects.
790This function ignores any arguments and returns @code{nil}. 789This function ignores any arguments and returns @code{nil}.
791@end defun 790@end defun
792 791
793 Emacs Lisp functions can also be user-visible @dfn{commands}. A 792 Some functions are user-visible @dfn{commands}, which can be called
794command is a function that has an @dfn{interactive} specification. 793interactively (usually by a key sequence). It is possible to invoke
795You may want to call these functions as if they were called 794such a command exactly as though it was called interactively, by using
796interactively. See @ref{Interactive Call} for details on how to do 795the @code{call-interactively} function. @xref{Interactive Call}.
797that.
798 796
799@node Mapping Functions 797@node Mapping Functions
800@section Mapping Functions 798@section Mapping Functions
@@ -802,12 +800,12 @@ that.
802 800
803 A @dfn{mapping function} applies a given function (@emph{not} a 801 A @dfn{mapping function} applies a given function (@emph{not} a
804special form or macro) to each element of a list or other collection. 802special form or macro) to each element of a list or other collection.
805Emacs Lisp has several such functions; @code{mapcar} and 803Emacs Lisp has several such functions; this section describes
806@code{mapconcat}, which scan a list, are described here. 804@code{mapcar}, @code{mapc}, and @code{mapconcat}, which map over a
807@xref{Definition of mapatoms}, for the function @code{mapatoms} which 805list. @xref{Definition of mapatoms}, for the function @code{mapatoms}
808maps over the symbols in an obarray. @xref{Definition of maphash}, 806which maps over the symbols in an obarray. @xref{Definition of
809for the function @code{maphash} which maps over key/value associations 807maphash}, for the function @code{maphash} which maps over key/value
810in a hash table. 808associations in a hash table.
811 809
812 These mapping functions do not allow char-tables because a char-table 810 These mapping functions do not allow char-tables because a char-table
813is a sparse array whose nominal range of indices is very large. To map 811is a sparse array whose nominal range of indices is very large. To map
@@ -898,48 +896,67 @@ bool-vector, or a string.
898@section Anonymous Functions 896@section Anonymous Functions
899@cindex anonymous function 897@cindex anonymous function
900 898
901 In Lisp, a function is a list that starts with @code{lambda}, a 899 Although functions are usually defined with @code{defun} and given
902byte-code function compiled from such a list, or alternatively a 900names at the same time, it is sometimes convenient to use an explicit
903primitive subr-object; names are ``extra.'' Although functions are 901lambda expression---an @dfn{anonymous function}. Anonymous functions
904usually defined with @code{defun} and given names at the same time, it 902are valid wherever function names are. They are often assigned as
905is occasionally more concise to use an explicit lambda expression---an 903variable values, or as arguments to functions; for instance, you might
906anonymous function. Such a list is valid wherever a function name is. 904pass one as the @var{function} argument to @code{mapcar}, which
905applies that function to each element of a list (@pxref{Mapping
906Functions}). @xref{describe-symbols example}, for a realistic example
907of this.
908
909 When defining a lambda expression that is to be used as an anonymous
910function, you can in principle use any method to construct the list.
911But typically you should use the @code{lambda} macro, or the
912@code{function} special form, or the @code{#'} read syntax:
913
914@defmac lambda args body...
915This macro returns an anonymous function with argument list @var{args}
916and body forms given by @var{body}. In effect, this macro makes
917@code{lambda} forms ``self-quoting'': evaluating a form whose @sc{car}
918is @code{lambda} yields the form itself:
919
920@example
921(lambda (x) (* x x))
922 @result{} (lambda (x) (* x x))
923@end example
924
925The @code{lambda} form has one other effect: it tells the Emacs
926evaluator and byte-compiler that its argument is a function, by using
927@code{function} as a subroutine (see below).
928@end defmac
907 929
908 Any method of creating such a list makes a valid function. Even this: 930@defspec function function-object
931@cindex function quoting
932This special form returns @var{function-object} without evaluating it.
933In this, it is similar to @code{quote} (@pxref{Quoting}). But unlike
934@code{quote}, it also serves as a note to the Emacs evaluator and
935byte-compiler that @var{function-object} is intended to be used as a
936function. Assuming @var{function-object} is a valid lambda
937expression, this has two effects:
909 938
910@smallexample 939@itemize
911@group 940@item
912(setq silly (append '(lambda (x)) (list (list '+ (* 3 4) 'x)))) 941When the code is byte-compiled, @var{function-object} is compiled into
913@result{} (lambda (x) (+ 12 x)) 942a byte-code function object (@pxref{Byte Compilation}).
914@end group
915@end smallexample
916 943
917@noindent 944@item
918This computes a list that looks like @code{(lambda (x) (+ 12 x))} and 945When lexical binding is enabled, @var{function-object} is converted
919makes it the value (@emph{not} the function definition!) of 946into a closure. @xref{Closures}.
920@code{silly}. 947@end itemize
948@end defspec
921 949
922 Here is how we might call this function: 950@cindex @samp{#'} syntax
951The read syntax @code{#'} is a short-hand for using @code{function}.
952The following forms are all equivalent:
923 953
924@example 954@example
925@group 955(lambda (x) (* x x))
926(funcall silly 1) 956(function (lambda (x) (* x x)))
927@result{} 13 957#'(lambda (x) (* x x))
928@end group
929@end example 958@end example
930 959
931@noindent
932It does @emph{not} work to write @code{(silly 1)}, because this
933function is not the @emph{function definition} of @code{silly}. We
934have not given @code{silly} any function definition, just a value as a
935variable.
936
937 Most of the time, anonymous functions are constants that appear in
938your program. For instance, you might want to pass one as an argument
939to the function @code{mapcar}, which applies any given function to
940each element of a list (@pxref{Mapping Functions}).
941@xref{describe-symbols example}, for a realistic example of this.
942
943 In the following example, we define a @code{change-property} 960 In the following example, we define a @code{change-property}
944function that takes a function as its third argument, followed by a 961function that takes a function as its third argument, followed by a
945@code{double-property} function that makes use of 962@code{double-property} function that makes use of
@@ -959,15 +976,11 @@ function that takes a function as its third argument, followed by a
959@end example 976@end example
960 977
961@noindent 978@noindent
962In the @code{double-property} function, we did not quote the 979Note that we do not quote the @code{lambda} form.
963@code{lambda} form. This is permissible, because a @code{lambda} form
964is @dfn{self-quoting}: evaluating the form yields the form itself.
965 980
966Whether or not you quote a @code{lambda} form makes a difference if 981 If you compile the above code, the anonymous function is also
967you compile the code (@pxref{Byte Compilation}). If the @code{lambda} 982compiled. This would not happen if, say, you had constructed the
968form is unquoted, as in the above example, the anonymous function is 983anonymous function by quoting it as a list:
969also compiled. Suppose, however, that we quoted the @code{lambda}
970form:
971 984
972@example 985@example
973@group 986@group
@@ -977,52 +990,10 @@ form:
977@end example 990@end example
978 991
979@noindent 992@noindent
980If you compile this, the argument passed to @code{change-property} is 993In that case, the anonymous function is kept as a lambda expression in
981the precise list shown: 994the compiled code. The byte-compiler cannot assume this list is a
982 995function, even though it looks like one, since it does not know that
983@example 996@code{change-property} intends to use it as a function.
984(lambda (x) (* x 2))
985@end example
986
987@noindent
988The Lisp compiler cannot assume this list is a function, even though
989it looks like one, since it does not know what @code{change-property}
990will do with the list. Perhaps it will check whether the @sc{car} of
991the third element is the symbol @code{*}!
992
993@findex function
994The @code{function} special form explicitly tells the byte-compiler
995that its argument is a function:
996
997@defspec function function-object
998@cindex function quoting
999This special form returns @var{function-object} without evaluating it.
1000In this, it is equivalent to @code{quote}. However, it serves as a
1001note to the Emacs Lisp compiler that @var{function-object} is intended
1002to be used only as a function, and therefore can safely be compiled.
1003Contrast this with @code{quote}, in @ref{Quoting}.
1004@end defspec
1005
1006@cindex @samp{#'} syntax
1007The read syntax @code{#'} is a short-hand for using @code{function}.
1008Generally, it is not necessary to use either @code{#'} or
1009@code{function}; just use an unquoted @code{lambda} form instead.
1010(Actually, @code{lambda} is a macro defined using @code{function}.)
1011The following forms are all equivalent:
1012
1013@example
1014#'(lambda (x) (* x x))
1015(function (lambda (x) (* x x)))
1016(lambda (x) (* x x))
1017@end example
1018
1019 We sometimes write @code{function} instead of @code{quote} when
1020quoting the name of a function, but this usage is just a sort of
1021comment:
1022
1023@example
1024(function @var{symbol}) @equiv{} (quote @var{symbol}) @equiv{} '@var{symbol}
1025@end example
1026 997
1027@node Function Cells 998@node Function Cells
1028@section Accessing Function Cell Contents 999@section Accessing Function Cell Contents
@@ -1118,77 +1089,60 @@ This function stores @var{definition} in the function cell of
1118this is not checked. The argument @var{symbol} is an ordinary evaluated 1089this is not checked. The argument @var{symbol} is an ordinary evaluated
1119argument. 1090argument.
1120 1091
1121There are three normal uses of this function: 1092The primary use of this function is as a subroutine by constructs that
1093define or alter functions, like @code{defadvice} (@pxref{Advising
1094Functions}). (If @code{defun} were not a primitive, it could be
1095written as a Lisp macro using @code{fset}.) You can also use it to
1096give a symbol a function definition that is not a list, e.g.@: a
1097keyboard macro (@pxref{Keyboard Macros}):
1122 1098
1123@itemize @bullet 1099@example
1124@item 1100;; @r{Define a named keyboard macro.}
1125Copying one symbol's function definition to another---in other words, 1101(fset 'kill-two-lines "\^u2\^k")
1126making an alternate name for a function. (If you think of this as the 1102 @result{} "\^u2\^k"
1127definition of the new name, you should use @code{defalias} instead of 1103@end example
1128@code{fset}; see @ref{Definition of defalias}.)
1129 1104
1130@item 1105It you wish to use @code{fset} to make an alternate name for a
1131Giving a symbol a function definition that is not a list and therefore 1106function, consider using @code{defalias} instead. @xref{Definition of
1132cannot be made with @code{defun}. For example, you can use @code{fset} 1107defalias}.
1133to give a symbol @code{s1} a function definition which is another symbol 1108@end defun
1134@code{s2}; then @code{s1} serves as an alias for whatever definition
1135@code{s2} presently has. (Once again use @code{defalias} instead of
1136@code{fset} if you think of this as the definition of @code{s1}.)
1137 1109
1138@item 1110@node Closures
1139In constructs for defining or altering functions. If @code{defun} 1111@section Closures
1140were not a primitive, it could be written in Lisp (as a macro) using
1141@code{fset}.
1142@end itemize
1143 1112
1144Here are examples of these uses: 1113 As explained in @ref{Variable Scoping}, Emacs can optionally enable
1114lexical binding of variables. When lexical binding is enabled, any
1115named function that you create (e.g.@: with @code{defun}), as well as
1116any anonymous function that you create using the @code{lambda} macro
1117or the @code{function} special form or the @code{#'} syntax
1118(@pxref{Anonymous Functions}), is automatically converted into a
1119closure.
1145 1120
1146@example 1121 A closure is a function that also carries a record of the lexical
1147@group 1122environment that existed when the function was defined. When it is
1148;; @r{Save @code{foo}'s definition in @code{old-foo}.} 1123invoked, any lexical variable references within its definition use the
1149(fset 'old-foo (symbol-function 'foo)) 1124retained lexical environment. In all other respects, closures behave
1150@end group 1125much like ordinary functions; in particular, they can be called in the
1126same way as ordinary functions.
1151 1127
1152@group 1128 @xref{Lexical Binding}, for an example of using a closure.
1153;; @r{Make the symbol @code{car} the function definition of @code{xfirst}.}
1154;; @r{(Most likely, @code{defalias} would be better than @code{fset} here.)}
1155(fset 'xfirst 'car)
1156 @result{} car
1157@end group
1158@group
1159(xfirst '(1 2 3))
1160 @result{} 1
1161@end group
1162@group
1163(symbol-function 'xfirst)
1164 @result{} car
1165@end group
1166@group
1167(symbol-function (symbol-function 'xfirst))
1168 @result{} #<subr car>
1169@end group
1170 1129
1171@group 1130 Currently, an Emacs Lisp closure object is represented by a list
1172;; @r{Define a named keyboard macro.} 1131with the symbol @code{closure} as the first element, a list
1173(fset 'kill-two-lines "\^u2\^k") 1132representing the lexical environment as the second element, and the
1174 @result{} "\^u2\^k" 1133argument list and body forms as the remaining elements:
1175@end group
1176 1134
1177@group 1135@example
1178;; @r{Here is a function that alters other functions.} 1136;; @r{lexical binding is enabled.}
1179(defun copy-function-definition (new old) 1137(lambda (x) (* x x))
1180 "Define NEW with the same function definition as OLD." 1138 @result{} (closure (t) (x) (* x x))
1181 (fset new (symbol-function old)))
1182@end group
1183@end example 1139@end example
1184@end defun
1185 1140
1186 @code{fset} is sometimes used to save the old definition of a 1141@noindent
1187function before redefining it. That permits the new definition to 1142However, the fact that the internal structure of a closure is
1188invoke the old definition. But it is unmodular and unclean for a Lisp 1143``exposed'' to the rest of the Lisp world is considered an internal
1189file to redefine a function defined elsewhere. If you want to modify 1144implementation detail. For this reason, we recommend against directly
1190a function defined by another package, it is cleaner to use 1145examining or altering the structure of closure objects.
1191@code{defadvice} (@pxref{Advising Functions}).
1192 1146
1193@node Obsolete Functions 1147@node Obsolete Functions
1194@section Declaring Functions Obsolete 1148@section Declaring Functions Obsolete
@@ -1254,41 +1208,46 @@ this:
1254@section Inline Functions 1208@section Inline Functions
1255@cindex inline functions 1209@cindex inline functions
1256 1210
1257@findex defsubst 1211@defmac defsubst name argument-list body-forms...
1258You can define an @dfn{inline function} by using @code{defsubst} instead 1212Define an inline function. The syntax is exactly the same as
1259of @code{defun}. An inline function works just like an ordinary 1213@code{defun} (@pxref{Defining Functions}).
1260function except for one thing: when you compile a call to the function, 1214@end defmac
1261the function's definition is open-coded into the caller. 1215
1216 You can define an @dfn{inline function} by using @code{defsubst}
1217instead of @code{defun}. An inline function works just like an
1218ordinary function except for one thing: when you byte-compile a call
1219to the function (@pxref{Byte Compilation}), the function's definition
1220is expanded into the caller.
1262 1221
1263Making a function inline makes explicit calls run faster. But it also 1222 Making a function inline often makes its function calls run faster.
1264has disadvantages. For one thing, it reduces flexibility; if you 1223But it also has disadvantages. For one thing, it reduces flexibility;
1265change the definition of the function, calls already inlined still use 1224if you change the definition of the function, calls already inlined
1266the old definition until you recompile them. 1225still use the old definition until you recompile them.
1267 1226
1268Another disadvantage is that making a large function inline can increase 1227 Another disadvantage is that making a large function inline can
1269the size of compiled code both in files and in memory. Since the speed 1228increase the size of compiled code both in files and in memory. Since
1270advantage of inline functions is greatest for small functions, you 1229the speed advantage of inline functions is greatest for small
1271generally should not make large functions inline. 1230functions, you generally should not make large functions inline.
1272 1231
1273Also, inline functions do not behave well with respect to debugging, 1232 Also, inline functions do not behave well with respect to debugging,
1274tracing, and advising (@pxref{Advising Functions}). Since ease of 1233tracing, and advising (@pxref{Advising Functions}). Since ease of
1275debugging and the flexibility of redefining functions are important 1234debugging and the flexibility of redefining functions are important
1276features of Emacs, you should not make a function inline, even if it's 1235features of Emacs, you should not make a function inline, even if it's
1277small, unless its speed is really crucial, and you've timed the code 1236small, unless its speed is really crucial, and you've timed the code
1278to verify that using @code{defun} actually has performance problems. 1237to verify that using @code{defun} actually has performance problems.
1279 1238
1280It's possible to define a macro to expand into the same code that an 1239 It's possible to define a macro to expand into the same code that an
1281inline function would execute. (@xref{Macros}.) But the macro would be 1240inline function would execute (@pxref{Macros}). But the macro would
1282limited to direct use in expressions---a macro cannot be called with 1241be limited to direct use in expressions---a macro cannot be called
1283@code{apply}, @code{mapcar} and so on. Also, it takes some work to 1242with @code{apply}, @code{mapcar} and so on. Also, it takes some work
1284convert an ordinary function into a macro. To convert it into an inline 1243to convert an ordinary function into a macro. To convert it into an
1285function is very easy; simply replace @code{defun} with @code{defsubst}. 1244inline function is easy; just replace @code{defun} with
1286Since each argument of an inline function is evaluated exactly once, you 1245@code{defsubst}. Since each argument of an inline function is
1287needn't worry about how many times the body uses the arguments, as you 1246evaluated exactly once, you needn't worry about how many times the
1288do for macros. (@xref{Argument Evaluation}.) 1247body uses the arguments, as you do for macros.
1289 1248
1290Inline functions can be used and open-coded later on in the same file, 1249 After an inline function is defined, its inline expansion can be
1291following the definition, just like macros. 1250performed later on in the same file, just like macros.
1292 1251
1293@node Declaring Functions 1252@node Declaring Functions
1294@section Telling the Compiler that a Function is Defined 1253@section Telling the Compiler that a Function is Defined
@@ -1352,12 +1311,10 @@ definition using @code{locate-library}; if that finds no file, they
1352expand the definition file name relative to the directory of the file 1311expand the definition file name relative to the directory of the file
1353that contains the @code{declare-function} call. 1312that contains the @code{declare-function} call.
1354 1313
1355 You can also say that a function is defined by C code by specifying a 1314 You can also say that a function is a primitive by specifying a file
1356file name ending in @samp{.c} or @samp{.m}. @code{check-declare-file} 1315name ending in @samp{.c} or @samp{.m}. This is useful only when you
1357looks for these files in the C source code directory. This is useful 1316call a primitive that is defined only on certain systems. Most
1358only when you call a function that is defined only on certain systems. 1317primitives are always defined, so they will never give you a warning.
1359Most of the primitive functions of Emacs are always defined so they will
1360never give you a warning.
1361 1318
1362 Sometimes a file will optionally use functions from an external package. 1319 Sometimes a file will optionally use functions from an external package.
1363If you prefix the filename in the @code{declare-function} statement with 1320If you prefix the filename in the @code{declare-function} statement with
diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi
index 678ea83465f..f6556639e98 100644
--- a/doc/lispref/help.texi
+++ b/doc/lispref/help.texi
@@ -582,11 +582,12 @@ If this variable is non-@code{nil}, its value is a form to evaluate
582whenever the character @code{help-char} is read. If evaluating the form 582whenever the character @code{help-char} is read. If evaluating the form
583produces a string, that string is displayed. 583produces a string, that string is displayed.
584 584
585A command that calls @code{read-event} or @code{read-char} probably 585A command that calls @code{read-event}, @code{read-char-choice}, or
586should bind @code{help-form} to a non-@code{nil} expression while it 586@code{read-char} probably should bind @code{help-form} to a
587does input. (The time when you should not do this is when @kbd{C-h} has 587non-@code{nil} expression while it does input. (The time when you
588some other meaning.) Evaluating this expression should result in a 588should not do this is when @kbd{C-h} has some other meaning.)
589string that explains what the input is for and how to enter it properly. 589Evaluating this expression should result in a string that explains
590what the input is for and how to enter it properly.
590 591
591Entry to the minibuffer binds this variable to the value of 592Entry to the minibuffer binds this variable to the value of
592@code{minibuffer-help-form} (@pxref{Definition of minibuffer-help-form}). 593@code{minibuffer-help-form} (@pxref{Definition of minibuffer-help-form}).
diff --git a/doc/lispref/hooks.texi b/doc/lispref/hooks.texi
index 95655324ab4..ef3ebc4be35 100644
--- a/doc/lispref/hooks.texi
+++ b/doc/lispref/hooks.texi
@@ -127,6 +127,9 @@ not exactly a hook, but does a similar job.
127@xref{Calendar Customizing,,, emacs}. 127@xref{Calendar Customizing,,, emacs}.
128@end ifnottex 128@end ifnottex
129 129
130@item change-major-mode-after-body-hook
131@xref{Mode Hooks}.
132
130@item change-major-mode-hook 133@item change-major-mode-hook
131@xref{Creating Buffer-Local}. 134@xref{Creating Buffer-Local}.
132 135
@@ -292,9 +295,15 @@ Manual}.
292@item post-command-hook 295@item post-command-hook
293@xref{Command Overview}. 296@xref{Command Overview}.
294 297
298@item post-self-insert-hook
299@xref{Keymaps and Minor Modes}.
300
295@item pre-command-hook 301@item pre-command-hook
296@xref{Command Overview}. 302@xref{Command Overview}.
297 303
304@item prog-mode-hook
305@xref{Basic Major Modes}.
306
298@item resume-tty-functions 307@item resume-tty-functions
299@xref{Suspending Emacs}. 308@xref{Suspending Emacs}.
300 309
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/minibuf.texi b/doc/lispref/minibuf.texi
index e3008470233..a71138f5268 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -1335,19 +1335,19 @@ but uses the predicate @code{user-variable-p} instead of
1335@deffn Command read-color &optional prompt convert allow-empty display 1335@deffn Command read-color &optional prompt convert allow-empty display
1336This function reads a string that is a color specification, either the 1336This function reads a string that is a color specification, either the
1337color's name or an RGB hex value such as @code{#RRRGGGBBB}. It 1337color's name or an RGB hex value such as @code{#RRRGGGBBB}. It
1338prompts with @var{prompt} (default: @code{"Color (name or #R+G+B+):"}) 1338prompts with @var{prompt} (default: @code{"Color (name or #RGB triplet):"})
1339and provides completion for color names, but not for hex RGB values. 1339and provides completion for color names, but not for hex RGB values.
1340In addition to names of standard colors, completion candidates include 1340In addition to names of standard colors, completion candidates include
1341the foreground and background colors at point. 1341the foreground and background colors at point.
1342 1342
1343Valid RGB values are described in @ref{Color Names}. 1343Valid RGB values are described in @ref{Color Names}.
1344 1344
1345The function's return value is the color name typed by the user in the 1345The function's return value is the string typed by the user in the
1346minibuffer. However, when called interactively or if the optional 1346minibuffer. However, when called interactively or if the optional
1347argument @var{convert} is non-@code{nil}, it converts the name into 1347argument @var{convert} is non-@code{nil}, it converts any input color
1348the color's RGB value and returns that value as a string. If an 1348name into the corresponding RGB value string and instead returns that.
1349invalid color name was specified, this function signals an error, 1349This function requires a valid color specification to be input.
1350except that empty color names are allowed when @code{allow-empty} is 1350Empty color names are allowed when @code{allow-empty} is
1351non-@code{nil} and the user enters null input. 1351non-@code{nil} and the user enters null input.
1352 1352
1353Interactively, or when @var{display} is non-@code{nil}, the return 1353Interactively, or when @var{display} is non-@code{nil}, the return
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 53120d72bd1..638ab89e37f 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -135,21 +135,32 @@ This macro runs the abnormal hook @code{hook} as a series of nested
135``wrapper functions'' around the @var{body} forms. The effect is 135``wrapper functions'' around the @var{body} forms. The effect is
136similar to nested @code{around} advices (@pxref{Around-Advice}). 136similar to nested @code{around} advices (@pxref{Around-Advice}).
137 137
138Each hook function must accept an argument list consisting of a function 138Each hook function should accept an argument list consisting of a function
139@var{fun}, followed by the additional arguments listed in @var{args}. 139@var{fun}, followed by the additional arguments listed in @var{args}.
140The function @var{fun} passed to the very first hook function in 140The first hook function is passed a function @var{fun} that, if it is
141@var{hook} does the same as @var{body}, if it is called with arguments 141called with arguments @var{args}, performs @var{body} (i.e., the default
142@var{args}. The @var{fun} passed to each successive hook function is 142operation). The @var{fun} passed to each successive hook function is
143constructed from all the preceding hook functions (and @var{body}); if 143constructed from all the preceding hook functions (and @var{body}); if
144this @var{fun} is called with arguments @var{args}, it does what the 144this @var{fun} is called with arguments @var{args}, it does what the
145@code{with-wrapper-hook} call would if the preceding hook functions were 145@code{with-wrapper-hook} call would if the preceding hook functions were
146the only ones in @var{hook}. 146the only ones in @var{hook}.
147 147
148In the function definition of the hook function, @var{fun} can be called 148Each hook function may call its @var{fun} argument as many times as it
149any number of times (including not calling it at all). This function 149wishes, including never. In that case, such a hook function acts to
150definition is then used to construct the @var{fun} passed to the next 150replace the default definition altogether, and any preceding hook
151hook function in @var{hook}, if any. The last or ``outermost'' 151functions. Of course, a subsequent hook function may do the same thing.
152@var{fun} is called once to produce the effect. 152
153Each hook function definition is used to construct the @var{fun} passed
154to the next hook function in @var{hook}, if any. The last or
155``outermost'' @var{fun} is called once to produce the overall effect.
156
157When might you want to use a wrapper hook? The function
158@code{filter-buffer-substring} illustrates a common case. There is a
159basic functionality, performed by @var{body}---in this case, to extract
160a buffer-substring. Then any number of hook functions can act in
161sequence to modify that string, before returning the final result.
162A wrapper-hook also allows for a hook function to completely replace the
163default definition (by not calling @var{fun}).
153@end defmac 164@end defmac
154 165
155@node Setting Hooks 166@node Setting Hooks
@@ -468,8 +479,9 @@ other packages would interfere with them.
468@cindex major mode hook 479@cindex major mode hook
469Each major mode should have a normal @dfn{mode hook} named 480Each major mode should have a normal @dfn{mode hook} named
470@code{@var{modename}-mode-hook}. The very last thing the major mode command 481@code{@var{modename}-mode-hook}. The very last thing the major mode command
471should do is to call @code{run-mode-hooks}. This runs the mode hook, 482should do is to call @code{run-mode-hooks}. This runs the normal
472and then runs the normal hook @code{after-change-major-mode-hook}. 483hook @code{change-major-mode-after-body-hook}, the mode hook,
484and then the normal hook @code{after-change-major-mode-hook}.
473@xref{Mode Hooks}. 485@xref{Mode Hooks}.
474 486
475@item 487@item
@@ -939,8 +951,9 @@ before it runs the mode hook variable @code{@var{mode}-hook}.
939@node Mode Hooks 951@node Mode Hooks
940@subsection Mode Hooks 952@subsection Mode Hooks
941 953
942 Every major mode command should finish by running its mode hook and 954 Every major mode command should finish by running the mode-independent
943the mode-independent normal hook @code{after-change-major-mode-hook}. 955normal hook @code{change-major-mode-after-body-hook}, its mode hook,
956and the normal hook @code{after-change-major-mode-hook}.
944It does this by calling @code{run-mode-hooks}. If the major mode is a 957It does this by calling @code{run-mode-hooks}. If the major mode is a
945derived mode, that is if it calls another major mode (the parent mode) 958derived mode, that is if it calls another major mode (the parent mode)
946in its body, it should do this inside @code{delay-mode-hooks} so that 959in its body, it should do this inside @code{delay-mode-hooks} so that
@@ -949,11 +962,12 @@ call to @code{run-mode-hooks} runs the parent's mode hook too.
949@xref{Major Mode Conventions}. 962@xref{Major Mode Conventions}.
950 963
951 Emacs versions before Emacs 22 did not have @code{delay-mode-hooks}. 964 Emacs versions before Emacs 22 did not have @code{delay-mode-hooks}.
952When user-implemented major modes have not been updated to use it, 965Versions before 24 did not have @code{change-major-mode-after-body-hook}.
953they won't entirely follow these conventions: they may run the 966When user-implemented major modes do not use @code{run-mode-hooks} and
954parent's mode hook too early, or fail to run 967have not been updated to use these newer features, they won't entirely
955@code{after-change-major-mode-hook}. If you encounter such a major 968follow these conventions: they may run the parent's mode hook too early,
956mode, please correct it to follow these conventions. 969or fail to run @code{after-change-major-mode-hook}. If you encounter
970such a major mode, please correct it to follow these conventions.
957 971
958 When you defined a major mode using @code{define-derived-mode}, it 972 When you defined a major mode using @code{define-derived-mode}, it
959automatically makes sure these conventions are followed. If you 973automatically makes sure these conventions are followed. If you
@@ -963,6 +977,7 @@ use the following functions to handle these conventions automatically.
963@defun run-mode-hooks &rest hookvars 977@defun run-mode-hooks &rest hookvars
964Major modes should run their mode hook using this function. It is 978Major modes should run their mode hook using this function. It is
965similar to @code{run-hooks} (@pxref{Hooks}), but it also runs 979similar to @code{run-hooks} (@pxref{Hooks}), but it also runs
980@code{change-major-mode-after-body-hook} and
966@code{after-change-major-mode-hook}. 981@code{after-change-major-mode-hook}.
967 982
968When this function is called during the execution of a 983When this function is called during the execution of a
@@ -982,6 +997,11 @@ The hooks will actually run during the next call to
982construct. 997construct.
983@end defmac 998@end defmac
984 999
1000@defvar change-major-mode-after-body-hook
1001This is a normal hook run by @code{run-mode-hooks}. It is run before
1002the mode hooks.
1003@end defvar
1004
985@defvar after-change-major-mode-hook 1005@defvar after-change-major-mode-hook
986This is a normal hook run by @code{run-mode-hooks}. It is run at the 1006This is a normal hook run by @code{run-mode-hooks}. It is run at the
987very end of every properly-written major mode command. 1007very end of every properly-written major mode command.
@@ -1332,11 +1352,12 @@ alist @code{minor-mode-map-alist}. @xref{Definition of minor-mode-map-alist}.
1332@cindex @code{self-insert-command}, minor modes 1352@cindex @code{self-insert-command}, minor modes
1333 One use of minor mode keymaps is to modify the behavior of certain 1353 One use of minor mode keymaps is to modify the behavior of certain
1334self-inserting characters so that they do something else as well as 1354self-inserting characters so that they do something else as well as
1335self-insert. In general, this is the only way to do that, since the 1355self-insert. (Another way to customize @code{self-insert-command} is
1336facilities for customizing @code{self-insert-command} are limited to 1356through @code{post-self-insert-hook}. Apart from this, the facilities
1337special cases (designed for abbrevs and Auto Fill mode). (Do not try 1357for customizing @code{self-insert-command} are limited to special cases,
1338substituting your own definition of @code{self-insert-command} for the 1358designed for abbrevs and Auto Fill mode. Do not try substituting your
1339standard one. The editor command loop handles this function specially.) 1359own definition of @code{self-insert-command} for the standard one. The
1360editor command loop handles this function specially.)
1340 1361
1341The key sequences bound in a minor mode should consist of @kbd{C-c} 1362The key sequences bound in a minor mode should consist of @kbd{C-c}
1342followed by one of @kbd{.,/?`'"[]\|~!#$%^&*()-_+=}. (The other 1363followed by one of @kbd{.,/?`'"[]\|~!#$%^&*()-_+=}. (The other
@@ -1351,11 +1372,11 @@ implementing a mode in one self-contained definition.
1351@defmac define-minor-mode mode doc [init-value [lighter [keymap]]] keyword-args@dots{} body@dots{} 1372@defmac define-minor-mode mode doc [init-value [lighter [keymap]]] keyword-args@dots{} body@dots{}
1352This macro defines a new minor mode whose name is @var{mode} (a 1373This macro defines a new minor mode whose name is @var{mode} (a
1353symbol). It defines a command named @var{mode} to toggle the minor 1374symbol). It defines a command named @var{mode} to toggle the minor
1354mode, with @var{doc} as its documentation string. It also defines a 1375mode, with @var{doc} as its documentation string. By default, it also
1355variable named @var{mode}, which is set to @code{t} or @code{nil} by 1376defines a variable named @var{mode}, which is set to @code{t} or
1356enabling or disabling the mode. The variable is initialized to 1377@code{nil} by enabling or disabling the mode. The variable is
1357@var{init-value}. Except in unusual circumstances (see below), this 1378initialized to @var{init-value}. Except in unusual circumstances (see
1358value must be @code{nil}. 1379below), this value must be @code{nil}.
1359 1380
1360The string @var{lighter} says what to display in the mode line 1381The string @var{lighter} says what to display in the mode line
1361when the mode is enabled; if it is @code{nil}, the mode is not displayed 1382when the mode is enabled; if it is @code{nil}, the mode is not displayed
@@ -1410,6 +1431,17 @@ This is equivalent to specifying @var{lighter} positionally.
1410 1431
1411@item :keymap @var{keymap} 1432@item :keymap @var{keymap}
1412This is equivalent to specifying @var{keymap} positionally. 1433This is equivalent to specifying @var{keymap} positionally.
1434
1435@item :variable @var{place}
1436This replaces the default variable @var{mode}, used to store the state
1437of the mode. If you specify this, the @var{mode} variable is not
1438defined, and any @var{init-value} argument is unused. @var{place}
1439can be a different named variable (which you must define yourself), or
1440anything that can be used with the @code{setf} function
1441(@pxref{Generalized Variables,,, cl, Common Lisp Extensions}).
1442@var{place} can also be a cons @code{(@var{get} . @var{set})},
1443where @var{get} is an expression that returns the current state,
1444and @var{set} is a function of one argument (a state) that sets it.
1413@end table 1445@end table
1414 1446
1415Any other keyword arguments are passed directly to the 1447Any other keyword arguments are passed directly to the
@@ -1510,8 +1542,15 @@ starts, for example by providing a @code{:require} keyword.
1510 1542
1511Use @code{:group @var{group}} in @var{keyword-args} to specify the 1543Use @code{:group @var{group}} in @var{keyword-args} to specify the
1512custom group for the mode variable of the global minor mode. 1544custom group for the mode variable of the global minor mode.
1545
1546Generally speaking, when you define a globalized minor mode, you should
1547also define a non-globalized version, so that people can use (or
1548disable) it in individual buffers. This also allows them to disable a
1549globally enabled minor mode in a specific major mode, by using that
1550mode's hook.
1513@end defmac 1551@end defmac
1514 1552
1553
1515@node Mode Line Format 1554@node Mode Line Format
1516@section Mode-Line Format 1555@section Mode-Line Format
1517@cindex mode line 1556@cindex mode line
diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi
index bec9f295227..82336aa537f 100644
--- a/doc/lispref/numbers.texi
+++ b/doc/lispref/numbers.texi
@@ -284,7 +284,7 @@ floating point), and returns @code{t} if so, @code{nil} otherwise.
284 284
285@defun natnump object 285@defun natnump object
286@cindex natural numbers 286@cindex natural numbers
287This predicate (whose name comes from the phrase ``natual number'') 287This predicate (whose name comes from the phrase ``natural number'')
288tests to see whether its argument is a nonnegative integer, and 288tests to see whether its argument is a nonnegative integer, and
289returns @code{t} if so, @code{nil} otherwise. 0 is considered 289returns @code{t} if so, @code{nil} otherwise. 0 is considered
290non-negative. 290non-negative.
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi
index 38eb5a86471..4cfc954cd1f 100644
--- a/doc/lispref/processes.texi
+++ b/doc/lispref/processes.texi
@@ -300,7 +300,8 @@ MS-DOS doesn't support asynchronous subprocesses, so this option doesn't
300work there. 300work there.
301 301
302@item @code{(:file @var{file-name})} 302@item @code{(:file @var{file-name})}
303Send the output to the file name specified. 303Send the output to the file name specified, overwriting it if it
304already exists.
304 305
305@item @code{(@var{real-destination} @var{error-destination})} 306@item @code{(@var{real-destination} @var{error-destination})}
306Keep the standard output stream separate from the standard error stream; 307Keep the standard output stream separate from the standard error stream;
diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi
index 71742e37a51..3d153e43b2d 100644
--- a/doc/lispref/syntax.texi
+++ b/doc/lispref/syntax.texi
@@ -606,11 +606,13 @@ expression prefix syntax class, and characters with the @samp{p} flag.
606@section Parsing Expressions 606@section Parsing Expressions
607 607
608 This section describes functions for parsing and scanning balanced 608 This section describes functions for parsing and scanning balanced
609expressions, also known as @dfn{sexps}. Basically, a sexp is either a 609expressions. We will refer to such expressions as @dfn{sexps},
610balanced parenthetical grouping, a string, or a symbol name (a 610following the terminology of Lisp, even though these functions can act
611sequence of characters whose syntax is either word constituent or 611on languages other than Lisp. Basically, a sexp is either a balanced
612symbol constituent). However, characters whose syntax is expression 612parenthetical grouping, a string, or a ``symbol'' (i.e.@: a sequence
613prefix are treated as part of the sexp if they appear next to it. 613of characters whose syntax is either word constituent or symbol
614constituent). However, characters whose syntax is expression prefix
615are treated as part of the sexp if they appear next to it.
614 616
615 The syntax table controls the interpretation of characters, so these 617 The syntax table controls the interpretation of characters, so these
616functions can be used for Lisp expressions when in Lisp mode and for C 618functions can be used for Lisp expressions when in Lisp mode and for C
@@ -830,10 +832,6 @@ The value is @code{nil} if @var{state} represents a parse which has
830arrived at a top level position. 832arrived at a top level position.
831@end defun 833@end defun
832 834
833 We have provided this access function rather than document how the
834data is represented in the state, because we plan to change the
835representation in the future.
836
837@node Low-Level Parsing 835@node Low-Level Parsing
838@subsection Low-Level Parsing 836@subsection Low-Level Parsing
839 837
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 55b0c0a4be8..8e7434de2ed 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -218,44 +218,46 @@ This is like @code{buffer-substring}, except that it does not copy text
218properties, just the characters themselves. @xref{Text Properties}. 218properties, just the characters themselves. @xref{Text Properties}.
219@end defun 219@end defun
220 220
221@defun filter-buffer-substring start end &optional delete noprops 221@defun filter-buffer-substring start end &optional delete
222This function passes the buffer text between @var{start} and @var{end} 222This function passes the buffer text between @var{start} and @var{end}
223through the filter functions specified by the variable 223through the filter functions specified by the wrapper hook
224@code{buffer-substring-filters}, and returns the value from the last 224@code{filter-buffer-substring-functions}, and returns the final
225filter function. If @code{buffer-substring-filters} is @code{nil}, 225result of applying all filters. The obsolete variable
226the value is the unaltered text from the buffer, what 226@code{buffer-substring-filters} is also consulted. If both of these
227@code{buffer-substring} would return. 227variables are @code{nil}, the value is the unaltered text from the
228buffer, as @code{buffer-substring} would return.
228 229
229If @var{delete} is non-@code{nil}, this function deletes the text 230If @var{delete} is non-@code{nil}, this function deletes the text
230between @var{start} and @var{end} after copying it, like 231between @var{start} and @var{end} after copying it, like
231@code{delete-and-extract-region}. 232@code{delete-and-extract-region}.
232 233
233If @var{noprops} is non-@code{nil}, the final string returned does not
234include text properties, while the string passed through the filters
235still includes text properties from the buffer text.
236
237Lisp code should use this function instead of @code{buffer-substring}, 234Lisp code should use this function instead of @code{buffer-substring},
238@code{buffer-substring-no-properties}, 235@code{buffer-substring-no-properties},
239or @code{delete-and-extract-region} when copying into user-accessible 236or @code{delete-and-extract-region} when copying into user-accessible
240data structures such as the kill-ring, X clipboard, and registers. 237data structures such as the kill-ring, X clipboard, and registers.
241Major and minor modes can add functions to 238Major and minor modes can add functions to
242@code{buffer-substring-filters} to alter such text as it is copied out 239@code{filter-buffer-substring-functions} to alter such text as it is
243of the buffer. 240copied out of the buffer.
244@end defun 241@end defun
245 242
246@defvar buffer-substring-filters 243@defvar filter-buffer-substring-functions
247This variable should be a list of functions that accept a single 244This variable is a wrapper hook (@pxref{Running Hooks}), whose members
248argument, a string, and return a string. 245should be functions that accept four arguments: @var{fun},
249@code{filter-buffer-substring} passes the buffer substring to the 246@var{start}, @var{end}, and @var{delete}. @var{fun} is a function
250first function in this list, and the return value of each function is 247that takes three arguments (@var{start}, @var{end}, and @var{delete}),
251passed to the next function. The return value of the last function is 248and returns a string. In both cases, the @var{start}, @var{end}, and
252used as the return value of @code{filter-buffer-substring}. 249@var{delete} arguments are the same as those of
253 250@code{filter-buffer-substring}.
254As a special convention, point is set to the start of the buffer text 251
255being operated on (i.e., the @var{start} argument for 252The first hook function is passed a @var{fun} that is equivalent to
256@code{filter-buffer-substring}) before these functions are called. 253the default operation of @code{filter-buffer-substring}, i.e. it
257 254returns the buffer-substring between @var{start} and @var{end}
258If this variable is @code{nil}, no filtering is performed. 255(processed by any @code{buffer-substring-filters}) and optionally
256deletes the original text from the buffer. In most cases, the hook
257function will call @var{fun} once, and then do its own processing of
258the result. The next hook function receives a @var{fun} equivalent to
259this, and so on. The actual return value is the result of all the
260hook functions acting in sequence.
259@end defvar 261@end defvar
260 262
261@defun buffer-string 263@defun buffer-string
@@ -500,6 +502,11 @@ syntax. (@xref{Abbrevs}, and @ref{Syntax Class Table}.) It is also
500responsible for calling @code{blink-paren-function} when the inserted 502responsible for calling @code{blink-paren-function} when the inserted
501character has close parenthesis syntax (@pxref{Blinking}). 503character has close parenthesis syntax (@pxref{Blinking}).
502 504
505@vindex post-self-insert-hook
506The final thing this command does is to run the hook
507@code{post-self-insert-hook}. You could use this to automatically
508reindent text as it is typed, for example.
509
503Do not try substituting your own definition of 510Do not try substituting your own definition of
504@code{self-insert-command} for the standard one. The editor command 511@code{self-insert-command} for the standard one. The editor command
505loop handles this function specially. 512loop handles this function specially.
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index 9e0c439e57e..bdb16cd10a8 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -9,16 +9,13 @@
9 9
10 A @dfn{variable} is a name used in a program to stand for a value. 10 A @dfn{variable} is a name used in a program to stand for a value.
11In Lisp, each variable is represented by a Lisp symbol 11In Lisp, each variable is represented by a Lisp symbol
12(@pxref{Symbols}). The symbol's name serves as the variable name, and 12(@pxref{Symbols}). The variable name is simply the symbol's name, and
13the symbol's value cell holds the variable's value@footnote{Strictly 13the variable's value is stored in the symbol's value cell@footnote{To
14speaking, the symbol's value cell always holds the variable's current 14be precise, under the default @dfn{dynamic binding} rules the value
15value under the default @dfn{dynamic binding} rules. Under 15cell always holds the variable's current value, but this is not the
16@dfn{lexical binding} rules, the value cell holds the variable's 16case under @dfn{lexical binding} rules. @xref{Variable Scoping}, for
17@dfn{global value}. @xref{Variable Scoping}, for details.}. 17details.}. @xref{Symbol Components}. In Emacs Lisp, the use of a
18@xref{Symbol Components}. 18symbol as a variable is independent of its use as a function name.
19
20 In Emacs Lisp, the use of a symbol as a variable is independent of
21its use as a function name.
22 19
23 As previously noted in this manual, a Lisp program is represented 20 As previously noted in this manual, a Lisp program is represented
24primarily by Lisp objects, and only secondarily as text. The textual 21primarily by Lisp objects, and only secondarily as text. The textual
@@ -151,8 +148,8 @@ does not raise an error if you actually change it.
151with new values. Sometimes it is useful to give a variable a 148with new values. Sometimes it is useful to give a variable a
152@dfn{local value}---a value that takes effect only within a certain 149@dfn{local value}---a value that takes effect only within a certain
153part of a Lisp program. When a variable has a local value, we say 150part of a Lisp program. When a variable has a local value, we say
154that it has a @dfn{local binding}, or that it is a @dfn{local 151that it is @dfn{locally bound} to that value, and that it is a
155variable}. 152@dfn{local variable}.
156 153
157 For example, when a function is called, its argument variables 154 For example, when a function is called, its argument variables
158receive local values, which are the actual arguments supplied to the 155receive local values, which are the actual arguments supplied to the
@@ -186,10 +183,10 @@ local binding. To be more precise, a rule called the @dfn{scoping
186rule} determines where in a program a local binding takes effect. The 183rule} determines where in a program a local binding takes effect. The
187default scoping rule in Emacs Lisp is called @dfn{dynamic scoping}, 184default scoping rule in Emacs Lisp is called @dfn{dynamic scoping},
188which simply states that the current binding at any given point in the 185which simply states that the current binding at any given point in the
189execution of a program is the most recently-created local binding for 186execution of a program is the most recently-created binding for that
190that variable that still exists. For details about dynamic scoping, 187variable that still exists. For details about dynamic scoping, and an
191and an alternative scoping rule called @dfn{lexical scoping}, 188alternative scoping rule called @dfn{lexical scoping}, @xref{Variable
192@xref{Variable Scoping}. 189Scoping}.
193 190
194 The special forms @code{let} and @code{let*} exist to create local 191 The special forms @code{let} and @code{let*} exist to create local
195bindings: 192bindings:
@@ -294,27 +291,27 @@ has room to execute.
294@cindex @code{void-variable} error 291@cindex @code{void-variable} error
295@cindex void variable 292@cindex void variable
296 293
297 If you have never given a symbol any value as a global variable, we 294 We say that a variable is void if its symbol has an unassigned value
298say that that symbol's global value is @dfn{void}. Note that this 295cell (@pxref{Symbol Components}). Under Emacs Lisp's default dynamic
299does @emph{not} mean the value is @code{nil}. The symbol @code{nil} 296binding rules (@pxref{Variable Scoping}), the value cell stores the
300is a Lisp object and can be the value of a variable, just as any other 297variable's current (local or global) value. Note that an unassigned
301object can be; but it is still a value. 298value cell is @emph{not} the same as having @code{nil} in the value
302 299cell. The symbol @code{nil} is a Lisp object and can be the value of
303 More precisely, a variable is void if its symbol has an unassigned 300a variable, just as any other object can be; but it is still a value.
304value cell (@pxref{Symbol Components}). Under Emacs Lisp's default 301If a variable is void, trying to evaluate the variable signals a
305dynamic binding rules, the value cell stores the variable's current 302@code{void-variable} error rather than a value.
306(local or global) value; if a variable is void, trying to evaluate the 303
307variable signals a @code{void-variable} error rather than a value. 304 Under lexical binding rules, the value cell only holds the
308But when a variable is lexically bound, it can have a local value 305variable's global value, i.e.@: the value outside of any lexical
309which is determined by the lexical environment, even if the value cell 306binding contruct. When a variable is lexically bound, the local value
310is empty and the variable is technically void. @xref{Variable 307is determined by the lexical environment; the variable may have a
311Scoping}. 308local value if its symbol's value cell is unassigned.
312 309
313@defun makunbound symbol 310@defun makunbound symbol
314This function empties out the value cell of @var{symbol}, making the 311This function empties out the value cell of @var{symbol}, making the
315variable void. It returns @var{symbol}. 312variable void. It returns @var{symbol}.
316 313
317If @var{symbol} has a (dynamic) local binding, @code{makunbound} voids 314If @var{symbol} has a dynamic local binding, @code{makunbound} voids
318the current binding, and this voidness lasts only as long as the local 315the current binding, and this voidness lasts only as long as the local
319binding is in effect. Afterwards, the previously shadowed local or 316binding is in effect. Afterwards, the previously shadowed local or
320global binding is reexposed; then the variable will no longer be void, 317global binding is reexposed; then the variable will no longer be void,
@@ -615,15 +612,15 @@ name in the text of the program. You can use the @code{symbol-value}
615function to extract the value. 612function to extract the value.
616 613
617@defun symbol-value symbol 614@defun symbol-value symbol
618This function returns the value of @var{symbol}. This is the value in 615This function returns the value stored in @var{symbol}'s value cell.
619the symbol's value cell, which is where the variable's current 616This is where the variable's current (dynamic) value is stored. If
620(dynamic) value is stored. If the variable has no local binding, this 617the variable has no local binding, this is simply its global value.
621is simply its global value. 618If the variable is void, a @code{void-variable} error is signaled.
622 619
623If the variable is lexically bound, the value reported by 620If the variable is lexically bound, the value reported by
624@code{symbol-value} is the dynamic value, and not the local lexical 621@code{symbol-value} is not necessarily the same as the variable's
625value (which is determined by the lexical environment rather than the 622lexical value, which is determined by the lexical environment rather
626symbol's value cell). @xref{Variable Scoping}. 623than the symbol's value cell. @xref{Variable Scoping}.
627 624
628@example 625@example
629@group 626@group
@@ -657,9 +654,6 @@ symbol's value cell). @xref{Variable Scoping}.
657 @result{} 5 654 @result{} 5
658@end group 655@end group
659@end example 656@end example
660
661A @code{void-variable} error is signaled if @var{symbol} is void as a
662variable.
663@end defun 657@end defun
664 658
665@node Setting Variables 659@node Setting Variables
@@ -945,13 +939,13 @@ construct.
945 939
946@example 940@example
947@group 941@group
948(defun getx ()
949 x) ; @r{@code{x} is used ``free'' in this function.}
950
951(let ((x 1)) ; @r{@code{x} is lexically bound.} 942(let ((x 1)) ; @r{@code{x} is lexically bound.}
952 (+ x 3)) 943 (+ x 3))
953 @result{} 4 944 @result{} 4
954 945
946(defun getx ()
947 x) ; @r{@code{x} is used ``free'' in this function.}
948
955(let ((x 1)) ; @r{@code{x} is lexically bound.} 949(let ((x 1)) ; @r{@code{x} is lexically bound.}
956 (getx)) 950 (getx))
957@error{} Symbol's value as variable is void: x 951@error{} Symbol's value as variable is void: x
@@ -972,20 +966,18 @@ itself.
972within the construct and their local values. When the Lisp evaluator 966within the construct and their local values. When the Lisp evaluator
973wants the current value of a variable, it looks first in the lexical 967wants the current value of a variable, it looks first in the lexical
974environment; if the variable is not specified in there, it looks in 968environment; if the variable is not specified in there, it looks in
975the symbol's value cell, where the dynamical value is stored. 969the symbol's value cell, where the dynamic value is stored.
976 970
977@cindex closures 971@cindex closures
978 Lexical bindings have indefinite extent. Even after a binding 972 Lexical bindings have indefinite extent. Even after a binding
979construct has finished executing, its lexical environment can be 973construct has finished executing, its lexical environment can be
980``kept around'' in Lisp objects called @dfn{closures}. A closure is 974``kept around'' in Lisp objects called @dfn{closures}. A closure is
981created whenever you evaluate a lambda expression (@pxref{Lambda 975created when you create a named or anonymous function with lexical
982Expressions}) with lexical binding enabled. It is represented by a 976binding enabled. @xref{Closures}, for details.
983list whose @sc{car} is the symbol @code{closure}. It is a function,
984in the sense that it can be passed as an argument to @code{funcall};
985when called as a function, any lexical variable references within its
986definition will use the retained lexical environment.
987 977
988 Here is an example which illustrates the use of a closure: 978 When a closure is called as a function, any lexical variable
979references within its definition use the retained lexical environment.
980Here is an example:
989 981
990@example 982@example
991(defvar my-ticker nil) ; @r{We will use this dynamically bound} 983(defvar my-ticker nil) ; @r{We will use this dynamically bound}
@@ -1199,7 +1191,8 @@ foo @result{} 'a
1199@end group 1191@end group
1200@end example 1192@end example
1201 1193
1202 Note that references to @code{foo} in @var{body} access the 1194@noindent
1195Note that references to @code{foo} in @var{body} access the
1203buffer-local binding of buffer @samp{b}. 1196buffer-local binding of buffer @samp{b}.
1204 1197
1205 When a file specifies local variable values, these become buffer-local 1198 When a file specifies local variable values, these become buffer-local
@@ -1642,6 +1635,11 @@ For boolean-valued variables that are safe, use @code{booleanp} as the
1642property value. Lambda expressions should be quoted so that 1635property value. Lambda expressions should be quoted so that
1643@code{describe-variable} can display the predicate. 1636@code{describe-variable} can display the predicate.
1644 1637
1638 When defining a user option using @code{defcustom}, you can set its
1639@code{safe-local-variable} property by adding the arguments
1640@code{:safe @var{function}} to @code{defcustom} (@pxref{Variable
1641Definitions}).
1642
1645@defopt safe-local-variable-values 1643@defopt safe-local-variable-values
1646This variable provides another way to mark some variable values as 1644This variable provides another way to mark some variable values as
1647safe. It is a list of cons cells @code{(@var{var} . @var{val})}, 1645safe. It is a list of cons cells @code{(@var{var} . @var{val})},
@@ -1661,28 +1659,31 @@ the value @var{val}, based on the above criteria.
1661@end defun 1659@end defun
1662 1660
1663@c @cindex risky local variable Duplicates risky-local-variable 1661@c @cindex risky local variable Duplicates risky-local-variable
1664 Some variables are considered @dfn{risky}. A variable whose name 1662 Some variables are considered @dfn{risky}. If a variable is risky,
1665ends in any of @samp{-command}, @samp{-frame-alist}, @samp{-function}, 1663it is never entered automatically into
1664@code{safe-local-variable-values}; Emacs always queries before setting
1665a risky variable, unless the user explicitly allows a value by
1666customizing @code{safe-local-variable-values} directly.
1667
1668 Any variable whose name has a non-@code{nil}
1669@code{risky-local-variable} property is considered risky. When you
1670define a user option using @code{defcustom}, you can set its
1671@code{risky-local-variable} property by adding the arguments
1672@code{:risky @var{value}} to @code{defcustom} (@pxref{Variable
1673Definitions}). In addition, any variable whose name ends in any of
1674@samp{-command}, @samp{-frame-alist}, @samp{-function},
1666@samp{-functions}, @samp{-hook}, @samp{-hooks}, @samp{-form}, 1675@samp{-functions}, @samp{-hook}, @samp{-hooks}, @samp{-form},
1667@samp{-forms}, @samp{-map}, @samp{-map-alist}, @samp{-mode-alist}, 1676@samp{-forms}, @samp{-map}, @samp{-map-alist}, @samp{-mode-alist},
1668@samp{-program}, or @samp{-predicate} is considered risky. The 1677@samp{-program}, or @samp{-predicate} is automatically considered
1669variables @samp{font-lock-keywords}, @samp{font-lock-keywords} 1678risky. The variables @samp{font-lock-keywords},
1670followed by a digit, and @samp{font-lock-syntactic-keywords} are also 1679@samp{font-lock-keywords} followed by a digit, and
1671considered risky. Finally, any variable whose name has a 1680@samp{font-lock-syntactic-keywords} are also considered risky.
1672non-@code{nil} @code{risky-local-variable} property is considered
1673risky.
1674 1681
1675@defun risky-local-variable-p sym 1682@defun risky-local-variable-p sym
1676This function returns non-@code{nil} if @var{sym} is a risky variable, 1683This function returns non-@code{nil} if @var{sym} is a risky variable,
1677based on the above criteria. 1684based on the above criteria.
1678@end defun 1685@end defun
1679 1686
1680 If a variable is risky, it will not be entered automatically into
1681@code{safe-local-variable-values} as described above. Therefore,
1682Emacs will always query before setting a risky variable, unless the
1683user explicitly allows the setting by customizing
1684@code{safe-local-variable-values} directly.
1685
1686@defvar ignored-local-variables 1687@defvar ignored-local-variables
1687This variable holds a list of variables that should not be given local 1688This variable holds a list of variables that should not be given local
1688values by files. Any value specified for one of these variables is 1689values by files. Any value specified for one of these variables is
diff --git a/doc/lispref/vol1.texi b/doc/lispref/vol1.texi
index 95f9f7f4d29..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
@@ -478,6 +479,7 @@ Functions
478* Anonymous Functions:: Lambda expressions are functions with no names. 479* Anonymous Functions:: Lambda expressions are functions with no names.
479* Function Cells:: Accessing or setting the function definition 480* Function Cells:: Accessing or setting the function definition
480 of a symbol. 481 of a symbol.
482* Closures:: Functions that enclose a lexical environment.
481* Obsolete Functions:: Declaring functions obsolete. 483* Obsolete Functions:: Declaring functions obsolete.
482* Inline Functions:: Defining functions that the compiler 484* Inline Functions:: Defining functions that the compiler
483 will open code. 485 will open code.
@@ -500,7 +502,6 @@ Macros
500* Expansion:: How, when and why macros are expanded. 502* Expansion:: How, when and why macros are expanded.
501* Compiling Macros:: How macros are expanded by the compiler. 503* Compiling Macros:: How macros are expanded by the compiler.
502* Defining Macros:: How to write a macro definition. 504* 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. 505* Problems with Macros:: Don't evaluate the macro arguments too many times.
505 Don't hide the user's variables. 506 Don't hide the user's variables.
506* Indenting Macros:: Specifying how to indent macro calls. 507* Indenting Macros:: Specifying how to indent macro calls.
@@ -1372,6 +1373,7 @@ Images
1372* Defining Images:: Convenient ways to define an image for later use. 1373* Defining Images:: Convenient ways to define an image for later use.
1373* Showing Images:: Convenient ways to display an image once 1374* Showing Images:: Convenient ways to display an image once
1374 it is defined. 1375 it is defined.
1376* Animated Images:: Some image formats can be animated.
1375* Image Cache:: Internal mechanisms of image display. 1377* Image Cache:: Internal mechanisms of image display.
1376 1378
1377Buttons 1379Buttons
diff --git a/doc/lispref/vol2.texi b/doc/lispref/vol2.texi
index 08ea022f6a7..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
@@ -477,6 +478,7 @@ Functions
477* Anonymous Functions:: Lambda expressions are functions with no names. 478* Anonymous Functions:: Lambda expressions are functions with no names.
478* Function Cells:: Accessing or setting the function definition 479* Function Cells:: Accessing or setting the function definition
479 of a symbol. 480 of a symbol.
481* Closures:: Functions that enclose a lexical environment.
480* Obsolete Functions:: Declaring functions obsolete. 482* Obsolete Functions:: Declaring functions obsolete.
481* Inline Functions:: Defining functions that the compiler 483* Inline Functions:: Defining functions that the compiler
482 will open code. 484 will open code.
@@ -499,7 +501,6 @@ Macros
499* Expansion:: How, when and why macros are expanded. 501* Expansion:: How, when and why macros are expanded.
500* Compiling Macros:: How macros are expanded by the compiler. 502* Compiling Macros:: How macros are expanded by the compiler.
501* Defining Macros:: How to write a macro definition. 503* Defining Macros:: How to write a macro definition.
502* Backquote:: Easier construction of list structure.
503* 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.
504 Don't hide the user's variables. 505 Don't hide the user's variables.
505* Indenting Macros:: Specifying how to indent macro calls. 506* Indenting Macros:: Specifying how to indent macro calls.
@@ -1371,6 +1372,7 @@ Images
1371* Defining Images:: Convenient ways to define an image for later use. 1372* Defining Images:: Convenient ways to define an image for later use.
1372* Showing Images:: Convenient ways to display an image once 1373* Showing Images:: Convenient ways to display an image once
1373 it is defined. 1374 it is defined.
1375* Animated Images:: Some image formats can be animated.
1374* Image Cache:: Internal mechanisms of image display. 1376* Image Cache:: Internal mechanisms of image display.
1375 1377
1376Buttons 1378Buttons
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index d1a045a730a..6bb1e065d37 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,8 @@
12012-01-30 Philipp Haselwarter <philipp.haselwarter@gmx.de> (tiny change)
2
3 * gnus.texi (Agent Basics): Fix outdated description of
4 `gnus-agent-auto-agentize-methods'.
5
12012-01-28 Andreas Schwab <schwab@linux-m68k.org> 62012-01-28 Andreas Schwab <schwab@linux-m68k.org>
2 7
3 * cc-mode.texi: Always @defindex ss. 8 * cc-mode.texi: Always @defindex ss.
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 7728041c83b..1883975b7f6 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -18236,8 +18236,7 @@ Agent. Go to the server buffer (@kbd{^} in the group buffer) and press
18236@kbd{J a} on the server (or servers) that you wish to have covered by the 18236@kbd{J a} on the server (or servers) that you wish to have covered by the
18237Agent (@pxref{Server Agent Commands}), or @kbd{J r} on automatically 18237Agent (@pxref{Server Agent Commands}), or @kbd{J r} on automatically
18238added servers you do not wish to have covered by the Agent. By default, 18238added servers you do not wish to have covered by the Agent. By default,
18239all @code{nntp} and @code{nnimap} servers in @code{gnus-select-method} and 18239no servers are agentized.
18240@code{gnus-secondary-select-methods} are agentized.
18241 18240
18242@item 18241@item
18243Decide on download policy. It's fairly simple once you decide whether 18242Decide on download policy. It's fairly simple once you decide whether
@@ -19263,7 +19262,7 @@ to agentize remote back ends. The auto-agentizing has the same effect
19263as running @kbd{J a} on the servers (@pxref{Server Agent Commands}). 19262as running @kbd{J a} on the servers (@pxref{Server Agent Commands}).
19264If the file exist, you must manage the servers manually by adding or 19263If the file exist, you must manage the servers manually by adding or
19265removing them, this variable is only applicable the first time you 19264removing them, this variable is only applicable the first time you
19266start Gnus. The default is @samp{(nntp nnimap)}. 19265start Gnus. The default is @samp{nil}.
19267 19266
19268@end table 19267@end table
19269 19268