aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2007-11-24 03:06:15 +0000
committerGlenn Morris2007-11-24 03:06:15 +0000
commite31dfb12aca5db57ea41bf93f755aa0af9f1a188 (patch)
tree2b9fa1ca1614bb1f3ab3baaa85e31a7c1965e4c2
parent193e7f80e63b4963b8be5025a6423656f32688f6 (diff)
downloademacs-e31dfb12aca5db57ea41bf93f755aa0af9f1a188.tar.gz
emacs-e31dfb12aca5db57ea41bf93f755aa0af9f1a188.zip
(Declaring Functions): New section.
-rw-r--r--doc/lispref/functions.texi51
1 files changed, 51 insertions, 0 deletions
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 601644629e5..1ea2defb059 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -23,6 +23,7 @@ define them.
23 of a symbol. 23 of a symbol.
24* Obsolete Functions:: Declaring functions obsolete. 24* Obsolete Functions:: Declaring functions obsolete.
25* Inline Functions:: Defining functions that the compiler will open code. 25* Inline Functions:: Defining functions that the compiler will open code.
26* Declaring Functions:: Telling the compiler that a function is defined.
26* Function Safety:: Determining whether a function is safe to call. 27* Function Safety:: Determining whether a function is safe to call.
27* Related Topics:: Cross-references to specific Lisp primitives 28* Related Topics:: Cross-references to specific Lisp primitives
28 that have a special bearing on how functions work. 29 that have a special bearing on how functions work.
@@ -1222,6 +1223,56 @@ do for macros. (@xref{Argument Evaluation}.)
1222Inline functions can be used and open-coded later on in the same file, 1223Inline functions can be used and open-coded later on in the same file,
1223following the definition, just like macros. 1224following the definition, just like macros.
1224 1225
1226@node Declaring Functions
1227@section Telling the Compiler that a Function is Defined
1228@cindex function declaration
1229@cindex declaring functions
1230
1231Byte-compiling a file often produces warnings about functions that are
1232@samp{not known to be defined} (@pxref{Compiler Errors}). The compiler
1233is technically correct, but the code is usually such that when it
1234actually runs, the function @emph{will} be defined. For example,
1235byte-compiling @file{fortran.el} used to warn:
1236
1237@example
1238In end of data:
1239fortran.el:2152:1:Warning: the function `gud-find-c-expr' is not known
1240to be defined.
1241@end example
1242
1243But @code{gud-find-c-expr} is only used in the function that Fortran
1244mode uses for the local value of @code{gud-find-expr-function}. This
1245would only ever be called from gud, so the warning can safely be
1246suppressed. It's nice to do this, so that real warnings are more
1247visible.
1248
1249All you need to do is add a @code{declare-function} statement before the
1250first use of the function in question:
1251
1252@example
1253(declare-function gud-find-c-expr "gud.el" nil)
1254@end example
1255
1256This says that @code{gud-find-c-expr} is defined in @file{gud.el} (the
1257`.el' can be omitted). The file is searched for using
1258@code{locate-library}, and failing that it is expanded relative to the
1259file containing the @code{declare-function} statement. Functions
1260defined in C can also be declared - @file{.c} files are expanded
1261relative to the Emacs @file{src/} directory.
1262
1263The optional third argument specifies the argument list of
1264@code{gud-find-c-expr}. In this case, it takes no arguments (@code{nil}
1265is different from not specifying a value). In other cases, this might
1266be something like @code{(file &optional overwrite)}. You don't have to
1267specify the argument list, but if you do the byte-compiler will check
1268that the calls match the declaration.
1269
1270The functions @code{check-declare-file} and
1271@code{check-declare-directory} check that all the
1272@code{declare-function} statements in a file or directory are true
1273(i.e. that the functions @emph{are} defined in the specified files, and
1274have matching argument lists, if these were specified).
1275
1225@node Function Safety 1276@node Function Safety
1226@section Determining whether a Function is Safe to Call 1277@section Determining whether a Function is Safe to Call
1227@cindex function safety 1278@cindex function safety