aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2007-11-24 16:00:57 +0000
committerRichard M. Stallman2007-11-24 16:00:57 +0000
commita0925923a22ca3fa3055e27396785262039ab247 (patch)
treedccd131027752885b09effe3731c4cfc5257bd76
parentfc37ae728d88a115c8e1b5c2d9d7705284e5f40e (diff)
downloademacs-a0925923a22ca3fa3055e27396785262039ab247.tar.gz
emacs-a0925923a22ca3fa3055e27396785262039ab247.zip
(Declaring Functions): Clarify previous change.
-rw-r--r--doc/lispref/ChangeLog6
-rw-r--r--doc/lispref/functions.texi84
2 files changed, 56 insertions, 34 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 16c78f429ea..05245e8126a 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,9 @@
12007-11-24 Richard Stallman <rms@gnu.org>
2
3 * functions.texi (Declaring Functions): Clarify previous change.
4
5 * compile.texi (Compiler Errors): Clarify previous change.
6
12007-11-24 Glenn Morris <rgm@gnu.org> 72007-11-24 Glenn Morris <rgm@gnu.org>
2 8
3 * functions.texi (Declaring Functions): New section. 9 * functions.texi (Declaring Functions): New section.
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 1ea2defb059..b8fc9a41954 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1228,50 +1228,66 @@ following the definition, just like macros.
1228@cindex function declaration 1228@cindex function declaration
1229@cindex declaring functions 1229@cindex declaring functions
1230 1230
1231Byte-compiling a file often produces warnings about functions that are 1231Byte-compiling a file often produces warnings about functions that the
1232@samp{not known to be defined} (@pxref{Compiler Errors}). The compiler 1232compiler doesn't know about (@pxref{Compiler Errors}). Sometimes this
1233is technically correct, but the code is usually such that when it 1233indicates a real problem, but usually the functions in question are
1234actually runs, the function @emph{will} be defined. For example, 1234defined in other files which would be loaded if that code is run. For
1235byte-compiling @file{fortran.el} used to warn: 1235example, byte-compiling @file{fortran.el} used to warn:
1236 1236
1237@example 1237@smallexample
1238In end of data: 1238In end of data:
1239fortran.el:2152:1:Warning: the function `gud-find-c-expr' is not known 1239fortran.el:2152:1:Warning: the function `gud-find-c-expr' is not known to be defined.
1240to be defined. 1240@end smallexample
1241@end example
1242 1241
1243But @code{gud-find-c-expr} is only used in the function that Fortran 1242In fact, @code{gud-find-c-expr} is only used in the function that
1244mode uses for the local value of @code{gud-find-expr-function}. This 1243Fortran mode uses for the local value of
1245would only ever be called from gud, so the warning can safely be 1244@code{gud-find-expr-function}, which is a callback from GUD; if it is
1246suppressed. It's nice to do this, so that real warnings are more 1245called, the GUD functions will be loaded. When you know that such a
1247visible. 1246warning does not indicate a real problem, it is good to suppress the
1247warning. That makes new warnings which might mean real problems more
1248visible. You do that with @code{declare-function}.
1248 1249
1249All you need to do is add a @code{declare-function} statement before the 1250All you need to do is add a @code{declare-function} statement before the
1250first use of the function in question: 1251first use of the function in question:
1251 1252
1252@example 1253@smallexample
1253(declare-function gud-find-c-expr "gud.el" nil) 1254(declare-function gud-find-c-expr "gud.el" nil)
1254@end example 1255@end smalllexample
1255 1256
1256This says that @code{gud-find-c-expr} is defined in @file{gud.el} (the 1257This 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@samp{.el} can be omitted). The compiler takes for granted that that file
1258@code{locate-library}, and failing that it is expanded relative to the 1259really defines the function, and does not check.
1259file containing the @code{declare-function} statement. Functions 1260
1260defined in C can also be declared - @file{.c} files are expanded 1261 The optional third argument specifies the argument list of
1261relative to the Emacs @file{src/} directory. 1262@code{gud-find-c-expr}. In this case, it takes no arguments
1262 1263(@code{nil} is different from not specifying a value). In other
1263The optional third argument specifies the argument list of 1264cases, this might be something like @code{(file &optional overwrite)}.
1264@code{gud-find-c-expr}. In this case, it takes no arguments (@code{nil} 1265You don't have to specify the argument list, but if you do the
1265is different from not specifying a value). In other cases, this might 1266byte compiler can check that the calls match the declaration.
1266be something like @code{(file &optional overwrite)}. You don't have to 1267
1267specify the argument list, but if you do the byte-compiler will check 1268@defmac declare-function function file arglist
1268that the calls match the declaration. 1269Tell the byte compiler to assume that @var{function} is defined, with
1269 1270arguments @var{arglist}, and that the definition should come from
1270The functions @code{check-declare-file} and 1271the file @var{file}.
1271@code{check-declare-directory} check that all the 1272@end defmac
1272@code{declare-function} statements in a file or directory are true 1273
1273(i.e. that the functions @emph{are} defined in the specified files, and 1274 To verify that these functions really are declared where
1274have matching argument lists, if these were specified). 1275@code{declare-function} says they are, use @code{check-declare-file}
1276to check all @code{declare-function} calls in one source file, or use
1277@code{check-declare-directory} check all the files in and under a
1278certain directory.
1279
1280 These commands find the file that ought to contain a function's
1281definition using @code{locate-library}; if that finds no file, they
1282expand the definition file name relative to the directory of the file
1283that contains the @code{declare-function} call.
1284
1285 You can also say that a function is defined by C code by specifying
1286a file name ending in @samp{.c}. @code{check-declare-file} looks for
1287these files in the C source code directory. This is useful only when
1288you call a function that is defined only on certain systems. Most
1289of the primitive functions of Emacs are always defined so they will
1290never give you a warning.
1275 1291
1276@node Function Safety 1292@node Function Safety
1277@section Determining whether a Function is Safe to Call 1293@section Determining whether a Function is Safe to Call