diff options
| author | Glenn Morris | 2007-11-24 03:06:15 +0000 |
|---|---|---|
| committer | Glenn Morris | 2007-11-24 03:06:15 +0000 |
| commit | e31dfb12aca5db57ea41bf93f755aa0af9f1a188 (patch) | |
| tree | 2b9fa1ca1614bb1f3ab3baaa85e31a7c1965e4c2 | |
| parent | 193e7f80e63b4963b8be5025a6423656f32688f6 (diff) | |
| download | emacs-e31dfb12aca5db57ea41bf93f755aa0af9f1a188.tar.gz emacs-e31dfb12aca5db57ea41bf93f755aa0af9f1a188.zip | |
(Declaring Functions): New section.
| -rw-r--r-- | doc/lispref/functions.texi | 51 |
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}.) | |||
| 1222 | Inline functions can be used and open-coded later on in the same file, | 1223 | Inline functions can be used and open-coded later on in the same file, |
| 1223 | following the definition, just like macros. | 1224 | following 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 | |||
| 1231 | Byte-compiling a file often produces warnings about functions that are | ||
| 1232 | @samp{not known to be defined} (@pxref{Compiler Errors}). The compiler | ||
| 1233 | is technically correct, but the code is usually such that when it | ||
| 1234 | actually runs, the function @emph{will} be defined. For example, | ||
| 1235 | byte-compiling @file{fortran.el} used to warn: | ||
| 1236 | |||
| 1237 | @example | ||
| 1238 | In end of data: | ||
| 1239 | fortran.el:2152:1:Warning: the function `gud-find-c-expr' is not known | ||
| 1240 | to be defined. | ||
| 1241 | @end example | ||
| 1242 | |||
| 1243 | But @code{gud-find-c-expr} is only used in the function that Fortran | ||
| 1244 | mode uses for the local value of @code{gud-find-expr-function}. This | ||
| 1245 | would only ever be called from gud, so the warning can safely be | ||
| 1246 | suppressed. It's nice to do this, so that real warnings are more | ||
| 1247 | visible. | ||
| 1248 | |||
| 1249 | All you need to do is add a @code{declare-function} statement before the | ||
| 1250 | first use of the function in question: | ||
| 1251 | |||
| 1252 | @example | ||
| 1253 | (declare-function gud-find-c-expr "gud.el" nil) | ||
| 1254 | @end example | ||
| 1255 | |||
| 1256 | This 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 | ||
| 1259 | file containing the @code{declare-function} statement. Functions | ||
| 1260 | defined in C can also be declared - @file{.c} files are expanded | ||
| 1261 | relative to the Emacs @file{src/} directory. | ||
| 1262 | |||
| 1263 | The optional third argument specifies the argument list of | ||
| 1264 | @code{gud-find-c-expr}. In this case, it takes no arguments (@code{nil} | ||
| 1265 | is different from not specifying a value). In other cases, this might | ||
| 1266 | be something like @code{(file &optional overwrite)}. You don't have to | ||
| 1267 | specify the argument list, but if you do the byte-compiler will check | ||
| 1268 | that the calls match the declaration. | ||
| 1269 | |||
| 1270 | The 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 | ||
| 1274 | have 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 |