diff options
| author | Richard M. Stallman | 1994-04-19 01:27:51 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-19 01:27:51 +0000 |
| commit | 4b6694ef36d88f5541c4e21142af5e9d58d155d9 (patch) | |
| tree | bec1127ff7ccf5c269277bfa2dd66ba57d710702 | |
| parent | 8d3d2a0cddfa96be9fa3f3d9733e6fc1569ea59a (diff) | |
| download | emacs-4b6694ef36d88f5541c4e21142af5e9d58d155d9.tar.gz emacs-4b6694ef36d88f5541c4e21142af5e9d58d155d9.zip | |
*** empty log message ***
| -rw-r--r-- | lispref/tips.texi | 131 |
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 | |||
| 101 | that context. | 101 | that context. |
| 102 | 102 | ||
| 103 | @item | 103 | @item |
| 104 | Applications should not bind mouse events based on button 1 with the | ||
| 105 | shift 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 | ||
| 107 | users. | ||
| 108 | |||
| 109 | @item | ||
| 110 | Modes should redefine @kbd{mouse-2} as a command to follow some sort of | ||
| 111 | reference in the text of a buffer, if users usually would not want to | ||
| 112 | alter the text in that buffer by hand. Modes such as Dired, Info, | ||
| 113 | Compilation, and Occur redefine it in this way. | ||
| 114 | |||
| 115 | @item | ||
| 104 | It is a bad idea to define aliases for the Emacs primitives. | 116 | It is a bad idea to define aliases for the Emacs primitives. |
| 105 | Use the standard names instead. | 117 | Use the standard names instead. |
| 106 | 118 | ||
| @@ -163,19 +175,18 @@ Do not use @code{message}, @code{throw}, @code{sleep-for}, | |||
| 163 | or @code{beep} to report errors. | 175 | or @code{beep} to report errors. |
| 164 | 176 | ||
| 165 | @item | 177 | @item |
| 166 | Avoid using recursive edits. Instead, do what the Rmail @kbd{w} command | 178 | Try to avoid using recursive edits. Instead, do what the Rmail @kbd{e} |
| 167 | does: use a new local keymap that contains one command defined to | 179 | command does: use a new local keymap that contains one command defined |
| 168 | switch back to the old local keymap. Or do what the @code{edit-options} | 180 | to switch back to the old local keymap. Or do what the |
| 169 | command 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 |
| 170 | will. @xref{Recursive Editing}. | 182 | user switch back at will. @xref{Recursive Editing}. |
| 171 | 183 | ||
| 172 | @item | 184 | @item |
| 173 | In some other systems there is a convention of choosing variable names | 185 | In some other systems there is a convention of choosing variable names |
| 174 | that begin and end with @samp{*}. We don't use that convention in Emacs | 186 | that begin and end with @samp{*}. We don't use that convention in Emacs |
| 175 | Lisp, so please don't use it in your library. (In fact, in Emacs names | 187 | Lisp, so please don't use it in your programs. (Emacs uses such names |
| 176 | of this form are conventionally used for program-generated buffers.) The | 188 | only for program-generated buffers.) The users will find Emacs more |
| 177 | users will find Emacs more coherent if all libraries use the same | 189 | coherent if all libraries use the same conventions. |
| 178 | conventions. | ||
| 179 | 190 | ||
| 180 | @item | 191 | @item |
| 181 | Indent each function with @kbd{C-M-q} (@code{indent-sexp}) using the | 192 | Indent 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 |
| 204 | lisp programs. | 215 | Lisp 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 | |||
| 223 | functions can be used. | 234 | functions can be used. |
| 224 | 235 | ||
| 225 | @item | 236 | @item |
| 226 | Certain built-in functions are handled specially by the byte compiler | 237 | Certain built-in functions are handled specially in byte-compiled code, |
| 227 | avoiding the need for an ordinary function call. It is a good idea to | 238 | avoiding the need for an ordinary function call. It is a good idea to |
| 228 | use these functions rather than alternatives. To see whether a function | 239 | use these functions rather than alternatives. To see whether a function |
| 229 | is handled specially by the compiler, examine its @code{byte-compile} | 240 | is 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 | |||
| 234 | compiled specially (@pxref{Array Functions}) while @code{elt} is not | 245 | compiled 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 |
| 250 | If calling a small function accounts for a substantial part of your | 261 | If calling a small function accounts for a substantial part of your |
| 251 | program's running time, make the function inline. This eliminates | 262 | program's running time, make the function inline. This eliminates |
| 252 | the function call overhead. Since making a function inline reduces | 263 | the function call overhead. Since making a function inline reduces |
| 253 | the flexibility of changing the program, don't do it unless it gives | 264 | the flexibility of changing the program, don't do it unless it gives |
| 254 | a noticeable speedup in something slow enough for users to care about | 265 | a noticeable speedup in something slow enough that users care about |
| 255 | the speed. @xref{Inline Functions}. | 266 | the 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 |
| 273 | The first line of the documentation string should consist of one or two | 284 | The first line of the documentation string should consist of one or two |
| 274 | complete sentences which stand on their own as a summary. In particular, | 285 | complete sentences which stand on their own as a summary. @kbd{M-x |
| 275 | start the line with a capital letter and end with a period. | 286 | apropos} displays just the first line, and if it doesn't stand on its |
| 276 | For instance, use ``Return the cons of A and B.'' in preference to | 287 | own, the result looks bad. In particular, start the first line with a |
| 277 | ``Returns the cons of A and B@.'' | 288 | capital letter and end with a period. |
| 278 | 289 | ||
| 279 | The documentation string can have additional lines which expand on the | 290 | The documentation string can have additional lines which expand on the |
| 280 | details of how to use the function or variable. The additional lines | 291 | details 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 | |||
| 282 | that looks good. | 293 | that looks good. |
| 283 | 294 | ||
| 284 | @item | 295 | @item |
| 296 | For consistency, phrase the verb in the first sentence of a | ||
| 297 | documentation string as an infinitive with ``to'' omitted. For | ||
| 298 | instance, use ``Return the cons of A and B.'' in preference to ``Returns | ||
| 299 | the cons of A and B@.'' Usually it looks good to do likewise for the | ||
| 300 | rest of the first paragraph. Subsequent paragraphs usually look better | ||
| 301 | if they have proper subjects. | ||
| 302 | |||
| 303 | @item | ||
| 285 | Write documentation strings in the active voice, not the passive, and in | 304 | Write documentation strings in the active voice, not the passive, and in |
| 286 | the present tense, not the future. For instance, use ``Return a list | 305 | the present tense, not the future. For instance, use ``Return a list |
| 287 | containing A and B.'' instead of ``A list containing A and B will be | 306 | containing 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 |
| 316 | A variable's documentation string should start with @samp{*} if the | 335 | A variable's documentation string should start with @samp{*} if the |
| 317 | variable is one that users would want to set interactively often. If | 336 | variable is one that users would often want to set interactively. If |
| 318 | the value is a long list, or a function, or if the variable would only | 337 | the value is a long list, or a function, or if the variable would only |
| 319 | be set in init files, then don't start the documentation string with | 338 | be 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 |
| 323 | The documentation string for a variable that is a yes-or-no flag should | 342 | The documentation string for a variable that is a yes-or-no flag should |
| 324 | start with words such as ``Non-nil means@dots{}'', to make it clear both | 343 | start with words such as ``Non-nil means@dots{}'', to make it clear that |
| 325 | that the variable only has two meaningfully distinct values and which value | 344 | all non-@code{nil} values are equivalent and indicate explicitly what |
| 326 | means ``yes''. | 345 | @code{nil} and non-@code{nil} mean. |
| 327 | 346 | ||
| 328 | @item | 347 | @item |
| 329 | When a function's documentation string mentions the value of an argument | 348 | When a function's documentation string mentions the value of an argument |
| 330 | of the function, use the argument name in capital letters as if it were | 349 | of the function, use the argument name in capital letters as if it were |
| 331 | a name for that value. Thus, the documentation string of the function | 350 | a 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 |
| 352 | actual argument name is @code{divisor}. | ||
| 333 | 353 | ||
| 334 | Also use all caps for meta-syntactic variables, such as when you show | 354 | Also use all caps for meta-syntactic variables, such as when you show |
| 335 | the decomposition of a list or vector into subunits, some of which may | 355 | the 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 |
| 354 | Don't write key sequences directly in documentation strings. Instead, | 374 | Don't write key sequences directly in documentation strings. Instead, |
| 355 | use the @samp{\\[@dots{}]} construct to stand for them. For example, | 375 | use the @samp{\\[@dots{}]} construct to stand for them. For example, |
| 356 | instead of writing @samp{C-f}, write @samp{\\[forward-char]}. When the | 376 | instead of writing @samp{C-f}, write @samp{\\[forward-char]}. When |
| 357 | documentation string is printed, Emacs will substitute whatever key is | 377 | Emacs displays the documentation string, it substitutes whatever key is |
| 358 | currently bound to @code{forward-char}. This will usually be | 378 | currently 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 | 379 | but it may be some other character if the user has moved key bindings.) |
| 360 | correct key for that user. @xref{Keys in Documentation}. | 380 | @xref{Keys in Documentation}. |
| 361 | 381 | ||
| 362 | @item | 382 | @item |
| 363 | In documentation strings for a major mode, you will want to refer to the | 383 | In 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 | |||
| 391 | comments usually explain how the code on the same line does its job. In | 411 | comments usually explain how the code on the same line does its job. In |
| 392 | Lisp mode and related modes, the @kbd{M-;} (@code{indent-for-comment}) | 412 | Lisp mode and related modes, the @kbd{M-;} (@code{indent-for-comment}) |
| 393 | command automatically inserts such a @samp{;} in the right place, or | 413 | command automatically inserts such a @samp{;} in the right place, or |
| 394 | aligns such a comment if it is already inserted. | 414 | aligns 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 ;; |
| 408 | Comments that start with two semicolons, @samp{;;}, should be aligned to | 428 | Comments that start with two semicolons, @samp{;;}, should be aligned to |
| 409 | the same level of indentation as the code. Such comments are used to | 429 | the same level of indentation as the code. Such comments usually |
| 410 | describe the purpose of the following lines or the state of the program | 430 | describe the purpose of the following lines or the state of the program |
| 411 | at that point. For example: | 431 | at 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 | ||
| 423 | These comments are also written before a function definition to explain | 443 | Every function that has no documentation string (because it is use only |
| 424 | what the function does and how to call it properly. | 444 | internally within the package it belongs to), should have instead a |
| 445 | two-semicolon comment right before the function, explaining what the | ||
| 446 | function does and how to call it properly. Explain precisely what each | ||
| 447 | argument means and how the function interprets its possible value. | ||
| 425 | 448 | ||
| 426 | @item ;;; | 449 | @item ;;; |
| 427 | Comments that start with three semicolons, @samp{;;;}, should start at | 450 | Comments that start with three semicolons, @samp{;;;}, should start at |
| 428 | the left margin. Such comments are not used within function | 451 | the left margin. Such comments are used outside function definitions to |
| 429 | definitions, but are used to make more general comments. For example: | 452 | make general statements explaining the design principles of the program. |
| 453 | For 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 | ||
| 463 | Another use for triple-semicolon comments is for commenting out line | ||
| 464 | within a function. We use triple-semicolons for this precisely so that | ||
| 465 | they 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 ;;;; |
| 440 | Comments that start with four semicolons, @samp{;;;;}, should be aligned | 475 | Comments that start with four semicolons, @samp{;;;;}, should be aligned |
| 441 | to the left margin and are used for headings of major sections of a | 476 | to the left margin and are used for headings of major sections of a |
| @@ -453,14 +488,6 @@ automatically indent comments according to these conventions, | |||
| 453 | depending on the the number of semicolons. @xref{Comments,, | 488 | depending on the the number of semicolons. @xref{Comments,, |
| 454 | Manipulating Comments, emacs, The GNU Emacs Manual}. | 489 | Manipulating Comments, emacs, The GNU Emacs Manual}. |
| 455 | 490 | ||
| 456 | If you wish to ``comment out'' a number of lines of code, use triple | ||
| 457 | semicolons at the beginnings of the lines. | ||
| 458 | |||
| 459 | Any character may be included in a comment, but it is advisable to | ||
| 460 | precede a character with syntactic significance in Lisp (such as | ||
| 461 | @samp{\} or unpaired @samp{(} or @samp{)}) with a @samp{\}, to prevent | ||
| 462 | it 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: | |||
| 499 | The description should be complete in one line. | 526 | The 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, |
| 502 | each beginning with @samp{;;; @var{header-name}:}. Here is a table of | 529 | each beginning with @samp{;; @var{header-name}:}. Here is a table of |
| 503 | the conventional possibilities for @var{header-name}: | 530 | the 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 | |||
| 508 | author of the library. | 535 | author of the library. |
| 509 | 536 | ||
| 510 | If there are multiple authors, you can list them on continuation lines | 537 | If there are multiple authors, you can list them on continuation lines |
| 511 | led by @code{;;<TAB>}, like this: | 538 | led 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 |
| 523 | This line should contain a single name/address as in the Author line, or | 550 | This line should contain a single name/address as in the Author line, or |
| 524 | an address only, or the string ``FSF''. If there is no maintainer line, | 551 | an address only, or the string @samp{FSF}. If there is no maintainer |
| 525 | the person(s) in the Author field are presumed to be the maintainers. | 552 | line, the person(s) in the Author field are presumed to be the |
| 526 | The example above is mildly bogus because the maintainer line is | 553 | maintainers. The example above is mildly bogus because the maintainer |
| 527 | redundant. | 554 | line is redundant. |
| 528 | 555 | ||
| 529 | The idea behind the @samp{Author} and @samp{Maintainer} lines is to make | 556 | The idea behind the @samp{Author} and @samp{Maintainer} lines is to make |
| 530 | possible a Lisp function to ``send mail to the maintainer'' without | 557 | possible a Lisp function to ``send mail to the maintainer'' without |