aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-04-19 01:27:51 +0000
committerRichard M. Stallman1994-04-19 01:27:51 +0000
commit4b6694ef36d88f5541c4e21142af5e9d58d155d9 (patch)
treebec1127ff7ccf5c269277bfa2dd66ba57d710702
parent8d3d2a0cddfa96be9fa3f3d9733e6fc1569ea59a (diff)
downloademacs-4b6694ef36d88f5541c4e21142af5e9d58d155d9.tar.gz
emacs-4b6694ef36d88f5541c4e21142af5e9d58d155d9.zip
*** empty log message ***
-rw-r--r--lispref/tips.texi131
1 files changed, 79 insertions, 52 deletions
diff --git a/lispref/tips.texi b/lispref/tips.texi
index e917e75f463..e4c2a9f9c12 100644
--- a/lispref/tips.texi
+++ b/lispref/tips.texi
@@ -101,6 +101,18 @@ any context prevents recognition of escape sequences as function keys in
101that context. 101that context.
102 102
103@item 103@item
104Applications should not bind mouse events based on button 1 with the
105shift key held down. These events include @kbd{S-mouse-1},
106@kbd{M-S-mouse-1}, @kbd{C-S-mouse-1}, and so on. They are reserved for
107users.
108
109@item
110Modes should redefine @kbd{mouse-2} as a command to follow some sort of
111reference in the text of a buffer, if users usually would not want to
112alter the text in that buffer by hand. Modes such as Dired, Info,
113Compilation, and Occur redefine it in this way.
114
115@item
104It is a bad idea to define aliases for the Emacs primitives. 116It is a bad idea to define aliases for the Emacs primitives.
105Use the standard names instead. 117Use the standard names instead.
106 118
@@ -163,19 +175,18 @@ Do not use @code{message}, @code{throw}, @code{sleep-for},
163or @code{beep} to report errors. 175or @code{beep} to report errors.
164 176
165@item 177@item
166Avoid using recursive edits. Instead, do what the Rmail @kbd{w} command 178Try to avoid using recursive edits. Instead, do what the Rmail @kbd{e}
167does: use a new local keymap that contains one command defined to 179command does: use a new local keymap that contains one command defined
168switch back to the old local keymap. Or do what the @code{edit-options} 180to switch back to the old local keymap. Or do what the
169command does: switch to another buffer and let the user switch back at 181@code{edit-options} command does: switch to another buffer and let the
170will. @xref{Recursive Editing}. 182user switch back at will. @xref{Recursive Editing}.
171 183
172@item 184@item
173In some other systems there is a convention of choosing variable names 185In some other systems there is a convention of choosing variable names
174that begin and end with @samp{*}. We don't use that convention in Emacs 186that begin and end with @samp{*}. We don't use that convention in Emacs
175Lisp, so please don't use it in your library. (In fact, in Emacs names 187Lisp, so please don't use it in your programs. (Emacs uses such names
176of this form are conventionally used for program-generated buffers.) The 188only for program-generated buffers.) The users will find Emacs more
177users will find Emacs more coherent if all libraries use the same 189coherent if all libraries use the same conventions.
178conventions.
179 190
180@item 191@item
181Indent each function with @kbd{C-M-q} (@code{indent-sexp}) using the 192Indent each function with @kbd{C-M-q} (@code{indent-sexp}) using the
@@ -201,7 +212,7 @@ Foundation's name.
201@cindex speedups 212@cindex speedups
202 213
203 Here are ways of improving the execution speed of byte-compiled 214 Here are ways of improving the execution speed of byte-compiled
204lisp programs. 215Lisp programs.
205 216
206@itemize @bullet 217@itemize @bullet
207@item 218@item
@@ -223,7 +234,7 @@ rearranging a data structure so that one of these primitive search
223functions can be used. 234functions can be used.
224 235
225@item 236@item
226Certain built-in functions are handled specially by the byte compiler 237Certain built-in functions are handled specially in byte-compiled code,
227avoiding the need for an ordinary function call. It is a good idea to 238avoiding the need for an ordinary function call. It is a good idea to
228use these functions rather than alternatives. To see whether a function 239use these functions rather than alternatives. To see whether a function
229is handled specially by the compiler, examine its @code{byte-compile} 240is handled specially by the compiler, examine its @code{byte-compile}
@@ -234,7 +245,7 @@ For example, the following input will show you that @code{aref} is
234compiled specially (@pxref{Array Functions}) while @code{elt} is not 245compiled specially (@pxref{Array Functions}) while @code{elt} is not
235(@pxref{Sequence Functions}): 246(@pxref{Sequence Functions}):
236 247
237@smallexample 248@example
238@group 249@group
239(get 'aref 'byte-compile) 250(get 'aref 'byte-compile)
240 @result{} byte-compile-two-args 251 @result{} byte-compile-two-args
@@ -244,14 +255,14 @@ compiled specially (@pxref{Array Functions}) while @code{elt} is not
244(get 'elt 'byte-compile) 255(get 'elt 'byte-compile)
245 @result{} nil 256 @result{} nil
246@end group 257@end group
247@end smallexample 258@end example
248 259
249@item 260@item
250If calling a small function accounts for a substantial part of your 261If calling a small function accounts for a substantial part of your
251program's running time, make the function inline. This eliminates 262program's running time, make the function inline. This eliminates
252the function call overhead. Since making a function inline reduces 263the function call overhead. Since making a function inline reduces
253the flexibility of changing the program, don't do it unless it gives 264the flexibility of changing the program, don't do it unless it gives
254a noticeable speedup in something slow enough for users to care about 265a noticeable speedup in something slow enough that users care about
255the speed. @xref{Inline Functions}. 266the speed. @xref{Inline Functions}.
256@end itemize 267@end itemize
257 268
@@ -271,10 +282,10 @@ string, and you can save space by using a comment instead.
271 282
272@item 283@item
273The first line of the documentation string should consist of one or two 284The first line of the documentation string should consist of one or two
274complete sentences which stand on their own as a summary. In particular, 285complete sentences which stand on their own as a summary. @kbd{M-x
275start the line with a capital letter and end with a period. 286apropos} displays just the first line, and if it doesn't stand on its
276For instance, use ``Return the cons of A and B.'' in preference to 287own, the result looks bad. In particular, start the first line with a
277``Returns the cons of A and B@.'' 288capital letter and end with a period.
278 289
279The documentation string can have additional lines which expand on the 290The documentation string can have additional lines which expand on the
280details of how to use the function or variable. The additional lines 291details of how to use the function or variable. The additional lines
@@ -282,6 +293,14 @@ should be made up of complete sentences also, but they may be filled if
282that looks good. 293that looks good.
283 294
284@item 295@item
296For consistency, phrase the verb in the first sentence of a
297documentation string as an infinitive with ``to'' omitted. For
298instance, use ``Return the cons of A and B.'' in preference to ``Returns
299the cons of A and B@.'' Usually it looks good to do likewise for the
300rest of the first paragraph. Subsequent paragraphs usually look better
301if they have proper subjects.
302
303@item
285Write documentation strings in the active voice, not the passive, and in 304Write documentation strings in the active voice, not the passive, and in
286the present tense, not the future. For instance, use ``Return a list 305the present tense, not the future. For instance, use ``Return a list
287containing A and B.'' instead of ``A list containing A and B will be 306containing A and B.'' instead of ``A list containing A and B will be
@@ -314,22 +333,23 @@ starting double-quote is not part of the string!
314 333
315@item 334@item
316A variable's documentation string should start with @samp{*} if the 335A variable's documentation string should start with @samp{*} if the
317variable is one that users would want to set interactively often. If 336variable is one that users would often want to set interactively. If
318the value is a long list, or a function, or if the variable would only 337the value is a long list, or a function, or if the variable would only
319be set in init files, then don't start the documentation string with 338be set in init files, then don't start the documentation string with
320@samp{*}. @xref{Defining Variables}. 339@samp{*}. @xref{Defining Variables}.
321 340
322@item 341@item
323The documentation string for a variable that is a yes-or-no flag should 342The documentation string for a variable that is a yes-or-no flag should
324start with words such as ``Non-nil means@dots{}'', to make it clear both 343start with words such as ``Non-nil means@dots{}'', to make it clear that
325that the variable only has two meaningfully distinct values and which value 344all non-@code{nil} values are equivalent and indicate explicitly what
326means ``yes''. 345@code{nil} and non-@code{nil} mean.
327 346
328@item 347@item
329When a function's documentation string mentions the value of an argument 348When a function's documentation string mentions the value of an argument
330of the function, use the argument name in capital letters as if it were 349of the function, use the argument name in capital letters as if it were
331a name for that value. Thus, the documentation string of the function 350a name for that value. Thus, the documentation string of the function
332@code{/} refers to its second argument as @samp{DIVISOR}. 351@code{/} refers to its second argument as @samp{DIVISOR}, because the
352actual argument name is @code{divisor}.
333 353
334Also use all caps for meta-syntactic variables, such as when you show 354Also use all caps for meta-syntactic variables, such as when you show
335the decomposition of a list or vector into subunits, some of which may 355the decomposition of a list or vector into subunits, some of which may
@@ -353,11 +373,11 @@ single-quotes for those symbols.)
353@item 373@item
354Don't write key sequences directly in documentation strings. Instead, 374Don't write key sequences directly in documentation strings. Instead,
355use the @samp{\\[@dots{}]} construct to stand for them. For example, 375use the @samp{\\[@dots{}]} construct to stand for them. For example,
356instead of writing @samp{C-f}, write @samp{\\[forward-char]}. When the 376instead of writing @samp{C-f}, write @samp{\\[forward-char]}. When
357documentation string is printed, Emacs will substitute whatever key is 377Emacs displays the documentation string, it substitutes whatever key is
358currently bound to @code{forward-char}. This will usually be 378currently bound to @code{forward-char}. (This is normally @samp{C-f},
359@samp{C-f}, but if the user has moved key bindings, it will be the 379but it may be some other character if the user has moved key bindings.)
360correct key for that user. @xref{Keys in Documentation}. 380@xref{Keys in Documentation}.
361 381
362@item 382@item
363In documentation strings for a major mode, you will want to refer to the 383In documentation strings for a major mode, you will want to refer to the
@@ -391,7 +411,7 @@ aligned to the same column on the right of the source code. Such
391comments usually explain how the code on the same line does its job. In 411comments usually explain how the code on the same line does its job. In
392Lisp mode and related modes, the @kbd{M-;} (@code{indent-for-comment}) 412Lisp mode and related modes, the @kbd{M-;} (@code{indent-for-comment})
393command automatically inserts such a @samp{;} in the right place, or 413command automatically inserts such a @samp{;} in the right place, or
394aligns such a comment if it is already inserted. 414aligns such a comment if it is already present.
395 415
396(The following examples are taken from the Emacs sources.) 416(The following examples are taken from the Emacs sources.)
397 417
@@ -406,7 +426,7 @@ aligns such a comment if it is already inserted.
406 426
407@item ;; 427@item ;;
408Comments that start with two semicolons, @samp{;;}, should be aligned to 428Comments that start with two semicolons, @samp{;;}, should be aligned to
409the same level of indentation as the code. Such comments are used to 429the same level of indentation as the code. Such comments usually
410describe the purpose of the following lines or the state of the program 430describe the purpose of the following lines or the state of the program
411at that point. For example: 431at that point. For example:
412 432
@@ -415,18 +435,22 @@ at that point. For example:
415(prog1 (setq auto-fill-function 435(prog1 (setq auto-fill-function
416 @dots{} 436 @dots{}
417 @dots{} 437 @dots{}
418 ;; update mode-line 438 ;; update mode line
419 (force-mode-line-update))) 439 (force-mode-line-update)))
420@end group 440@end group
421@end smallexample 441@end smallexample
422 442
423These comments are also written before a function definition to explain 443Every function that has no documentation string (because it is use only
424what the function does and how to call it properly. 444internally within the package it belongs to), should have instead a
445two-semicolon comment right before the function, explaining what the
446function does and how to call it properly. Explain precisely what each
447argument means and how the function interprets its possible value.
425 448
426@item ;;; 449@item ;;;
427Comments that start with three semicolons, @samp{;;;}, should start at 450Comments that start with three semicolons, @samp{;;;}, should start at
428the left margin. Such comments are not used within function 451the left margin. Such comments are used outside function definitions to
429definitions, but are used to make more general comments. For example: 452make general statements explaining the design principles of the program.
453For example:
430 454
431@smallexample 455@smallexample
432@group 456@group
@@ -436,6 +460,17 @@ definitions, but are used to make more general comments. For example:
436@end group 460@end group
437@end smallexample 461@end smallexample
438 462
463Another use for triple-semicolon comments is for commenting out line
464within a function. We use triple-semicolons for this precisely so that
465they remain at the left margin.
466
467@smallexample
468(defun foo (a)
469;;; This is no longer necessary.
470;;; (force-mode-line-update)
471 (message "Finished with %s" a))
472@end smallexample
473
439@item ;;;; 474@item ;;;;
440Comments that start with four semicolons, @samp{;;;;}, should be aligned 475Comments that start with four semicolons, @samp{;;;;}, should be aligned
441to the left margin and are used for headings of major sections of a 476to the left margin and are used for headings of major sections of a
@@ -453,14 +488,6 @@ automatically indent comments according to these conventions,
453depending on the the number of semicolons. @xref{Comments,, 488depending on the the number of semicolons. @xref{Comments,,
454Manipulating Comments, emacs, The GNU Emacs Manual}. 489Manipulating Comments, emacs, The GNU Emacs Manual}.
455 490
456 If you wish to ``comment out'' a number of lines of code, use triple
457semicolons at the beginnings of the lines.
458
459 Any character may be included in a comment, but it is advisable to
460precede a character with syntactic significance in Lisp (such as
461@samp{\} or unpaired @samp{(} or @samp{)}) with a @samp{\}, to prevent
462it from confusing the Emacs commands for editing Lisp.
463
464@node Library Headers 491@node Library Headers
465@section Conventional Headers for Emacs Libraries 492@section Conventional Headers for Emacs Libraries
466@cindex header comments 493@cindex header comments
@@ -499,7 +526,7 @@ them. This section explains these conventions. First, an example:
499The description should be complete in one line. 526The description should be complete in one line.
500 527
501 After the copyright notice come several @dfn{header comment} lines, 528 After the copyright notice come several @dfn{header comment} lines,
502each beginning with @samp{;;; @var{header-name}:}. Here is a table of 529each beginning with @samp{;; @var{header-name}:}. Here is a table of
503the conventional possibilities for @var{header-name}: 530the conventional possibilities for @var{header-name}:
504 531
505@table @samp 532@table @samp
@@ -508,23 +535,23 @@ This line states the name and net address of at least the principal
508author of the library. 535author of the library.
509 536
510If there are multiple authors, you can list them on continuation lines 537If there are multiple authors, you can list them on continuation lines
511led by @code{;;<TAB>}, like this: 538led by @code{;;} and a tab character, like this:
512 539
513@smallexample 540@smallexample
514@group 541@group
515;; Author: Ashwin Ram <Ram-Ashwin@@cs.yale.edu> 542;; Author: Ashwin Ram <Ram-Ashwin@@cs.yale.edu>
516;; Dave Sill <de5@@ornl.gov> 543;; Dave Sill <de5@@ornl.gov>
517;; Dave Brennan <brennan@@hal.com> 544;; Dave Brennan <brennan@@hal.com>
518;; Eric Raymond <esr@@snark.thyrsus.com> 545;; Eric Raymond <esr@@snark.thyrsus.com>
519@end group 546@end group
520@end smallexample 547@end smallexample
521 548
522@item Maintainer 549@item Maintainer
523This line should contain a single name/address as in the Author line, or 550This line should contain a single name/address as in the Author line, or
524an address only, or the string ``FSF''. If there is no maintainer line, 551an address only, or the string @samp{FSF}. If there is no maintainer
525the person(s) in the Author field are presumed to be the maintainers. 552line, the person(s) in the Author field are presumed to be the
526The example above is mildly bogus because the maintainer line is 553maintainers. The example above is mildly bogus because the maintainer
527redundant. 554line is redundant.
528 555
529The idea behind the @samp{Author} and @samp{Maintainer} lines is to make 556The idea behind the @samp{Author} and @samp{Maintainer} lines is to make
530possible a Lisp function to ``send mail to the maintainer'' without 557possible a Lisp function to ``send mail to the maintainer'' without