home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i19 (.txt) < prev    next >
GNU Info File  |  1993-06-14  |  52KB  |  910 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: Case Changes,  Next: Substitution,  Prev: Columns,  Up: Text
  21. Case Changes
  22. ============
  23.    The case change commands described here work on text in the current
  24. buffer.  *Note Character Case::, for case conversion commands that work
  25. on strings and characters.
  26.  -- Command: capitalize-region START END
  27.      This function capitalizes all words in the region defined by START
  28.      and END.  To capitalize means to convert each word's first
  29.      character to upper case and convert the rest of each word to lower
  30.      case.  The function returns `nil'.
  31.      If one end of the region is in the middle of a word, the part of
  32.      the word within the region is treated as an entire word.
  33.      When `capitalize-region' is called interactively, START and END
  34.      are point and the mark, with the smallest first.
  35.           ---------- Buffer: foo ----------
  36.           This is the contents of the 5th foo.
  37.           ---------- Buffer: foo ----------
  38.           
  39.           (capitalize-region 1 44)
  40.           => nil
  41.           
  42.           ---------- Buffer: foo ----------
  43.           This Is The Contents Of The 5th Foo.
  44.           ---------- Buffer: foo ----------
  45.  -- Command: downcase-region START END
  46.      This function converts all of the letters in the region defined by
  47.      START and END to lower case.  The function returns `nil'.
  48.      When `downcase-region' is called interactively, START and END are
  49.      point and the mark, with the smallest first.
  50.  -- Command: upcase-region START END
  51.      This function converts all of the letters in the region defined by
  52.      START and END to upper case.  The function returns `nil'.
  53.      When `upcase-region' is called interactively, START and END are
  54.      point and the mark, with the smallest first.
  55.  -- Command: capitalize-word COUNT
  56.      This function capitalizes COUNT words after point, moving point
  57.      over as it does.  To capitalize means to convert each word's first
  58.      character to upper case and convert the rest of each word to lower
  59.      case. If COUNT is negative, the function capitalizes the -COUNT
  60.      previous words but does not move point.  The value is `nil'.
  61.      If point is in the middle of a word, the part of word the before
  62.      point (if moving forward) or after point (if operating backward)
  63.      is ignored. The rest is treated as an entire word.
  64.      When `capitalize-word' is called interactively, COUNT is set to
  65.      the numeric prefix argument.
  66.  -- Command: downcase-word COUNT
  67.      This function converts the COUNT words after point to all lower
  68.      case, moving point over as it does.  If COUNT is negative, it
  69.      converts the -COUNT previous words but does not move point. The
  70.      value is `nil'.
  71.      When `downcase-word' is called interactively, COUNT is set to the
  72.      numeric prefix argument.
  73.  -- Command: upcase-word COUNT
  74.      This function converts the COUNT words after point to all upper
  75.      case, moving point over as it does.  If COUNT is negative, it
  76.      converts the -COUNT previous words but does not move point. The
  77.      value is `nil'.
  78.      When `upcase-word' is called interactively, COUNT is set to the
  79.      numeric prefix argument.
  80. File: elisp,  Node: Substitution,  Next: Underlining,  Prev: Case Changes,  Up: Text
  81. Substituting for a Character Code
  82. =================================
  83.    The following function replaces characters within a specified region
  84. based on their character code.
  85.  -- Function: subst-char-in-region START END OLD-CHAR NEW-CHAR
  86.           &optional NOUNDO
  87.      This function replaces all occurrences of the character OLD-CHAR
  88.      with the character NEW-CHAR in the region of the current buffer
  89.      defined by START and END.
  90.      If NOUNDO is non-`nil', then `subst-char-in-region' does not
  91.      record the change for undo and does not mark the buffer as
  92.      modified.  This feature is useful for changes which are not
  93.      considered significant, such as when Outline mode changes visible
  94.      lines to invisible lines and vice versa.
  95.      `subst-char-in-region' does not move point and returns `nil'.
  96.           ---------- Buffer: foo ----------
  97.           This is the contents of the buffer before.
  98.           ---------- Buffer: foo ----------
  99.           
  100.           (subst-char-in-region 1 20 ?i ?X)
  101.                => nil
  102.           
  103.           ---------- Buffer: foo ----------
  104.           ThXs Xs the contents of the buffer before.
  105.           ---------- Buffer: foo ----------
  106. File: elisp,  Node: Underlining,  Next: Registers,  Prev: Substitution,  Up: Text
  107. Underlining
  108. ===========
  109.    The underlining commands are somewhat obsolete.  The
  110. `underline-region' function actually inserts `_^H' before each
  111. appropriate character in the region.  This command provides a minimal
  112. text formatting feature that might work on your printer; however, we
  113. recommend instead that you use more powerful text formatting facilities,
  114. such as Texinfo.
  115.  -- Command: underline-region START END
  116.      This function underlines all nonblank characters in the region
  117.      defined by START and END.  That is, an underscore character and a
  118.      backspace character are inserted just before each non-whitespace
  119.      character in the region.  The backspace characters are intended to
  120.      cause overstriking, but in Emacs they display as either `\010' or
  121.      `^H', depending on the setting of `ctl-arrow'.  There is no way to
  122.      see the effect of the overstriking within Emacs.  The value is
  123.      `nil'.
  124.  -- Command: ununderline-region START END
  125.      This function removes all underlining (overstruck underscores) in
  126.      the region defined by START and END.  The value is `nil'.
  127. File: elisp,  Node: Registers,  Prev: Underlining,  Up: Text
  128. Registers
  129. =========
  130.    A register is a sort of variable used in Emacs editing that can hold
  131. a marker, a string, or a rectangle.  Each register is named by a single
  132. character.  All characters, including control and meta characters (but
  133. with the exception of `C-g'), can be used to name registers.  Thus,
  134. there are 255 possible registers.  A register is designated in Emacs
  135. Lisp by a character which is its name.
  136.    The functions in this section return unpredictable values unless
  137. otherwise stated.
  138.  -- Variable: register-alist
  139.      This variable is an alist of elements of the form `(NAME .
  140.      CONTENTS)'.  Normally, there is one element for each Emacs
  141.      register that has been used.
  142.      The object NAME is a character (an integer) identifying the
  143.      register.  The object CONTENTS is a string, marker, or list
  144.      representing the register contents.  A string represents text
  145.      stored in the register.  A marker represents a position.  A list
  146.      represents a rectangle; its elements are strings, one per line of
  147.      the rectangle.
  148.  -- Command: view-register REG
  149.      This command displays what is contained in register REG.
  150.  -- Function: get-register REG
  151.      This function returns the contents of the register REG, or `nil'
  152.      if it has no contents.
  153.  -- Function: set-register REG VALUE
  154.      This function sets the contents of register REG to VALUE. A
  155.      register can be set to any value, but the other register functions
  156.      expect only strings, markers, and lists.
  157.  -- Command: point-to-register REG
  158.      This command stores both the current location of point and the
  159.      current buffer in register REG as a marker.
  160.  -- Command: register-to-point REG
  161.      This command moves point to the position stored in register REG.
  162.      Since both the buffer and the location within the buffer are
  163.      stored by the `point-to-register' function, this command can
  164.      switch you to another buffer.
  165.      If the register does not contain a saved position (a marker), then
  166.      an error is signaled.
  167.  -- Command: insert-register REG &optional BEFOREP
  168.      This command inserts contents of register REG into the current
  169.      buffer.
  170.      Normally, this command puts point before the inserted text, and the
  171.      mark after it.  However, if the optional second argument BEFOREP
  172.      is non-`nil', it puts the mark before and point after. You can
  173.      pass a non-`nil' second argument BEFOREP to this function
  174.      interactively by supplying any prefix argument.
  175.      If the register contains a rectangle, then the rectangle is
  176.      inserted with its upper left corner at point.  This means that
  177.      text is inserted in the current line and underneath it on
  178.      successive lines.
  179.      If the register contains something other than saved text (a
  180.      string) or a rectangle (a list), currently useless things happen. 
  181.      This may be changed in the future.
  182.  -- Command: copy-to-register REG START END &optional DELETE-FLAG
  183.      This command copies the region from START to END into register
  184.      REG.  If DELETE-FLAG is non-`nil', it deletes the region from the
  185.      buffer after copying it into the register.
  186.  -- Command: prepend-to-register REG START END &optional DELETE-FLAG
  187.      This command prepends the region from START to END into register
  188.      REG.  If DELETE-FLAG is non-`nil', it deletes the region from the
  189.      buffer after copying it to the register.
  190.  -- Command: append-to-register REG START END &optional DELETE-FLAG
  191.      This command appends the region from START to END to the text
  192.      already in register REG.  If DELETE-FLAG is non-`nil', it deletes
  193.      the region from the buffer after copying it to the register.
  194.  -- Command: copy-rectangle-to-register REG START END &optional
  195.           DELETE-FLAG
  196.      This command copies a rectangular region from START to END into
  197.      register REG.  If DELETE-FLAG is non-`nil', it deletes the region
  198.      from the buffer after copying it to the register.
  199. File: elisp,  Node: Searching and Matching,  Next: Syntax Tables,  Prev: Text,  Up: Top
  200. Searching and Matching
  201. **********************
  202.    GNU Emacs provides two ways to search through a buffer for specified
  203. text: exact string searches and regular expression searches.  After a
  204. regular expression search, you can identify the text matched by parts of
  205. the regular expression by examining the "match data".
  206. * Menu:
  207. * String Search::         Search for an exact match.
  208. * Regular Expressions::   Describing classes of strings.
  209. * Regexp Search::         Searching for a match for a regexp.
  210. * Match Data::            Finding out which part of the text matched
  211.                             various parts of a regexp, after regexp search.
  212. * Saving Match Data::     Saving and restoring this information.
  213. * Standard Regexps::      Useful regexps for finding sentences, pages,...
  214. * Searching and Case::    Case-independent or case-significant searching.
  215. File: elisp,  Node: String Search,  Next: Regular Expressions,  Prev: Searching and Matching,  Up: Searching and Matching
  216. Searching for Strings
  217. =====================
  218.    These are the primitive functions for searching through the text in a
  219. buffer.  They are meant for use in programs, but you may call them
  220. interactively.  If you do so, they prompt for the search string; LIMIT
  221. and NOERROR are set to `nil', and REPEAT is set to 1.
  222.  -- Command: search-forward STRING &optional LIMIT NOERROR REPEAT
  223.      This function searches forward from point for an exact match for
  224.      STRING.  It sets point to the end of the occurrence found, and
  225.      returns `t'.  If no match is found, the value and side effects
  226.      depend on NOERROR.
  227.      In the following example, point is positioned at the beginning of
  228.      the line.  Then `(search-forward "fox")' is evaluated in the
  229.      minibuffer and point is left after the last letter of `fox':
  230.           ---------- Buffer: foo ----------
  231.           -!-The quick brown fox jumped over the lazy dog.
  232.           ---------- Buffer: foo ----------
  233.           
  234.           (search-forward "fox")
  235.                => t
  236.           
  237.           ---------- Buffer: foo ----------
  238.           The quick brown fox-!- jumped over the lazy dog.
  239.           ---------- Buffer: foo ----------
  240.      If LIMIT is non-`nil', then it is the upper bound to the search. 
  241.      (It must be a position in the current buffer.)  No match extending
  242.      after that position is accepted.
  243.      What happens when the search fails depends on the value of
  244.      NOERROR.  If NOERROR is `nil', a `search-failed' error is
  245.      signaled.  If NOERROR is `t', `search-forward' returns `nil' and
  246.      doesn't signal an error.  If NOERROR is neither `nil' nor `t',
  247.      then `search-forward' moves point to LIMIT and returns `nil'.
  248.      If REPEAT is non-`nil', then the search is repeated that many
  249.      times.  Point is positioned at the end of the last match.
  250.  -- Command: search-backward STRING &optional LIMIT NOERROR REPEAT
  251.      This function searches backward from point for STRING.  It is just
  252.      like `search-forward' except that it searches backwards and leaves
  253.      point at the beginning of the match.
  254.  -- Command: word-search-forward STRING &optional LIMIT NOERROR REPEAT
  255.      This function searches forward from point for a "word" match for
  256.      STRING.  It sets point to the end of the occurrence found, and
  257.      returns `t'.
  258.      A word search differs from a simple string search in that a word
  259.      search *requires* that the words it searches for are present as
  260.      entire words (searching for the word `ball' will not match the word
  261.      `balls'), and punctuation and spacing are ignored (searching for
  262.      `ball boy' will match `ball.  Boy!').
  263.      In this example, point is first placed at the beginning of the
  264.      buffer; the search leaves it between the `y' and the `!'.
  265.           ---------- Buffer: foo ----------
  266.           -!-He said "Please!  Find
  267.           the ball boy!"
  268.           ---------- Buffer: foo ----------
  269.           
  270.           (word-search-forward "Please find the ball, boy.")
  271.                => t
  272.           
  273.           ---------- Buffer: foo ----------
  274.           He said "Please!  Find
  275.           the ball boy-!-!"
  276.           ---------- Buffer: foo ----------
  277.      If LIMIT is non-`nil' (it must be a position in the current
  278.      buffer), then it is the upper bound to the search.  The match
  279.      found must not extend after that position.
  280.      If NOERROR is `t', then `word-search-forward' returns `nil' when a
  281.      search fails, instead of signaling an error.  If NOERROR is
  282.      neither `nil' nor `t', then `word-search-forward' moves point to
  283.      LIMIT and returns `nil'.
  284.      If REPEAT is non-`nil', then the search is repeated that many
  285.      times.  Point is positioned at the end of the last match.
  286.  -- Command: word-search-backward STRING &optional LIMIT NOERROR REPEAT
  287.      This function searches backward from point for a word match to
  288.      STRING.  This function is just like `word-search-forward' except
  289.      that it searches backward and normally leaves point at the
  290.      beginning of the match.
  291. File: elisp,  Node: Regular Expressions,  Next: Regexp Search,  Prev: String Search,  Up: Searching and Matching
  292. Regular Expressions
  293. ===================
  294.    A "regular expression" ("regexp", for short) is a pattern that
  295. denotes a (possibly infinite) set of strings.  Searching for matches for
  296. a regexp is a very powerful operation.  This section explains how to
  297. write regexps; the following section says how to search for them.
  298. * Menu:
  299. * Syntax of Regexps::       Rules for writing regular expressions.
  300. * Regexp Example::          Illustrates regular expression syntax.
  301. File: elisp,  Node: Syntax of Regexps,  Next: Regexp Example,  Prev: Regular Expressions,  Up: Regular Expressions
  302. Syntax of Regular Expressions
  303. -----------------------------
  304.    Regular expressions have a syntax in which a few characters are
  305. special constructs and the rest are "ordinary".  An ordinary character
  306. is a simple regular expression which matches that character and nothing
  307. else. The special characters are `$', `^', `.', `*', `+', `?', `[', `]'
  308. and `\'; no new special characters will be defined in the future.  Any
  309. other character appearing in a regular expression is ordinary, unless a
  310. `\' precedes it.
  311.    For example, `f' is not a special character, so it is ordinary, and
  312. therefore `f' is a regular expression that matches the string `f' and
  313. no other string.  (It does *not* match the string `ff'.)  Likewise, `o'
  314. is a regular expression that matches only `o'.
  315.    Any two regular expressions A and B can be concatenated.  The result
  316. is a regular expression which matches a string if A matches some amount
  317. of the beginning of that string and B matches the rest of the string.
  318.    As a simple example, we can concatenate the regular expressions `f'
  319. and `o' to get the regular expression `fo', which matches only the
  320. string `fo'.  Still trivial.  To do something more powerful, you need
  321. to use one of the special characters.  Here is a list of them:
  322. `. (Period)'
  323.      is a special character that matches any single character except a
  324.      newline. Using concatenation, we can make regular expressions like
  325.      `a.b' which matches any three-character string which begins with
  326.      `a' and ends with `b'.
  327.      is not a construct by itself; it is a suffix that means the
  328.      preceding regular expression is to be repeated as many times as
  329.      possible.  In `fo*', the `*' applies to the `o', so `fo*' matches
  330.      one `f' followed by any number of `o's.  The case of zero `o's is
  331.      allowed: `fo*' does match `f'.
  332.      `*' always applies to the *smallest* possible preceding
  333.      expression.  Thus, `fo*' has a repeating `o', not a repeating `fo'.
  334.      The matcher processes a `*' construct by matching, immediately, as
  335.      many repetitions as can be found.  Then it continues with the rest
  336.      of the pattern.  If that fails, backtracking occurs, discarding
  337.      some of the matches of the `*'-modified construct in case that
  338.      makes it possible to match the rest of the pattern.  For example,
  339.      matching `ca*ar' against the string `caaar', the `a*' first tries
  340.      to match all three `a's; but the rest of the pattern is `ar' and
  341.      there is only `r' left to match, so this try fails. The next
  342.      alternative is for `a*' to match only two `a's. With this choice,
  343.      the rest of the regexp matches successfully.
  344.      is a suffix character similar to `*' except that it must match the
  345.      preceding expression at least once.  So, for example, `ca+r' will
  346.      match the strings `car' and `caaaar' but not the string `cr',
  347.      whereas `ca*r' would match all three strings.
  348.      is a suffix character similar to `*' except that it can match the
  349.      preceding expression either once or not at all.  For example,
  350.      `ca?r' will match `car' or `cr'; nothing else.
  351. `[ ... ]'
  352.      `[' begins a "character set", which is terminated by a `]'.  In
  353.      the simplest case, the characters between the two form the set. 
  354.      Thus, `[ad]' matches either one `a' or one `d', and `[ad]*'
  355.      matches any string composed of just `a's and `d's (including the
  356.      empty string), from which it follows that `c[ad]*r' matches `cr',
  357.      `car', `cdr', `caddaar', etc.
  358.      Character ranges can also be included in a character set, by
  359.      writing two characters with a `-' between them.  Thus, `[a-z]'
  360.      matches any lower case letter.  Ranges may be intermixed freely
  361.      with individual characters, as in `[a-z$%.]', which matches any
  362.      lower case letter or `$', `%' or a period.
  363.      Note that the usual special characters are not special any more
  364.      inside a character set.  A completely different set of special
  365.      characters exists inside character sets: `]', `-' and `^'.
  366.      To include a `]' in a character set, make it the first character.
  367.      For example, `[]a]' matches `]' or `a'.  To include a `-', write
  368.      `---', which is a range containing only `-', or write `-' as the
  369.      first character in the range.
  370.      To include `^', make it other than the first character in the set.
  371. `[^ ... ]'
  372.      `[^' begins a "complement character set", which matches any
  373.      character except the ones specified.  Thus, `[^a-z0-9A-Z]' matches
  374.      all characters *except* letters and digits.
  375.      `^' is not special in a character set unless it is the first
  376.      character.  The character following the `^' is treated as if it
  377.      were first (thus, `-' and `]' are not special there).
  378.      Note that a complement character set can match a newline, unless
  379.      newline is mentioned as one of the characters not to match.
  380.      is a special character that matches the empty string, but only at
  381.      the beginning of a line in the text being matched.  Otherwise it
  382.      fails to match anything.  Thus, `^foo' matches a `foo' which occurs
  383.      at the beginning of a line.
  384.      When matching a string, `^' matches at the beginning of the string
  385.      or after a newline character `\n'.
  386.      is similar to `^' but matches only at the end of a line.  Thus,
  387.      `x+$' matches a string of one `x' or more at the end of a line.
  388.      When matching a string, `$' matches at the end of the string or
  389.      before a newline character `\n'.
  390.      has two functions: it quotes the special characters (including
  391.      `\'), and it introduces additional special constructs.
  392.      Because `\' quotes special characters, `\$' is a regular
  393.      expression which matches only `$', and `\[' is a regular
  394.      expression which matches only `[', and so on.
  395.      Note that `\' also has special meaning in the read syntax of Lisp
  396.      strings (*note String Type::.), and must be quoted with `\'.  For
  397.      example, the regular expression that matches the `\' character is
  398.      `\\'.  To write a Lisp string that contains `\\', Lisp syntax
  399.      requires you to quote each `\' with another `\'.  Therefore, the
  400.      read syntax for this string is `"\\\\"'.
  401.    *Note:* for historical compatibility, special characters are treated
  402. as ordinary ones if they are in contexts where their special meanings
  403. make no sense.  For example, `*foo' treats `*' as ordinary since there
  404. is no preceding expression on which the `*' can act.  It is poor
  405. practice to depend on this behavior; better to quote the special
  406. character anyway, regardless of where it appears.
  407.    For the most part, `\' followed by any character matches only that
  408. character.  However, there are several exceptions: characters which,
  409. when preceded by `\', are special constructs.  Such characters are
  410. always ordinary when encountered on their own.  Here is a table of `\'
  411. constructs:
  412.      specifies an alternative. Two regular expressions A and B with
  413.      `\|' in between form an expression that matches anything that
  414.      either A or B matches.
  415.      Thus, `foo\|bar' matches either `foo' or `bar' but no other string.
  416.      `\|' applies to the largest possible surrounding expressions. 
  417.      Only a surrounding `\( ... \)' grouping can limit the grouping
  418.      power of `\|'.
  419.      Full backtracking capability exists to handle multiple uses of
  420.      `\|'.
  421. `\( ... \)'
  422.      is a grouping construct that serves three purposes:
  423.        1. To enclose a set of `\|' alternatives for other operations.
  424.           Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
  425.        2. To enclose a complicated expression for a suffix character
  426.           such as `*' to operate on.  Thus, `ba\(na\)*' matches
  427.           `bananana', etc., with any (zero or more) number of `na'
  428.           strings.
  429.        3. To record a matched substring for future reference.
  430.      This last application is not a consequence of the idea of a
  431.      parenthetical grouping; it is a separate feature which happens to
  432.      be assigned as a second meaning to the same `\( ... \)' construct
  433.      because there is no conflict in practice between the two meanings.
  434.      Here is an explanation of this feature:
  435. `\DIGIT'
  436.      after the end of a `\( ... \)' construct, the matcher remembers the
  437.      beginning and end of the text matched by that construct.  Then,
  438.      later on in the regular expression, you can use `\' followed by
  439.      DIGIT to mean "match the same text matched the DIGITth time by the
  440.      `\( ... \)' construct."
  441.      The strings matching the first nine `\( ... \)' constructs
  442.      appearing in a regular expression are assigned numbers 1 through 9
  443.      in the order that the open parentheses appear in the regular
  444.      expression. `\1' through `\9' can be used to refer to the text
  445.      matched by the corresponding `\( ... \)' construct.
  446.      For example, `\(.*\)\1' matches any newline-free string that is
  447.      composed of two identical halves.  The `\(.*\)' matches the first
  448.      half, which may be anything, but the `\1' that follows must match
  449.      the same exact text.
  450.      matches the empty string, provided it is at the beginning of the
  451.      buffer.
  452.      matches the empty string, provided it is at the end of the buffer.
  453.      matches the empty string, provided it is at the beginning or end
  454.      of a word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a
  455.      separate word.  `\bballs?\b' matches `ball' or `balls' as a
  456.      separate word.
  457.      matches the empty string, provided it is *not* at the beginning or
  458.      end of a word.
  459.      matches the empty string, provided it is at the beginning of a
  460.      word.
  461.      matches the empty string, provided it is at the end of a word.
  462.      matches any word-constituent character.  The editor syntax table
  463.      determines which characters these are.  *Note Syntax Tables::.
  464.      matches any character that is not a word-constituent.
  465. `\sCODE'
  466.      matches any character whose syntax is CODE.  Here CODE is a
  467.      character which represents a syntax code: thus, `w' for word
  468.      constituent, `-' for whitespace, `(' for open parenthesis, etc. 
  469.      *Note Syntax Tables::, for a list of the codes.
  470. `\SCODE'
  471.      matches any character whose syntax is not CODE.
  472.    Not every string is a valid regular expression.  For example, any
  473. string with unbalanced square brackets is invalid, and so is a string
  474. that ends with a single `\'.  If an invalid regular expression is
  475. passed to any of the search functions, an `invalid-regexp' error is
  476. signaled.
  477.  -- Function: regexp-quote STRING
  478.      This function returns a regular expression string which matches
  479.      exactly STRING and nothing else.  This allows you to request an
  480.      exact string match when calling a function that wants a regular
  481.      expression.
  482.           (regexp-quote "^The cat$")
  483.                => "\\^The cat\\$"
  484.      One use of `regexp-quote' is to combine an exact string match with
  485.      context described as a regular expression.  For example, this
  486.      searches for the string which is the value of `string', surrounded
  487.      by whitespace:
  488.           (re-search-forward (concat "\\s " (regexp-quote string) "\\s "))
  489. File: elisp,  Node: Regexp Example,  Prev: Syntax of Regexps,  Up: Regular Expressions
  490. Complex Regexp Example
  491. ----------------------
  492.    Here is a complicated regexp, used by Emacs to recognize the end of a
  493. sentence together with any whitespace that follows.  It is the value of
  494. the variable `sentence-end'.
  495.    First, we show the regexp as a string in Lisp syntax to enable you to
  496. distinguish the spaces from the tab characters.  The string constant
  497. begins and ends with a double-quote.  `\"' stands for a double-quote as
  498. part of the string, `\\' for a backslash as part of the string, `\t'
  499. for a tab and `\n' for a newline.
  500.      "[.?!][]\"')}]*\\($\\|\t\\|  \\)[ \t\n]*"
  501.    In contrast, if you evaluate the variable `sentence-end', you will
  502. see the following:
  503.      sentence-end
  504.      =>
  505.      "[.?!][]\"')}]*\\($\\|  \\|  \\)[
  506.      ]*"
  507. In this case, the tab and carriage return are the actual characters.
  508.    This regular expression contains four parts in succession and can be
  509. deciphered as follows:
  510. `[.?!]'
  511.      The first part of the pattern consists of three characters, a
  512.      period, a question mark and an exclamation mark, within square
  513.      brackets.  The match must begin with one of these three characters.
  514. `[]\"')}]*'
  515.      The second part of the pattern matches any closing braces and
  516.      quotation marks, zero or more of them, that may follow the period,
  517.      question mark or exclamation mark.  The `\"' is Lisp syntax for a
  518.      double-quote in a string.  The `*' at the end indicates that the
  519.      immediately preceding regular expression (a character set, in this
  520.      case) may be repeated zero or more times.
  521. `\\($\\|\t\\|  \\)'
  522.      The third part of the pattern matches the whitespace that follows
  523.      the end of a sentence: the end of a line, or a tab, or two spaces.
  524.       The double backslashes are needed to prevent Emacs from reading
  525.      the parentheses and vertical bars as part of the search pattern;
  526.      the parentheses are used to mark the group and the vertical bars
  527.      are used to indicated that the patterns to either side of them are
  528.      alternatives. The dollar sign is used to match the end of a line. 
  529.      The tab character is written using `\t' and the two spaces are
  530.      written as themselves.
  531. `[ \t\n]*'
  532.      Finally, the last part of the pattern indicates that the end of
  533.      the line or the whitespace following the period, question mark or
  534.      exclamation mark may, but need not, be followed by additional
  535.      whitespace.
  536. File: elisp,  Node: Regexp Search,  Next: Match Data,  Prev: Regular Expressions,  Up: Searching and Matching
  537. Regular Expression Searching
  538. ============================
  539.    In GNU Emacs, you can search for the next match for a regexp either
  540. incrementally or not.  Incremental search commands are described in the
  541. `The GNU Emacs Manual'.  *Note Regular Expression Search: (emacs)Regexp
  542. Search.  Here we describe only the search functions useful in programs.
  543.  The principal is `re-search-forward'.
  544.  -- Command: re-search-forward REGEXP &optional LIMIT NOERROR REPEAT
  545.      This function searches forward in the current buffer for a string
  546.      of text that is matched by the regular expression REGEXP.  The
  547.      function skips over any amount of text that is not matched by
  548.      REGEXP, and leaves point at the end of the first string found that
  549.      does match.
  550.      If the search is successful (i.e., if text matching REGEXP is
  551.      found), then point is left at the end of that text, and the
  552.      function returns `t'.
  553.      What happens when the search fails depends on the value of
  554.      NOERROR.  If NOERROR is `nil', a `search-failed' error is
  555.      signaled.  If NOERROR is `t', `re-search-forward' returns `nil'
  556.      and doesn't signal an error. If NOERROR is neither `nil' nor `t',
  557.      then `search-forward' moves point to LIMIT and returns `nil'.
  558.      If LIMIT is non-`nil' (it must be a position in the current
  559.      buffer), then it is the upper bound to the search.  No match
  560.      extending after that position is accepted.
  561.      If REPEAT is supplied (it must be a positive number), then the
  562.      search is repeated that many times (each time starting at the end
  563.      of the previous time's match).  The call succeeds if all these
  564.      searches succeeded, and point is left at the end of the match
  565.      found by the last search.  Otherwise the search fails.
  566.      In the following example, point is initially located directly
  567.      before the `T'.  After evaluating the form, point is located at
  568.      the end of that line (between the `t' of `hat' and before the
  569.      newline).
  570.           ---------- Buffer: foo ----------
  571.           I read "-!-The cat in the hat
  572.           comes back" twice.
  573.           ---------- Buffer: foo ----------
  574.           
  575.           (re-search-forward "[a-z]+" nil t 5)
  576.                => t
  577.           
  578.           ---------- Buffer: foo ----------
  579.           I read "The cat in the hat-!-
  580.           comes back" twice.
  581.           ---------- Buffer: foo ----------
  582.  -- Command: re-search-backward REGEXP &optional LIMIT NOERROR REPEAT
  583.      This function searches backward in the current buffer for a string
  584.      of text that is matched by the regular expression REGEXP, leaving
  585.      point at the beginning of the first text found.
  586.      This function is analogous to `re-search-forward', but they are
  587.      not simple mirror images.  `re-search-forward' finds the match
  588.      whose beginning is as close as possible.  If `re-search-backward'
  589.      were a perfect mirror image, it would find the match whose end is
  590.      as close as possible.  However, in fact it finds the match whose
  591.      beginning is as close as possible.  The reason is that matching a
  592.      regular expression at a given spot always works from beginning to
  593.      end, and is done at a specified beginning position.  Thus, true
  594.      mirror-image behavior would require a special feature for matching
  595.      regexps from end to beginning.
  596.  -- Function: string-match REGEXP STRING &optional START
  597.      This function returns the index of the start of the first match for
  598.      the regular expression REGEXP in STRING, or `nil' if there is no
  599.      match.  If START is non-`nil', the search starts at that index in
  600.      STRING.
  601.      For example,
  602.           (string-match "quick" "The quick brown fox jumped quickly.")
  603.                => 4
  604.           (string-match "quick" "The quick brown fox jumped quickly." 8)
  605.                => 27
  606.      The index of the first character of the string is 0, the index of
  607.      the second character is 1, and so on.
  608.      After this function returns, the index of the first character
  609.      beyond the match is available as `(match-end 0)'.  *Note Match
  610.      Data::.
  611.           (string-match "quick" "The quick brown fox jumped quickly." 8)
  612.                => 27
  613.           
  614.           (match-end 0)
  615.                => 32
  616.      The `match-end' function is described along with
  617.      `match-beginning'; see *Note Match Data::.
  618.  -- Function: looking-at REGEXP
  619.      This function determines whether the text in the current buffer
  620.      directly following point matches the regular expression REGEXP. 
  621.      "Directly following" means precisely that: the search is
  622.      "anchored" and it must succeed starting with the first character
  623.      following point.  The result is `t' if so, `nil' otherwise.
  624.      Point is not moved, but the match data is updated and can be used
  625.      with `match-beginning' or `match-end'.  *Note Match Data::.
  626.      In this example, point is located directly before the `T'.  If it
  627.      were anywhere else, the result would be `nil'.
  628.           ---------- Buffer: foo ----------
  629.           I read "-!-The cat in the hat
  630.           comes back" twice.
  631.           ---------- Buffer: foo ----------
  632.           (looking-at "The cat in the hat$")
  633.                => t
  634. File: elisp,  Node: Match Data,  Next: Saving Match Data,  Prev: Regexp Search,  Up: Searching and Matching
  635. The Match Data
  636. ==============
  637.    Emacs keeps track of the positions of the start and end of segments
  638. of text found during a regular expression search.  This means, for
  639. example, that you can search for a complex pattern, such as a date in
  640. an Rmail message, and extract parts of it.
  641.  -- Function: match-beginning COUNT
  642.      This function returns the position of the start of text matched by
  643.      the last regular expression searched for.  COUNT, a number,
  644.      specifies a subexpression whose start position is the value.  If
  645.      COUNT is zero, then the value is the position of the text matched
  646.      by the whole regexp.  If COUNT is greater than zero, then the
  647.      value is the position of the beginning of the text matched by the
  648.      COUNTth subexpression, regardless of whether it was used in the
  649.      final match.
  650.      Subexpressions of a regular expression are those expressions
  651.      grouped inside of parentheses, `\(...\)'.  The COUNTth
  652.      subexpression is found by counting occurrences of `\(' from the
  653.      beginning of the whole regular expression.  The first
  654.      subexpression is numbered 1, the second 2, and so on.
  655.      The `match-end' function is similar to the `match-beginning'
  656.      function except that it returns the position of the end of the
  657.      matched text.
  658.      Here is an example, with a comment showing the numbers of the
  659.      positions in the text:
  660.           (string-match "\\(qu\\)\\(ick\\)" "The quick fox jumped quickly.")
  661.                => 4                         ;^^^^^^^^^^
  662.                                             ;0123456789
  663.           
  664.           (match-beginning 1)               ; The beginning of the match
  665.                => 4                         ; with `qu' is at index 4.
  666.           
  667.           (match-beginning 2)               ; The beginning of the match
  668.                => 6                         ; with `ick' is at index 6.
  669.           
  670.           (match-end 1)                     ; The end of the match
  671.                => 6                         ; with `qu' is at index 6.
  672.           
  673.           (match-end 2)                     ; The end of the match
  674.                => 9                         ; with `ick' is at index 9.
  675.      Here is another example.  Before the form is evaluated, point is
  676.      located at the beginning of the line.  After evaluating the search
  677.      form, point is located on the line between the space and the word
  678.      `in'.  The beginning of the entire match is at the 9th character
  679.      of the buffer (`T'), and the beginning of the match for the first
  680.      subexpression is at the 13th character (`c').
  681.           (list
  682.             (re-search-forward "The \\(cat \\)")
  683.             (match-beginning 0)
  684.             (match-beginning 1))
  685.           => (t 9 13)
  686.           
  687.           ---------- Buffer: foo ----------
  688.           I read "The cat -!-in the hat comes back" twice.
  689.                   ^   ^
  690.                   9  13
  691.           ---------- Buffer: foo ----------
  692.      (Note that in this case, the index returned is a buffer position;
  693.      the first character of the buffer counts as 1.)
  694.      It is essential that `match-beginning' be called after the search
  695.      desired, but before any other searches are performed.
  696.      `match-beginning' may not give the desired results if any other
  697.      Lisp programs are executed between the search and it, since they
  698.      may do other searches.  This example shows misuse of
  699.      `match-beginning'.
  700.           (re-search-forward "The \\(cat \\)")
  701.                => t
  702.           (foo)                   ; Perhaps `foo' does more regexp searching.
  703.           (match-beginning 0)
  704.                => 61              ; Unexpected result!
  705.      See the discussion of `store-match-data' for an example of how to
  706.      save and restore the match data around a search.
  707.  -- Function: match-end COUNT
  708.      This function returns the position of the end of text matched by
  709.      the last regular expression searched for.  This function is
  710.      otherwise similar to `match-beginning'.
  711.  -- Function: replace-match REPLACEMENT &optional FIXEDCASE LITERAL
  712.      This function replaces the text matched by the last search with
  713.      REPLACEMENT.
  714.      If FIXEDCASE is non-`nil', then the case of the replacement text
  715.      is not changed; otherwise, the replacement text is converted to a
  716.      different case depending upon the capitalization of the text to be
  717.      replaced.  If the original text is all upper case, the replacement
  718.      text is converted to upper case, except when all of the words in
  719.      the original text are only one character long.  In that event, the
  720.      replacement text is capitalized.  If *all* of the words in the
  721.      original text are capitalized, then all of the words in the
  722.      replacement text are capitalized.
  723.      If LITERAL is non-`nil', then REPLACEMENT is inserted exactly as
  724.      it is, the only alterations being case changes as needed. If it is
  725.      `nil' (the default), then the character `\' is treated specially. 
  726.      If a `\' appears in REPLACEMENT, then it must be part of one of
  727.      the following sequences:
  728.     `\&'
  729.           `\&' stands for the entire text being replaced.
  730.     `\N'
  731.           `\N' stands for the Nth subexpression in the original regexp.
  732.            Subexpressions are those expressions grouped inside of
  733.           `\(...\)'.  N is a digit.
  734.     `\\'
  735.           `\\' stands for a single `\' in the replacement text.
  736.      `replace-match' leaves point at the end of the replacement text,
  737.      and returns `t'.
  738. File: elisp,  Node: Saving Match Data,  Next: Standard Regexps,  Prev: Match Data,  Up: Searching and Matching
  739. Saving and Restoring the Match Data
  740. ===================================
  741.  -- Function: match-data
  742.      This function returns a new list containing all the information on
  743.      what text the last search matched.  Element zero is the position
  744.      of the beginning of the match for the whole expression; element
  745.      one is the position of the end of the match for the expression. 
  746.      The next two elements are the positions of the beginning and end
  747.      of the match for the first subexpression.  In general, element
  748.      number 2N corresponds to `(match-beginning N)'; and element number
  749.      2N + 1 corresponds to `(match-end N)'.
  750.      All the elements are markers, or the integer 0 for a match at the
  751.      beginning of a string (with `string-match'), or `nil' if there was
  752.      no match for that subexpression.  As with other functions that get
  753.      information about a search, there must be no possibility of
  754.      intervening searches between the call to a search function and the
  755.      call to `match-data' that is intended to save the match-data for
  756.      that search.
  757.           (match-data)
  758.                =>  (#<marker at 9 in foo> #<marker at 17 in foo>
  759.                     #<marker at 13 in foo> #<marker at 17 in foo>)
  760.      In version 19, all elements will be markers or `nil' if matching
  761.      was done on a buffer, and all will be integers or `nil' if matching
  762.      was done on a string with `string-match'.
  763.  -- Function: store-match-data MATCH-LIST
  764.      This function sets the match data within Emacs Lisp from the
  765.      elements of MATCH-LIST, which should be a list created by a
  766.      previous call to `match-data'.
  767.      `store-match-data' may be used together with `match-data' to
  768.      perform a search without changing the `match-data'.  This is useful
  769.      when such searches occur in subroutines whose callers may not
  770.      expect searches to go on.  Here is how:
  771.           (let ((data (match-data)))
  772.             (unwind-protect
  773.                 ... ; May change the original match data.
  774.               (store-match-data data)))
  775.      All asynchronous process functions (filters and sentinels) and some
  776.      modes that use `recursive-edit' should save and restore the match
  777.      data if they do a search or if they let the user type arbitrary
  778.      commands.
  779.      Here is a function which will restore the match data if the buffer
  780.      associated with it still exists.
  781.           (defun restore-match-data (data)
  782.             "Restore the match data DATA unless the buffer is missing."
  783.             (catch 'foo
  784.               (let ((d data))
  785.                 (while d
  786.                   (and (car d)
  787.                        (null (marker-buffer (car d)))
  788.                        ;; match-data buffer is deleted.
  789.                        (throw 'foo nil))
  790.                   (setq d (cdr d)))
  791.                 (store-match-data data))))
  792. File: elisp,  Node: Standard Regexps,  Next: Searching and Case,  Prev: Saving Match Data,  Up: Searching and Matching
  793. Standard Regular Expressions Used in Editing
  794. ============================================
  795.  -- Variable: page-delimiter
  796.      This is the regexp describing line-beginnings that separate pages.
  797.       The default value is `"^\014"' (i.e., `"^^L"' or `"^\C-l"').
  798.  -- Variable: paragraph-separate
  799.      This is the regular expression for recognizing the beginning of a
  800.      line that separates paragraphs.  (If you change this, you may have
  801.      to change `paragraph-start' also.)  The default value is `"^[
  802.      \t\f]*$"', which is a line that consists entirely of spaces, tabs,
  803.      and form feeds.
  804.  -- Variable: paragraph-start
  805.      This is the regular expression for recognizing the beginning of a
  806.      line that starts *or* separates paragraphs.  The default value is
  807.      `"^[ \t\n\f]"', which matches a line starting with a space, tab,
  808.      newline, or form feed.
  809.  -- Variable: sentence-end
  810.      This is the regular expression describing the end of a sentence. 
  811.      (All paragraph boundaries also end sentences, regardless.)  The
  812.      default value is:
  813.           "[.?!][]\"')}]*\\($\\|\t\\| \\)[ \t\n]*"
  814.      This means a period, question mark or exclamation mark, followed
  815.      by a closing brace, followed by tabs, spaces or new lines.
  816.      For a detailed explanation of this regular expression, see *Note
  817.      Regexp Example::.
  818. File: elisp,  Node: Searching and Case,  Prev: Standard Regexps,  Up: Searching and Matching
  819. Searching and Case
  820. ==================
  821.    By default, searches in Emacs ignore the case of the text they are
  822. searching through; if you specify searching for `FOO', then `Foo' or
  823. `foo' is also considered a match.  Regexps, and in particular character
  824. sets, are included: thus, `[aB]' would match `a' or `A' or `b' or `B'.
  825.    If you do not want this feature, set the variable `case-fold-search'
  826. to `nil'.  Then all letters must match exactly, including case.  This
  827. is a per-buffer-local variable; altering the variable affects only the
  828. current buffer.  (*Note Intro to Buffer-Local::.)  Alternatively, you
  829. may change the value of `default-case-fold-search', which is the
  830. default value of `case-fold-search' for buffers that do not override it.
  831.  -- User Option: case-replace
  832.      This variable determines whether `query-replace' should preserve
  833.      case in replacements.  If the variable is `nil', then case need
  834.      not be preserved.
  835.  -- User Option: case-fold-search
  836.      This buffer-local variable determines whether searches should
  837.      ignore case.  If the variable is `nil' they do not ignore case;
  838.      otherwise they do ignore case.
  839.  -- Variable: default-case-fold-search
  840.      The value of this variable is the default value for
  841.      `case-fold-search' in buffers that do not override it.  This is the
  842.      same as `(default-value 'case-fold-search)'.
  843. File: elisp,  Node: Syntax Tables,  Next: Abbrevs,  Prev: Searching and Matching,  Up: Top
  844. Syntax Tables
  845. *************
  846.    A "syntax table" provides Emacs with the information that determines
  847. the syntactic use of each character in a buffer.  This information is
  848. used by the parsing commands, the complex movement commands, and others
  849. to determine where words, symbols, and other syntactic constructs begin
  850. and end.
  851.    A syntax table is a vector of 256 elements; it contains one entry for
  852. each of the 256 ASCII characters of an 8-bit byte.  Each element is an
  853. integer that encodes the syntax of the character in question.
  854.    Syntax tables are used only for moving across text, not for the GNU
  855. Emacs Lisp reader.  GNU Emacs Lisp uses built-in syntactic rules when
  856. reading Lisp expressions, and these rules cannot be changed.
  857.    Each buffer has its own major mode, and each major mode has its own
  858. idea of the syntactic class of various characters.  For example, in Lisp
  859. mode, the character `;' begins a comment, but in C mode, it terminates
  860. a statement.  To support these variations, Emacs makes the choice of
  861. syntax table local to the each buffer.  Typically, each major mode has
  862. its own syntax table and installs that table in each buffer which uses
  863. that mode.  Changing this table alters the syntax in all those buffers
  864. as well as in any buffers subsequently put in that mode. Occasionally
  865. several similar modes share one syntax table. *Note Example Major
  866. Modes::, for an example of how to set up a syntax table.
  867.  -- Function: syntax-table-p OBJECT
  868.      This function returns `t' if OBJECT is a vector of length 256
  869.      elements.  This means that the vector may be a syntax table.
  870.      However, according to this test, any vector of length 256 is
  871.      considered to be a syntax table, no matter what its contents.
  872. * Menu:
  873. * Syntax Descriptors::       How characters are classified.
  874. * Syntax Table Functions::   How to create, examine and alter syntax tables.
  875. * Parsing Expressions::      Parsing balanced expressions
  876.                                 using the syntax table.
  877. * Standard Syntax Tables::   Syntax tables used by various major modes.
  878. * Syntax Table Internals::   How syntax table information is stored.
  879. File: elisp,  Node: Syntax Descriptors,  Next: Syntax Table Functions,  Prev: Syntax Tables,  Up: Syntax Tables
  880. Syntax Descriptors
  881. ==================
  882.    This section describes the syntax classes and flags that denote the
  883. syntax of a character, and how they are represented as a "syntax
  884. descriptor", which is a Lisp string that you pass to
  885. `modify-syntax-entry' to specify the desired syntax.
  886.    Emacs defines twelve "syntax classes".  Each syntax table contains a
  887. mapping that puts each character into one class.  There is no necessary
  888. relationship between the class of a character in one syntax table and
  889. its class in any other table.
  890.    Each class is designated by a mnemonic character which serves as the
  891. name of the class when you need to specify a class.  Usually the
  892. designator character is one which is frequently put in that class;
  893. however, its meaning as a designator is unvarying and independent of how
  894. it is actually classified.
  895.    A syntax descriptor is a Lisp string which specifies a syntax class,
  896. a matching character (unused except for parenthesis classes) and flags.
  897. The first character is the designator for a syntax class.  The second
  898. character is the character to match; if it is unused, put a space there.
  899. Then come the characters for any desired flags.  If no matching
  900. character or flags are needed, one character is sufficient.
  901.    Thus, the descriptor for the character `*' in C mode is `. 23'
  902. (i.e., punctuation, matching character slot unused, second character of
  903. a comment-starter, first character of an comment-ender), and the entry
  904. for `/' is `. 14' (i.e., punctuation, matching character slot unused,
  905. first character of a comment-starter, second character of a
  906. comment-ender).
  907. * Menu:
  908. * Syntax Class Table::      Table of syntax classes.
  909. * Syntax Flags::            Additional flags each character can have.
  910.