aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2016-05-27 09:46:44 -0700
committerPaul Eggert2016-05-27 09:47:19 -0700
commitb342815c0a9af8d94d4290d17882de73f6fd9373 (patch)
tree6dccd2ee6891d29a3f134f542a94b9f1317fe488
parent09b72fc38aee1032b6d2c8476bcc22a2e7ec5642 (diff)
downloademacs-b342815c0a9af8d94d4290d17882de73f6fd9373.tar.gz
emacs-b342815c0a9af8d94d4290d17882de73f6fd9373.zip
Improve define-function omitted-arg documentation
* doc/lispref/functions.texi (Declaring Functions): * lisp/subr.el (declare-function): Be clearer when documenting omitted args for define-function.
-rw-r--r--doc/lispref/functions.texi41
-rw-r--r--lisp/subr.el18
2 files changed, 31 insertions, 28 deletions
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index ff21abba61e..7513adfbbef 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -2172,44 +2172,49 @@ Byte-compiling a file often produces warnings about functions that the
2172compiler doesn't know about (@pxref{Compiler Errors}). Sometimes this 2172compiler doesn't know about (@pxref{Compiler Errors}). Sometimes this
2173indicates a real problem, but usually the functions in question are 2173indicates a real problem, but usually the functions in question are
2174defined in other files which would be loaded if that code is run. For 2174defined in other files which would be loaded if that code is run. For
2175example, byte-compiling @file{fortran.el} used to warn: 2175example, byte-compiling @file{simple.el} used to warn:
2176 2176
2177@example 2177@example
2178In end of data: 2178simple.el:8727:1:Warning: the function ‘shell-mode’ is not known to be
2179fortran.el:2152:1:Warning: the function ‘gud-find-c-expr’ is not 2179 defined.
2180 known to be defined.
2181@end example 2180@end example
2182 2181
2183In fact, @code{gud-find-c-expr} is only used in the function that 2182In fact, @code{shell-mode} is used only in a function that executes
2184Fortran mode uses for the local value of 2183@code{(require 'shell)} before calling @code{shell-mode}, so
2185@code{gud-find-expr-function}, which is a callback from GUD; if it is 2184@code{shell-mode} will be defined properly at run-time. When you know
2186called, the GUD functions will be loaded. When you know that such a 2185that such a warning does not indicate a real problem, it is good to
2187warning does not indicate a real problem, it is good to suppress the 2186suppress the warning. That makes new warnings which might mean real
2188warning. That makes new warnings which might mean real problems more 2187problems more visible. You do that with @code{declare-function}.
2189visible. You do that with @code{declare-function}.
2190 2188
2191All you need to do is add a @code{declare-function} statement before the 2189All you need to do is add a @code{declare-function} statement before the
2192first use of the function in question: 2190first use of the function in question:
2193 2191
2194@example 2192@example
2195(declare-function gud-find-c-expr "gud.el" nil) 2193(declare-function shell-mode "shell" ())
2196@end example 2194@end example
2197 2195
2198This says that @code{gud-find-c-expr} is defined in @file{gud.el} (the 2196This says that @code{shell-mode} is defined in @file{shell.el} (the
2199@samp{.el} can be omitted). The compiler takes for granted that that file 2197@samp{.el} can be omitted). The compiler takes for granted that that file
2200really defines the function, and does not check. 2198really defines the function, and does not check.
2201 2199
2202 The optional third argument specifies the argument list of 2200 The optional third argument specifies the argument list of
2203@code{gud-find-c-expr}. In this case, it takes no arguments 2201@code{shell-mode}. In this case, it takes no arguments
2204(@code{nil} is different from not specifying a value). In other 2202(@code{nil} is different from not specifying a value). In other
2205cases, this might be something like @code{(file &optional overwrite)}. 2203cases, this might be something like @code{(file &optional overwrite)}.
2206You don't have to specify the argument list, but if you do the 2204You don't have to specify the argument list, but if you do the
2207byte compiler can check that the calls match the declaration. 2205byte compiler can check that the calls match the declaration.
2208 2206
2209@defmac declare-function function file &optional arglist fileonly 2207@defmac declare-function function file &rest args
2210Tell the byte compiler to assume that @var{function} is defined, with 2208Tell the byte compiler to assume that @var{function} is defined in the
2211arguments @var{arglist}, and that the definition should come from the 2209file @var{file}. The trailing arguments @var{args} can contain one or
2212file @var{file}. @var{fileonly} non-@code{nil} means only check that 2210two optional arguments. The first optional argument @var{arglist} is
2211either @code{t}, meaning the argument list is unspecified, or a list
2212of formal parameters in the same style as @code{defun}.@footnote{An
2213omitted @var{arglist} defaults to @code{t}, not @code{nil}; this
2214atypical behavior is why @code{declare-function} is defined to have
2215the formal parameters @code{(function file &rest args)}, not
2216@code{(function file &optional arglist fileonly)}.} The second
2217optional argument @var{fileonly} non-@code{nil} means only check that
2213@var{file} exists, not that it actually defines @var{function}. 2218@var{file} exists, not that it actually defines @var{function}.
2214@end defmac 2219@end defmac
2215 2220
diff --git a/lisp/subr.el b/lisp/subr.el
index 44d7eaccf02..239bdc08d6b 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -31,7 +31,6 @@
31 31
32(defmacro declare-function (_fn _file &rest _args) 32(defmacro declare-function (_fn _file &rest _args)
33 "Tell the byte-compiler that function FN is defined, in FILE. 33 "Tell the byte-compiler that function FN is defined, in FILE.
34Optional ARGLIST is the argument list used by the function.
35The FILE argument is not used by the byte-compiler, but by the 34The FILE argument is not used by the byte-compiler, but by the
36`check-declare' package, which checks that FILE contains a 35`check-declare' package, which checks that FILE contains a
37definition for FN. Remaining ARGS are used by both the 36definition for FN. Remaining ARGS are used by both the
@@ -47,15 +46,14 @@ declaration. A FILE with an \"ext:\" prefix is an external file.
47them without error if they are not. 46them without error if they are not.
48 47
49ARGS can contain one or two optional args. First optional arg 48ARGS can contain one or two optional args. First optional arg
50ARGLIST specifies the function arguments. Second optional arg 49ARGLIST specifies FN's arguments, or is t to not specify FN's
51FILEONLY non-nil means that `check-declare' will only check that 50arguments. An omitted ARGLIST defaults to t, not nil: a nil
52FILE exists, not that it defines FN. This is intended for 51ARGLIST specifies an empty argument list, and an explicit t
53function-definitions that `check-declare' does not recognize, e.g. 52ARGLIST is a placeholder that allows supplying a later arg.
54`defstruct'. 53Second optional arg FILEONLY non-nil means that `check-declare'
55 54will check only that FILE exists, not that it defines FN. This
56To specify a value for FILEONLY without passing an argument list, 55is intended for function definitions that `check-declare' does
57set ARGLIST to t. This is necessary because nil means an 56not recognize, e.g., `defstruct'.
58empty argument list, rather than an unspecified one.
59 57
60Note that for the purposes of `check-declare', this statement 58Note that for the purposes of `check-declare', this statement
61must be the first non-whitespace on a line. 59must be the first non-whitespace on a line.