home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / elisp / elisp-35 < prev    next >
Encoding:
GNU Info File  |  1993-05-11  |  49.0 KB  |  947 lines

  1. This is Info file elisp, produced by Makeinfo-1.52 from the input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  7. Emacs Version 19.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  10. Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28. 
  29. File: elisp,  Node: Sexp Diary Entries,  Next: Appt Customizing,  Prev: Including Diary Files,  Up: Calendar
  30.  
  31. Sexp Entries and the Fancy Diary Display
  32. ========================================
  33.  
  34.                                       Sexp diary entries allow you to
  35. do more than just have complicated conditions under which a diary entry
  36. applies.  If you use the fancy diary display, sexp entries can generate
  37. the text of the entry depending on the date itself.  For example, the
  38. anniversary diary entry described above (*note Special Diary
  39. Entries::.) can insert the number of years since the anniversary date
  40. into the text of the diary entry.  Thus the `%d' in the dairy entry
  41.  
  42.                                         %%(diary-anniversary 10 31 1948) Arthur's birthday (%d years old)
  43.  
  44.                                    gets replaced by the age, so on
  45. October 31, 1990 the entry appears in the fancy diary buffer as
  46.  
  47.                                         Arthur's birthday (42 years old)
  48.  
  49.                                    If the diary file instead contains
  50. the entry
  51.  
  52.                                         %%(diary-anniversary 10 31 1948) Arthur's %d%s birthday
  53.  
  54.                                    the entry in the fancy diary buffer
  55. for October 31, 1990 becomes
  56.  
  57.                                         Arthur's 42nd birthday
  58.  
  59.                                       Similarly, cyclic diary entries
  60. can interpolate the number of repetitions that have occurred:
  61.  
  62.                                         %%(diary-cyclic 50 1 1 1990) Renew medication (%d%s time)
  63.  
  64.                                    causes the diary entry
  65.  
  66.                                         Renew medication (5th time)
  67.  
  68.                                    to appear in the fancy diary display
  69. on September 8, 1990.
  70.  
  71.                                       The generality of sexp diary
  72. entries lets you specify any diary entry that you can describe
  73. algorithmically.  Suppose you get paid on the 21st of the month if it
  74. is a weekday, and to the Friday before if the 21st is on a weekend.
  75. The diary entry
  76.  
  77.                                         &%%(let ((dayname (calendar-day-of-week date))
  78.                                                  (day (car (cdr date))))
  79.                                               (or (and (= day 21) (memq dayname '(1 2 3 4 5)))
  80.                                                   (and (memq day '(19 20)) (= dayname 5)))
  81.                                                  ) Pay check deposited
  82.  
  83.                                    applies to just those dates.  This
  84. example illustrates how the sexp can depend on the variable `date';
  85. this variable is a list (MONTH DAY YEAR) that gives the Gregorian date
  86. for which the diary entries are being found.  If the value of the
  87. expression is `t', the entry applies to that date.  If the expression
  88. evaluates to `nil', the entry does *not* apply to that date.
  89.  
  90.                                       The following sexp diary entries
  91. take advantage of the ability (in the fancy diary display) to concoct
  92. diary entries based on the date:
  93.  
  94.                                   `%%(diary-sunrise-sunset)'
  95.                                         Make a diary entry for the
  96.                                         local times of today's sunrise
  97.                                         and sunset.
  98.  
  99.                                   `%%(diary-phases-of-moon)'
  100.                                         Make a diary entry for the
  101.                                         phases (quarters) of the moon.
  102.  
  103.                                   `%%(diary-day-of-year)'
  104.                                         Make a diary entry with today's
  105.                                         day number in the current year
  106.                                         and the number of days
  107.                                         remaining in the current year.
  108.  
  109.                                   `%%(diary-iso-date)'
  110.                                         Make a diary entry with today's
  111.                                         equivalent ISO commercial date.
  112.  
  113.                                   `%%(diary-julian-date)'
  114.                                         Make a diary entry with today's
  115.                                         equivalent date on the Julian
  116.                                         calendar.
  117.  
  118.                                   `%%(diary-astro-day-number)'
  119.                                         Make a diary entry with today's
  120.                                         equivalent astronomical
  121.                                         (Julian) day number.
  122.  
  123.                                   `%%(diary-hebrew-date)'
  124.                                         Make a diary entry with today's
  125.                                         equivalent date on the Hebrew
  126.                                         calendar.
  127.  
  128.                                   `%%(diary-islamic-date)'
  129.                                         Make a diary entry with today's
  130.                                         equivalent date on the Islamic
  131.                                         calendar.
  132.  
  133.                                   `%%(diary-french-date)'
  134.                                         Make a diary entry with today's
  135.                                         equivalent date on the French
  136.                                         Revolutionary calendar.
  137.  
  138.                                   `%%(diary-mayan-date)'
  139.                                         Make a diary entry with today's
  140.                                         equivalent date on the Mayan
  141.                                         calendar.
  142.  
  143.                                    Thus including the diary entry
  144.  
  145.                                         &%%(diary-hebrew-date)
  146.  
  147.                                    causes every day's diary display to
  148. contain the equivalent date on the Hebrew calendar, if you are using
  149. the fancy diary display.  (With simple diary display, the line
  150. `&%%(diary-hebrew-date)' appears in the diary for any date, but does
  151. nothing particularly useful.)
  152.  
  153.                                       There are a number of other
  154. available sexp diary entries that are important to those who follow the
  155. Hebrew calendar:
  156.  
  157.                                   `%%(diary-rosh-hodesh)'
  158.                                         Make a diary entry that tells
  159.                                         the occurrence and ritual
  160.                                         announcement of each new Hebrew
  161.                                         month.
  162.  
  163.                                   `%%(diary-parasha)'
  164.                                         Make a Saturday diary entry
  165.                                         that tells the weekly synagogue
  166.                                         scripture reading.
  167.  
  168.                                   `%%(diary-sabbath-candles)'
  169.                                         Make a Friday diary entry that
  170.                                         tells the *local time* of
  171.                                         Sabbath candle lighting.
  172.  
  173.                                   `%%(diary-omer)'
  174.                                         Make a diary entry that gives
  175.                                         the omer count, when
  176.                                         appropriate.
  177.  
  178.                                   `%%(diary-yahrzeit MONTH DAY YEAR) NAME'
  179.                                         Make a diary entry marking the
  180.                                         anniversary of a date of death.
  181.                                         The date is the *Gregorian*
  182.                                         (civil) date of death.  The
  183.                                         diary entry appears on the
  184.                                         proper Hebrew calendar
  185.                                         anniversary and on the day
  186.                                         before.  (In the European
  187.                                         style, the order of the
  188.                                         parameters is changed to DAY,
  189.                                         MONTH, YEAR.)
  190.  
  191. 
  192. File: elisp,  Node: Appt Customizing,  Prev: Sexp Diary Entries,  Up: Calendar
  193.  
  194. Customizing Appointment Reminders
  195. =================================
  196.  
  197.                                       You can specify exactly how Emacs
  198. reminds you of an appointment and how far in advance it begins doing
  199. so.  Here are the variables that you can set:
  200.  
  201.                                   `appt-message-warning-time'
  202.                                         The time in minutes before an
  203.                                         appointment that the reminder
  204.                                         begins.  The default is 10
  205.                                         minutes.
  206.  
  207.                                   `appt-audible'
  208.                                         If this is `t' (the default),
  209.                                         Emacs rings the terminal bell
  210.                                         for appointment reminders.
  211.  
  212.                                   `appt-visible'
  213.                                         If this is `t' (the default),
  214.                                         Emacs displays the appointment
  215.                                         message in echo area.
  216.  
  217.                                   `appt-display-mode-line'
  218.                                         If this is `t' (the default),
  219.                                         Emacs displays the number of
  220.                                         minutes to the appointment on
  221.                                         the mode line.
  222.  
  223.                                   `appt-msg-window'
  224.                                         If this is `t' (the default),
  225.                                         Emacs displays the appointment
  226.                                         message in another window.
  227.  
  228.                                   `appt-display-duration'
  229.                                         The number of seconds an
  230.                                         appointment message is
  231.                                         displayed.  The default is 5
  232.                                         seconds.
  233.  
  234. 
  235. File: elisp,  Node: Tips,  Next: GNU Emacs Internals,  Prev: Calendar,  Up: Top
  236.  
  237. Tips and Standards
  238. ******************
  239.  
  240.                                       This chapter describes no
  241. additional features of Emacs Lisp.  Instead it gives advice on making
  242. effective use of the features described in the previous chapters.
  243.  
  244.                                    * Menu:
  245.                                    
  246.                                    * Style Tips::                Writing clean and robust programs.
  247.                                    * Compilation Tips::          Making compiled code run fast.
  248.                                    * Documentation Tips::        Writing readable documentation strings.
  249.                                    * Comment Tips::          Conventions for writing comments.
  250.                                    * Library headers::           Standard headers for library packages.
  251.  
  252. 
  253. File: elisp,  Node: Style Tips,  Next: Compilation Tips,  Prev: Tips,  Up: Tips
  254.  
  255. Writing Clean Lisp Programs
  256. ===========================
  257.  
  258.                                       Here are some tips for avoiding
  259. common errors in writing Lisp code intended for widespread use:
  260.  
  261.                                       * Since all global variables
  262.                                         share the same name space, and
  263.                                         all functions share another
  264.                                         name space, you should choose a
  265.                                         short word to distinguish your
  266.                                         program from other Lisp
  267.                                         programs.  Then take care to
  268.                                         begin the names of all global
  269.                                         variables, constants, and
  270.                                         functions with the chosen
  271.                                         prefix.  This helps avoid name
  272.                                         conflicts.
  273.  
  274.                                         This recommendation applies
  275.                                         even to names for traditional
  276.                                         Lisp primitives that are not
  277.                                         primitives in Emacs Lisp--even
  278.                                         to `cadr'.  Believe it or not,
  279.                                         there is more than one
  280.                                         plausible way to define `cadr'.
  281.                                         Play it safe; append your name
  282.                                         prefix to produce a name like
  283.                                         `foo-cadr' or `mylib-cadr'
  284.                                         instead.
  285.  
  286.                                         If one prefix is insufficient,
  287.                                         your package may use two or
  288.                                         three alternative common
  289.                                         prefixes, so long as they make
  290.                                         sense.
  291.  
  292.                                         Separate the prefix from the
  293.                                         rest of the symbol name with a
  294.                                         hyphen, `-'.  This will be
  295.                                         consistent with Emacs itself
  296.                                         and with most Emacs Lisp
  297.                                         programs.
  298.  
  299.                                       * It is often useful to put a
  300.                                         call to `provide' in each
  301.                                         separate library program, at
  302.                                         least if there is more than one
  303.                                         entry point to the program.
  304.  
  305.                                       * If one file FOO uses a macro
  306.                                         defined in another file BAR,
  307.                                         FOO should contain `(require
  308.                                         'BAR)' before the first use of
  309.                                         the macro.  (And BAR should
  310.                                         contain `(provide 'BAR)', to
  311.                                         make the `require' work.)  This
  312.                                         will cause BAR to be loaded
  313.                                         when you byte-compile FOO.
  314.                                         Otherwise, you risk compiling
  315.                                         FOO without the necessary macro
  316.                                         loaded, and that would produce
  317.                                         compiled code that won't work
  318.                                         right.  *Note Compiling
  319.                                         Macros::.
  320.  
  321.                                       * If you define a major mode,
  322.                                         make sure to run a hook
  323.                                         variable using `run-hooks',
  324.                                         just as the existing major
  325.                                         modes do.  *Note Hooks::.
  326.  
  327.                                       * Please do not define `C-c
  328.                                         LETTER' as a key in your major
  329.                                         modes.  These sequences are
  330.                                         reserved for users; they are the
  331.                                         *only* sequences reserved for
  332.                                         users, so we cannot do without
  333.                                         them.
  334.  
  335.                                         Instead, define sequences
  336.                                         consisting of `C-c' followed by
  337.                                         a non-letter.  These sequences
  338.                                         are reserved for major modes.
  339.  
  340.                                         Changing all the major modes in
  341.                                         Emacs 18 so they would follow
  342.                                         this convention was a lot of
  343.                                         work.  Abandoning this
  344.                                         convention would waste that
  345.                                         work and inconvenience the
  346.                                         users.
  347.  
  348.                                       * It is a bad idea to define
  349.                                         aliases for the Emacs
  350.                                         primitives.  Use the standard
  351.                                         names instead.
  352.  
  353.                                       * Redefining an Emacs primitive
  354.                                         is an even worse idea.  It may
  355.                                         do the right thing for a
  356.                                         particular program, but there
  357.                                         is no telling what other
  358.                                         programs might break as a
  359.                                         result.
  360.  
  361.                                       * If a file does replace any of
  362.                                         the functions or library
  363.                                         programs of standard Emacs,
  364.                                         prominent comments at the
  365.                                         beginning of the file should
  366.                                         say which functions are
  367.                                         replaced, and how the behavior
  368.                                         of the replacements differs
  369.                                         from that of the originals.
  370.  
  371.                                       * If a file requires certain
  372.                                         standard library programs to be
  373.                                         loaded beforehand, then the
  374.                                         comments at the beginning of
  375.                                         the file should say so.
  376.  
  377.                                       * Please keep the names of your
  378.                                         Emacs Lisp source files to 13
  379.                                         characters or less.  This way,
  380.                                         if the files are compiled, the
  381.                                         compiled files' names will be
  382.                                         14 characters or less, which is
  383.                                         short enough to fit on all kinds
  384.                                         of Unix systems.
  385.  
  386.                                       * Don't use `next-line' or
  387.                                         `previous-line' in programs;
  388.                                         nearly always, `forward-line'
  389.                                         is more convenient as well as
  390.                                         more predictable and robust.
  391.                                         *Note Text Lines::.
  392.  
  393.                                       * Don't use functions that set
  394.                                         the mark in your Lisp code
  395.                                         (unless you are writing a
  396.                                         command to set the mark).  The
  397.                                         mark is a user-level feature,
  398.                                         so it is incorrect to change
  399.                                         the mark except to supply a
  400.                                         value for the user's benefit.
  401.                                         *Note The Mark::.
  402.  
  403.                                         In particular, don't use these
  404.                                         functions:
  405.  
  406.                                            * `beginning-of-buffer',
  407.                                              `end-of-buffer'
  408.  
  409.                                            * `replace-string',
  410.                                              `replace-regexp'
  411.  
  412.                                         If you just want to move point,
  413.                                         or replace a certain string,
  414.                                         without any of the other
  415.                                         features intended for
  416.                                         interactive users, you can
  417.                                         replace these functions with
  418.                                         one or two lines of simple Lisp
  419.                                         code.
  420.  
  421.                                       * The recommended way to print a
  422.                                         message in the echo area is with
  423.                                         the `message' function, not
  424.                                         `princ'.  *Note The Echo Area::.
  425.  
  426.                                       * When you encounter an error
  427.                                         condition, call the function
  428.                                         `error' (or `signal').  The
  429.                                         function `error' does not
  430.                                         return.  *Note Signaling
  431.                                         Errors::.
  432.  
  433.                                         Do not use `message', `throw',
  434.                                         `sleep-for', or `beep' to
  435.                                         report errors.
  436.  
  437.                                       * Avoid using recursive edits.
  438.                                         Instead, do what the Rmail `w'
  439.                                         command does: use a new local
  440.                                         keymap that contains one
  441.                                         command defined to switch back
  442.                                         to the old local keymap.  Or do
  443.                                         what the `edit-options' command
  444.                                         does: switch to another buffer
  445.                                         and let the user switch back at
  446.                                         will.  *Note Recursive
  447.                                         Editing::.
  448.  
  449.                                       * In some other systems there is
  450.                                         a convention of choosing
  451.                                         variable names that begin and
  452.                                         end with `*'.  We don't use
  453.                                         that convention in Emacs Lisp,
  454.                                         so please don't use it in your
  455.                                         library.  (In fact, in Emacs
  456.                                         names of this form are
  457.                                         conventionally used for
  458.                                         program-generated buffers.) The
  459.                                         users will find Emacs more
  460.                                         coherent if all libraries use
  461.                                         the same conventions.
  462.  
  463.                                       * Indent each function with
  464.                                         `C-M-q' (`indent-sexp') using
  465.                                         the default indentation
  466.                                         parameters.
  467.  
  468.                                       * Don't make a habit of putting
  469.                                         close-parentheses on lines by
  470.                                         themselves; Lisp programmers
  471.                                         find this disconcerting.  Once
  472.                                         in a while, when there is a
  473.                                         sequence of many consecutive
  474.                                         close-parentheses, it may make
  475.                                         sense to split them in one or
  476.                                         two significant places.
  477.  
  478.                                       * Please put a copyright notice
  479.                                         on the file if you give copies
  480.                                         to anyone.  Use the same lines
  481.                                         that appear at the top of the
  482.                                         Lisp files in Emacs itself.  If
  483.                                         you have not signed papers to
  484.                                         assign the copyright to the
  485.                                         Foundation, then place your
  486.                                         name in the copyright notice in
  487.                                         place of the Foundation's name.
  488.  
  489. 
  490. File: elisp,  Node: Compilation Tips,  Next: Documentation Tips,  Prev: Style Tips,  Up: Tips
  491.  
  492. Tips for Making Compiled Code Fast
  493. ==================================
  494.  
  495.                                       Here are ways of improving the
  496. execution speed of byte-compiled lisp programs.
  497.  
  498.                                       * Use the `profile' library to
  499.                                         profile your program.  See the
  500.                                         file `profile.el' for
  501.                                         instructions.
  502.  
  503.                                       * Use iteration rather than
  504.                                         recursion whenever possible.
  505.                                         Function calls are slow in
  506.                                         Emacs Lisp even when a compiled
  507.                                         function is calling another
  508.                                         compiled function.
  509.  
  510.                                       * Using the primitive
  511.                                         list-searching functions
  512.                                         `memq', `assq' or `assoc' is
  513.                                         even faster than explicit
  514.                                         iteration.  It may be worth
  515.                                         rearranging a data structure so
  516.                                         that one of these primitive
  517.                                         search functions can be used.
  518.  
  519.                                       * Certain built-in functions are
  520.                                         handled specially by the byte
  521.                                         compiler avoiding the need for
  522.                                         an ordinary function call.  It
  523.                                         is a good idea to use these
  524.                                         functions rather than
  525.                                         alternatives.  To see whether a
  526.                                         function is handled specially
  527.                                         by the compiler, examine its
  528.                                         `byte-compile' property.  If
  529.                                         the property is non-`nil', then
  530.                                         the function is handled
  531.                                         specially.
  532.  
  533.                                         For example, the following
  534.                                         input will show you that `aref'
  535.                                         is compiled specially (*note
  536.                                         Array Functions::.) while `elt'
  537.                                         is not (*note Sequence
  538.                                         Functions::.):
  539.  
  540.                                              (get 'aref 'byte-compile)
  541.                                                   => byte-compile-two-args
  542.  
  543.                                              (get 'elt 'byte-compile)
  544.                                                   => nil
  545.  
  546.                                       * Make small functions inline, so
  547.                                         that calls to them in compiled
  548.                                         code run faster.  *Note Inline
  549.                                         Functions::.
  550.  
  551. 
  552. File: elisp,  Node: Documentation Tips,  Next: Comment Tips,  Prev: Compilation Tips,  Up: Tips
  553.  
  554. Tips for Documentation Strings
  555. ==============================
  556.  
  557.                                       Here are some tips for the
  558. writing of documentation strings.
  559.  
  560.                                       * Every command, function or
  561.                                         variable intended for users to
  562.                                         know about should have a
  563.                                         documentation string.
  564.  
  565.                                       * An internal subroutine of a
  566.                                         Lisp program need not have a
  567.                                         documentation string, and you
  568.                                         can save space by using a
  569.                                         comment instead.
  570.  
  571.                                       * The first line of the
  572.                                         documentation string should
  573.                                         consist of one or two complete
  574.                                         sentences which stand on their
  575.                                         own as a summary.  In
  576.                                         particular, start the line with
  577.                                         a capital letter and end with a
  578.                                         period.
  579.  
  580.                                         The documentation string can
  581.                                         have additional lines which
  582.                                         expand on the details of how to
  583.                                         use the function or variable.
  584.                                         The additional lines should be
  585.                                         made up of complete sentences
  586.                                         also, but they may be filled if
  587.                                         that looks good.
  588.  
  589.                                       * Do not start or end a
  590.                                         documentation string with
  591.                                         whitespace.
  592.  
  593.                                       * Format the documentation string
  594.                                         so that it fits in an Emacs
  595.                                         window on an 80 column screen.
  596.                                         It is a good idea for most
  597.                                         lines to be no wider than 60
  598.                                         characters.  The first line can
  599.                                         be wider if necessary to fit the
  600.                                         information that ought to be
  601.                                         there.
  602.  
  603.                                         However, rather than simply
  604.                                         filling the entire
  605.                                         documentation string, you can
  606.                                         make it much more readable by
  607.                                         choosing line breaks with care.
  608.                                         Use blank lines between topics
  609.                                         if the documentation string is
  610.                                         long.
  611.  
  612.                                       * *Do not* indent subsequent
  613.                                         lines of a documentation string
  614.                                         so that the text is lined up in
  615.                                         the source code with the text
  616.                                         of the first line.  This looks
  617.                                         nice in the source code, but
  618.                                         looks bizarre when users view
  619.                                         the documentation.  Remember
  620.                                         that the indentation before the
  621.                                         starting double-quote is not
  622.                                         part of the string!
  623.  
  624.                                       * A variable's documentation
  625.                                         string should start with `*' if
  626.                                         the variable is one that users
  627.                                         would want to set interactively
  628.                                         often.  If the value is a long
  629.                                         list, or a function, or if the
  630.                                         variable would only be set in
  631.                                         init files, then don't start
  632.                                         the documentation string with
  633.                                         `*'.  *Note Defining
  634.                                         Variables::.
  635.  
  636.                                       * The documentation string for a
  637.                                         variable that is a yes-or-no
  638.                                         flag should start with words
  639.                                         such as "Non-nil means...", to
  640.                                         make it clear both that the
  641.                                         variable only has two
  642.                                         meaningfully distinct values
  643.                                         and which value means "yes".
  644.  
  645.                                       * When a function's documentation
  646.                                         string mentions the value of an
  647.                                         argument of the function, use
  648.                                         the argument name in capital
  649.                                         letters as if it were a name
  650.                                         for that value.  Thus, the
  651.                                         documentation string of the
  652.                                         function `/' refers to its
  653.                                         second argument as `DIVISOR'.
  654.  
  655.                                         Also use all caps for
  656.                                         meta-syntactic variables, such
  657.                                         as when you show the
  658.                                         decomposition of a list or
  659.                                         vector into subunits, some of
  660.                                         which may be variable.
  661.  
  662.                                       * When a documentation string
  663.                                         refers to a Lisp symbol, write
  664.                                         it as it would be printed
  665.                                         (which usually means in lower
  666.                                         case), with single-quotes
  667.                                         around it.  For example:
  668.                                         ``lambda''.  There are two
  669.                                         exceptions: write `t' and `nil'
  670.                                         without single-quotes.
  671.  
  672.                                       * Don't write key sequences
  673.                                         directly in documentation
  674.                                         strings.  Instead, use the
  675.                                         `\\[...]' construct to stand
  676.                                         for them.  For example, instead
  677.                                         of writing `C-f', write
  678.                                         `\\[forward-char]'.  When the
  679.                                         documentation string is
  680.                                         printed, Emacs will substitute
  681.                                         whatever key is currently bound
  682.                                         to `forward-char'.  This will
  683.                                         usually be `C-f', but if the
  684.                                         user has moved key bindings, it
  685.                                         will be the correct key for
  686.                                         that user.  *Note Keys in
  687.                                         Documentation::.
  688.  
  689.                                       * In documentation strings for a
  690.                                         major mode, you will want to
  691.                                         refer to the key bindings of
  692.                                         that mode's local map, rather
  693.                                         than global ones.  Therefore,
  694.                                         use the construct `\\<...>'
  695.                                         once in the documentation
  696.                                         string to specify which key map
  697.                                         to use.  Do this before the
  698.                                         first use of `\\[...]'.  The
  699.                                         text inside the `\\<...>'
  700.                                         should be the name of the
  701.                                         variable containing the local
  702.                                         keymap for the major mode.
  703.  
  704.                                         It is not practical to use
  705.                                         `\\[...]' very many times,
  706.                                         because display of the
  707.                                         documentation string will
  708.                                         become slow.  So use this to
  709.                                         describe the most important
  710.                                         commands in your major mode,
  711.                                         and then use `\\{...}' to
  712.                                         display the rest of the mode's
  713.                                         keymap.
  714.  
  715.                                       * Don't use the term "Elisp",
  716.                                         since that is or was a
  717.                                         trademark.  Use the term "Emacs
  718.                                         Lisp".
  719.  
  720. 
  721. File: elisp,  Node: Comment Tips,  Next: Library Headers,  Prev: Documentation Tips,  Up: Tips
  722.  
  723. Tips on Writing Comments
  724. ========================
  725.  
  726.                                       We recommend these conventions
  727. for where to put comments and how to indent them:
  728.  
  729.                                   `;'
  730.                                         Comments that start with a
  731.                                         single semicolon, `;', should
  732.                                         all be aligned to the same
  733.                                         column on the right of the
  734.                                         source code.  Such comments
  735.                                         usually explain how the code on
  736.                                         the same line does its job.  In
  737.                                         Lisp mode and related modes,
  738.                                         the `M-;' (`indent-for-comment')
  739.                                         command automatically inserts
  740.                                         such a `;' in the right place,
  741.                                         or aligns such a comment if it
  742.                                         is already inserted.
  743.  
  744.                                         (The following examples are
  745.                                         taken from the Emacs sources.)
  746.  
  747.                                              (setq base-version-list                 ; there was a base
  748.                                                    (assoc (substring fn 0 start-vn)  ; version to which
  749.                                                           file-version-assoc-list))  ; this looks like
  750.                                                                                      ; a subversion
  751.  
  752.                                   `;;'
  753.                                         Comments that start with two
  754.                                         semicolons, `;;', should be
  755.                                         aligned to the same level of
  756.                                         indentation as the code.  Such
  757.                                         comments are used to describe
  758.                                         the purpose of the following
  759.                                         lines or the state of the
  760.                                         program at that point.  For
  761.                                         example:
  762.  
  763.                                              (prog1 (setq auto-fill-function
  764.                                                           ...
  765.                                                           ...
  766.                                                ;; update mode-line
  767.                                                (force-mode-line-update)))
  768.  
  769.                                         These comments are also written
  770.                                         before a function definition to
  771.                                         explain what the function does
  772.                                         and how to call it properly.
  773.  
  774.                                   `;;;'
  775.                                         Comments that start with three
  776.                                         semicolons, `;;;', should start
  777.                                         at the left margin.  Such
  778.                                         comments are not used within
  779.                                         function definitions, but are
  780.                                         used to make more general
  781.                                         comments.  For example:
  782.  
  783.                                              ;;; This Lisp code is run in Emacs
  784.                                              ;;; when it is to operate asa server
  785.                                              ;;; for other processes.
  786.  
  787.                                   `;;;;'
  788.                                         Comments that start with four
  789.                                         semicolons, `;;;;', should be
  790.                                         aligned to the left margin and
  791.                                         are used for headings of major
  792.                                         sections of a program.  For
  793.                                         example:
  794.  
  795.                                              ;;;; The kill ring
  796.  
  797.                                    The indentation commands of the Lisp
  798. modes in Emacs, such as `M-;' (`indent-for-comment') and TAB
  799. (`lisp-indent-line') automatically indent comments according to these
  800. conventions, depending on the the number of semicolons.  *Note
  801. Manipulating Comments: (emacs)Comments.
  802.  
  803.                                       If you wish to "comment out" a
  804. number of lines of code, use triple semicolons at the beginnings of the
  805. lines.
  806.  
  807.                                       Any character may be included in
  808. a comment, but it is advisable to precede a character with syntactic
  809. significance in Lisp (such as `\' or unpaired `(' or `)') with a `\',
  810. to prevent it from confusing the Emacs commands for editing Lisp.
  811.  
  812. 
  813. File: elisp,  Node: Library Headers,  Prev: Comment Tips,  Up: Tips
  814.  
  815. Conventional Headers for Emacs Library Packages
  816. ===============================================
  817.  
  818.                                       There are some standard
  819. identication headers used in Emacs 19 library packages to assist the
  820. help system, track authors and versions for maintainence purposes, and
  821. enable the generation of various kinds of databases and documentation.
  822.  
  823.                                       This section explains them and
  824. why you should try to use the same conventions in your packages,
  825. especially if you want to submit them to FSF.
  826.  
  827.                                       Here's the head of a file written
  828. using the library conventions:
  829.  
  830.                                         ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers
  831.                                         
  832.                                         ;; Copyright (C) 1992 Free Software Foundation, Inc.
  833.                                         
  834.                                         ;; Author: Eric S. Raymond <esr
  835.                                         ;; Maintainer: Eric S. Raymond <esr
  836.                                         ;; Created: 14 Jul 1992
  837.                                         ;; Version: 1.2
  838.                                         ;; Keywords: docs
  839.                                         ;; Bogus-Bureaucratic-Cruft: Gruad will get you if you don't watch out!
  840.                                         
  841.                                         ;; This file is part of GNU Emacs.
  842.  
  843.                                       Here are the new features:
  844.  
  845.                                       *Header line* -- makes it
  846. possible to extract a one-line summary of the package's uses
  847. automatically for use in library synopses, KWIC indexes and the like.
  848.  
  849.                                       Format is three semicolons,
  850. followed by the filename, followed by three dashes, followed by the
  851. summary.  All fields space-separated.
  852.  
  853.                                       *Author line* -- contains the
  854. name and net address of at least the principal author.
  855.  
  856.                                       If there are multiple authors,
  857. they should be listed on continuation lines led by `;;<TAB>', like this:
  858.  
  859.                                         ;; Author: Ashwin Ram <Ram-Ashwin
  860.                                         ;;    Dave Sill <de5
  861.                                         ;;    David Lawrence <tale
  862.                                         ;;    Noah Friedman <friedman
  863.                                         ;;    Joe Wells <jbw
  864.                                         ;;    Dave Brennan <brennan
  865.                                         ;;    Eric Raymond <esr
  866.  
  867.                                       This field may have some special
  868. values; notably "FSF", meaning "Free Software Foundation".
  869.  
  870.                                       *Maintainer line* -- should be a
  871. single name/address as in the Author line, or an address only, or the
  872. string "FSF".  If there is no maintainer line, the person(s) in the
  873. Author field are presumed to be it.  The example in this file is mildly
  874. bogus because the maintainer line is redundant.
  875.  
  876.                                       The idea behind these two fields
  877. is to be able to write a lisp function that does "send mail to the
  878. author" without having to mine the name out by hand. Please be careful
  879. about surrounding the network address with <> if there's also a name in
  880. the field.
  881.  
  882.                                       *Created line* -- optional, gives
  883. the original creation date of the file.  For historical interest,
  884. basically.
  885.  
  886.                                       *Version line* -- intended to
  887. give the reader a clue if they're looking at a different version of the
  888. file than the one they're accustomed to.  Not needed if you have an RCS
  889. or SCCS header.
  890.  
  891.                                       *Adapted-By line* -- this is for
  892. FSF's internal use.  The person named in this field was the one
  893. responsible for installing and adapting the package for the
  894. distribution.  (This file doesn't have one because the author *is* one
  895. of the maintainers.)
  896.  
  897.                                       *Keywords line* -- used by the
  898. package-finder code for finding elisp code related to a topic.  This
  899. field is important; it's how people will find your package when they're
  900. looking forthings by topic area.
  901.  
  902.                                       *Bogus-Bureaucratic-Cruft line*
  903. -- this is a joke.  We figured we should satirize this design before
  904. someone else did.  Also, it illustrates the possibility that other
  905. headers may be added in the future for new purposes.
  906.  
  907.                                       There are a few other stylized
  908. comments all the distribution files comtain.  These are:
  909.  
  910.                                       *Commentary line* -- optional,
  911. enables lisp code to find the developer's and maintainers' explanations
  912. of the package internals.  It looks like this:
  913.  
  914.                                       smallexample ;;; Commentary:
  915. smallexample
  916.  
  917.                                       and should be located after the
  918. GNU copyright but before the package's header comments (if any).
  919.  
  920.                                       *Change log line* -- optional,
  921. exists to terminate the commentary section and start a change-log part,
  922. if one exists.  It looks like this:
  923.  
  924.                                       smallexample ;;; Change Log:
  925. smallexample
  926.  
  927.                                       *Code line* -- exists so lisp can
  928. know where the commentary and/or change-log sections end.  It looks
  929. like this:
  930.  
  931.                                       smallexample ;;; Code:
  932. smallexample
  933.  
  934.                                       *Footer line* -- marks
  935. end-of-file so it can be distinguished from an expanded formfeed or the
  936. results of truncation.  This must be the *last* line in the file.
  937. Example:
  938.  
  939.                                       smallexample ;;; lisp-mnt.el ends
  940. here  smallexample
  941.  
  942.                                       The mode used as an example
  943. actually exists and can actually be used to generate these headers
  944. semi-automatically.  It provides functions which lisp programs can use
  945. to etract various useful pieces of information from these headers.
  946.  
  947.