diff options
| -rw-r--r-- | admin/FOR-RELEASE | 2 | ||||
| -rw-r--r-- | doc/lispref/ChangeLog | 13 | ||||
| -rw-r--r-- | doc/lispref/tips.texi | 273 |
3 files changed, 142 insertions, 146 deletions
diff --git a/admin/FOR-RELEASE b/admin/FOR-RELEASE index 8e712f5fcf8..31a2a7ddbf7 100644 --- a/admin/FOR-RELEASE +++ b/admin/FOR-RELEASE | |||
| @@ -227,7 +227,7 @@ strings.texi cyd | |||
| 227 | symbols.texi cyd | 227 | symbols.texi cyd |
| 228 | syntax.texi cyd | 228 | syntax.texi cyd |
| 229 | text.texi | 229 | text.texi |
| 230 | tips.texi | 230 | tips.texi rgm |
| 231 | variables.texi cyd | 231 | variables.texi cyd |
| 232 | windows.texi | 232 | windows.texi |
| 233 | 233 | ||
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 254ad0ae83b..bfd49e82d83 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2012-03-03 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * tips.texi: Copyedits. | ||
| 4 | (Coding Conventions): Mention autoloads. | ||
| 5 | Combine partially duplicated macro items. Fix xref. | ||
| 6 | Refer to Library Headers for copyright notice. | ||
| 7 | (Programming Tips): edit-options is long-obsolete. | ||
| 8 | (Compilation Tips): Mention loading bytecomp for byte-compile props. | ||
| 9 | (Warning Tips): Mention declare-function. | ||
| 10 | (Documentation Tips): Remove old info. | ||
| 11 | (Comment Tips): Mention comment-dwim, not indent-for-comment. | ||
| 12 | (Library Headers): General update. | ||
| 13 | |||
| 1 | 2012-03-02 Glenn Morris <rgm@gnu.org> | 14 | 2012-03-02 Glenn Morris <rgm@gnu.org> |
| 2 | 15 | ||
| 3 | * backups.texi (Reverting): Un-duplicate revert-buffer-in-progress-p, | 16 | * backups.texi (Reverting): Un-duplicate revert-buffer-in-progress-p, |
diff --git a/doc/lispref/tips.texi b/doc/lispref/tips.texi index ad1f622bfac..5874a848807 100644 --- a/doc/lispref/tips.texi +++ b/doc/lispref/tips.texi | |||
| @@ -58,7 +58,7 @@ Separate the prefix from the rest of the name with a hyphen, @samp{-}. | |||
| 58 | This practice helps avoid name conflicts, since all global variables | 58 | This practice helps avoid name conflicts, since all global variables |
| 59 | in Emacs Lisp share the same name space, and all functions share | 59 | in Emacs Lisp share the same name space, and all functions share |
| 60 | another name space@footnote{The benefits of a Common Lisp-style | 60 | another name space@footnote{The benefits of a Common Lisp-style |
| 61 | package system are considered not to outweigh the costs.} | 61 | package system are considered not to outweigh the costs.}. |
| 62 | 62 | ||
| 63 | Occasionally, for a command name intended for users to use, it is more | 63 | Occasionally, for a command name intended for users to use, it is more |
| 64 | convenient if some words come before the package's name prefix. And | 64 | convenient if some words come before the package's name prefix. And |
| @@ -110,6 +110,17 @@ called before the first use of the macro in the file. @xref{Compiling | |||
| 110 | Macros}. | 110 | Macros}. |
| 111 | 111 | ||
| 112 | @item | 112 | @item |
| 113 | Avoid loading additional libraries at run time unless they are really | ||
| 114 | needed. If your file simply cannot work without some other library, | ||
| 115 | then just @code{require} that library at the top-level and be done | ||
| 116 | with it. But if your file contains several independent features, and | ||
| 117 | only one or two require the extra library, then consider putting | ||
| 118 | @code{require} statements inside the relevant functions rather than at | ||
| 119 | the top-level. Or use @code{autoload} statements to load the extra | ||
| 120 | library when needed. This way people who don't use those aspects of | ||
| 121 | your file do not need to load the extra library. | ||
| 122 | |||
| 123 | @item | ||
| 113 | Please don't require the @code{cl} package of Common Lisp extensions at | 124 | Please don't require the @code{cl} package of Common Lisp extensions at |
| 114 | run time. Use of this package is optional, and it is not part of the | 125 | run time. Use of this package is optional, and it is not part of the |
| 115 | standard Emacs namespace. If your package loads @code{cl} at run time, | 126 | standard Emacs namespace. If your package loads @code{cl} at run time, |
| @@ -194,11 +205,8 @@ replacements differs from that of the originals. | |||
| 194 | 205 | ||
| 195 | @item | 206 | @item |
| 196 | Constructs that define a function or variable should be macros, | 207 | Constructs that define a function or variable should be macros, |
| 197 | not functions, and their names should start with @samp{def}. | 208 | not functions, and their names should start with @samp{define-}. |
| 198 | 209 | The macro should receive the name to be | |
| 199 | @item | ||
| 200 | A macro that defines a function or variable should have a name that | ||
| 201 | starts with @samp{define-}. The macro should receive the name to be | ||
| 202 | defined as the first argument. That will help various tools find the | 210 | defined as the first argument. That will help various tools find the |
| 203 | definition automatically. Avoid constructing the names in the macro | 211 | definition automatically. Avoid constructing the names in the macro |
| 204 | itself, since that would confuse these tools. | 212 | itself, since that would confuse these tools. |
| @@ -207,7 +215,7 @@ itself, since that would confuse these tools. | |||
| 207 | In some other systems there is a convention of choosing variable names | 215 | In some other systems there is a convention of choosing variable names |
| 208 | that begin and end with @samp{*}. We don't use that convention in Emacs | 216 | that begin and end with @samp{*}. We don't use that convention in Emacs |
| 209 | Lisp, so please don't use it in your programs. (Emacs uses such names | 217 | Lisp, so please don't use it in your programs. (Emacs uses such names |
| 210 | only for special-purpose buffers.) The users will find Emacs more | 218 | only for special-purpose buffers.) People will find Emacs more |
| 211 | coherent if all libraries use the same conventions. | 219 | coherent if all libraries use the same conventions. |
| 212 | 220 | ||
| 213 | @item | 221 | @item |
| @@ -216,7 +224,7 @@ constants, you should make sure Emacs always decodes these characters | |||
| 216 | the same way, regardless of the user's settings. The easiest way to | 224 | the same way, regardless of the user's settings. The easiest way to |
| 217 | do this is to use the coding system @code{utf-8-emacs} (@pxref{Coding | 225 | do this is to use the coding system @code{utf-8-emacs} (@pxref{Coding |
| 218 | System Basics}), and specify that coding in the @samp{-*-} line or the | 226 | System Basics}), and specify that coding in the @samp{-*-} line or the |
| 219 | local variables list. @xref{File variables, , Local Variables in | 227 | local variables list. @xref{File Variables, , Local Variables in |
| 220 | Files, emacs, The GNU Emacs Manual}. | 228 | Files, emacs, The GNU Emacs Manual}. |
| 221 | 229 | ||
| 222 | @example | 230 | @example |
| @@ -224,8 +232,7 @@ Files, emacs, The GNU Emacs Manual}. | |||
| 224 | @end example | 232 | @end example |
| 225 | 233 | ||
| 226 | @item | 234 | @item |
| 227 | Indent each function with @kbd{C-M-q} (@code{indent-sexp}) using the | 235 | Indent the file using the default indentation parameters. |
| 228 | default indentation parameters. | ||
| 229 | 236 | ||
| 230 | @item | 237 | @item |
| 231 | Don't make a habit of putting close-parentheses on lines by | 238 | Don't make a habit of putting close-parentheses on lines by |
| @@ -233,29 +240,8 @@ themselves; Lisp programmers find this disconcerting. | |||
| 233 | 240 | ||
| 234 | @item | 241 | @item |
| 235 | Please put a copyright notice and copying permission notice on the | 242 | Please put a copyright notice and copying permission notice on the |
| 236 | file if you distribute copies. Use a notice like this one: | 243 | file if you distribute copies. @xref{Library Headers}. |
| 237 | |||
| 238 | @smallexample | ||
| 239 | ;; Copyright (C) @var{year} @var{name} | ||
| 240 | |||
| 241 | ;; This program is free software: you can redistribute it and/or | ||
| 242 | ;; modify it under the terms of the GNU General Public License as | ||
| 243 | ;; published by the Free Software Foundation, either version 3 of | ||
| 244 | ;; the License, or (at your option) any later version. | ||
| 245 | 244 | ||
| 246 | ;; This program is distributed in the hope that it will be useful, | ||
| 247 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 248 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 249 | ;; GNU General Public License for more details. | ||
| 250 | |||
| 251 | ;; You should have received a copy of the GNU General Public License | ||
| 252 | ;; along with this program. If not, see | ||
| 253 | ;; <http://www.gnu.org/licenses/>. | ||
| 254 | @end smallexample | ||
| 255 | |||
| 256 | If you have signed papers to assign the copyright to the Foundation, | ||
| 257 | then use @samp{Free Software Foundation, Inc.} as @var{name}. | ||
| 258 | Otherwise, use your name. @xref{Library Headers}. | ||
| 259 | @end itemize | 245 | @end itemize |
| 260 | 246 | ||
| 261 | @node Key Binding Conventions | 247 | @node Key Binding Conventions |
| @@ -324,11 +310,11 @@ Similarly, don't bind a key sequence ending in @key{C-g}, since that | |||
| 324 | is commonly used to cancel a key sequence. | 310 | is commonly used to cancel a key sequence. |
| 325 | 311 | ||
| 326 | @item | 312 | @item |
| 327 | Anything which acts like a temporary mode or state which the user can | 313 | Anything that acts like a temporary mode or state that the user can |
| 328 | enter and leave should define @kbd{@key{ESC} @key{ESC}} or | 314 | enter and leave should define @kbd{@key{ESC} @key{ESC}} or |
| 329 | @kbd{@key{ESC} @key{ESC} @key{ESC}} as a way to escape. | 315 | @kbd{@key{ESC} @key{ESC} @key{ESC}} as a way to escape. |
| 330 | 316 | ||
| 331 | For a state which accepts ordinary Emacs commands, or more generally any | 317 | For a state that accepts ordinary Emacs commands, or more generally any |
| 332 | kind of state in which @key{ESC} followed by a function key or arrow key | 318 | kind of state in which @key{ESC} followed by a function key or arrow key |
| 333 | is potentially meaningful, then you must not define @kbd{@key{ESC} | 319 | is potentially meaningful, then you must not define @kbd{@key{ESC} |
| 334 | @key{ESC}}, since that would preclude recognizing an escape sequence | 320 | @key{ESC}}, since that would preclude recognizing an escape sequence |
| @@ -398,8 +384,8 @@ An error message should start with a capital letter but should not end | |||
| 398 | with a period. | 384 | with a period. |
| 399 | 385 | ||
| 400 | @item | 386 | @item |
| 401 | A question asked in the minibuffer with @code{y-or-n-p} or | 387 | A question asked in the minibuffer with @code{yes-or-no-p} or |
| 402 | @code{yes-or-no-p} should start with a capital letter and end with | 388 | @code{y-or-n-p} should start with a capital letter and end with |
| 403 | @samp{? }. | 389 | @samp{? }. |
| 404 | 390 | ||
| 405 | @item | 391 | @item |
| @@ -457,10 +443,9 @@ to generate such messages. | |||
| 457 | 443 | ||
| 458 | @item | 444 | @item |
| 459 | Try to avoid using recursive edits. Instead, do what the Rmail @kbd{e} | 445 | Try to avoid using recursive edits. Instead, do what the Rmail @kbd{e} |
| 460 | command does: use a new local keymap that contains one command defined | 446 | command does: use a new local keymap that contains a command defined |
| 461 | to switch back to the old local keymap. Or do what the | 447 | to switch back to the old local keymap. Or simply switch to another |
| 462 | @code{edit-options} command does: switch to another buffer and let the | 448 | buffer and let the user switch back at will. @xref{Recursive Editing}. |
| 463 | user switch back at will. @xref{Recursive Editing}. | ||
| 464 | @end itemize | 449 | @end itemize |
| 465 | 450 | ||
| 466 | @node Compilation Tips | 451 | @node Compilation Tips |
| @@ -515,6 +500,10 @@ compiled specially (@pxref{Array Functions}): | |||
| 515 | @end group | 500 | @end group |
| 516 | @end example | 501 | @end example |
| 517 | 502 | ||
| 503 | @noindent | ||
| 504 | Note that in this case (and many others), you must first load the | ||
| 505 | @file{bytecomp} library, which defines the @code{byte-compile} property. | ||
| 506 | |||
| 518 | @item | 507 | @item |
| 519 | If calling a small function accounts for a substantial part of your | 508 | If calling a small function accounts for a substantial part of your |
| 520 | program's running time, make the function inline. This eliminates | 509 | program's running time, make the function inline. This eliminates |
| @@ -541,6 +530,11 @@ Such a definition has no effect except to tell the compiler | |||
| 541 | not to warn about uses of the variable @code{foo} in this file. | 530 | not to warn about uses of the variable @code{foo} in this file. |
| 542 | 531 | ||
| 543 | @item | 532 | @item |
| 533 | Similarly, to avoid a compiler warning about an undefined function | ||
| 534 | that you know @emph{will} be defined, use a @code{declare-function} | ||
| 535 | statement (@pxref{Declaring Functions}). | ||
| 536 | |||
| 537 | @item | ||
| 544 | If you use many functions and variables from a certain file, you can | 538 | If you use many functions and variables from a certain file, you can |
| 545 | add a @code{require} for that package to avoid compilation warnings | 539 | add a @code{require} for that package to avoid compilation warnings |
| 546 | for them. For instance, | 540 | for them. For instance, |
| @@ -561,8 +555,8 @@ functions and variables in your package. | |||
| 561 | 555 | ||
| 562 | @item | 556 | @item |
| 563 | The last resort for avoiding a warning, when you want to do something | 557 | The last resort for avoiding a warning, when you want to do something |
| 564 | that usually is a mistake but it's not a mistake in this one case, | 558 | that is usually a mistake but you know is not a mistake in your usage, |
| 565 | is to put a call to @code{with-no-warnings} around it. | 559 | is to put it inside @code{with-no-warnings}. @xref{Compiler Errors}. |
| 566 | @end itemize | 560 | @end itemize |
| 567 | 561 | ||
| 568 | @node Documentation Tips | 562 | @node Documentation Tips |
| @@ -580,11 +574,9 @@ Every command, function, or variable intended for users to know about | |||
| 580 | should have a documentation string. | 574 | should have a documentation string. |
| 581 | 575 | ||
| 582 | @item | 576 | @item |
| 583 | An internal variable or subroutine of a Lisp program might as well have | 577 | An internal variable or subroutine of a Lisp program might as well |
| 584 | a documentation string. In earlier Emacs versions, you could save space | 578 | have a documentation string. Documentation strings take up very |
| 585 | by using a comment instead of a documentation string, but that is no | 579 | little space in a running Emacs. |
| 586 | longer the case---documentation strings now take up very little space in | ||
| 587 | a running Emacs. | ||
| 588 | 580 | ||
| 589 | @item | 581 | @item |
| 590 | Format the documentation string so that it fits in an Emacs window on an | 582 | Format the documentation string so that it fits in an Emacs window on an |
| @@ -595,14 +587,14 @@ or it will look bad in the output of @code{apropos}. | |||
| 595 | You can fill the text if that looks good. However, rather than blindly | 587 | You can fill the text if that looks good. However, rather than blindly |
| 596 | filling the entire documentation string, you can often make it much more | 588 | filling the entire documentation string, you can often make it much more |
| 597 | readable by choosing certain line breaks with care. Use blank lines | 589 | readable by choosing certain line breaks with care. Use blank lines |
| 598 | between topics if the documentation string is long. | 590 | between sections if the documentation string is long. |
| 599 | 591 | ||
| 600 | @item | 592 | @item |
| 601 | The first line of the documentation string should consist of one or two | 593 | The first line of the documentation string should consist of one or two |
| 602 | complete sentences that stand on their own as a summary. @kbd{M-x | 594 | complete sentences that stand on their own as a summary. @kbd{M-x |
| 603 | apropos} displays just the first line, and if that line's contents don't | 595 | apropos} displays just the first line, and if that line's contents don't |
| 604 | stand on their own, the result looks bad. In particular, start the | 596 | stand on their own, the result looks bad. In particular, start the |
| 605 | first line with a capital letter and end with a period. | 597 | first line with a capital letter and end it with a period. |
| 606 | 598 | ||
| 607 | For a function, the first line should briefly answer the question, | 599 | For a function, the first line should briefly answer the question, |
| 608 | ``What does this function do?'' For a variable, the first line should | 600 | ``What does this function do?'' For a variable, the first line should |
| @@ -630,7 +622,7 @@ important arguments. | |||
| 630 | When a function's documentation string mentions the value of an argument | 622 | When a function's documentation string mentions the value of an argument |
| 631 | of the function, use the argument name in capital letters as if it were | 623 | of the function, use the argument name in capital letters as if it were |
| 632 | a name for that value. Thus, the documentation string of the function | 624 | a name for that value. Thus, the documentation string of the function |
| 633 | @code{eval} refers to its second argument as @samp{FORM}, because the | 625 | @code{eval} refers to its first argument as @samp{FORM}, because the |
| 634 | actual argument name is @code{form}: | 626 | actual argument name is @code{form}: |
| 635 | 627 | ||
| 636 | @example | 628 | @example |
| @@ -654,7 +646,7 @@ string. If the symbol's name is @code{foo}, write ``foo,'' not | |||
| 654 | 646 | ||
| 655 | This might appear to contradict the policy of writing function | 647 | This might appear to contradict the policy of writing function |
| 656 | argument values, but there is no real contradiction; the argument | 648 | argument values, but there is no real contradiction; the argument |
| 657 | @emph{value} is not the same thing as the @emph{symbol} which the | 649 | @emph{value} is not the same thing as the @emph{symbol} that the |
| 658 | function uses to hold the value. | 650 | function uses to hold the value. |
| 659 | 651 | ||
| 660 | If this puts a lower-case letter at the beginning of a sentence | 652 | If this puts a lower-case letter at the beginning of a sentence |
| @@ -825,8 +817,8 @@ In Dired, visit the file or directory named on this line. | |||
| 825 | @end example | 817 | @end example |
| 826 | 818 | ||
| 827 | @item | 819 | @item |
| 828 | When you define a variable that users ought to set interactively, you | 820 | When you define a variable that represents an option users might want |
| 829 | should use @code{defcustom}. @xref{Defining Variables}. | 821 | to set, use @code{defcustom}. @xref{Defining Variables}. |
| 830 | 822 | ||
| 831 | @item | 823 | @item |
| 832 | The documentation string for a variable that is a yes-or-no flag should | 824 | The documentation string for a variable that is a yes-or-no flag should |
| @@ -839,19 +831,14 @@ all non-@code{nil} values are equivalent and indicate explicitly what | |||
| 839 | @section Tips on Writing Comments | 831 | @section Tips on Writing Comments |
| 840 | @cindex comments, Lisp convention for | 832 | @cindex comments, Lisp convention for |
| 841 | 833 | ||
| 842 | We recommend these conventions for where to put comments and how to | 834 | We recommend these conventions for comments: |
| 843 | indent them: | ||
| 844 | 835 | ||
| 845 | @table @samp | 836 | @table @samp |
| 846 | @item ; | 837 | @item ; |
| 847 | Comments that start with a single semicolon, @samp{;}, should all be | 838 | Comments that start with a single semicolon, @samp{;}, should all be |
| 848 | aligned to the same column on the right of the source code. Such | 839 | aligned to the same column on the right of the source code. Such |
| 849 | comments usually explain how the code on the same line does its job. In | 840 | comments usually explain how the code on that line does its job. |
| 850 | Lisp mode and related modes, the @kbd{M-;} (@code{indent-for-comment}) | 841 | For example: |
| 851 | command automatically inserts such a @samp{;} in the right place, or | ||
| 852 | aligns such a comment if it is already present. | ||
| 853 | |||
| 854 | This and following examples are taken from the Emacs sources. | ||
| 855 | 842 | ||
| 856 | @smallexample | 843 | @smallexample |
| 857 | @group | 844 | @group |
| @@ -873,7 +860,7 @@ at that point. For example: | |||
| 873 | (prog1 (setq auto-fill-function | 860 | (prog1 (setq auto-fill-function |
| 874 | @dots{} | 861 | @dots{} |
| 875 | @dots{} | 862 | @dots{} |
| 876 | ;; update mode line | 863 | ;; Update mode line. |
| 877 | (force-mode-line-update))) | 864 | (force-mode-line-update))) |
| 878 | @end group | 865 | @end group |
| 879 | @end smallexample | 866 | @end smallexample |
| @@ -882,17 +869,17 @@ We also normally use two semicolons for comments outside functions. | |||
| 882 | 869 | ||
| 883 | @smallexample | 870 | @smallexample |
| 884 | @group | 871 | @group |
| 885 | ;; This Lisp code is run in Emacs | 872 | ;; This Lisp code is run in Emacs when it is to operate as |
| 886 | ;; when it is to operate as a server | 873 | ;; a server for other processes. |
| 887 | ;; for other processes. | ||
| 888 | @end group | 874 | @end group |
| 889 | @end smallexample | 875 | @end smallexample |
| 890 | 876 | ||
| 891 | Every function that has no documentation string (presumably one that is | 877 | If a function has no documentation string, it should instead have a |
| 892 | used only internally within the package it belongs to), should instead | 878 | two-semicolon comment right before the function, explaining what the |
| 893 | have a two-semicolon comment right before the function, explaining what | 879 | function does and how to call it properly. Explain precisely what |
| 894 | the function does and how to call it properly. Explain precisely what | 880 | each argument means and how the function interprets its possible |
| 895 | each argument means and how the function interprets its possible values. | 881 | values. It is much better to convert such comments to documentation |
| 882 | strings, though. | ||
| 896 | 883 | ||
| 897 | @item ;;; | 884 | @item ;;; |
| 898 | Comments that start with three semicolons, @samp{;;;}, should start at | 885 | Comments that start with three semicolons, @samp{;;;}, should start at |
| @@ -903,7 +890,7 @@ semicolons depends on whether the comment should be considered a | |||
| 903 | ``heading'' by Outline minor mode. By default, comments starting with | 890 | ``heading'' by Outline minor mode. By default, comments starting with |
| 904 | at least three semicolons (followed by a single space and a | 891 | at least three semicolons (followed by a single space and a |
| 905 | non-whitespace character) are considered headings, comments starting | 892 | non-whitespace character) are considered headings, comments starting |
| 906 | with two or less are not. | 893 | with two or fewer are not. |
| 907 | 894 | ||
| 908 | Another use for triple-semicolon comments is for commenting out lines | 895 | Another use for triple-semicolon comments is for commenting out lines |
| 909 | within a function. We use three semicolons for this precisely so that | 896 | within a function. We use three semicolons for this precisely so that |
| @@ -934,11 +921,11 @@ program. For example: | |||
| 934 | @end table | 921 | @end table |
| 935 | 922 | ||
| 936 | @noindent | 923 | @noindent |
| 937 | The indentation commands of the Lisp modes in Emacs, such as @kbd{M-;} | 924 | Generally speaking, the @kbd{M-;} (@code{comment-dwim}) command |
| 938 | (@code{indent-for-comment}) and @key{TAB} (@code{lisp-indent-line}), | 925 | automatically starts a comment of the appropriate type; or indents an |
| 939 | automatically indent comments according to these conventions, | 926 | existing comment to the right place, depending on the number of |
| 940 | depending on the number of semicolons. @xref{Comments,, | 927 | semicolons. |
| 941 | Manipulating Comments, emacs, The GNU Emacs Manual}. | 928 | @xref{Comments,, Manipulating Comments, emacs, The GNU Emacs Manual}. |
| 942 | 929 | ||
| 943 | @node Library Headers | 930 | @node Library Headers |
| 944 | @section Conventional Headers for Emacs Libraries | 931 | @section Conventional Headers for Emacs Libraries |
| @@ -947,39 +934,28 @@ Manipulating Comments, emacs, The GNU Emacs Manual}. | |||
| 947 | 934 | ||
| 948 | Emacs has conventions for using special comments in Lisp libraries | 935 | Emacs has conventions for using special comments in Lisp libraries |
| 949 | to divide them into sections and give information such as who wrote | 936 | to divide them into sections and give information such as who wrote |
| 950 | them. This section explains these conventions. | 937 | them. Using a standard format for these items makes it easier for |
| 951 | 938 | tools (and people) to extract the relevant information. This section | |
| 952 | We'll start with an example, a package that is included in the Emacs | 939 | explains these conventions, starting with an example: |
| 953 | distribution. | ||
| 954 | |||
| 955 | Parts of this example reflect its status as part of Emacs; for | ||
| 956 | example, the copyright notice lists the Free Software Foundation as the | ||
| 957 | copyright holder, and the copying permission says the file is part of | ||
| 958 | Emacs. When you write a package and post it, the copyright holder would | ||
| 959 | be you (unless your employer claims to own it instead), and you should | ||
| 960 | get the suggested copying permission from the end of the GNU General | ||
| 961 | Public License itself. Don't say your file is part of Emacs | ||
| 962 | if we haven't installed it in Emacs yet! | ||
| 963 | |||
| 964 | With that warning out of the way, on to the example: | ||
| 965 | 940 | ||
| 966 | @smallexample | 941 | @smallexample |
| 967 | @group | 942 | @group |
| 968 | ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers | 943 | ;;; foo.el --- Support for the Foo programming language |
| 969 | 944 | ||
| 970 | ;; Copyright (C) 1992 Free Software Foundation, Inc. | 945 | ;; Copyright (C) 2010-2012 Your Name |
| 971 | @end group | 946 | @end group |
| 972 | 947 | ||
| 973 | ;; Author: Eric S. Raymond <esr@@snark.thyrsus.com> | 948 | ;; Author: Your Name <yourname@@example.com> |
| 974 | ;; Maintainer: Eric S. Raymond <esr@@snark.thyrsus.com> | 949 | ;; Maintainer: Someone Else <someone@@example.com> |
| 975 | ;; Created: 14 Jul 1992 | 950 | ;; Created: 14 Jul 2010 |
| 976 | ;; Version: 1.2 | ||
| 977 | @group | 951 | @group |
| 978 | ;; Keywords: docs | 952 | ;; Keywords: languages |
| 979 | 953 | ||
| 980 | ;; This file is part of GNU Emacs. | 954 | ;; This file is not part of GNU Emacs. |
| 955 | |||
| 956 | ;; This file is free software@dots{} | ||
| 981 | @dots{} | 957 | @dots{} |
| 982 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | 958 | ;; along with this file. If not, see <http://www.gnu.org/licenses/>. |
| 983 | @end group | 959 | @end group |
| 984 | @end smallexample | 960 | @end smallexample |
| 985 | 961 | ||
| @@ -990,8 +966,19 @@ if we haven't installed it in Emacs yet! | |||
| 990 | @end example | 966 | @end example |
| 991 | 967 | ||
| 992 | @noindent | 968 | @noindent |
| 993 | The description should be complete in one line. If the file | 969 | The description should be contained in one line. If the file |
| 994 | needs a @samp{-*-} specification, put it after @var{description}. | 970 | needs a @samp{-*-} specification, put it after @var{description}. |
| 971 | If this would make the first line too long, use a Local Variables | ||
| 972 | section at the end of the file. | ||
| 973 | |||
| 974 | The copyright notice usually lists your name (if you wrote the | ||
| 975 | file). If you have an employer who claims copyright on your work, you | ||
| 976 | might need to list them instead. Do not say that the copyright holder | ||
| 977 | is the Free Software Foundation (or that the file is part of GNU | ||
| 978 | Emacs) unless your file has been accepted into the Emacs distribution. | ||
| 979 | For more information on the form of copyright and license notices, see | ||
| 980 | @uref{http://www.gnu.org/licenses/gpl-howto.html, the guide on the GNU | ||
| 981 | website}. | ||
| 995 | 982 | ||
| 996 | After the copyright notice come several @dfn{header comment} lines, | 983 | After the copyright notice come several @dfn{header comment} lines, |
| 997 | each beginning with @samp{;; @var{header-name}:}. Here is a table of | 984 | each beginning with @samp{;; @var{header-name}:}. Here is a table of |
| @@ -999,55 +986,55 @@ the conventional possibilities for @var{header-name}: | |||
| 999 | 986 | ||
| 1000 | @table @samp | 987 | @table @samp |
| 1001 | @item Author | 988 | @item Author |
| 1002 | This line states the name and net address of at least the principal | 989 | This line states the name and email address of at least the principal |
| 1003 | author of the library. | 990 | author of the library. If there are multiple authors, list them on |
| 1004 | 991 | continuation lines led by @code{;;} and whitespace (this is easier | |
| 1005 | If there are multiple authors, you can list them on continuation lines | 992 | for tools to parse than having more than one author on one line). |
| 1006 | led by @code{;;} and a tab character, like this: | 993 | We recommend including a contact email address, of the form |
| 994 | @samp{<@dots{}>}. For example: | ||
| 1007 | 995 | ||
| 1008 | @smallexample | 996 | @smallexample |
| 1009 | @group | 997 | @group |
| 1010 | ;; Author: Ashwin Ram <Ram-Ashwin@@cs.yale.edu> | 998 | ;; Author: Your Name <yourname@@example.com> |
| 1011 | ;; Dave Sill <de5@@ornl.gov> | 999 | ;; Someone Else <someone@@example.com> |
| 1012 | ;; Dave Brennan <brennan@@hal.com> | 1000 | ;; Another Person <another@@example.com> |
| 1013 | ;; Eric Raymond <esr@@snark.thyrsus.com> | ||
| 1014 | @end group | 1001 | @end group |
| 1015 | @end smallexample | 1002 | @end smallexample |
| 1016 | 1003 | ||
| 1017 | @item Maintainer | 1004 | @item Maintainer |
| 1018 | This line should contain a single name/address as in the Author line, or | 1005 | This header has the same format as the Author header. It lists the |
| 1019 | an address only, or the string @samp{FSF}. If there is no maintainer | 1006 | person(s) who currently maintain(s) the file (respond to bug reports, |
| 1020 | line, the person(s) in the Author field are presumed to be the | 1007 | etc.). |
| 1021 | maintainers. The example above is mildly bogus because the maintainer | ||
| 1022 | line is redundant. | ||
| 1023 | |||
| 1024 | The idea behind the @samp{Author} and @samp{Maintainer} lines is to make | ||
| 1025 | possible a Lisp function to ``send mail to the maintainer'' without | ||
| 1026 | having to mine the name out by hand. | ||
| 1027 | 1008 | ||
| 1028 | Be sure to surround the network address with @samp{<@dots{}>} if | 1009 | If there is no maintainer line, the person(s) in the Author field |
| 1029 | you include the person's full name as well as the network address. | 1010 | is/are presumed to be the maintainers. Some files in Emacs use |
| 1011 | @samp{FSF} for the maintainer. This means that the original author is | ||
| 1012 | no longer responsible for the file, and that it is maintained as part | ||
| 1013 | of Emacs. | ||
| 1030 | 1014 | ||
| 1031 | @item Created | 1015 | @item Created |
| 1032 | This optional line gives the original creation date of the | 1016 | This optional line gives the original creation date of the file, and |
| 1033 | file. For historical interest only. | 1017 | is for historical interest only. |
| 1034 | 1018 | ||
| 1035 | @item Version | 1019 | @item Version |
| 1036 | If you wish to record version numbers for the individual Lisp program, put | 1020 | If you wish to record version numbers for the individual Lisp program, |
| 1037 | them in this line. | 1021 | put them in this line. Lisp files distributed with Emacs generally do |
| 1038 | 1022 | not have a @samp{Version} header, since the version number of Emacs | |
| 1039 | @item Adapted-By | 1023 | itself serves the same purpose. If you are distributing a collection |
| 1040 | In this header line, place the name of the person who adapted the | 1024 | of multiple files, we recommend not writing the version in every file, |
| 1041 | library for installation (to make it fit the style conventions, for | 1025 | but only the main one. |
| 1042 | example). | ||
| 1043 | 1026 | ||
| 1044 | @item Keywords | 1027 | @item Keywords |
| 1045 | This line lists keywords for the @code{finder-by-keyword} help command. | 1028 | This line lists keywords for the @code{finder-by-keyword} help command. |
| 1046 | Please use that command to see a list of the meaningful keywords. | 1029 | Please use that command to see a list of the meaningful keywords. |
| 1047 | 1030 | ||
| 1048 | This field is important; it's how people will find your package when | 1031 | This field is how people will find your package when they're looking |
| 1049 | they're looking for things by topic area. To separate the keywords, you | 1032 | for things by topic. To separate the keywords, you can use spaces, |
| 1050 | can use spaces, commas, or both. | 1033 | commas, or both. |
| 1034 | |||
| 1035 | The name of this field is unfortunate, since people often assume it is | ||
| 1036 | the place to write arbitrary keywords that describe their package, | ||
| 1037 | rather than just the relevant Finder keywords. | ||
| 1051 | 1038 | ||
| 1052 | @item Package-Version | 1039 | @item Package-Version |
| 1053 | If @samp{Version} is not suitable for use by the package manager, then | 1040 | If @samp{Version} is not suitable for use by the package manager, then |
| @@ -1060,7 +1047,7 @@ If this exists, it names packages on which the current package depends | |||
| 1060 | for proper operation. @xref{Packaging Basics}. This is used by the | 1047 | for proper operation. @xref{Packaging Basics}. This is used by the |
| 1061 | package manager both at download time (to ensure that a complete set | 1048 | package manager both at download time (to ensure that a complete set |
| 1062 | of packages is downloaded) and at activation time (to ensure that a | 1049 | of packages is downloaded) and at activation time (to ensure that a |
| 1063 | package is activated if and only if all its dependencies have been). | 1050 | package is only activated if all its dependencies have been). |
| 1064 | 1051 | ||
| 1065 | Its format is a list of lists. The @code{car} of each sub-list is the | 1052 | Its format is a list of lists. The @code{car} of each sub-list is the |
| 1066 | name of a package, as a symbol. The @code{cadr} of each sub-list is | 1053 | name of a package, as a symbol. The @code{cadr} of each sub-list is |
| @@ -1081,8 +1068,8 @@ appropriate. You can also put in header lines with other header | |||
| 1081 | names---they have no standard meanings, so they can't do any harm. | 1068 | names---they have no standard meanings, so they can't do any harm. |
| 1082 | 1069 | ||
| 1083 | We use additional stylized comments to subdivide the contents of the | 1070 | We use additional stylized comments to subdivide the contents of the |
| 1084 | library file. These should be separated by blank lines from anything | 1071 | library file. These should be separated from anything else by blank |
| 1085 | else. Here is a table of them: | 1072 | lines. Here is a table of them: |
| 1086 | 1073 | ||
| 1087 | @table @samp | 1074 | @table @samp |
| 1088 | @item ;;; Commentary: | 1075 | @item ;;; Commentary: |
| @@ -1092,16 +1079,12 @@ It should come right after the copying permissions, terminated by a | |||
| 1092 | text is used by the Finder package, so it should make sense in that | 1079 | text is used by the Finder package, so it should make sense in that |
| 1093 | context. | 1080 | context. |
| 1094 | 1081 | ||
| 1095 | @item ;;; Documentation: | ||
| 1096 | This was used in some files in place of @samp{;;; Commentary:}, | ||
| 1097 | but it is deprecated. | ||
| 1098 | |||
| 1099 | @item ;;; Change Log: | 1082 | @item ;;; Change Log: |
| 1100 | This begins change log information stored in the library file (if you | 1083 | This begins an optional log of changes to the file over time. Don't |
| 1101 | store the change history there). For Lisp files distributed with Emacs, | 1084 | put too much information in this section---it is better to keep the |
| 1102 | the change history is kept in the file @file{ChangeLog} and not in the | 1085 | detailed logs in a separate @file{ChangeLog} file (as Emacs does), |
| 1103 | source file at all; these files generally do not have a @samp{;;; Change | 1086 | and/or to use a version control system. @samp{History} is an |
| 1104 | Log:} line. @samp{History} is an alternative to @samp{Change Log}. | 1087 | alternative to @samp{Change Log}. |
| 1105 | 1088 | ||
| 1106 | @item ;;; Code: | 1089 | @item ;;; Code: |
| 1107 | This begins the actual code of the program. | 1090 | This begins the actual code of the program. |