diff options
| author | Chong Yidong | 2012-10-15 12:03:04 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-10-15 12:03:04 +0800 |
| commit | d18a0d2460cbcf73f9bd136912006fc0c11f55e0 (patch) | |
| tree | 23fc9313372ab844ccc9fe41bd3aaae71fe29a3d | |
| parent | 3e0341b0a481d833942f3964a70e7f3494588ce6 (diff) | |
| download | emacs-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/ChangeLog | 11 | ||||
| -rw-r--r-- | doc/lispref/functions.texi | 81 | ||||
| -rw-r--r-- | doc/lispref/macros.texi | 47 | ||||
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/byte-run.el | 3 |
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 @@ | |||
| 1 | 2012-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 | |||
| 1 | 2012-10-13 Chong Yidong <cyd@gnu.org> | 12 | 2012-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.) | |||
| 522 | is called @dfn{defining a function}, and it is done with the | 522 | is 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 |
| 527 | defines the symbol @var{name} as a function that looks like this: | 527 | defines 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}) | 532 | documentation string (@pxref{Function Documentation}). @var{declare}, |
| 531 | @end example | 533 | if present, should be a @code{declare} form specifying function |
| 534 | metadata (@pxref{Declare Form}). @var{interactive}, if present, | ||
| 535 | should be an @code{interactive} form specifying how the function is to | ||
| 536 | be called interactively (@pxref{Interactive Call}). | ||
| 532 | 537 | ||
| 533 | @code{defun} stores this lambda expression in the function cell of | 538 | The return value of @code{defun} is undefined. |
| 534 | @var{name}. Its return value is @emph{undefined}. | ||
| 535 | |||
| 536 | As described previously, @var{argument-list} is a list of argument | ||
| 537 | names and may include the keywords @code{&optional} and @code{&rest}. | ||
| 538 | Also, the first two of the @var{body-forms} may be a documentation | ||
| 539 | string and an interactive declaration. @xref{Lambda Components}. | ||
| 540 | 539 | ||
| 541 | Here are some examples: | 540 | Here 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} |
| 587 | This special form defines the symbol @var{name} as a function, with | 586 | This special form defines the symbol @var{name} as a function, with |
| 588 | definition @var{definition} (which can be any valid Lisp function). | 587 | definition @var{definition} (which can be any valid Lisp function). |
| 589 | Its return value is @emph{undefined}. | 588 | Its return value is @emph{undefined}. |
| 590 | 589 | ||
| 591 | If @var{docstring} is non-@code{nil}, it becomes the function | 590 | If @var{doc} is non-@code{nil}, it becomes the function documentation |
| 592 | documentation of @var{name}. Otherwise, any documentation provided by | 591 | of @var{name}. Otherwise, any documentation provided by |
| 593 | @var{definition} is used. | 592 | @var{definition} is used. |
| 594 | 593 | ||
| 595 | The proper place to use @code{defalias} is where a specific function | 594 | The 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. | |||
| 902 | But typically you should use the @code{lambda} macro, or the | 901 | But 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{} |
| 906 | This macro returns an anonymous function with argument list @var{args} | 905 | This macro returns an anonymous function with argument list |
| 907 | and 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}. |
| 909 | is @code{lambda} yields the form itself: | 908 | |
| 909 | In effect, this macro makes @code{lambda} forms ``self-quoting'': | ||
| 910 | evaluating a form whose @sc{car} is @code{lambda} yields the form | ||
| 911 | itself: | ||
| 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 | |||
| 1169 | was first made obsolete---for example, a date or a release number. | 1171 | was 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 |
| 1173 | This convenience macro marks the function @var{obsolete-name} obsolete | 1175 | This convenience macro marks the function @var{obsolete-name} obsolete |
| 1174 | and also defines it as an alias for the function @var{current-name}. | 1176 | and also defines it as an alias for the function @var{current-name}. |
| 1175 | It is equivalent to the following: | 1177 | It 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 |
| 1217 | Define an inline function. The syntax is exactly the same as | 1219 | ordinary 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} | ||
| 1222 | instead of @code{defun}. An inline function works just like an | ||
| 1223 | ordinary function except for one thing: when you byte-compile a call | ||
| 1224 | to the function (@pxref{Byte Compilation}), the function's definition | 1220 | to the function (@pxref{Byte Compilation}), the function's definition |
| 1225 | is expanded into the caller. | 1221 | is 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{} | ||
| 1225 | This macro defines an inline function. Its syntax is exactly the same | ||
| 1226 | as @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. |
| 1228 | But it also has disadvantages. For one thing, it reduces flexibility; | 1230 | But 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{} |
| 1268 | This macro ignores its arguments and evaluates to @code{nil}; it has | 1270 | This macro ignores its arguments and evaluates to @code{nil}; it has |
| 1269 | no run-time effect. However, when a @code{declare} form occurs as the | 1271 | no 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 |
| 1271 | definition or a @code{defmacro} macro definition (@pxref{Defining | 1273 | definition (@pxref{Defining Functions}) or a @code{defmacro} macro |
| 1272 | Macros}, for a description of @code{defmacro}), it appends the | 1274 | definition (@pxref{Defining Macros}), it appends the properties |
| 1273 | properties specified by @var{specs} to the function or macro. This | 1275 | specified by @var{specs} to the function or macro. This work is |
| 1274 | work is specially performed by the @code{defun} and @code{defmacro} | 1276 | specially performed by @code{defun}, @code{defsubst}, and |
| 1275 | macros. | 1277 | @code{defmacro}. |
| 1276 | |||
| 1277 | Note that if you put a @code{declare} form in an interactive function, | ||
| 1278 | it should go before the @code{interactive} form. | ||
| 1279 | 1278 | ||
| 1280 | Each element in @var{specs} should have the form @code{(@var{property} | 1279 | Each 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 |
| 189 | be a function; expansion of the macro works by applying the function | 189 | whose @sc{cdr} is a lambda expression. Expansion of the macro works |
| 190 | (with @code{apply}) to the list of unevaluated argument-expressions | 190 | by applying the lambda expression (with @code{apply}) to the list of |
| 191 | from 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 |
| 194 | function, but this is never done, because it does not make sense to pass | 194 | function, but this is never done, because it does not make sense to |
| 195 | an anonymous macro to functionals such as @code{mapcar}. In practice, | 195 | pass an anonymous macro to functionals such as @code{mapcar}. In |
| 196 | all Lisp macros have names, and they are usually defined with the | 196 | practice, all Lisp macros have names, and they are almost always |
| 197 | special form @code{defmacro}. | 197 | defined 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 |
| 201 | like this: | 201 | quoted) 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 |
| 208 | This macro object is stored in the function cell of @var{name}. Its return | 208 | macro object is stored in the function cell of @var{name}. The |
| 209 | value is @emph{undefined}. | 209 | meaning 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}). | |
| 211 | The shape and meaning of @var{argument-list} is the same as in a | 211 | Neither @var{name} nor @var{args} should be quoted. The return value |
| 212 | function, and the keywords @code{&rest} and @code{&optional} may be used | 212 | of @code{defmacro} is undefined. |
| 213 | (@pxref{Argument List}). Macros may have a documentation string, but | 213 | |
| 214 | any @code{interactive} declaration is ignored since macros cannot be | 214 | @var{doc}, if present, should be a string specifying the macro's |
| 215 | called interactively. | 215 | documentation string. @var{declare}, if present, should be a |
| 216 | @end defspec | 216 | @code{declare} form specifying metadata for the macro (@pxref{Declare |
| 217 | Form}). Note that macros cannot have interactive declarations, since | ||
| 218 | they 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 |
| 219 | of constants and nonconstant parts. To make this easier, use the | 222 | of 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 @@ | |||
| 1 | 2012-10-15 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * emacs-lisp/byte-run.el (defsubst): Doc fix. | ||
| 4 | |||
| 1 | 2012-10-14 Eli Zaretskii <eliz@gnu.org> | 5 | 2012-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)) |