home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i20 (.txt) < prev    next >
GNU Info File  |  1993-06-14  |  51KB  |  909 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: Syntax Class Table,  Next: Syntax Flags,  Prev: Syntax Descriptors,  Up: Syntax Descriptors
  21. Table of Syntax Classes
  22. -----------------------
  23.    Here is a summary of the classes, the characters that stand for them,
  24. their meanings, and examples of their use.
  25.  -- Syntax class: whitespace character
  26.      "Whitespace characters" (designated with ` ' or `-') separate
  27.      symbols and words from each other.  Typically, whitespace
  28.      characters have no other syntactic use, and multiple whitespace
  29.      characters are syntactically equivalent to one.  Space, tab,
  30.      newline and formfeed are almost always considered whitespace.
  31.  -- Syntax class: word constituent
  32.      "Word constituents" (designated with `w') are parts of normal
  33.      English words and are typically used in variable and command names
  34.      in programs.  All upper and lower case letters and the digits are
  35.      typically word constituents.
  36.  -- Syntax class: symbol constituent
  37.      "Symbol constituents" (designated with `_') are the extra
  38.      characters that are used in variable and command names along with
  39.      word constituents.  For example, the symbol constituents class is
  40.      used in Lisp mode to indicate that certain characters may be part
  41.      of symbol names even though they are not part of English words. 
  42.      These characters are `$&*+-_<>'.  In standard C, the only
  43.      non-word-constituent character that is valid in symbols is
  44.      underscore (`_').
  45.  -- Syntax class: punctuation character
  46.      "Punctuation characters" (`.') are those characters that are used
  47.      as punctuation in English, or are used in some way in a programming
  48.      language to separate symbols from one another.  Most programming
  49.      language modes, including Emacs Lisp mode, have no characters in
  50.      this class since the few characters that are not symbol or word
  51.      constituents all have other uses.
  52.  -- Syntax class: open parenthesis character
  53.  -- Syntax class: close parenthesis character
  54.      Open and close "parenthesis characters" are characters used in
  55.      dissimilar pairs to surround sentences or expressions.  Such a
  56.      grouping is begun with an open parenthesis character and
  57.      terminated with a close. Each open parenthesis character matches a
  58.      particular close parenthesis character, and vice versa.  Normally,
  59.      Emacs indicates momentarily the matching open parenthesis when you
  60.      insert a close parenthesis. *Note Blinking::.
  61.      The class of open parentheses is designated with `(', and that of
  62.      close parentheses with `)'.
  63.      In English text, and in C code, the parenthesis pairs are `()',
  64.      `[]', and `{}'.  In Emacs Lisp, the delimiters for lists and
  65.      vectors (`()' and `[]') are classified as parenthesis characters.
  66.  -- Syntax class: string quote
  67.      "String quote characters" (designated with `"') is used to delimit
  68.      string constants in many languages, including Lisp and C.  The
  69.      same string quote character appears at the beginning and the end
  70.      of a string.  Such quoted strings do not nest.
  71.      The parsing facilities of Emacs consider a string as a single
  72.      token. The usual syntactic meanings of the characters in the
  73.      string are suppressed.
  74.      The Lisp modes have two string quote characters: double-quote (`"')
  75.      and vertical bar (`|').  `|' is not used in Emacs Lisp, but it is
  76.      used in Common Lisp.  C also has two string quote characters:
  77.      double-quote for strings, and single-quote (`'') for character
  78.      constants.
  79.      English text has no string quote characters because English is not
  80.      a programming language.  Although quotation marks are used in
  81.      English, we do not want them to turn off the usual syntactic
  82.      properties of other characters in the quotation.
  83.  -- Syntax class: escape
  84.      An "escape character" (designated with `\') starts an escape
  85.      sequence such as is used in C string and character constants.  The
  86.      character `\' belongs to this class in both C and Lisp.  (In C, it
  87.      is used thus only inside strings, but it turns out to cause no
  88.      trouble to treat it this way throughout C code.)
  89.  -- Syntax class: character quote
  90.      A "character quote character" (designated with `/') quotes the
  91.      following character so that it loses its normal syntactic meaning.
  92.       This differs from an escape character in that only the character
  93.      immediately following is ever affected.
  94.      This class is not currently used in any standard Emacs modes.
  95.  -- Syntax class: paired delimiter
  96.      "Paired delimiter characters" (designated with `$') are like
  97.      string quote characters except that the syntactic properties of the
  98.      characters between the delimiters are not suppressed.  Only TeX
  99.      mode uses a paired identical delimiter presently--the `$' that
  100.      begins and ends math mode.
  101.  -- Syntax class: expression prefix
  102.      An "expression prefix operator" (designated with `'') is used for
  103.      syntactic operators that are part of an expression if they appear
  104.      next to one but are not part of an adjoining symbol.  These
  105.      characters in Lisp include the apostrophe, `'' (used for quoting),
  106.      and the comma, `,' (used in macros).
  107.  -- Syntax class: comment starter
  108.  -- Syntax class: comment ender
  109.      The "comment starter" and "comment ender" characters are used in
  110.      different languages to delimit comments.  These classes are
  111.      designated with `<' and `>', respectively.
  112.      English text has no comment characters.  In Lisp, the semi-colon
  113.      (`;') starts a comment and a newline or formfeed ends one.
  114. File: elisp,  Node: Syntax Flags,  Prev: Syntax Class Table,  Up: Syntax Descriptors
  115. Syntax Flags
  116. ------------
  117.    In addition to the classes, entries for characters in a syntax table
  118. can include flags.  There are four possible flags, represented by the
  119. characters `1', `2', `3', and `4'.  All are used to describe
  120. multi-character comment delimiters.  A flag indicates that the
  121. character for which the entry is being made can *also* be part of a
  122. comment sequence, in addition to the syntactic properties associated
  123. with its character class.  The flags are independent of the class and
  124. each other for the sake of characters such as `*' in C mode, which is a
  125. punctuation character, *and* the second character of a start-of-comment
  126. sequence (`/*'), *and* the first character of an end-of-comment
  127. sequence (`*/').
  128.    The flags for a character C are:
  129.    * `1' means C is the start of a two-character comment start sequence.
  130.    * `2' means C is the second character of such a sequence.
  131.    * `3' means C is the start of a two-character comment end sequence.
  132.    * `4' means C is the second character of such a sequence.
  133. File: elisp,  Node: Syntax Table Functions,  Next: Parsing Expressions,  Prev: Syntax Descriptors,  Up: Syntax Tables
  134. Syntax Table Functions
  135. ======================
  136.    In this section we describe functions for creating, accessing and
  137. altering syntax tables.
  138.  -- Function: make-syntax-table &optional TABLE
  139.      This function constructs a copy of TABLE and returns it.  If TABLE
  140.      is not supplied (or is `nil'), it returns a copy of the current
  141.      syntax table.  Otherwise, an error is signaled if TABLE is not a
  142.      syntax table.
  143.  -- Function: copy-syntax-table &optional TABLE
  144.      This function is identical to `make-syntax-table'.
  145.  -- Command: modify-syntax-entry CHAR SYNTAX-DESCRIPTOR &optional TABLE
  146.      This function sets the syntax entry for CHAR according to
  147.      SYNTAX-DESCRIPTOR.  The syntax is changed only for TABLE, which
  148.      defaults to the current buffer's syntax table, and not in any
  149.      other syntax table.  The argument SYNTAX-DESCRIPTOR specifies the
  150.      desired syntax; this is a string beginning with a class designator
  151.      character, and optionally containing a matching character and
  152.      flags as well.  *Note Syntax Descriptors::.
  153.      This function always returns `nil'.  The old syntax information in
  154.      the table for this character is discarded.
  155.      An error is signaled if the first character of the syntax
  156.      descriptor is not one of the twelve syntax class designator
  157.      characters.  An error is also signaled if CHAR is not a character.
  158.      Examples:
  159.           ;; Put the space character in class whitespace.
  160.           (modify-syntax-entry ?\  " ")
  161.                => nil
  162.           
  163.           ;; Make `$' an open parenthesis character,
  164.           ;; with `^' as its matching close.
  165.           (modify-syntax-entry ?$ "(^")
  166.                => nil
  167.           ;; Make `^' a close parenthesis character,
  168.           ;; with `$' as its matching open.
  169.           (modify-syntax-entry ?^ ")$")
  170.                => nil
  171.           
  172.           ;; Make `/' a punctuation character,
  173.           ;; the first character of a start-comment sequence,
  174.           ;; and the second character of an end-comment sequence.
  175.           ;; This is used in C mode.
  176.           (modify-syntax-entry ?/ ".13")
  177.                => nil
  178.  -- Function: char-syntax CHARACTER
  179.      This function returns the syntax class of CHARACTER, represented
  180.      by its mnemonic designator character.  This *only* returns the
  181.      class, not any matching parenthesis or flags.
  182.      An error is signaled if CHAR is not a character.
  183.      The first example shows that the syntax class of space is
  184.      whitespace (represented by a space).  The second example shows
  185.      that the syntax of `/' is punctuation in C-mode.  This does not
  186.      show the fact that it is also a comment sequence character.  The
  187.      third example shows that open parenthesis is in the class of open
  188.      parentheses.  This does not show the fact that it has a matching
  189.      character, `)'.
  190.           (char-to-string (char-syntax ?\ ))
  191.                => " "
  192.           
  193.           (char-to-string (char-syntax ?/))
  194.                => "."
  195.           
  196.           (char-to-string (char-syntax ?\())
  197.                => "("
  198.  -- Function: set-syntax-table TABLE
  199.      This function makes TABLE the syntax table for the current buffer.
  200.      It returns TABLE.
  201.  -- Function: syntax-table
  202.      This function returns the current syntax table, which is the table
  203.      for the current buffer.
  204.  -- command: describe-syntax
  205.      This function describes the syntax specifications of the current
  206.      syntax table.  It makes a listing in the `*Help*' buffer, and then
  207.      pops up a window to display it.  It returns `nil'.
  208.      A portion of a description is shown here:
  209.           (describe-syntax)
  210.                => nil
  211.           
  212.           ---------- Buffer: *Help* ----------
  213.           C-q             \       which means: escape
  214.           C-r .. C-_              which means: whitespace
  215.           !               .       which means: punctuation
  216.           (               ()      which means: open, matches )
  217.           )               )(      which means: close, matches (
  218.           * .. +          _       which means: symbol
  219.           ,               .       which means: punctuation
  220.           -               _       which means: symbol
  221.           .               .       which means: punctuation
  222.           /               . 13    which means: punctuation,
  223.                     is the first character of a comment-start sequence,
  224.                     is the first character of a comment-end sequence
  225.           0 .. 9          w       which means: word
  226.           ---------- Buffer: *Help* ----------
  227. File: elisp,  Node: Parsing Expressions,  Next: Standard Syntax Tables,  Prev: Syntax Table Functions,  Up: Syntax Tables
  228. Parsing and Moving Over Balanced Expressions
  229. ============================================
  230.    Here are several functions for parsing and scanning balanced
  231. expressions.  The syntax table controls the interpretation of
  232. characters, so these functions can be used for Lisp expressions when in
  233. Lisp mode and for C expressions when in C mode.  *Note List Motion::,
  234. for convenient higher-level functions for moving over balanced
  235. expressions.
  236.  -- Function: parse-partial-sexp START LIMIT &optional TARGET-DEPTH
  237.           STOP-BEFORE STATE
  238.      This function parses an expression in the current buffer starting
  239.      at START, not scanning past LIMIT.  Parsing stops at LIMIT or when
  240.      certain criteria described below are met; point is set to the
  241.      location where parsing stops.  The value returned is a description
  242.      of the status of the parse at the point where it stops.
  243.      Normally, START is assumed to be the top level of an expression to
  244.      be parsed, such as the beginning of a function definition.
  245.      Alternatively, you might wish to resume parsing in the middle of an
  246.      expression.  To do this, you must provide a STATE argument that
  247.      describes the initial status of parsing.  If STATE is omitted (or
  248.      `nil'), parsing assumes that START is the beginning of a new parse
  249.      at level 0.
  250.      If the third argument TARGET-DEPTH is non-`nil', parsing stops if
  251.      the depth in parentheses becomes equal to TARGET-DEPTH. The depth
  252.      starts at 0, or at whatever is given in STATE.
  253.      If the fourth argument STOP-BEFORE is non-`nil', parsing stops
  254.      when it comes to any character that starts a sexp.
  255.      The fifth argument STATE is a seven-element list of the same form
  256.      as the value of this function, described below.  The return value
  257.      of one call may be used to initialize the state of the parse on
  258.      another call to `parse-partial-sexp'.
  259.      The result is a list of seven elements describing the final state
  260.      of the parse:
  261.        1. The depth in parentheses, starting at 0.
  262.        2. The character position of the start of the innermost
  263.           containing parenthetical grouping; `nil' if none.
  264.        3. The character position of the start of the last complete
  265.           subexpression terminated; `nil' if none.
  266.        4. Non-`nil' if inside a string.  (It is the character that will
  267.           terminate the string.)
  268.        5. `t' if inside a comment.
  269.        6. `t' if point is just after a quote character.
  270.        7. The minimum parenthesis depth encountered during this scan.
  271.      Elements 1, 4, 5, and 6 are significant in the argument STATE.
  272.      This function is used to determine how to indent lines in programs
  273.      written in languages that have nested parentheses.
  274.  -- Function: scan-lists FROM COUNT DEPTH
  275.      This function scans forward COUNT balanced parenthetical groupings
  276.      from character number FROM.  It returns the character number of
  277.      the position thus found.
  278.      If DEPTH is nonzero, parenthesis depth counting begins from that
  279.      value.  The only candidates for stopping are places where the
  280.      depth in parentheses becomes zero; `scan-lists' counts COUNT such
  281.      places and then stops.  Thus, a positive value for DEPTH means go
  282.      out levels of parenthesis.
  283.      Comments are ignored if `parse-sexp-ignore-comments' is non-`nil'.
  284.      If the beginning or end of the buffer (or its accessible portion)
  285.      is reached and the depth is not zero, an `end-of-file' error is
  286.      signaled.  If the depth is zero but the count is not used up, `nil'
  287.      is returned.
  288.  -- Function: scan-sexps FROM COUNT
  289.      Scan from character number FROM by COUNT balanced expressions.  It
  290.      returns the character number of the position thus found.
  291.      Comments are ignored if `parse-sexp-ignore-comments' is non-`nil'.
  292.      If the beginning or end of (the accessible part of) the buffer is
  293.      reached in the middle of a parenthetical grouping, an `end-of-file'
  294.      error is signaled.  If the beginning or end is reached between
  295.      groupings but before count is used up, `nil' is returned.
  296.  -- Function: backward-prefix-chars
  297.      This function moves point backward over any number of chars with
  298.      expression prefix syntax.
  299.  -- Variable: parse-sexp-ignore-comments
  300.      If the value is non-`nil', then comments are treated as whitespace
  301.      by the functions in this section and by `forward-sexp'.
  302.      This works only when the comment terminator is something like
  303.      `*/', and appears only to end a comment.  If comments are
  304.      terminated by newlines, you must make this variable `nil', since
  305.      not every newline is the end of a comment.  (In version 19, this
  306.      limitation is removed.)
  307. File: elisp,  Node: Standard Syntax Tables,  Next: Syntax Table Internals,  Prev: Parsing Expressions,  Up: Syntax Tables
  308. Some Standard Syntax Tables
  309. ===========================
  310.    Each of the major modes in Emacs has its own syntax table.  Here are
  311. several of them:
  312.  -- Function: standard-syntax-table
  313.      This function returns the standard syntax table, which is the
  314.      syntax table used in Fundamental mode.
  315.  -- Variable: text-mode-syntax-table
  316.      The value of this variable is the syntax table used in Text mode.
  317.  -- Variable: c-mode-syntax-table
  318.      The value of this variable is the syntax table in use in C-mode
  319.      buffers.
  320.  -- Variable: emacs-lisp-mode-syntax-table
  321.      The value of this variable is the syntax table used in Emacs Lisp
  322.      mode by editing commands.  (It has no effect on the Lisp `read'
  323.      function.)
  324. File: elisp,  Node: Syntax Table Internals,  Prev: Standard Syntax Tables,  Up: Syntax Tables
  325. Syntax Table Internals
  326. ======================
  327.    Each element of a syntax table is an integer that translates into the
  328. full meaning of the entry: class, possible matching character, and
  329. flags.  However, it is not common for a programmer to work with the
  330. entries directly in this form since the Lisp-level syntax table
  331. functions usually work with syntax descriptors (*note Syntax
  332. Descriptors::.).
  333.    The low 8 bits of each element of a syntax table indicates the
  334. syntax class.
  335. Integer
  336.      Class
  337.      whitespace
  338.      punctuation
  339.      word
  340.      symbol
  341.      open parenthesis
  342.      close parenthesis
  343.      expression prefix
  344.      string quote
  345.      paired delimiter
  346.      escape
  347.      character quote
  348.      comment-start
  349.      comment-end
  350.    The next 8 bits are the matching opposite parenthesis (if the
  351. character has parenthesis syntax); otherwise, they are not meaningful.
  352. The next 4 bits are the flags.
  353. File: elisp,  Node: Abbrevs,  Next: Processes,  Prev: Syntax Tables,  Up: Top
  354. Abbrevs And Abbrev Expansion
  355. ****************************
  356.    An abbreviation or "abbrev" is a string of characters that may be
  357. expanded to a longer string.  The user can insert the abbrev string and
  358. find it replaced automatically with the expansion of the abbrev.  This
  359. saves typing.
  360.    The set of abbrevs currently in effect is recorded in an "abbrev
  361. table".  Each buffer has a local abbrev table, but normally all buffers
  362. in the same major mode share one abbrev table.  There is also a global
  363. abbrev table.  Normally both are used.
  364.    An abbrev table is represented as an obarray containing a symbol for
  365. each abbreviation.  The symbol's name is the abbreviation.  Its value is
  366. the expansion; its function definition is the hook; its property list
  367. cell contains the use count, the number of times the abbreviation has
  368. been expanded.  Because these symbols are not inturned in the usual
  369. obarray, they will never appear as the result of reading a Lisp
  370. expression; in fact, they will never be used except by the code that
  371. handles abbrevs.  Therefore, it is safe to use them in an extremely
  372. nonstandard way.  *Note Creating Symbols::.
  373.    For the user-level commands for abbrevs, see *Note Abbrev Mode:
  374. (emacs)Abbrevs.
  375. * Menu:
  376. * Abbrev Mode::                 Setting up Emacs for abbreviation.
  377. * Tables: Abbrev Tables.        Creating and working with abbrev tables.
  378. * Defining Abbrevs::            Specifying abbreviations and their expansions.
  379. * Files: Abbrev Files.          Saving abbrevs in files.
  380. * Expansion: Abbrev Expansion.  Controlling expansion; expansion subroutines.
  381. * Standard Abbrev Tables::      Abbrev tables used by various major modes.
  382. File: elisp,  Node: Abbrev Mode,  Next: Abbrev Tables,  Prev: Abbrevs,  Up: Abbrevs
  383. Setting Up Abbrev Mode
  384. ======================
  385.    Abbrev mode is a minor mode controlled by the value of the variable
  386. `abbrev-mode'.
  387.  -- Variable: abbrev-mode
  388.      A non-`nil' value of this variable turns on the automatic expansion
  389.      of abbrevs when their abbreviations are inserted into a buffer. If
  390.      the value is `nil', abbrevs may be defined, but they are not
  391.      expanded automatically.
  392.      This variable automatically becomes local when set in any fashion.
  393.  -- Variable: default-abbrev-mode
  394.      This is the value `abbrev-mode' for buffers that do not override
  395.      it. This is the same as `(default-value 'abbrev-mode)'.
  396. File: elisp,  Node: Abbrev Tables,  Next: Defining Abbrevs,  Prev: Abbrev Mode,  Up: Abbrevs
  397. Abbrev Tables
  398. =============
  399.    This section describes how to create and manipulate abbrev tables.
  400.  -- Function: make-abbrev-table
  401.      This function creates and returns a new, empty abbrev table--an
  402.      obarray containing no symbols.  It is a vector filled with `nil's.
  403.  -- Function: clear-abbrev-table TABLE
  404.      This function undefines all the abbrevs in abbrev table TABLE,
  405.      leaving it empty.  The function returns `nil'.
  406.  -- Function: define-abbrev-table TABNAME DEFINITIONS
  407.      This function defines TABNAME (a symbol) as an abbrev table name,
  408.      i.e., as a variable whose value is an abbrev table.  It defines
  409.      abbrevs in the table according to DEFINITIONS, a list of elements
  410.      of the form `(ABBREVNAME EXPANSION HOOK USECOUNT)'.  The value is
  411.      always `nil'.
  412.  -- Variable: abbrev-table-name-list
  413.      This is a list of symbols whose values are abbrev tables.
  414.      `define-abbrev-table' adds the new abbrev table name to this list.
  415.  -- Function: insert-abbrev-table-description NAME HUMAN
  416.      This function inserts before point a description of the abbrev
  417.      table named NAME.  The argument NAME is a symbol whose value is an
  418.      abbrev table.  The value is always `nil'.
  419.      If HUMAN is non-`nil', a human-oriented description is inserted. 
  420.      Otherwise the description is a Lisp expression--a call to
  421.      `define-abbrev-table' which would define NAME exactly as it is
  422.      currently defined.
  423. File: elisp,  Node: Defining Abbrevs,  Next: Abbrev Files,  Prev: Abbrev Tables,  Up: Abbrevs
  424. Defining Abbrevs
  425. ================
  426.    These functions define an abbrev in a specified abbrev table.
  427. `define-abbrev' is the low-level basic function, while `add-abbrev' is
  428. used by commands that ask for information from the user.
  429.  -- Function: add-abbrev TABLE TYPE ARG
  430.      This function adds an abbreviation to abbrev table TABLE.  The
  431.      argument TYPE is a string describing in English the kind of abbrev
  432.      this will be (typically, `"global"' or `"mode-specific"'); this is
  433.      used in prompting the user.  The argument ARG is the number of
  434.      words in the expansion.
  435.      The return value is the symbol which internally represents the new
  436.      abbrev, or `nil' if the user declines to redefine an existing
  437.      abbrev.
  438.  -- Function: define-abbrev TABLE NAME EXPANSION HOOK
  439.      This function defines an abbrev in TABLE named NAME, to expand to
  440.      EXPANSION, and call HOOK.  The return value is an uninterned
  441.      symbol which represents the abbrev inside Emacs; its name is NAME.
  442.      The argument NAME should be a string.  The argument EXPANSION
  443.      should be a string, or `nil', to undefine the abbrev.
  444.      The argument HOOK is a function or `nil'.  If HOOK is non-`nil',
  445.      then it is called with no arguments after the abbrev is replaced
  446.      with EXPANSION; point is located at the end of EXPANSION.
  447.      The use count of the abbrev is initialized to zero.
  448.  -- User Option: only-global-abbrevs
  449.      If this variable is non-`nil', it means that the user plans to use
  450.      global abbrevs only.  This tells the commands that define
  451.      mode-specific abbrevs to define global ones instead.  This
  452.      variable does not alter the functioning of the functions in this
  453.      section; it is examined by their callers.
  454. File: elisp,  Node: Abbrev Files,  Next: Abbrev Expansion,  Prev: Defining Abbrevs,  Up: Abbrevs
  455. Saving Abbrevs in Files
  456. =======================
  457.    A file of saved abbrev definitions is actually a file of Lisp code.
  458. The abbrevs are saved in the form of a Lisp program to define the same
  459. abbrev tables with the same contents.  Therefore, you can load the file
  460. with `load' (*note How Programs Do Loading::.).  However, the function
  461. `quietly-read-abbrev-file' is provided as a more convenient interface.
  462.    User-level facilities such as `save-some-buffers' can save abbrevs
  463. in a file automatically, under the control of variables described here.
  464.  -- User Option: abbrev-file-name
  465.      This is the default file name for reading and saving abbrevs.
  466.  -- Function: quietly-read-abbrev-file FILENAME
  467.      This function reads abbrev definitions from a file named FILENAME,
  468.      previously written with `write-abbrev-file'.  If FILENAME is
  469.      `nil', the file specified in `abbrev-file-name' is used.
  470.      `save-abbrevs' is set to `t' so that changes will be saved.
  471.      This function does not display any messages.  It returns `nil'.
  472.  -- User Option: save-abbrevs
  473.      A non-`nil' value for `save-abbrev' means that Emacs should save
  474.      abbrevs when files are saved.  `abbrev-file-name' specifies the
  475.      file to save the abbrevs in.
  476.  -- Variable: abbrevs-changed
  477.      This variable is set non-`nil' by defining or altering any
  478.      abbrevs.  This serves as a flag for various Emacs commands to
  479.      offer to save your abbrevs.
  480.  -- Command: write-abbrev-file FILENAME
  481.      Save all abbrev definitions, in all abbrev tables, in the file
  482.      FILENAME as a Lisp program which will define the same abbrevs when
  483.      loaded.  This function returns `nil'.
  484. File: elisp,  Node: Abbrev Expansion,  Next: Standard Abbrev Tables,  Prev: Abbrev Files,  Up: Abbrevs
  485. Looking Up and Expanding Abbreviations
  486. ======================================
  487.    Abbrevs are usually expanded by commands for interactive use, or
  488. automatically by `self-insert'.  This section describes the subroutines
  489. used in writing such functions, as well as the variables they use for
  490. communication.
  491.  -- Function: abbrev-symbol ABBREV TABLE
  492.      This function returns the symbol representing the abbrev named
  493.      ABBREV.  The value returned is `nil' if that abbrev is not
  494.      defined.  The optional second argument TABLE is the abbrev table
  495.      to look it up in.  By default, this function tries first the
  496.      current buffer's local abbrev table, and second the global abbrev
  497.      table.
  498.  -- User Option: abbrev-all-caps
  499.      When this is set non-`nil', an abbrev entered entirely in upper
  500.      case is expanded using all upper case.  Otherwise, an abbrev
  501.      entered entirely in upper case is expanded by capitalizing each
  502.      word of the expansion.
  503.  -- Function: abbrev-expansion ABBREV &optional TABLE
  504.      This function returns the string that ABBREV would expand into (as
  505.      defined by the abbrev tables used for the current buffer).  The
  506.      optional argument TABLE specifies the abbrev table to use; if it is
  507.      specified, the abbrev is looked up in that table only.
  508.  -- Variable: abbrev-start-location
  509.      This is the buffer position for `expand-abbrev' to use as the start
  510.      of the next abbrev to be expanded.  `nil' means use the word before
  511.      point as the abbrev.  `abbrev-start-location' is set to `nil' each
  512.      time `expand-abbrev' is called.  This variable is set by
  513.      `abbrev-prefix-mark'.
  514.  -- Variable: abbrev-start-location-buffer
  515.      The value of this variable is the buffer for which
  516.      `abbrev-start-location' has been set.  Trying to expand an abbrev
  517.      in any other buffer clears `abbrev-start-location'.  This variable
  518.      is set by `abbrev-prefix-mark'.
  519.  -- Variable: last-abbrev
  520.      This is the `abbrev-symbol' of the last abbrev expanded.  This
  521.      information is left by `expand-abbrev' for the sake of the
  522.      `unexpand-abbrev' command.
  523.  -- Variable: last-abbrev-location
  524.      This is the location of the last abbrev expanded.  This contains
  525.      information left by `expand-abbrev' for the sake of the
  526.      `unexpand-abbrev' command.
  527.  -- Variable: last-abbrev-text
  528.      This is the exact expansion  text of the last abbrev expanded, as
  529.      results from case conversion.  Its value is `nil' if the abbrev
  530.      has already been unexpanded.  This contains information left by
  531.      `expand-abbrev' for the sake of the `unexpand-abbrev' command.
  532. File: elisp,  Node: Standard Abbrev Tables,  Prev: Abbrev Expansion,  Up: Abbrevs
  533. Standard Abbrev Tables
  534. ======================
  535.    Here we list the variables that hold the abbrev tables for the
  536. preloaded major modes of Emacs.
  537.  -- Variable: global-abbrev-table
  538.      This is the abbrev table for mode-independent abbrevs.  The abbrevs
  539.      defined in it apply to all buffers.  Each buffer may also have a
  540.      local abbrev table, whose abbrev definitions take precedence over
  541.      those in the global table.
  542.  -- Variable: local-abbrev-table
  543.      The value of this buffer-local variable is the (mode-specific)
  544.      abbreviation table of the current buffer.
  545.  -- Variable: fundamental-mode-abbrev-table
  546.      This is the local abbrev table used in Fundamental mode.  It is the
  547.      local abbrev table in all buffers in Fundamental mode.
  548.  -- Variable: text-mode-abbrev-table
  549.      This is the local abbrev table used in Text mode.
  550.  -- Variable: c-mode-abbrev-table
  551.      This is the local abbrev table used in C mode.
  552.  -- Variable: lisp-mode-abbrev-table
  553.      This is the local abbrev table used in Lisp mode and Emacs Lisp
  554.      mode.
  555. File: elisp,  Node: Processes,  Next: System Interface,  Prev: Abbrevs,  Up: Top
  556. Processes
  557. *********
  558.    In the terminology of operating systems, a "process" is a space in
  559. which a program can execute.  Emacs runs in a process.  Emacs Lisp
  560. programs can invoke other programs in processes of their own.  These are
  561. called "subprocesses" or "child processes" of the Emacs process, which
  562. is their "parent process".
  563.    A subprocess of Emacs may be "synchronous" or "asynchronous".
  564. depending on how it is created.  When you create a synchronous
  565. subprocess, the Lisp program waits for the subprocess to terminate
  566. before continuing execution.  When you create an asynchronous
  567. subprocess, it can run in parallel with the Lisp program.  This kind of
  568. subprocess is represented within Emacs by a Lisp object which is also
  569. called a "process".  Lisp programs can use this object to communicate
  570. with the subprocess or to control it.  For example, you can send
  571. signals, obtain status information, receive output from the process, or
  572. send input to it.
  573.  -- Function: processp OBJECT
  574.      This function returns `t' if OBJECT is a process, `nil' otherwise.
  575. * Menu:
  576. * Subprocess Creation::      Functions that start subprocesses.
  577. * Synchronous Processes::    Details of using synchronous subprocesses.
  578. * Asynchronous Processes::   Starting up an asynchronous subprocess.
  579. * Deleting Processes::       Eliminating an asynchronous subprocess.
  580. * Process Information::      Accessing run-status and other attributes.
  581. * Input to Processes::       Sending input to an asynchronous subprocess.
  582. * Signals to Processes::     Stopping, continuing or interrupting
  583.                                an asynchronous subprocess.
  584. * Output from Processes::    Collecting output from an asynchronous subprocess.
  585. * Sentinels::                Sentinels run when process run-status changes.
  586. * VMS Subprocesses::         VMS has completely different subprocess features.
  587. * TCP::                      Opening network connections.
  588. File: elisp,  Node: Subprocess Creation,  Next: Synchronous Processes,  Prev: Processes,  Up: Processes
  589. Functions that Create Subprocesses
  590. ==================================
  591.    There are three functions that create a new Unix subprocess in which
  592. to run a program.  One of them, `start-process', creates an
  593. asynchronous process and returns a process object (*note Asynchronous
  594. Processes::.).  The other two, `call-process' and
  595. `call-process-region', create a synchronous process and do not return a
  596. process object (*note Synchronous Processes::.).
  597.    Synchronous and asynchronous processes are explained in following
  598. sections.  Since the three functions are all called in a similar
  599. fashion, their common arguments are described here.
  600.    In all cases, the program to be run is specified with the function's
  601. PROGRAM argument.  An error is signaled if the file is not found or
  602. cannot be executed.  The actual file containing the program is found by
  603. following normal Unix rules: if an absolute file name is given, then
  604. the program must be found in the specified file; if a relative file name
  605. is given, then the directories in `exec-path' are searched sequentially
  606. for a suitable file.  The variable `exec-path' is initialized when
  607. Emacs is started, based on the value of the environment variable
  608. `PATH'.  The standard Unix abbreviations, `~', `.', and `..', are
  609. interpreted as usual, but environment variable substitutions (`$HOME',
  610. etc.) are not recognized; use `substitute-in-file-name' to perform them
  611. (*note File Name Expansion::.).
  612.    Each of the subprocess-creating functions has a BUFFER-OR-NAME
  613. argument which specifies where the standard output from the program will
  614. go.  If BUFFER-OR-NAME is `nil', then the output will be discarded (by
  615. directing it to `/dev/null') unless a filter function is specified to
  616. handle it.  (*Note Filter Functions::, and *Note Streams::.)  Normally,
  617. you should avoid having multiple processes send output to the same
  618. buffer because the outputs will be intermixed randomly.
  619.    All three of the subprocess-creating functions have a `&rest'
  620. argument, ARGS.  The ARGS must all be strings, and they are supplied to
  621. PROGRAM as separate command line arguments.  Wildcard characters and
  622. other shell constructs are not allowed in these strings, since they are
  623. passed directly to the specified program.  *Note:* the argument PROGRAM
  624. contains only the name of the program; it may not contain any
  625. command-line arguments.  Such arguments must be provided via ARGS.
  626.    The subprocess gets its current directory from the value of
  627. `default-directory' (*note File Name Expansion::.).
  628.    The subprocess inherits its environment from Emacs; but you can
  629. specify overrides for it with `process-environment'.
  630.  -- Variable: process-environment
  631.      This variable is a list of strings to append to the environment of
  632.      processes as they are created.  Each string assigns a value to a
  633.      shell environment variable.  (This applies both to asynchronous and
  634.      synchronous processes.)
  635.           process-environment
  636.           => ("l=/usr/stanford/lib/gnuemacs/lisp"
  637.               "PATH=.:/user/lewis/bin:/usr/class:/nfsusr/local/bin"
  638.               "USER=lewis"
  639.               "TERM=ibmapa16"
  640.               "SHELL=/bin/csh"
  641.               "HOME=/user/lewis")
  642.  -- Variable: exec-directory
  643.      The value of this variable is the name of a directory (a string)
  644.      that contains programs that come with GNU Emacs, that are intended
  645.      for Emacs to invoke.  The program `loadst' is an example of such a
  646.      program; it is used by the `display-time' command to print the
  647.      current time (and certain other information) once per minute.
  648.      The default value is the name of a directory whose name ends in
  649.      `etc'.  We call the directory `emacs/etc', since its name usually
  650.      ends that way.  We sometimes refer to "the directory `emacs/etc',"
  651.      when strictly speaking we ought to say, "the directory named by
  652.      the variable `exec-directory'."  Most of the time, there is no
  653.      difference.
  654.  -- User Option: exec-path
  655.      The value of this variable is a list of directories to search for
  656.      programs to run in subprocesses.  Each element is either the name
  657.      of a directory (i.e., a string), or `nil', which stands for the
  658.      default directory (which is the value of `default-directory').
  659.      The value of `exec-path' is used by `call-process' and
  660.      `start-process' when the PROGRAM argument is not an absolute file
  661.      name.
  662. File: elisp,  Node: Synchronous Processes,  Next: Asynchronous Processes,  Prev: Subprocess Creation,  Up: Processes
  663. Creating a Synchronous Process
  664. ==============================
  665.    After a "synchronous process" is created, Emacs waits for the
  666. process to terminate before continuing.  Starting Dired is an example of
  667. this: it runs `ls' in a synchronous process, then modifies the output
  668. slightly.  Because the process is synchronous, the entire directory
  669. listing arrives in the buffer before Emacs tries to do anything with it.
  670.    While Emacs waits for the synchronous subprocess to terminate, the
  671. user can quit by typing `C-g', and the process is killed by sending it
  672. a `SIGKILL' signal.  *Note Quitting::.
  673.    The synchronous subprocess functions return `nil' in version 18. In
  674. version 19, they will return an indication of how the process
  675. terminated.
  676.  -- Function: call-process PROGRAM &optional INFILE BUFFER-OR-NAME
  677.           DISPLAY &rest ARGS
  678.      This function calls PROGRAM in a separate process and waits for it
  679.      to finish.
  680.      The standard input for the process comes from file INFILE if
  681.      INFILE is not `nil' and from `/dev/null' otherwise.  The process
  682.      output gets inserted in buffer BUFFER-OR-NAME before point, if
  683.      that argument names a buffer.  If BUFFER-OR-NAME is `t', output is
  684.      sent to the current buffer; if BUFFER-OR-NAME is `nil', output is
  685.      discarded.
  686.      If BUFFER-OR-NAME is the integer 0, the output is discarded and
  687.      `call-process' returns immediately.  In this case, the process is
  688.      not truly synchronous, since it can run in parallel with Emacs;
  689.      but you can think of it as synchronous in that Emacs is
  690.      essentially finished with the subprocess as soon as this function
  691.      returns.
  692.      If DISPLAY is non-`nil', then `call-process' redisplays the buffer
  693.      as output is inserted.  Otherwise the function does no redisplay,
  694.      and the results become visible on the screen only when Emacs
  695.      redisplays that buffer in the normal course of events.
  696.      The remaining arguments, ARGS, are strings that are supplied as
  697.      the command line arguments for the program.
  698.      The examples below are both run with the buffer `foo' current.
  699.           (call-process "pwd" nil t)
  700.                => nil
  701.           
  702.           ---------- Buffer: foo ----------
  703.           /usr/user/lewis/manual
  704.           ---------- Buffer: foo ----------
  705.           
  706.           (call-process "grep" nil "bar" nil "lewis" "/etc/passwd")
  707.                => nil
  708.           
  709.           ---------- Buffer: bar ----------
  710.           lewis:5LTsHm66CSWKg:398:21:Bil Lewis:/user/lewis:/bin/csh
  711.           
  712.           ---------- Buffer: bar ----------
  713.      The `dired-readin' function contains a good example of the use of
  714.      `call-process':
  715.           (call-process "ls" nil buffer nil dired-listing-switches dirname)
  716.  -- Function: call-process-region START END PROGRAM &optional DELETE
  717.           BUFFER-OR-NAME DISPLAY &rest ARGS
  718.      This function sends the text between START to END as standard
  719.      input to a process running PROGRAM.  It deletes the text sent if
  720.      DELETE is non-`nil', which may be useful when the output is going
  721.      to be inserted back in the current buffer.
  722.      If BUFFER-OR-NAME names a buffer, the output is inserted in that
  723.      buffer at point.  If BUFFER-OR-NAME is `t', the output is sent to
  724.      the current buffer.  If BUFFER-OR-NAME is `nil', the output is
  725.      discarded.  If BUFFER-OR-NAME is the integer 0, the output is
  726.      discarded and `call-process' returns immediately, as in
  727.      `call-process'.
  728.      If DISPLAY is non-`nil', then `call-process-region' redisplays the
  729.      buffer as output is inserted.  Otherwise the function does no
  730.      redisplay, and the results become visible on the screen only when
  731.      Emacs redisplays that buffer in the normal course of events.
  732.      The remaining arguments, ARGS, are strings that are supplied as
  733.      the command line arguments for the program.
  734.      In the following example, we use `call-process-region' to run the
  735.      `cat' utility, with standard input being the first five characters
  736.      in buffer `foo' (the word `input').  `cat' copies its standard
  737.      input into its standard output.  Since the argument BUFFER-OR-NAME
  738.      is `t', this output is inserted in the current buffer.
  739.           ---------- Buffer: foo ----------
  740.           input-!-
  741.           ---------- Buffer: foo ----------
  742.           
  743.           (call-process-region 1 6 "cat" nil t)
  744.                => nil
  745.           
  746.           ---------- Buffer: foo ----------
  747.           inputinput-!-
  748.           ---------- Buffer: foo ----------
  749.      The `shell-command-on-region' command uses `call-process-region'
  750.      like this:
  751.           (call-process-region start end
  752.                                shell-file-name    ; Name of program.
  753.                                nil                ; Do not delete region.
  754.                                buffer             ; Send output to `buffer'.
  755.                                nil                ; No redisplay during output.
  756.                                "-c" command)      ; Arguments for the shell.
  757. File: elisp,  Node: Asynchronous Processes,  Next: Deleting Processes,  Prev: Synchronous Processes,  Up: Processes
  758. Creating an Asynchronous Process
  759. ================================
  760.    After an "asynchronous process" is created, Emacs and the Lisp
  761. program can continue running immediately.  The process may thereafter
  762. run in parallel with Emacs, and the two may communicate with each other
  763. using the functions described in following sections.  Here we describe
  764. how to create an asynchronous process, with `start-process'.
  765.  -- Function: start-process NAME BUFFER-OR-NAME PROGRAM &rest ARGS
  766.      This function creates a new asynchronous subprocess and starts the
  767.      program PROGRAM running in it.  It returns a process object that
  768.      stands for the new subprocess for Emacs Lisp programs.  The
  769.      argument NAME specifies the name for the process object; if a
  770.      process with this name already exists, then NAME is modified (by
  771.      adding `<1>', etc.) to be unique.  The buffer BUFFER-OR-NAME is the
  772.      buffer to associate with the process.
  773.      The remaining arguments, ARGS, are strings that are supplied as
  774.      the command line arguments for the program.
  775.      In the example below, the first process is started and runs
  776.      (rather, sleeps) for 100 seconds.  Meanwhile, the second process
  777.      is started, given the name `my-process<1>' for the sake of
  778.      uniqueness.  It inserts the directory listing at the end of the
  779.      buffer `foo', before the first process finishes.  Then it
  780.      finishes, and a message to that effect is inserted in the buffer. 
  781.      Much later, the first process finishes, and another message is
  782.      inserted in the buffer for it.
  783.           (start-process "my-process" "foo" "sleep" "100")
  784.                => #<process my-process>
  785.           
  786.           (start-process "my-process" "foo" "ls" "-l" "/user/lewis/bin")
  787.                => #<process my-process<1>>
  788.           
  789.           ---------- Buffer: foo ----------
  790.           total 2
  791.           lrwxrwxrwx  1 lewis          14 Jul 22 10:12 gnuemacs --> /emacs
  792.           -rwxrwxrwx  1 lewis          19 Jul 30 21:02 lemon
  793.           
  794.           Process my-process<1> finished
  795.           
  796.           Process my-process finished
  797.           ---------- Buffer: foo ----------
  798.  -- Variable: process-connection-type
  799.      This variable controls the type of device used to communicate with
  800.      asynchronous subprocesses.  If it is `nil', then pipes are used.
  801.      If it is `t', then PTYs are used (or pipes if PTYs not supported).
  802.      PTYs are usually preferable for processes visible to the user, as
  803.      in Shell mode, because they allow job control (`C-c', `C-z', etc.)
  804.      to work between the process and its children whereas pipes do not.
  805.      For subprocesses used for internal purposes by programs, it is
  806.      often better to use a pipe, because they are more efficient.  In
  807.      addition, the total number of PTYs is limited on many systems and
  808.      it is good not to waste them.
  809.      The value `process-connection-type' is used when `start-process'
  810.      is called, so in order to change it for just one call of
  811.      `start-process', temporarily rebind it with `let'.
  812.           (let ((process-connection-type nil))  ; Use a pipe.
  813.             (start-process ...))
  814. File: elisp,  Node: Deleting Processes,  Next: Process Information,  Prev: Asynchronous Processes,  Up: Processes
  815. Deleting Processes
  816. ==================
  817.    "Deleting a process" disconnects Emacs immediately from the
  818. subprocess, and removes it from the list of active processes.  It sends
  819. a signal to the subprocess to make the subprocess terminate, but this is
  820. not guaranteed to happen immediately.  (The process object itself
  821. continues to exist as long as other Lisp objects point to it.)
  822.    You can delete a process explicitly at any time.  Processes are
  823. deleted automatically after they terminate, but not necessarily right
  824. away.  If you delete a terminated process explicitly before it is
  825. deleted automatically, no harm results.
  826.  -- Variable: delete-exited-processes
  827.      This variable controls automatic deletion of processes that have
  828.      terminated (due to calling `exit' or to a signal).  If it is
  829.      `nil', then they continue to exist until the user runs
  830.      `list-processes'.  Otherwise, they are deleted immediately after
  831.      they exit.
  832.  -- Function: delete-process NAME
  833.      This function deletes the process associated with NAME.  The
  834.      argument NAME may be a process, the name of a process, a buffer,
  835.      or the name of a buffer.  The subprocess is killed with a `SIGHUP'
  836.      signal.
  837.           (delete-process "*shell*")
  838.                => nil
  839.  -- Function: process-kill-without-query PROCESS
  840.      This function declares that Emacs need not query the user if
  841.      PROCESS is still running when Emacs is exited.  The process will
  842.      be deleted silently.  The value is `t'.
  843.           (process-kill-without-query (get-process "shell"))
  844.                => t
  845. File: elisp,  Node: Process Information,  Next: Input to Processes,  Prev: Deleting Processes,  Up: Processes
  846. Process Information
  847. ===================
  848.    Several functions return information about processes.
  849. `list-processes' is provided for interactive use.
  850.  -- Command: list-processes
  851.      This command displays a listing of all living processes.  (Any
  852.      processes listed as `Exited' or `Signaled' are actually eliminated
  853.      after the listing is made.)  This function returns `nil'.
  854.  -- Function: process-list
  855.      This function returns a list of all processes that have not been
  856.      deleted.
  857.           (process-list)
  858.                => (#<process display-time> #<process shell>)
  859.  -- Function: get-process NAME
  860.      This function returns the process named NAME, or `nil' if there is
  861.      none.  An error is signaled if NAME is not a string.
  862.           (get-process "shell")
  863.                => #<process shell>
  864.  -- Function: process-command PROCESS
  865.      This function returns the command that was executed to start
  866.      PROCESS.  This is a list of strings, the first string being the
  867.      program executed and the rest of the strings being the arguments
  868.      that were given to the program.
  869.           (process-command (get-process "shell"))
  870.                => ("/bin/csh" "-i")
  871.  -- Function: process-exit-status PROCESS
  872.      This function returns the exit status of PROCESS or the signal
  873.      number that killed it.  If PROCESS has not yet terminated, the
  874.      value is 0.
  875.  -- Function: process-id PROCESS
  876.      This function returns the PID of PROCESS.  This is an integer
  877.      which distinguishes the process PROCESS from all other processes
  878.      running on the same computer at the current time.  The PID of a
  879.      process is chosen by the operating system kernel when the process
  880.      is started and remains constant as long as the process exists.
  881.  -- Function: process-name PROCESS
  882.      This function returns the name of PROCESS.
  883.  -- Function: process-status PROCESS-NAME
  884.      This function returns the status of PROCESS-NAME as a symbol. The
  885.      argument PROCESS-NAME must be either a process or a string. If it
  886.      is a string, it need not name an actual process.
  887.      The possible values for an actual subprocess are:
  888.     `run'
  889.           for a process that is running.
  890.     `stop'
  891.           for a process that is stopped but continuable.
  892.     `exit'
  893.           for a process that has exited.
  894.     `signal'
  895.           for a process that has received a fatal signal.
  896.     `nil'
  897.           if PROCESS-NAME is not the name of an existing process.
  898.           (process-status "shell")
  899.                => run
  900.           (process-status "never-existed")
  901.                => nil
  902.           x
  903.                => #<process xx<1>>
  904.           (process-status x)
  905.                => exit
  906.      For a network stream, `process-status' returns one of the symbols
  907.      `open' or `closed'.  The latter means that the other side closed
  908.      the connection, or Emacs did `delete-process'.
  909.