aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-10-15 12:03:04 +0800
committerChong Yidong2012-10-15 12:03:04 +0800
commitd18a0d2460cbcf73f9bd136912006fc0c11f55e0 (patch)
tree23fc9313372ab844ccc9fe41bd3aaae71fe29a3d
parent3e0341b0a481d833942f3964a70e7f3494588ce6 (diff)
downloademacs-d18a0d2460cbcf73f9bd136912006fc0c11f55e0.tar.gz
emacs-d18a0d2460cbcf73f9bd136912006fc0c11f55e0.zip
More documentation fixes for changes to defun, defmacro, etc.
* doc/lispref/functions.texi (Anonymous Functions): Explicitly list the docstring, declare, and interactive arguments to lambda. (Defining Functions): Likewise for defun. (Inline Functions): Likewise for defsubst. (Declare Form): Tweak description. * doc/lispref/macros.texi (Defining Macros): defmacro is now a macro. Explicitly list the docstring and declare arguments. * emacs-lisp/byte-run.el (defsubst): Doc fix.
-rw-r--r--doc/lispref/ChangeLog11
-rw-r--r--doc/lispref/functions.texi81
-rw-r--r--doc/lispref/macros.texi47
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/emacs-lisp/byte-run.el3
5 files changed, 82 insertions, 64 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 40c457ffe07..acf6f8a51ff 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,14 @@
12012-10-15 Chong Yidong <cyd@gnu.org>
2
3 * macros.texi (Defining Macros): defmacro is now a macro.
4 Explicitly list the docstring and declare arguments.
5
6 * functions.texi (Anonymous Functions): Explicitly list the
7 docstring, declare, and interactive arguments to lambda.
8 (Defining Functions): Likewise for defun.
9 (Inline Functions): Likewise for defsubst.
10 (Declare Form): Tweak description.
11
12012-10-13 Chong Yidong <cyd@gnu.org> 122012-10-13 Chong Yidong <cyd@gnu.org>
2 13
3 * display.texi (ImageMagick Images): ImageMagick enabled by default. 14 * display.texi (ImageMagick Images): ImageMagick enabled by default.
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 845561f91ec..c94e46dad18 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -522,21 +522,20 @@ Scheme.)
522is called @dfn{defining a function}, and it is done with the 522is called @dfn{defining a function}, and it is done with the
523@code{defun} special form. 523@code{defun} special form.
524 524
525@defmac defun name argument-list body-forms... 525@defmac defun name args [doc] [declare] [interactive] body@dots{}
526@code{defun} is the usual way to define new Lisp functions. It 526@code{defun} is the usual way to define new Lisp functions. It
527defines the symbol @var{name} as a function that looks like this: 527defines the symbol @var{name} as a function with argument list
528@var{args} and body forms given by @var{body}. Neither @var{name} nor
529@var{args} should be quoted.
528 530
529@example 531@var{doc}, if present, should be a string specifying the function's
530(lambda @var{argument-list} . @var{body-forms}) 532documentation string (@pxref{Function Documentation}). @var{declare},
531@end example 533if present, should be a @code{declare} form specifying function
534metadata (@pxref{Declare Form}). @var{interactive}, if present,
535should be an @code{interactive} form specifying how the function is to
536be called interactively (@pxref{Interactive Call}).
532 537
533@code{defun} stores this lambda expression in the function cell of 538The return value of @code{defun} is undefined.
534@var{name}. Its return value is @emph{undefined}.
535
536As described previously, @var{argument-list} is a list of argument
537names and may include the keywords @code{&optional} and @code{&rest}.
538Also, the first two of the @var{body-forms} may be a documentation
539string and an interactive declaration. @xref{Lambda Components}.
540 539
541Here are some examples: 540Here are some examples:
542 541
@@ -582,14 +581,14 @@ redefinition from unintentional redefinition.
582@end defmac 581@end defmac
583 582
584@cindex function aliases 583@cindex function aliases
585@defun defalias name definition &optional docstring 584@defun defalias name definition &optional doc
586@anchor{Definition of defalias} 585@anchor{Definition of defalias}
587This special form defines the symbol @var{name} as a function, with 586This special form defines the symbol @var{name} as a function, with
588definition @var{definition} (which can be any valid Lisp function). 587definition @var{definition} (which can be any valid Lisp function).
589Its return value is @emph{undefined}. 588Its return value is @emph{undefined}.
590 589
591If @var{docstring} is non-@code{nil}, it becomes the function 590If @var{doc} is non-@code{nil}, it becomes the function documentation
592documentation of @var{name}. Otherwise, any documentation provided by 591of @var{name}. Otherwise, any documentation provided by
593@var{definition} is used. 592@var{definition} is used.
594 593
595The proper place to use @code{defalias} is where a specific function 594The proper place to use @code{defalias} is where a specific function
@@ -902,11 +901,14 @@ function, you can in principle use any method to construct the list.
902But typically you should use the @code{lambda} macro, or the 901But typically you should use the @code{lambda} macro, or the
903@code{function} special form, or the @code{#'} read syntax: 902@code{function} special form, or the @code{#'} read syntax:
904 903
905@defmac lambda args body... 904@defmac lambda args [doc] [interactive] body@dots{}
906This macro returns an anonymous function with argument list @var{args} 905This macro returns an anonymous function with argument list
907and body forms given by @var{body}. In effect, this macro makes 906@var{args}, documentation string @var{doc} (if any), interactive spec
908@code{lambda} forms ``self-quoting'': evaluating a form whose @sc{car} 907@var{interactive} (if any), and body forms given by @var{body}.
909is @code{lambda} yields the form itself: 908
909In effect, this macro makes @code{lambda} forms ``self-quoting'':
910evaluating a form whose @sc{car} is @code{lambda} yields the form
911itself:
910 912
911@example 913@example
912(lambda (x) (* x x)) 914(lambda (x) (* x x))
@@ -1169,13 +1171,13 @@ If provided, @var{when} should be a string indicating when the function
1169was first made obsolete---for example, a date or a release number. 1171was first made obsolete---for example, a date or a release number.
1170@end defun 1172@end defun
1171 1173
1172@defmac define-obsolete-function-alias obsolete-name current-name &optional when docstring 1174@defmac define-obsolete-function-alias obsolete-name current-name &optional when doc
1173This convenience macro marks the function @var{obsolete-name} obsolete 1175This convenience macro marks the function @var{obsolete-name} obsolete
1174and also defines it as an alias for the function @var{current-name}. 1176and also defines it as an alias for the function @var{current-name}.
1175It is equivalent to the following: 1177It is equivalent to the following:
1176 1178
1177@example 1179@example
1178(defalias @var{obsolete-name} @var{current-name} @var{docstring}) 1180(defalias @var{obsolete-name} @var{current-name} @var{doc})
1179(make-obsolete @var{obsolete-name} @var{current-name} @var{when}) 1181(make-obsolete @var{obsolete-name} @var{current-name} @var{when})
1180@end example 1182@end example
1181@end defmac 1183@end defmac
@@ -1213,16 +1215,16 @@ this:
1213@section Inline Functions 1215@section Inline Functions
1214@cindex inline functions 1216@cindex inline functions
1215 1217
1216@defmac defsubst name argument-list body-forms... 1218 An @dfn{inline function} is a function that works just like an
1217Define an inline function. The syntax is exactly the same as 1219ordinary function, except for one thing: when you byte-compile a call
1218@code{defun} (@pxref{Defining Functions}).
1219@end defmac
1220
1221 You can define an @dfn{inline function} by using @code{defsubst}
1222instead of @code{defun}. An inline function works just like an
1223ordinary function except for one thing: when you byte-compile a call
1224to the function (@pxref{Byte Compilation}), the function's definition 1220to the function (@pxref{Byte Compilation}), the function's definition
1225is expanded into the caller. 1221is expanded into the caller. To define an inline function, use
1222@code{defsubst} instead of @code{defun}.
1223
1224@defmac defsubst name args [doc] [declare] [interactive] body@dots{}
1225This macro defines an inline function. Its syntax is exactly the same
1226as @code{defun} (@pxref{Defining Functions}).
1227@end defmac
1226 1228
1227 Making a function inline often makes its function calls run faster. 1229 Making a function inline often makes its function calls run faster.
1228But it also has disadvantages. For one thing, it reduces flexibility; 1230But it also has disadvantages. For one thing, it reduces flexibility;
@@ -1266,16 +1268,13 @@ convention in Emacs Lisp mode.
1266@anchor{Definition of declare} 1268@anchor{Definition of declare}
1267@defmac declare @var{specs}@dots{} 1269@defmac declare @var{specs}@dots{}
1268This macro ignores its arguments and evaluates to @code{nil}; it has 1270This macro ignores its arguments and evaluates to @code{nil}; it has
1269no run-time effect. However, when a @code{declare} form occurs as the 1271no run-time effect. However, when a @code{declare} form occurs in the
1270@emph{very first form} in the body of a @code{defun} function 1272@var{declare} argument of a @code{defun} or @code{defsubst} function
1271definition or a @code{defmacro} macro definition (@pxref{Defining 1273definition (@pxref{Defining Functions}) or a @code{defmacro} macro
1272Macros}, for a description of @code{defmacro}), it appends the 1274definition (@pxref{Defining Macros}), it appends the properties
1273properties specified by @var{specs} to the function or macro. This 1275specified by @var{specs} to the function or macro. This work is
1274work is specially performed by the @code{defun} and @code{defmacro} 1276specially performed by @code{defun}, @code{defsubst}, and
1275macros. 1277@code{defmacro}.
1276
1277Note that if you put a @code{declare} form in an interactive function,
1278it should go before the @code{interactive} form.
1279 1278
1280Each element in @var{specs} should have the form @code{(@var{property} 1279Each element in @var{specs} should have the form @code{(@var{property}
1281@var{args}@dots{})}, which should not be quoted. These have the 1280@var{args}@dots{})}, which should not be quoted. These have the
diff --git a/doc/lispref/macros.texi b/doc/lispref/macros.texi
index 0a5152a43a1..8be6a3fbcde 100644
--- a/doc/lispref/macros.texi
+++ b/doc/lispref/macros.texi
@@ -185,35 +185,38 @@ During Compile}).
185@node Defining Macros 185@node Defining Macros
186@section Defining Macros 186@section Defining Macros
187 187
188 A Lisp macro is a list whose @sc{car} is @code{macro}. Its @sc{cdr} should 188 A Lisp macro object is a list whose @sc{car} is @code{macro}, and
189be a function; expansion of the macro works by applying the function 189whose @sc{cdr} is a lambda expression. Expansion of the macro works
190(with @code{apply}) to the list of unevaluated argument-expressions 190by applying the lambda expression (with @code{apply}) to the list of
191from the macro call. 191@emph{unevaluated} arguments from the macro call.
192 192
193 It is possible to use an anonymous Lisp macro just like an anonymous 193 It is possible to use an anonymous Lisp macro just like an anonymous
194function, but this is never done, because it does not make sense to pass 194function, but this is never done, because it does not make sense to
195an anonymous macro to functionals such as @code{mapcar}. In practice, 195pass an anonymous macro to functionals such as @code{mapcar}. In
196all Lisp macros have names, and they are usually defined with the 196practice, all Lisp macros have names, and they are almost always
197special form @code{defmacro}. 197defined with the @code{defmacro} macro.
198 198
199@defspec defmacro name argument-list body-forms@dots{} 199@defmac defmacro name args [doc] [declare] body@dots{}
200@code{defmacro} defines the symbol @var{name} as a macro that looks 200@code{defmacro} defines the symbol @var{name} (which should not be
201like this: 201quoted) as a macro that looks like this:
202 202
203@example 203@example
204(macro lambda @var{argument-list} . @var{body-forms}) 204(macro lambda @var{args} . @var{body})
205@end example 205@end example
206 206
207(Note that the @sc{cdr} of this list is a function---a lambda expression.) 207(Note that the @sc{cdr} of this list is a lambda expression.) This
208This macro object is stored in the function cell of @var{name}. Its return 208macro object is stored in the function cell of @var{name}. The
209value is @emph{undefined}. 209meaning of @var{args} is the same as in a function, and the keywords
210 210@code{&rest} and @code{&optional} may be used (@pxref{Argument List}).
211The shape and meaning of @var{argument-list} is the same as in a 211Neither @var{name} nor @var{args} should be quoted. The return value
212function, and the keywords @code{&rest} and @code{&optional} may be used 212of @code{defmacro} is undefined.
213(@pxref{Argument List}). Macros may have a documentation string, but 213
214any @code{interactive} declaration is ignored since macros cannot be 214@var{doc}, if present, should be a string specifying the macro's
215called interactively. 215documentation string. @var{declare}, if present, should be a
216@end defspec 216@code{declare} form specifying metadata for the macro (@pxref{Declare
217Form}). Note that macros cannot have interactive declarations, since
218they cannot be called interactively.
219@end defmac
217 220
218 Macros often need to construct large list structures from a mixture 221 Macros often need to construct large list structures from a mixture
219of constants and nonconstant parts. To make this easier, use the 222of constants and nonconstant parts. To make this easier, use the
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a14217358dc..96f859ec603 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12012-10-15 Chong Yidong <cyd@gnu.org>
2
3 * emacs-lisp/byte-run.el (defsubst): Doc fix.
4
12012-10-14 Eli Zaretskii <eliz@gnu.org> 52012-10-14 Eli Zaretskii <eliz@gnu.org>
2 6
3 * window.el (display-buffer): Doc fix. 7 * window.el (display-buffer): Doc fix.
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index d740574f1e4..462b4a25154 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -232,7 +232,8 @@ The return value is undefined.
232;; fns))) 232;; fns)))
233 233
234(defmacro defsubst (name arglist &rest body) 234(defmacro defsubst (name arglist &rest body)
235 "Define an inline function. The syntax is just like that of `defun'." 235 "Define an inline function. The syntax is just like that of `defun'.
236\(fn NAME ARGLIST &optional DOCSTRING DECL &rest BODY)"
236 (declare (debug defun) (doc-string 3)) 237 (declare (debug defun) (doc-string 3))
237 (or (memq (get name 'byte-optimizer) 238 (or (memq (get name 'byte-optimizer)
238 '(nil byte-compile-inline-expand)) 239 '(nil byte-compile-inline-expand))