Mercurial > emacs
comparison lispref/tips.texi @ 25751:467b88fab665
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 17 Sep 1999 06:59:04 +0000 |
parents | 78aaef52e28f |
children | df0efa93750b |
comparison
equal
deleted
inserted
replaced
25750:f1968a807f56 | 25751:467b88fab665 |
---|---|
12 This chapter describes no additional features of Emacs Lisp. Instead | 12 This chapter describes no additional features of Emacs Lisp. Instead |
13 it gives advice on making effective use of the features described in the | 13 it gives advice on making effective use of the features described in the |
14 previous chapters, and describes conventions Emacs Lisp programmers | 14 previous chapters, and describes conventions Emacs Lisp programmers |
15 should follow. | 15 should follow. |
16 | 16 |
17 You can automatically check some of the conventions described below by | |
18 running the command @kbd{M-x checkdoc RET} when visiting a Lisp file. | |
19 It cannot check all of the conventions, and not all the warnings it | |
20 gives necessarily correspond to problems, but it is worth examining them | |
21 all. | |
22 | |
17 @menu | 23 @menu |
18 * Coding Conventions:: Conventions for clean and robust programs. | 24 * Coding Conventions:: Conventions for clean and robust programs. |
19 * Compilation Tips:: Making compiled code run fast. | 25 * Compilation Tips:: Making compiled code run fast. |
20 * Documentation Tips:: Writing readable documentation strings. | 26 * Documentation Tips:: Writing readable documentation strings. |
21 * Comment Tips:: Conventions for writing comments. | 27 * Comment Tips:: Conventions for writing comments. |
285 | 291 |
286 @item | 292 @item |
287 Try to avoid compiler warnings about undefined free variables, by adding | 293 Try to avoid compiler warnings about undefined free variables, by adding |
288 @code{defvar} definitions for these variables. | 294 @code{defvar} definitions for these variables. |
289 | 295 |
296 Sometimes adding a @code{require} for another package is useful to avoid | |
297 compilation warnings for variables and functions defined in that | |
298 package. If you do this, often it is better if the @cpde{require} acts | |
299 only at compile time. Here's how to do that: | |
300 | |
301 @example | |
302 (eval-when-compile | |
303 (require 'foo) | |
304 (defvar bar-baz)) | |
305 @end example | |
306 | |
290 If you bind a variable in one function, and use it or set it in another | 307 If you bind a variable in one function, and use it or set it in another |
291 function, the compiler warns about the latter function unless the | 308 function, the compiler warns about the latter function unless the |
292 variable has a definition. But often these variables have short names, | 309 variable has a definition. But often these variables have short names, |
293 and it is not clean for Lisp packages to define such variable names. | 310 and it is not clean for Lisp packages to define such variable names. |
294 Therefore, you should rename the variable to start with the name prefix | 311 Therefore, you should rename the variable to start with the name prefix |
419 details of how to use the function or variable. The additional lines | 436 details of how to use the function or variable. The additional lines |
420 should be made up of complete sentences also, but they may be filled if | 437 should be made up of complete sentences also, but they may be filled if |
421 that looks good. | 438 that looks good. |
422 | 439 |
423 @item | 440 @item |
424 For consistency, phrase the verb in the first sentence of a | 441 For consistency, phrase the verb in the first sentence of a function's |
425 function's documentation string as an infinitive with ``to'' omitted. For | 442 documentation string as an imperative--for instance, use ``Return the |
426 instance, use ``Return the cons of A and B.'' in preference to ``Returns | 443 cons of A and B.'' in preference to ``Returns the cons of A and B@.'' |
427 the cons of A and B@.'' Usually it looks good to do likewise for the | 444 Usually it looks good to do likewise for the rest of the first |
428 rest of the first paragraph. Subsequent paragraphs usually look better | 445 paragraph. Subsequent paragraphs usually look better if each sentence |
429 if they have proper subjects. | 446 has a proper subject. |
430 | 447 |
431 @item | 448 @item |
432 Write documentation strings in the active voice, not the passive, and in | 449 Write documentation strings in the active voice, not the passive, and in |
433 the present tense, not the future. For instance, use ``Return a list | 450 the present tense, not the future. For instance, use ``Return a list |
434 containing A and B.'' instead of ``A list containing A and B will be | 451 containing A and B.'' instead of ``A list containing A and B will be |
483 of the function, use the argument name in capital letters as if it were | 500 of the function, use the argument name in capital letters as if it were |
484 a name for that value. Thus, the documentation string of the function | 501 a name for that value. Thus, the documentation string of the function |
485 @code{/} refers to its second argument as @samp{DIVISOR}, because the | 502 @code{/} refers to its second argument as @samp{DIVISOR}, because the |
486 actual argument name is @code{divisor}. | 503 actual argument name is @code{divisor}. |
487 | 504 |
488 Also use all caps for meta-syntactic variables, such as when you show | 505 Also use all caps for metasyntactic variables, such as when you show |
489 the decomposition of a list or vector into subunits, some of which may | 506 the decomposition of a list or vector into subunits, some of which may |
490 vary. | 507 vary. @samp{KEY} and @samp{VALUE} in the following example |
508 illustrate this practice: | |
509 | |
510 @example | |
511 The argument TABLE should be an alist whose elements | |
512 have the form (KEY . VALUE). Here, KEY is ... | |
513 @end example | |
491 | 514 |
492 @item | 515 @item |
493 @iftex | 516 @iftex |
494 When a documentation string refers to a Lisp symbol, write it as it | 517 When a documentation string refers to a Lisp symbol, write it as it |
495 would be printed (which usually means in lower case), with single-quotes | 518 would be printed (which usually means in lower case), with single-quotes |
535 | 558 |
536 @noindent | 559 @noindent |
537 does not make a hyperlink to the documentation, irrelevant here, of the | 560 does not make a hyperlink to the documentation, irrelevant here, of the |
538 function @code{list}. | 561 function @code{list}. |
539 | 562 |
563 To make a hyperlink to Info documentation, write the name of the Info | |
564 node in single quotes, preceded by @samp{info node} or @samp{Info | |
565 node}. The Info file name defaults to @samp{emacs}. For example, | |
566 | |
567 @smallexample | |
568 See Info node `Font Lock' and Info node `(elisp)Font Lock Basics'. | |
569 @end smallexample | |
570 | |
540 @item | 571 @item |
541 Don't write key sequences directly in documentation strings. Instead, | 572 Don't write key sequences directly in documentation strings. Instead, |
542 use the @samp{\\[@dots{}]} construct to stand for them. For example, | 573 use the @samp{\\[@dots{}]} construct to stand for them. For example, |
543 instead of writing @samp{C-f}, write the construct | 574 instead of writing @samp{C-f}, write the construct |
544 @samp{\\[forward-char]}. When Emacs displays the documentation string, | 575 @samp{\\[forward-char]}. When Emacs displays the documentation string, |
657 @cindex header comments | 688 @cindex header comments |
658 @cindex library header comments | 689 @cindex library header comments |
659 | 690 |
660 Emacs has conventions for using special comments in Lisp libraries | 691 Emacs has conventions for using special comments in Lisp libraries |
661 to divide them into sections and give information such as who wrote | 692 to divide them into sections and give information such as who wrote |
662 them. This section explains these conventions. First, an example: | 693 them. This section explains these conventions. |
694 | |
695 We'll start with an example, a package that is included in the Emacs | |
696 distribution. | |
697 | |
698 Parts of this example reflect its status as part of Emacs; for | |
699 example, the copyright notice lists the Free Software Foundation as the | |
700 copyright holder, and the copying permission says the file is part of | |
701 Emacs. When you write a package and post it, the copyright holder would | |
702 be you (unless your employer claims to own it instead), and you should | |
703 get the suggested copying permission from the end of the GNU General | |
704 Public License itself. Don't say your file is part of Emacs | |
705 if we haven't installed it in Emacs yet! | |
706 | |
707 With that warning out of the way, on to the example: | |
663 | 708 |
664 @smallexample | 709 @smallexample |
665 @group | 710 @group |
666 ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers | 711 ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers |
667 | 712 |
771 @item ;;; Change Log: | 816 @item ;;; Change Log: |
772 This begins change log information stored in the library file (if you | 817 This begins change log information stored in the library file (if you |
773 store the change history there). For most of the Lisp | 818 store the change history there). For most of the Lisp |
774 files distributed with Emacs, the change history is kept in the file | 819 files distributed with Emacs, the change history is kept in the file |
775 @file{ChangeLog} and not in the source file at all; these files do | 820 @file{ChangeLog} and not in the source file at all; these files do |
776 not have a @samp{;;; Change Log:} line. | 821 not have a @samp{;;; Change Log:} line. @samp{History} is an |
822 alternative to @samp{Change Log}. | |
777 | 823 |
778 @item ;;; Code: | 824 @item ;;; Code: |
779 This begins the actual code of the program. | 825 This begins the actual code of the program. |
780 | 826 |
781 @item ;;; @var{filename} ends here | 827 @item ;;; @var{filename} ends here |