comparison lispref/tips.texi @ 21682:90da2489c498

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 20 Apr 1998 17:43:57 +0000
parents 66d807bdc5b4
children d4ac295a98b3
comparison
equal deleted inserted replaced
21681:11eafe90b842 21682:90da2489c498
1 @c -*-texinfo-*- 1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual. 2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1995, 1998 Free Software Foundation, Inc. 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1995, 1998 Free Software Foundation, Inc.
4 @c See the file elisp.texi for copying conditions. 4 @c See the file elisp.texi for copying conditions.
5 @setfilename ../info/tips 5 @setfilename ../info/tips
6 @node Tips, GNU Emacs Internals, Calendar, Top 6 @node Tips, GNU Emacs Internals, System Interface, Top
7 @appendix Tips and Conventions 7 @appendix Tips and Conventions
8 @cindex tips 8 @cindex tips
9 @cindex standards of coding style 9 @cindex standards of coding style
10 @cindex coding standards 10 @cindex coding standards
11 11
35 your program from other Lisp programs. Then take care to begin the 35 your program from other Lisp programs. Then take care to begin the
36 names of all global variables, constants, and functions with the chosen 36 names of all global variables, constants, and functions with the chosen
37 prefix. This helps avoid name conflicts. 37 prefix. This helps avoid name conflicts.
38 38
39 This recommendation applies even to names for traditional Lisp 39 This recommendation applies even to names for traditional Lisp
40 primitives that are not primitives in Emacs Lisp---even to @code{cadr}. 40 primitives that are not primitives in Emacs Lisp---even to
41 Believe it or not, there is more than one plausible way to define 41 @code{copy-list}. Believe it or not, there is more than one plausible
42 @code{cadr}. Play it safe; append your name prefix to produce a name 42 way to define @code{copy-list}. Play it safe; append your name prefix
43 like @code{foo-cadr} or @code{mylib-cadr} instead. 43 to produce a name like @code{foo-copy-list} or @code{mylib-copy-list}
44 instead.
44 45
45 If you write a function that you think ought to be added to Emacs under 46 If you write a function that you think ought to be added to Emacs under
46 a certain name, such as @code{twiddle-files}, don't call it by that name 47 a certain name, such as @code{twiddle-files}, don't call it by that name
47 in your program. Call it @code{mylib-twiddle-files} in your program, 48 in your program. Call it @code{mylib-twiddle-files} in your program,
48 and send mail to @samp{bug-gnu-emacs@@prep.ai.mit.edu} suggesting we add 49 and send mail to @samp{bug-gnu-emacs@@prep.ai.mit.edu} suggesting we add
73 @example 74 @example
74 (eval-when-compile (require '@var{bar})) 75 (eval-when-compile (require '@var{bar}))
75 @end example 76 @end example
76 77
77 @noindent 78 @noindent
78 (And @var{bar} should contain @code{(provide '@var{bar})}, to make the 79 (And the library @var{bar} should contain @code{(provide '@var{bar})},
79 @code{require} work.) This will cause @var{bar} to be loaded when you 80 to make the @code{require} work.) This will cause @var{bar} to be
80 byte-compile @var{foo}. Otherwise, you risk compiling @var{foo} without 81 loaded when you byte-compile @var{foo}. Otherwise, you risk compiling
81 the necessary macro loaded, and that would produce compiled code that 82 @var{foo} without the necessary macro loaded, and that would produce
82 won't work right. @xref{Compiling Macros}. 83 compiled code that won't work right. @xref{Compiling Macros}.
83 84
84 Using @code{eval-when-compile} avoids loading @var{bar} when 85 Using @code{eval-when-compile} avoids loading @var{bar} when
85 the compiled version of @var{foo} is @emph{used}. 86 the compiled version of @var{foo} is @emph{used}.
86 87
87 @item 88 @item
109 110
110 Instead, define sequences consisting of @kbd{C-c} followed by a control 111 Instead, define sequences consisting of @kbd{C-c} followed by a control
111 character, a digit, or certain punctuation characters. These sequences 112 character, a digit, or certain punctuation characters. These sequences
112 are reserved for major modes. 113 are reserved for major modes.
113 114
114 Changing all the major modes in Emacs 18 so they would follow this 115 Changing all the Emacs major modes to follow this convention was a lot
115 convention was a lot of work. Abandoning this convention would make 116 of work. Abandoning this convention would make that work go to waste,
116 that work go to waste, and inconvenience users. 117 and inconvenience users.
117 118
118 @item 119 @item
119 Sequences consisting of @kbd{C-c} followed by @kbd{@{}, @kbd{@}}, 120 Sequences consisting of @kbd{C-c} followed by @kbd{@{}, @kbd{@}},
120 @kbd{<}, @kbd{>}, @kbd{:} or @kbd{;} are also reserved for major modes. 121 @kbd{<}, @kbd{>}, @kbd{:} or @kbd{;} are also reserved for major modes.
121 122
134 @kbd{C-c}). If you don't bind @kbd{C-h}, it is automatically available 135 @kbd{C-c}). If you don't bind @kbd{C-h}, it is automatically available
135 as a help character for listing the subcommands of the prefix character. 136 as a help character for listing the subcommands of the prefix character.
136 137
137 @item 138 @item
138 Do not bind a key sequence ending in @key{ESC} except following 139 Do not bind a key sequence ending in @key{ESC} except following
139 another @key{ESC}. (That is, it is ok to bind a sequence ending in 140 another @key{ESC}. (That is, it is OK to bind a sequence ending in
140 @kbd{@key{ESC} @key{ESC}}.) 141 @kbd{@key{ESC} @key{ESC}}.)
141 142
142 The reason for this rule is that a non-prefix binding for @key{ESC} in 143 The reason for this rule is that a non-prefix binding for @key{ESC} in
143 any context prevents recognition of escape sequences as function keys in 144 any context prevents recognition of escape sequences as function keys in
144 that context. 145 that context.
249 250
250 @item 251 @item
251 In some other systems there is a convention of choosing variable names 252 In some other systems there is a convention of choosing variable names
252 that begin and end with @samp{*}. We don't use that convention in Emacs 253 that begin and end with @samp{*}. We don't use that convention in Emacs
253 Lisp, so please don't use it in your programs. (Emacs uses such names 254 Lisp, so please don't use it in your programs. (Emacs uses such names
254 only for program-generated buffers.) The users will find Emacs more 255 only for special-purpose buffers.) The users will find Emacs more
255 coherent if all libraries use the same conventions. 256 coherent if all libraries use the same conventions.
256 257
257 @item 258 @item
258 Try to avoid compiler warnings about undefined free variables, by adding 259 Try to avoid compiler warnings about undefined free variables, by adding
259 @code{defvar} definitions for these variables. 260 @code{defvar} definitions for these variables.
271 272
272 @item 273 @item
273 Don't make a habit of putting close-parentheses on lines by themselves; 274 Don't make a habit of putting close-parentheses on lines by themselves;
274 Lisp programmers find this disconcerting. Once in a while, when there 275 Lisp programmers find this disconcerting. Once in a while, when there
275 is a sequence of many consecutive close-parentheses, it may make sense 276 is a sequence of many consecutive close-parentheses, it may make sense
276 to split them in one or two significant places. 277 to split the sequence in one or two significant places.
277 278
278 @item 279 @item
279 Please put a copyright notice on the file if you give copies to anyone. 280 Please put a copyright notice on the file if you give copies to anyone.
280 Use a message like this one: 281 Use a message like this one:
281 282
364 @end itemize 365 @end itemize
365 366
366 @node Documentation Tips 367 @node Documentation Tips
367 @section Tips for Documentation Strings 368 @section Tips for Documentation Strings
368 369
369 Here are some tips for the writing of documentation strings. 370 @tindex checkdoc-minor-mode
371 @findex checkdoc-minor-mode
372 Here are some tips and conventions for the writing of documentation
373 strings. You can check many of these conventions by running the command
374 @kbd{M-x checkdoc-minor-mode}.
370 375
371 @itemize @bullet 376 @itemize @bullet
372 @item 377 @item
373 Every command, function, or variable intended for users to know about 378 Every command, function, or variable intended for users to know about
374 should have a documentation string. 379 should have a documentation string.
469 @end iftex 474 @end iftex
470 @ifinfo 475 @ifinfo
471 When a documentation string refers to a Lisp symbol, write it as it 476 When a documentation string refers to a Lisp symbol, write it as it
472 would be printed (which usually means in lower case), with single-quotes 477 would be printed (which usually means in lower case), with single-quotes
473 around it. For example: @samp{lambda}. There are two exceptions: write 478 around it. For example: @samp{lambda}. There are two exceptions: write
474 t and nil without single-quotes. (In this manual, we normally do use 479 t and nil without single-quotes. (In this manual, we use a different
475 single-quotes for those symbols.) 480 convention, with single-quotes for all symbols.)
476 @end ifinfo 481 @end ifinfo
482
483 For example:
484
485 @example
486 The value of `swim-speed' specifies how fast to swim.
487 Possible values are t for high speed, nil for low speed,
488 and `medium' for medium speed.
489 @end example
477 490
478 @item 491 @item
479 Don't write key sequences directly in documentation strings. Instead, 492 Don't write key sequences directly in documentation strings. Instead,
480 use the @samp{\\[@dots{}]} construct to stand for them. For example, 493 use the @samp{\\[@dots{}]} construct to stand for them. For example,
481 instead of writing @samp{C-f}, write the construct 494 instead of writing @samp{C-f}, write the construct
539 ;; update mode line 552 ;; update mode line
540 (force-mode-line-update))) 553 (force-mode-line-update)))
541 @end group 554 @end group
542 @end smallexample 555 @end smallexample
543 556
544 Every function that has no documentation string (because it is use only 557 Every function that has no documentation string (presumably one that is
545 internally within the package it belongs to), should have instead a 558 used only internally within the package it belongs to), should have
546 two-semicolon comment right before the function, explaining what the 559 instead a two-semicolon comment right before the function, explaining
547 function does and how to call it properly. Explain precisely what each 560 what the function does and how to call it properly. Explain precisely
548 argument means and how the function interprets its possible values. 561 what each argument means and how the function interprets its possible
562 values.
549 563
550 @item ;;; 564 @item ;;;
551 Comments that start with three semicolons, @samp{;;;}, should start at 565 Comments that start with three semicolons, @samp{;;;}, should start at
552 the left margin. Such comments are used outside function definitions to 566 the left margin. Such comments are used outside function definitions to
553 make general statements explaining the design principles of the program. 567 make general statements explaining the design principles of the program.
582 @end smallexample 596 @end smallexample
583 @end table 597 @end table
584 598
585 @noindent 599 @noindent
586 The indentation commands of the Lisp modes in Emacs, such as @kbd{M-;} 600 The indentation commands of the Lisp modes in Emacs, such as @kbd{M-;}
587 (@code{indent-for-comment}) and @key{TAB} (@code{lisp-indent-line}) 601 (@code{indent-for-comment}) and @key{TAB} (@code{lisp-indent-line}),
588 automatically indent comments according to these conventions, 602 automatically indent comments according to these conventions,
589 depending on the number of semicolons. @xref{Comments,, 603 depending on the number of semicolons. @xref{Comments,,
590 Manipulating Comments, emacs, The GNU Emacs Manual}. 604 Manipulating Comments, emacs, The GNU Emacs Manual}.
591 605
592 @node Library Headers 606 @node Library Headers
611 ;; Version: 1.2 625 ;; Version: 1.2
612 @group 626 @group
613 ;; Keywords: docs 627 ;; Keywords: docs
614 628
615 ;; This file is part of GNU Emacs. 629 ;; This file is part of GNU Emacs.
616 @var{copying permissions}@dots{} 630 @dots{}
631 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
632 ;; Boston, MA 02111-1307, USA.
617 @end group 633 @end group
618 @end smallexample 634 @end smallexample
619 635
620 The very first line should have this format: 636 The very first line should have this format:
621 637