home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i22 (.txt) < prev    next >
GNU Info File  |  1993-06-14  |  51KB  |  888 lines

  1. This is Info file elisp, produced by Makeinfo-1.47 from the input file
  2. elisp.texi.
  3.    This file documents GNU Emacs Lisp.
  4.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual, for
  5. Emacs Version 18.
  6.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  7. Cambridge, MA 02139 USA
  8.    Copyright (C) 1990 Free Software Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that
  14. the entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20. File: elisp,  Node: Flow Control,  Next: Batch Mode,  Prev: Terminal Output,  Up: System Interface
  21. Flow Control
  22. ============
  23.    This section attempts to answer the question "Why does Emacs choose
  24. to use flow-control characters in its command character set?"  For a
  25. second view on this issue, read the comments on flow control in the
  26. `emacs/INSTALL' file from the distribution; for help with termcaps and
  27. DEC terminal concentrators, see `emacs/etc/TERMS'.
  28.    At one time, most terminals did not need flow control.  This meant
  29. that the choice of `C-s' and `C-q' as command characters was
  30. reasonable.  Emacs, for economy of keystrokes and portability, chose to
  31. use the control characters in the ASCII character set, and tried to
  32. make the assignments mnemonic (thus, `C-s' for search and `C-q' for
  33. quote).
  34.    Later, some terminals were introduced which used these characters for
  35. flow control.  They were not very good terminals, so Emacs maintainers
  36. did not pay attention.  In later years, the practice became widespread
  37. among terminals, but by this time it was usually an option.  And the
  38. majority of users, who can turn flow control off, were unwilling to
  39. switch to less mnemonic key bindings for the sake of flow control.
  40.    So which usage is "right", Emacs's or that of some terminal and
  41. concentrator manufacturers?  This is a rhetorical (or religious)
  42. question; it has no simple answer.
  43.    One reason why we are reluctant to cater to the problems caused by
  44. `C-s' and `C-q' is that they are gratuitous.  There are other
  45. techniques (albeit less common in practice) for flow control that
  46. preserve transparency of the character stream.  Note also that their use
  47. for flow control is not an official standard.  Interestingly, on the
  48. model 33 teletype with a paper tape punch (which is very old), `C-s'
  49. and `C-q' were sent by the computer to turn the punch on and off!
  50.    GNU Emacs (version 18.48 and later) provides several options for
  51. coping with terminals or front-ends that insist on using flow control
  52. characters.  Listed in estimated order of preference, these options are
  53. as follows:
  54.   1. Have Emacs run in CBREAK mode with the kernel handling flow
  55.      control.  Issue `(set-input-mode nil t)' from `.emacs'.  After
  56.      doing this, it is necessary to find other keys to bind to the
  57.      commands `isearch-forward' and `quoted-insert'.  The usual
  58.      nominees are `C-^' and `C-\'.  There are two ways to get this
  59.      effect:
  60.        1. Use the `keyboard-translate-table' to cause `C-^' and `C-\'
  61.           to be received by Emacs as though `C-s' and `C-q' were typed.
  62.            Emacs (except at its very lowest level) never knows that the
  63.           characters typed were anything but `C-s' and `C-q', so the use
  64.           of these keys inside `isearch-forward' still works--typing
  65.           `C-^' while incremental searching will move the cursor to the
  66.           next match, etc.  For example:
  67.                (setq keyboard-translate-table (make-string 128 0))
  68.                (let ((i 0))
  69.                  (while (< i 128)
  70.                    (aset keyboard-translate-table i i)
  71.                    (setq i (1+ i))))
  72.                
  73.                  ;; Swap `C-s' and `C-\'.
  74.                  (aset the-table ?\034 ?\^s)
  75.                  (aset the-table ?\^s ?\034)
  76.                  ;; Swap `C-q' and `C-^'.
  77.                  (aset the-table ?\036 ?\^q)
  78.                  (aset the-table ?\^q ?\036)))
  79.        2. Simply rebind the keys `C-^' and `C-\' to `isearch-forward'
  80.           and `quoted-insert'.  To use the new keys to repeat searches,
  81.           it is necessary to set `search-repeat-char' to `C-^' as well.
  82.   2. Don't use CBREAK mode, but cause `C-s' and `C-q' to be bound to a
  83.      null command.  The problem with this solution is that the flow
  84.      control characters were probably sent because whatever sent them is
  85.      falling behind on the characters being sent to it.  The characters
  86.      that find their way to the terminal screen will not in general be
  87.      those that are intended.  Also, it will be be necessary to find
  88.      other keys to bind to `isearch-forward' and `quoted-insert'; see
  89.      the previous alternative.
  90.      Here is a suitable null command:
  91.           (defun noop ()
  92.             "Do nothing; return nil."
  93.             (interactive))
  94.   3. Don't use CBREAK mode, and unset the `C-s' and `C-q' keys with the
  95.      `global-unset-key' function.  This is similar to the previous
  96.      alternative, except that the flow control characters will probably
  97.      cause beeps or visible bells.
  98.      Note that if the terminal is the source of the flow control
  99.      characters and kernel flow control handling is enabled, you
  100.      probably will not have to send padding characters as specified in
  101.      a termcap or terminfo entry. In this case, it may be possible to
  102.      customize a termcap entry to provide better Emacs performance on
  103.      the assumption that flow control is in use. This effect can also
  104.      be simulated by announcing (with `stty' or its equivalent) that
  105.      the terminal is running at a very slow speed, provided you are
  106.      communicating across a network so that `stty' does not actually
  107.      try to change the line speed.
  108. File: elisp,  Node: Batch Mode,  Prev: Flow Control,  Up: System Interface
  109. Batch Mode
  110. ==========
  111.    The command line option `-batch' causes Emacs to run
  112. noninteractively.  In this mode, Emacs does not read commands from the
  113. terminal, it does not alter the terminal modes, and it does not expect
  114. to be outputting to an erasable screen.  The idea is that you will
  115. specify Lisp programs to run; when they are finished, Emacs should exit.
  116. The way to specify the programs to run is with `-l FILE', which causes
  117. the library named FILE to be loaded, and `-f FUNCTION', which causes
  118. FUNCTION to be called with no arguments.
  119.    Any Lisp program output that would normally go to the echo area,
  120. either using `message' or using `prin1', etc., with `t' as the stream,
  121. will actually go to Emacs's standard output descriptor when in batch
  122. mode.  Thus, Emacs behaves much like a noninteractive application
  123. program.  (The echo area output that Emacs itself normally generates,
  124. such as command echoing, is suppressed entirely.)
  125.  -- Variable: noninteractive
  126.      This variable is non-`nil' when Emacs is running in batch mode.
  127. File: elisp,  Node: Emacs Display,  Next: Tips,  Prev: System Interface,  Up: Top
  128. Emacs Display
  129. *************
  130.    This chapter describes a number of features related to the display
  131. that Emacs presents to the user.
  132. * Menu:
  133. * Refresh Screen::      Clearing the screen and redrawing everything on it.
  134. * Screen Attributes::   How big is the Emacs screen.
  135. * Truncation::          Folding or wrapping long text lines.
  136. * The Echo Area::       Where messages are displayed.
  137. * Selective Display::   Hiding part of the buffer text.
  138. * Overlay Arrow::       Display of an arrow to indicate position.
  139. * Temporary Displays::  Displays that go away automatically.
  140. * Waiting::             Forcing display update and waiting for user.
  141. * Blinking::            How Emacs shows the matching open parenthesis.
  142. * Control Char Display::  How control characters are displayed.
  143. * Beeping::             Audible signal to the user.
  144. * Window Systems::      Which window system is being used.
  145. File: elisp,  Node: Refresh Screen,  Next: Screen Attributes,  Prev: Emacs Display,  Up: Emacs Display
  146. Refreshing the Screen
  147. =====================
  148.  -- Command: redraw-display
  149.      This function clears the screen and redraws what is supposed to
  150.      appear on it.
  151. File: elisp,  Node: Screen Attributes,  Next: Truncation,  Prev: Refresh Screen,  Up: Emacs Display
  152. Screen Attributes
  153. =================
  154.    The screen attribute functions describe and define the
  155. characteristics of the terminal.
  156.  -- Function: screen-height
  157.      This function returns the number of lines on the screen that are
  158.      available for display.
  159.           (screen-height)
  160.                => 50
  161.  -- Function: screen-width
  162.      This function returns the number of columns on the screen that are
  163.      available for display.
  164.           (screen-width)
  165.                => 80
  166.  -- Function: set-screen-height LINES &optional NOT-ACTUAL-SIZE
  167.      This function declares that the terminal can display LINES lines.
  168.      The sizes of existing windows will be altered proportionally to
  169.      fit.
  170.      If NOT-ACTUAL-SIZE is non-`nil', then Emacs will display LINES
  171.      lines of output, but will not change its value for the actual
  172.      height of the screen.  Knowing the correct actual size may be
  173.      necessary for correct cursor positioning.
  174.      If LINES is different from what it was previously, then the entire
  175.      screen is cleared and redisplayed using the new size.
  176.      This function returns `nil'.
  177.  -- Function: set-screen-width COLUMNS &optional NOT-ACTUAL-SIZE
  178.      This function declares that the terminal can display COLUMNS
  179.      columns.  The details are as in `set-screen-height'.
  180.  -- Variable: no-redraw-on-reenter
  181.      This variable controls whether Emacs redraws the entire screen
  182.      after it has been suspended and resumed.  Non-`nil' means yes,
  183.      `nil' means no.  On most terminals, it is necessary to redraw. 
  184.      Not redrawing is useful if the terminal can remember and restore
  185.      the Emacs screen contents.
  186.  -- Variable: inverse-video
  187.      This variable controls whether Emacs uses inverse video for all
  188.      text on the screen.  Non-`nil' means yes, `nil' means no.  The
  189.      default is `nil'.
  190.  -- User Option: mode-line-inverse-video
  191.      This variable controls the use of inverse video for mode lines. 
  192.      If it is non-`nil', then mode lines are displayed in inverse video
  193.      (or another suitable display mode).  Otherwise, mode lines are
  194.      displayed normal, just like the rest of the screen.  The default
  195.      is `t'.
  196. File: elisp,  Node: Truncation,  Next: The Echo Area,  Prev: Screen Attributes,  Up: Emacs Display
  197. Truncation
  198. ==========
  199.    When a line of text extends beyond the right edge of a window, the
  200. line can either be truncated or continued on the next line.  When a line
  201. is truncated, this is shown with a `$' in the rightmost column of the
  202. window.  When a line is continued or "wrapped" onto the next line, this
  203. is shown with a `\' on the rightmost column of the window. The
  204. additional screen lines used to display a long text line are called
  205. "continuation" lines.  (Note that wrapped lines are not filled; filling
  206. has nothing to do with truncation and continuation. *Note Filling::.)
  207.  -- User Option: truncate-lines
  208.      This buffer-local variable controls how Emacs displays lines that
  209.      extend beyond the right edge of the window.  If it is non-`nil',
  210.      then Emacs does not display continuation lines; but rather each
  211.      line of text will take exactly one screen line, and a dollar sign
  212.      will be shown at the edge of any line that extends to or beyond
  213.      the edge of the window.  The default is `nil'.
  214.      If the variable `truncate-partial-width-windows' is non-`nil',
  215.      then truncation is used for windows that are not the full width of
  216.      the screen, regardless of the value of `truncate-lines'.
  217.  -- Variable: default-truncate-lines
  218.      This variable is the default value for `truncate-lines' in buffers
  219.      that do not override it.
  220.  -- User Option: truncate-partial-width-windows
  221.      This variable determines how lines that are too wide to fit on the
  222.      screen are displayed in side-by-side windows (*note Splitting
  223.      Windows::.).  If it is non-`nil', then wide lines are truncated
  224.      (with a `$' at the end of the line); otherwise they are wrapped
  225.      (with a `\' at the end of the line).
  226. File: elisp,  Node: The Echo Area,  Next: Selective Display,  Prev: Truncation,  Up: Emacs Display
  227. The Echo Area
  228. =============
  229.    The "echo area" is used for displaying messages made with the
  230. `message' primitive, and for echoing keystrokes.  It is not the same as
  231. the minibuffer, despite the fact that the minibuffer appears (when
  232. active) in the same place on the screen as the echo area.  The `GNU
  233. Emacs Manual' specifies the rules for resolving conflicts between the
  234. echo area and the minibuffer for use of that screen space (*note The
  235. Minibuffer: (emacs)Minibuffer.).
  236.    You can write output in the echo area by using the Lisp printing
  237. funtions with `t' as the stream (*note Output Functions::.), or as
  238. follows:
  239.  -- Function: message STRING &rest ARGUMENTS
  240.      This function prints a one-line message in the echo area.  The
  241.      argument STRING is similar to a C language `printf' control
  242.      string.  See `format' in *Note String Conversion::, for the details
  243.      on the conversion specifications.  `message' returns the
  244.      constructed string.
  245.           (message "Minibuffer depth is %d." (minibuffer-depth))
  246.           => "Minibuffer depth is 0."
  247.           
  248.           ---------- Echo Area ----------
  249.           Minibuffer depth is 0.
  250.           ---------- Echo Area ----------
  251.  -- Variable: cursor-in-echo-area
  252.      This variable controls where the cursor is positioned when a
  253.      message is displayed in the echo area.  If it is non-`nil', then
  254.      the cursor appears at the end of the message.  Otherwise, the
  255.      cursor appears at point--not in the echo area at all.
  256.      The value is normally `nil' except when bound to `t' for brief
  257.      periods of time.
  258. File: elisp,  Node: Selective Display,  Next: Overlay Arrow,  Prev: The Echo Area,  Up: Emacs Display
  259. Selective Display
  260. =================
  261.    "Selective display" is a class of minor modes in which specially
  262. marked lines do not appear on the screen, or in which highly indented
  263. lines do not appear.
  264.    The first variant, explicit selective display, is designed for use in
  265. a Lisp program.  The program controls which lines are hidden by altering
  266. the text.  Outline mode uses this variant.  In the second variant, the
  267. choice of lines to hide is made automatically based on indentation.
  268. This variant is designed as a user-level feature.
  269.    The way you control explicit selective display is by replacing a
  270. newline (control-j) with a control-m.  The text which was formerly a
  271. line following that newline is now invisible.  Strictly speaking, it is
  272. no longer a separate line, since only newlines can separate lines; it is
  273. now part of the previous line.
  274.    On its own, selective display does not affect editing commands.  For
  275. example, `C-f' (`forward-char') moves point unhesitatingly into
  276. invisible space.  However, the replacement of newline characters with
  277. carriage return characters affects some editing commands.  For example,
  278. `next-line' skips invisible lines, since it searches only for newlines.
  279.  Modes that use selective display can also define commands that take
  280. account of the newlines, or which make parts of the text visible or
  281. invisible.
  282.    When you write a selectively displayed buffer into a file, all the
  283. control-m's are replaced by their original newlines.  This means that
  284. when you next read in the file, it looks OK, with nothing invisible.
  285. Selective display is an effect that is seen only in Emacs.
  286.  -- Variable: selective-display
  287.      This buffer-local variable enables selective display.  This means
  288.      that lines, or portions of lines, may be made invisible.
  289.         * If the value of `selective-display' is `t', then any portion
  290.           of a line that follows a control-m will not be displayed.
  291.         * If the value of `selective-display' is a positive integer,
  292.           then lines that start with more than `selective-display'
  293.           columns of indentation will not be displayed.
  294.      When some portion of a buffer is invisible, the vertical movement
  295.      commands operate as if that portion did not exist, allowing a
  296.      single `next-line' command to skip any number of invisible lines.
  297.      However, character movement commands (such as `forward-char') will
  298.      not skip the invisible portion, and it is possible (if tricky) to
  299.      insert or delete parts of an invisible portion.
  300.      In the examples below, what is shown is the *display* of the buffer
  301.      `foo', which changes with the value of `selective-display'.  The
  302.      *contents* of the buffer do not change.
  303.           (setq selective-display nil)
  304.                => nil
  305.           
  306.           ---------- Buffer: foo ----------
  307.           1 on this column
  308.            2on this column
  309.             3n this column
  310.             3n this column
  311.            2on this column
  312.           1 on this column
  313.           ---------- Buffer: foo ----------
  314.           
  315.           (setq selective-display 2)
  316.                => 2
  317.           
  318.           ---------- Buffer: foo ----------
  319.           1 on this column
  320.            2on this column
  321.            2on this column
  322.           1 on this column
  323.           ---------- Buffer: foo ----------
  324.  -- Variable: selective-display-ellipses
  325.      If this buffer-local variable is non-`nil', then Emacs displays
  326.      `...' at the end of a line that is followed by invisible text.
  327.      This example is a continuation of the previous one.
  328.           (setq selective-display-ellipses t)
  329.                => t
  330.           
  331.           ---------- Buffer: foo ----------
  332.           1 on this column
  333.            2on this column ...
  334.            2on this column
  335.           1 on this column
  336.           ---------- Buffer: foo ----------
  337. File: elisp,  Node: Overlay Arrow,  Next: Temporary Displays,  Prev: Selective Display,  Up: Emacs Display
  338. Overlay Arrow
  339. =============
  340.    The "overlay arrow" is useful for directing the user's attention to
  341. a particular line in a buffer.  For example, in the modes used for
  342. interface to debuggers, the overlay arrow indicates the current line of
  343. code about to be executed.
  344.  -- Variable: overlay-arrow-string
  345.      This variable holds the string to display as an arrow, or `nil' if
  346.      the arrow feature is not in use.
  347.  -- Variable: overlay-arrow-position
  348.      This variable holds a marker which indicates where to display the
  349.      arrow. It should point at the beginning of a line.  The arrow text
  350.      will be displayed at the beginning of that line, overlaying any
  351.      text that would otherwise appear.  Since the arrow is usually
  352.      short, and the line usually begins with indentation, normally
  353.      nothing significant is overwritten.
  354.      The overlay string is displayed only in the buffer which this
  355.      marker points into.  Thus, only one buffer can have an overlay
  356.      arrow at any given time.
  357. File: elisp,  Node: Temporary Displays,  Next: Waiting,  Prev: Overlay Arrow,  Up: Emacs Display
  358. Temporary Displays
  359. ==================
  360.    Temporary displays are used by commands to put output into a buffer
  361. and then present it to the user for perusal rather than for editing.
  362. Many of the help commands use this feature.
  363.  -- Special Form: with-output-to-temp-buffer BUFFER-NAME FORMS...
  364.      This function executes FORMS while arranging to insert any output
  365.      they print into the buffer named BUFFER-NAME.  The buffer is then
  366.      shown in some window for viewing, displayed but not selected.
  367.      The buffer is named by the string BUFFER-NAME, and it need not
  368.      already exist.  The argument BUFFER-NAME must be a string, not a
  369.      buffer.  The buffer is erased initially (with no questions asked),
  370.      and it is marked as unmodified after `with-output-to-temp-buffer'
  371.      exits.
  372.      `with-output-to-temp-buffer' first binds `standard-output' to the
  373.      buffer, then it evaluates the forms in FORMS.  With
  374.      `standard-output' rebound, any output directed there will naturally
  375.      be inserted into that buffer.  Only Lisp output directed to the
  376.      stream `standard-output' is affected; screen display and messages
  377.      in the echo area, although output in the general sense of the
  378.      word, are not affected.  *Note Output Functions::.
  379.      The value of the last form in FORMS is returned.
  380.           ---------- Buffer: foo ----------
  381.            This is the contents of foo.
  382.           ---------- Buffer: foo ----------
  383.           
  384.           (with-output-to-temp-buffer "foo"
  385.               (print 20)
  386.               (print standard-output))
  387.           => #<buffer foo>
  388.           
  389.           ---------- Buffer: foo ----------
  390.           20
  391.           
  392.           #<buffer foo>
  393.           
  394.           ---------- Buffer: foo ----------
  395.  -- Variable: temp-buffer-show-hook
  396.      The value of the `temp-buffer-show-hook' variable is either `nil'
  397.      or is called as a function to display a help buffer.  This
  398.      variable is used by `with-output-to-temp-buffer'.
  399.  -- Function: momentary-string-display STRING POSITION &optional CHAR
  400.           MESSAGE
  401.      This function momentarily displays STRING in the current buffer at
  402.      POSITION (which is a character offset from the beginning of the
  403.      buffer).  The display remains until the next character is typed.
  404.      If the next character the user types is CHAR, Emacs ignores it.
  405.      Otherwise, that character remains buffered for subsequent use as
  406.      input. Thus, typing CHAR will simply remove the string from the
  407.      display, while typing (say) `C-f' will remove the string from the
  408.      display and later (presumably) move point forward.  The argument
  409.      CHAR is a space by default.
  410.      The result of `momentary-string-display' is not useful.
  411.      If MESSAGE is non-`nil', it is displayed in the echo area.  If it
  412.      is `nil', then instructions to type CHAR are displayed there,
  413.      e.g., `Type RET to continue editing'.
  414.      In this example, point is initially located at the beginning of the
  415.      second line:
  416.           ---------- Buffer: foo ----------
  417.           This is the contents of foo.
  418.           -!-This is the contents of foo.
  419.           ---------- Buffer: foo ----------
  420.           
  421.           (momentary-string-display
  422.              "******* Important Message! *******" (point) ?\r
  423.              "Type RET when done reading")
  424.           => t
  425.           
  426.           ---------- Buffer: foo ----------
  427.           This is the contents of foo.
  428.           ******* Important Message! *******This is the contents of foo.
  429.           ---------- Buffer: foo ----------
  430.           
  431.           ---------- Echo Area ----------
  432.           Type RET when done reading
  433.      This function works by actually changing the text in the buffer. 
  434.      As a result, if you later undo in this buffer, you will see the
  435.      message come and go.
  436. File: elisp,  Node: Waiting,  Next: Blinking,  Prev: Temporary Displays,  Up: Emacs Display
  437. Waiting for Elapsed Time or Input
  438. =================================
  439.    The waiting commands are designed to make Emacs wait for a certain
  440. amount of time to pass or until there is input.  For example, you may
  441. wish to pause in the middle of a computation to allow the user time to
  442. view the display.  `sit-for' performs a pause with an update of screen,
  443. while `sleep-for' performs a pause without updating the screen.
  444.  -- Function: sit-for SECONDS
  445.      This function performs redisplay (provided there is no pending
  446.      input from the user), then waits SECONDS seconds, or until input is
  447.      available.  The result is `t' if `sit-for' waited the full time
  448.      with no input arriving (see `input-pending-p' in *Note Keyboard
  449.      Input::).  Otherwise, `nil' is returned.
  450.      Redisplay is always preempted if input arrives, and does not
  451.      happen at all if input is available before it starts.  Thus, there
  452.      is no way to force screen updating if there is pending input;
  453.      however, if there is no input pending, you can force an update
  454.      with no delay by using `(sit-for 0)'.
  455.      The purpose of `sit-for' to give the user time to read text that
  456.      you display.
  457.  -- Function: sleep-for SECONDS
  458.      This function simply pauses for SECONDS seconds without updating
  459.      the display.  It pays no attention to available input.  It returns
  460.      `nil'.
  461.      Use `sleep-for' when you wish to guarantee a delay.
  462. File: elisp,  Node: Blinking,  Next: Control Char Display,  Prev: Waiting,  Up: Emacs Display
  463. Blinking
  464. ========
  465.    This section describes the mechanism by which Emacs shows a matching
  466. open parenthesis when the user inserts a close parenthesis.
  467.  -- Variable: blink-paren-hook
  468.      The value of this variable should be a function (of no arguments)
  469.      to be called whenever a char with close parenthesis syntax is
  470.      inserted. The value of `blink-paren-hook' may be `nil', in which
  471.      case nothing is done.
  472.           *Note:* in version 18, this function is named
  473.           `blink-paren-hook', but since it is not called with the
  474.           standard convention for hooks, it is being renamed to
  475.           `blink-paren-function' in version 19.
  476.  -- Variable: blink-matching-paren
  477.      If this variable is `nil', then `blink-matching-open' does nothing.
  478.  -- Variable: blink-matching-paren-distance
  479.      This variable specifies the maximum distance to scan for a matching
  480.      parenthesis before giving up.
  481.  -- Function: blink-matching-open
  482.      This function is the default value of `blink-paren-hook'.  It
  483.      assumes that point follows a character with close parenthesis
  484.      syntax and moves the cursor momentarily to the matching opening
  485.      character.  If that character is not already on the screen, then
  486.      its context is shown by displaying it in the echo area.  To avoid
  487.      long delays, this function does not search farther than
  488.      `blink-matching-paren-distance' characters.
  489.      Here is an example of calling this function explicitly.
  490.           (defun interactive-blink-matching-open ()
  491.             "Indicate momentarily the start of sexp before point."
  492.             (interactive)
  493.             (let ((blink-matching-paren-distance (buffer-size))
  494.                   (blink-matching-paren t))
  495.               (blink-matching-open)))
  496. File: elisp,  Node: Control Char Display,  Next: Beeping,  Prev: Blinking,  Up: Emacs Display
  497. Display of Control Characters
  498. =============================
  499.    These variables affect the way certain characters are displayed on
  500. the screen.  Since they change the number of columns the characters
  501. occupy, they also affect the indentation functions.
  502.  -- User Option: ctl-arrow
  503.      This buffer-local variable controls how control characters are
  504.      displayed.  If it is non-`nil', they are displayed as an uparrow
  505.      followed by the character: `^A'.  If it is `nil', they are
  506.      displayed as a backslash followed by three octal digits: `\001'.
  507.  -- Variable: default-ctl-arrow
  508.      The value of this variable is the default value for `ctl-arrow' in
  509.      buffers that do not override it.  This is the same as
  510.      `(default-value 'ctl-arrow)' (*note Default Value::.).
  511.  -- User Option: tab-width
  512.      The value of this variable is the spacing between tab stops used
  513.      for displaying tab characters in Emacs buffers.  The default is 8.
  514.       Note that this feature is completely independent from the
  515.      user-settable tab stops used by the command `tab-to-tab-stop'. 
  516.      *Note Indent Tabs::.
  517. File: elisp,  Node: Beeping,  Next: Window Systems,  Prev: Control Char Display,  Up: Emacs Display
  518. Beeping
  519. =======
  520.    You can make Emacs ring a bell (or blink the screen) to attract the
  521. user's attention.  Be conservative about how often you do this; frequent
  522. bells can become irritating.  Also be careful not to use beeping alone
  523. when signaling an error is appropriate.  (*Note Errors::.)
  524.  -- Function: ding &optional DONT-TERMINATE
  525.      This function beeps, or flashes the screen (see `visible-bell'
  526.      below). It also terminates any keyboard macro currently executing
  527.      unless DONT-TERMINATE is non-`nil'.
  528.  -- Function: beep &optional DONT-TERMINATE
  529.      This is a synonym for `ding'.
  530.  -- Variable: visible-bell
  531.      This variable determines whether Emacs will try to flash the
  532.      screen to represent a bell.  Non-`nil' means yes, `nil' means no. 
  533.      This is effective only if the termcap entry for the terminal in
  534.      use has the visible bell flag (`vb') set.
  535. File: elisp,  Node: Window Systems,  Prev: Beeping,  Up: Emacs Display
  536. Window Systems
  537. ==============
  538.    Emacs works with several window systems, most notably X Windows. 
  539. Note that both Emacs and the X Window System use the term "window", but
  540. use it differently.  The entire Emacs screen is a single window as far
  541. as X Windows is concerned; the individual Emacs windows are not known
  542. to X Windows at all.
  543.  -- Variable: window-system
  544.      This variable tells Lisp programs what window system Emacs is
  545.      running under.  Its value should be a symbol such as `x' (if Emacs
  546.      is running under X Windows) or `nil' (if Emacs is running on an
  547.      ordinary terminal).
  548.  -- Variable: window-system-version
  549.      This variable distinguishes between different versions of the X
  550.      Window System.  Its value is 10 or 11 when using X Windows; `nil'
  551.      otherwise.
  552.  -- Variable: window-setup-hook
  553.      The value of the `window-setup-hook' variable is either `nil' or a
  554.      function for Emacs to call after loading your `.emacs' file and
  555.      the default initialization file (if any), after loading
  556.      terminal-specific Lisp code, and after calling `term-setup-hook'. 
  557.      `window-setup-hook' is called with no arguments.
  558.      This hook is used for internal purposes: setting up communication
  559.      with the window system, and creating the initial window.  Users
  560.      should not interfere with it.
  561. File: elisp,  Node: Tips,  Next: GNU Emacs Internals,  Prev: Emacs Display,  Up: Top
  562. Tips and Standards
  563. ******************
  564.    This chapter describes no additional features of Emacs Lisp. Instead
  565. it gives advice on making effective use of the features described in
  566. the previous chapters.
  567. * Menu:
  568. * Style Tips::                Writing clean and robust programs.
  569. * Compilation Tips::          Making compiled code run fast.
  570. * Documentation Tips::        Writing readable documentation strings.
  571. File: elisp,  Node: Style Tips,  Next: Compilation Tips,  Prev: Tips,  Up: Tips
  572. Writing Clean Lisp Programs
  573. ===========================
  574.    Here are some tips for avoiding common errors in writing Lisp code
  575. intended for widespread use:
  576.    * Since all global variables share the same name space, and all
  577.      functions share another name space, you should choose a short word
  578.      to distinguish your program from other Lisp programs.  Then take
  579.      care to begin the names of all global variables, constants, and
  580.      functions with the chosen prefix.  This helps avoid name conflicts.
  581.      This recommendation applies even to names for traditional Lisp
  582.      primitives that are not primitives in Emacs Lisp--even to `cadr'.
  583.      Believe it or not, there is more than one plausible way to define
  584.      `cadr'.  Play it safe; append your name prefix to produce a name
  585.      like `foo-cadr' or `mylib-cadr' instead.
  586.      If one prefix is insufficient, your package may use two or three
  587.      alternative common prefixes, so long as they make sense.
  588.    * It is often useful to put a call to `provide' in each separate
  589.      library program, at least if there is more than one entry point to
  590.      the program.
  591.    * If one file FOO uses a macro defined in another file BAR, FOO
  592.      should contain `(require 'BAR)' before the first use of the macro.
  593.       (And BAR should contain `(provide 'BAR)', to make the `require'
  594.      work.)  This will cause BAR to be loaded when you byte-compile
  595.      FOO.  Otherwise, you risk compiling FOO without the necessary
  596.      macro loaded, and that would produce compiled code that won't work
  597.      right.  *Note Compiling Macros::.
  598.    * If you define a major mode, make sure to run a hook variable using
  599.      `run-hooks', just as the existing major modes do.  *Note Hooks::.
  600.    * Please do not define `C-c LETTER' as a key.  These sequences are
  601.      reserved for users; they are the *only* sequences reserved for
  602.      users, so we cannot do without them.
  603.      Everything in Emacs that used to define such sequences has been
  604.      changed, which was a lot of work.  Abandoning this convention
  605.      would waste that work and inconvenience the users.
  606.    * It is a bad idea to define aliases for the Emacs primitives. Use
  607.      the standard names instead.
  608.    * Redefining an Emacs primitive is an even worse idea. It may do the
  609.      right thing for a particular program, but there is no telling what
  610.      other programs might break as a result.
  611.    * If a file does replace any of the functions or library programs of
  612.      standard Emacs, prominent comments at the beginning of the file
  613.      should say which functions are replaced, and how the behavior of
  614.      the replacements differs from that of the originals.
  615.    * If a file requires certain standard library programs to be loaded
  616.      beforehand, then the comments at the beginning of the file should
  617.      say so.
  618.    * Don't use `next-line' or `previous-line' in programs; nearly
  619.      always, `forward-line' is more convenient as well as more
  620.      predictable and robust.  *Note Text Lines::.
  621.    * Don't use functions that set the mark in your Lisp code (unless
  622.      you are writing a command to set the mark).  The mark is a
  623.      user-level feature, so it is incorrect to change the mark except
  624.      to supply a value for the user's benefit.  *Note The Mark::.
  625.      In particular, don't use these functions:
  626.         * `beginning-of-buffer', `end-of-buffer'
  627.         * `replace-string', `replace-regexp'
  628.      If you just want to move point, or replace a certain string,
  629.      without any of the other features intended for interactive users,
  630.      you can replace these functions with one or two lines of simple
  631.      Lisp code.
  632.    * The recommended way to print a message in the echo area is with
  633.      the `message' function, not `princ'.  *Note The Echo Area::.
  634.    * When you encounter an error condition, call the function `error'
  635.      (or `signal').  The function `error' does not return. *Note
  636.      Signaling Errors::.
  637.      Do not use `message', `throw', `sleep-for', or `beep' to report
  638.      errors.
  639.    * Avoid using recursive edits.  Instead, do what the Rmail `w'
  640.      command does: use a new local keymap that contains one command
  641.      defined to switch back to the old local keymap.  Or do what the
  642.      `edit-options' command does: switch to another buffer and let the
  643.      user switch back at will.  *Note Recursive Editing::.
  644.    * In some other systems there is a convention of choosing variable
  645.      names that begin and end with `*'.  We don't use that convention
  646.      in Emacs Lisp, so please don't use it in your library.  The users
  647.      will find Emacs more coherent if all libraries use the same
  648.      conventions.
  649.    * Indent each function with `C-M-q' (`indent-sexp') using the
  650.      default indentation parameters.
  651.    * Don't make a habit of putting close-parentheses on lines by
  652.      themselves; Lisp programmers find this disconcerting.  Once in a
  653.      while, when there is a sequence of many consecutive
  654.      close-parentheses, it may make sense to split them in one or two
  655.      significant places.
  656.    * Please put a copyright notice on the file if you give copies to
  657.      anyone. Use the same lines that appear at the top of the Lisp
  658.      files in Emacs itself.  If you have not signed papers to assign
  659.      the copyright to the Foundation, then place your name in the
  660.      copyright notice in place of the Foundation's name.
  661. File: elisp,  Node: Compilation Tips,  Next: Documentation Tips,  Prev: Style Tips,  Up: Tips
  662. Tips for Making Compiled Code Fast
  663. ==================================
  664.    Here are ways of improving the execution speed of byte-compiled lisp
  665. programs.
  666.    * Use iteration rather than recursion whenever possible. Function
  667.      calls are slow in Emacs Lisp even when a compiled function is
  668.      calling another compiled function.
  669.    * Using the primitive list-searching functions `memq', `assq' or
  670.      `assoc' is even faster than explicit iteration.  It may be worth
  671.      rearranging a data structure so that one of these primitive search
  672.      functions can be used.
  673.      For example, if you want to search a list of strings for a string
  674.      equal to a given one, you can use an explicit loop:
  675.           (let ((tail list))
  676.             (while (and tail (not (string= string (car tail))))
  677.               (setq tail (cdr tail))))
  678.      However, if you use a list of elements of the form `(STRING)',
  679.      such as `(("foo") ("#&") ("bar"))', then you can search it with
  680.      `assoc':
  681.           (assoc string list)
  682.      The latter runs entirely in C code, so it is much faster.
  683.    * Certain built-in functions are handled specially by the byte
  684.      compiler avoiding the need for an ordinary function call.  It is a
  685.      good idea to use these functions rather than alternatives.  To see
  686.      whether a function is handled specially by the compiler, examine
  687.      its `byte-compile' property.  If the property is non-`nil', then
  688.      the function is handled specially.
  689.      For example, the following input will show you that `aref' is
  690.      compiled specially (*note Array Functions::.) while `elt' is not
  691.      (*note Sequence Functions::.):
  692.           (get 'aref 'byte-compile)
  693.                => byte-compile-two-args
  694.           
  695.           (get 'elt 'byte-compile)
  696.                => nil
  697.    * Often macros result in faster execution than functions.  For
  698.      example, the following macro and the following function have the
  699.      same effect when called, but code using the macro runs faster
  700.      because it avoids an extra call to a user-defined function:
  701.           (defmacro fast-cadr (x) (list 'car (list 'cdr x)))
  702.           
  703.           (defun slow-cadr (x) (car (cdr x)))
  704. File: elisp,  Node: Documentation Tips,  Prev: Compilation Tips,  Up: Tips
  705. Tips for Documentation Strings
  706. ==============================
  707.    Here are some tips for the writing of documentation strings.
  708.    * Every command, function or variable intended for users to know
  709.      about should have a documentation string.
  710.    * An internal subroutine of a Lisp program need not have a
  711.      documentation string, and you can save space by using a comment
  712.      instead.
  713.    * The first line of the documentation string should consist of one
  714.      or two complete sentences which stand on their own as a summary. 
  715.      In particular, start the line with a capital letter and end with a
  716.      period.
  717.      The documentation string can have additional lines which expand on
  718.      the details of how to use the function or variable.  The
  719.      additional lines should be made up of complete sentences also, but
  720.      they may be filled if that looks good.
  721.    * Do not start or end a documentation string with whitespace.
  722.    * Format the documentation string so that it fits in an Emacs window
  723.      on an 80 column screen.  It is a good idea for most lines to be no
  724.      wider than 60 characters.  The first line can be wider if
  725.      necessary to fit the information that ought to be there.
  726.      However, rather than simply filling the entire documentation
  727.      string, you can make it much more readable by choosing line breaks
  728.      with care. Use blank lines between topics if the documentation
  729.      string is long.
  730.    * *Do not* indent subsequent lines of a documentation string so that
  731.      the text is lined up in the source code with the text of the first
  732.      line.  This looks nice in the source code, but looks bizarre when
  733.      users view the documentation.  Remember that the indentation
  734.      before the starting double-quote is not part of the string!
  735.    * A variable's documentation string should start with `*' if the
  736.      variable is one that users would want to set interactively often. 
  737.      If the value is a long list, or a function, or if the variable
  738.      would only be set in init files, then don't start the
  739.      documentation string with `*'.  *Note Defining Variables::.
  740.    * The documentation string for a variable that is a yes-or-no flag
  741.      should start with words such as "Non-nil means...", to make it
  742.      clear both that the variable only has two meaningfully distinct
  743.      values and which value means "yes".
  744.    * When a function's documentation string mentions the value of an
  745.      argument of the function, use the argument name in capital letters
  746.      as if it were a name for that value.  Thus, the documentation
  747.      string of the function `/' refers to its second argument as
  748.      `DIVISOR'.
  749.      Also use all caps for meta-syntactic variables, such as when you
  750.      show the decomposition of a list or vector into subunits, some of
  751.      which may be variable.
  752.    * When a documentation string refers to a Lisp symbol, write it as it
  753.      would be printed (which usually means in lower case), with
  754.      single-quotes around it.  For example: ``lambda''.  There are two
  755.      exceptions: write `t' and `nil' without single-quotes.
  756.    * Don't write key sequences directly in documentation strings. 
  757.      Instead, use the `\\[...]' construct to stand for them.  For
  758.      example, instead of writing `C-f', write `\\[forward-char]'.  When
  759.      the documentation string is printed, Emacs will substitute
  760.      whatever key is currently bound to `forward-char'.  This will
  761.      usually be `C-f', but if the user has moved key bindings, it will
  762.      be the correct key for that user.  *Note Keys in Documentation::.
  763.    * In documentation strings for a major mode, you will want to refer
  764.      to the key bindings of that mode's local map, rather than global
  765.      ones. Therefore, use the construct `\\<...>' once in the
  766.      documentation string to specify which key map to use.  Do this
  767.      before the first use of `\\[...]'.  The text inside the `\\<...>'
  768.      should be the name of the variable containing the local keymap for
  769.      the major mode.
  770. File: elisp,  Node: GNU Emacs Internals,  Next: Standard Errors,  Prev: Tips,  Up: Top
  771. GNU Emacs Internals
  772. *******************
  773.    This chapter describes how the runnable Emacs executable is dumped
  774. with the preloaded Lisp libraries in it, how storage is allocated, and
  775. some internal aspects of GNU Emacs that may be of interest to C
  776. programmers.
  777. * Menu:
  778. * Building Emacs::      How to preload Lisp libraries into Emacs.
  779. * Pure Storage::        A kludge to make preloaded Lisp functions sharable.
  780. * Garbage Collection::  Reclaiming space for Lisp objects no longer used.
  781. * Object Internals::    Data formats of buffers, windows, processes.
  782. * Writing Emacs Primitives::   Writing C code for Emacs.
  783. File: elisp,  Node: Building Emacs,  Next: Pure Storage,  Prev: GNU Emacs Internals,  Up: GNU Emacs Internals
  784. Building Emacs
  785. ==============
  786.    The first step in building Emacs is to compile the C sources.  This
  787. produces a program called `temacs', also called a "bare impure Emacs". 
  788. It contains the Emacs Lisp interpreter and I/O routines, but not the
  789. editing commands.
  790.    Then, to create a working Emacs editor, issue the command `temacs -l
  791. loadup'.  This directs `temacs' to evaluate the Lisp files specified in
  792. the file `loadup.el'.  These files set up the normal Emacs editing
  793. environment, resulting in an Emacs which is still impure but no longer
  794. bare.
  795.    It takes long time to load the standard Lisp files.  Luckily, you
  796. don't have to do this each time you run Emacs; `temacs' can dump out an
  797. executable program called `xemacs' which has these files preloaded. 
  798. `xemacs' starts more quickly because it does not need to load the
  799. files.  It is `xemacs' that is normally installed under the name
  800. `emacs' for users to run.
  801.    To create `xemacs', use the command `temacs -batch -l loadup dump'. 
  802. The purpose of `-batch' here is to prevent `temacs' from trying to
  803. initialize any of its data on the terminal; this ensures that the
  804. tables of terminal information are empty in the dumped Emacs.
  805.    When the `xemacs' executable is started, it will automatically load
  806. the user's `.emacs' file, or the default initialization file
  807. `default.el' if the user has none.  With the `.emacs' file, you can
  808. produce a version of Emacs that suits you and is not the same as the
  809. version other people use.  With `default.el', you can customize Emacs
  810. for all the users at your site who don't choose to customize it for
  811. themselves.  (For further reflection: why is this different from the
  812. case of the barber who shaves every man who doesn't shave himself?)
  813.    On some systems, dumping does not work.  Then, you must start Emacs
  814. with the `temacs -l loadup' command each time you use it.  This takes a
  815. long time, but since you need to start Emacs once a day at most--and
  816. once a week or less frequently if you never log out--the extra time is
  817. not too severe a problem.
  818.    Before `xemacs' is dumped, the documentation strings for primitive
  819. and preloaded functions (and variables) need to be found in the file
  820. where they are stored.  This is done by calling `Snarf-documentation'
  821. (*note Accessing Documentation::.).  These strings are omitted from
  822. `temacs' to save space. *Note Documentation Basics::.
  823.  -- Function: dump-emacs TO-FILE FROM-FILE
  824.      This function dumps the current state of Emacs into an executable
  825.      file TO-FILE.  It takes symbols from FROM-FILE (this is normally
  826.      the executable file `temacs').
  827.      If you use this function in an Emacs that was already dumped, you
  828.      must set `command-line-processed' to `nil' first for good results.
  829.      *Note Command Line Arguments::.
  830.  -- Command: emacs-version
  831.      This function returns a string describing the version of Emacs
  832.      that is running.  It is useful to include this string in bug
  833.      reports.
  834.           (emacs-version)
  835.             => "GNU Emacs 18.36.1 of Fri Feb 27 1987 on slug (berkeley-unix)"
  836.      Called interactively, the function prints the same information in
  837.      the echo area.
  838.  -- Variable: emacs-build-time
  839.      The value of this variable is the time at which Emacs was built at
  840.      the local site.
  841.           emacs-build-time
  842.                => "Fri Feb 27 14:55:57 1987"
  843.  -- Variable: emacs-version
  844.      The value of this variable is the version of Emacs being run.  It
  845.      is a string, e.g. `"18.36.1"'.
  846. File: elisp,  Node: Pure Storage,  Next: Garbage Collection,  Prev: Building Emacs,  Up: GNU Emacs Internals
  847. Pure Storage
  848. ============
  849.    There are two types of storage in GNU Emacs Lisp for user-created
  850. Lisp objects: "normal storage" and "pure storage".  Normal storage is
  851. where all the new data which is created during an Emacs session is kept;
  852. see the following section for information on normal storage.  Pure
  853. storage is used for certain data in the preloaded standard Lisp files:
  854. data that should never change during actual use of Emacs.
  855.    Pure storage is allocated only while `temacs' is loading the
  856. standard preloaded Lisp libraries.  In the file `xemacs', it is marked
  857. as read-only (on operating systems which permit this), so that the
  858. memory space can be shared by all the Emacs jobs running on the machine
  859. at once.  Pure storage is not expandable; a fixed amount is allocated
  860. when Emacs is compiled, and if that is not sufficient for the preloaded
  861. libraries, `temacs' crashes.  If that happens, you will have to
  862. increase the compilation parameter `PURESIZE' in the file `config.h'. 
  863. This normally won't happen unless you try to preload additional
  864. libraries or add features to the standard ones.
  865.  -- Function: purecopy OBJECT
  866.      This function makes a copy of OBJECT in pure storage and returns
  867.      it.  It copies strings by simply making a new string with the same
  868.      characters in pure storage.  It recursively copies the contents of
  869.      vectors and cons cells.  It does not make copies of symbols, or any
  870.      other objects, but just returns them unchanged.  It signals an
  871.      error if asked to copy markers.
  872.      This function is used only while Emacs is being built and dumped,
  873.      and is called only in the file `emacs/lisp/loaddefs.el'.
  874.  -- Variable: pure-bytes-used
  875.      The value of this variable is the number of bytes of pure storage
  876.      allocated so far.  Typically, in a dumped Emacs, this number is
  877.      very close to the total amount of pure storage available--if it
  878.      were not, we would preallocate less.
  879.  -- Variable: purify-flag
  880.      This variable determines whether `defun' should make a copy of the
  881.      function definition in pure storage.  If it is non-`nil', then the
  882.      function definition is copied into pure storage.
  883.      This flag is `t' while loading all of the basic functions for
  884.      building Emacs initially (allowing those functions to be sharable
  885.      and non-collectible).  It is set to `nil' when Emacs is saved out
  886.      as `xemacs'.  The flag is set and reset in the C sources.
  887.      You should not change this flag in a running Emacs.
  888.