Mercurial > emacs
comparison lispref/tips.texi @ 58281:b6f9481dcccd
(Coding Conventions): Separate defvar and require
methods to avoid warnings. Use require only when there are many
functions and variables from that package.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 16 Nov 2004 17:30:48 +0000 |
parents | 4732f3096a88 |
children | 7c9759696709 b637c617432f |
comparison
equal
deleted
inserted
replaced
58280:08330213d737 | 58281:b6f9481dcccd |
---|---|
368 only for special-purpose buffers.) The users will find Emacs more | 368 only for special-purpose buffers.) The users will find Emacs more |
369 coherent if all libraries use the same conventions. | 369 coherent if all libraries use the same conventions. |
370 | 370 |
371 @item | 371 @item |
372 Try to avoid compiler warnings about undefined free variables, by adding | 372 Try to avoid compiler warnings about undefined free variables, by adding |
373 @code{defvar} definitions for these variables. | 373 dummy @code{defvar} definitions for these variables, like this: |
374 | 374 |
375 Sometimes adding a @code{require} for another package is useful to avoid | 375 @example |
376 compilation warnings for variables and functions defined in that | 376 (defvar foo) |
377 package. If you do this, often it is better if the @code{require} acts | 377 @end example |
378 only at compile time. Here's how to do that: | 378 |
379 Such a definition has no effect except to tell the compiler | |
380 not to warn about uses of the variable @code{foo} in this file. | |
381 | |
382 @item | |
383 If you use many functions and variables from a certain file, you can | |
384 add a @code{require} for that package to avoid compilation warnings | |
385 for them. It is better if the @code{require} acts only at compile | |
386 time. Here's how to do this: | |
379 | 387 |
380 @example | 388 @example |
381 (eval-when-compile | 389 (eval-when-compile |
382 (require 'foo) | 390 (require 'foo)) |
383 (defvar bar-baz)) | 391 @end example |
384 @end example | 392 |
385 | 393 @item |
386 If you bind a variable in one function, and use it or set it in another | 394 If you bind a variable in one function, and use it or set it in |
387 function, the compiler warns about the latter function unless the | 395 another function, the compiler warns about the latter function unless |
388 variable has a definition. But often these variables have short names, | 396 the variable has a definition. But adding a definition would be |
389 and it is not clean for Lisp packages to define such variable names. | 397 unclean if the variable has a short names, since Lisp packages should |
390 Therefore, you should rename the variable to start with the name prefix | 398 not define short variable names. The right thing to do is to rename |
391 used for the other functions and variables in your package. | 399 this variable to start with the name prefix used for the other |
400 functions and variables in your package. | |
392 | 401 |
393 @item | 402 @item |
394 Indent each function with @kbd{C-M-q} (@code{indent-sexp}) using the | 403 Indent each function with @kbd{C-M-q} (@code{indent-sexp}) using the |
395 default indentation parameters. | 404 default indentation parameters. |
396 | 405 |