home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / elisp / elisp-24 < prev    next >
Encoding:
GNU Info File  |  1993-05-31  |  47.0 KB  |  1,113 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  5. Emacs Version 19.
  6.  
  7.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26. 
  27. File: elisp,  Node: Case Changes,  Next: Text Properties,  Prev: Columns,  Up: Text
  28.  
  29. Case Changes
  30. ============
  31.  
  32.    The case change commands described here work on text in the current
  33. buffer.  *Note Character Case::, for case conversion commands that work
  34. on strings and characters.  *Note Case Table::, for how to customize
  35. which characters are upper or lower case and how to convert them.
  36.  
  37.  - Command: capitalize-region START END
  38.      This function capitalizes all words in the region defined by START
  39.      and END.  To capitalize means to convert each word's first
  40.      character to upper case and convert the rest of each word to lower
  41.      case.  The function returns `nil'.
  42.  
  43.      If one end of the region is in the middle of a word, the part of
  44.      the word within the region is treated as an entire word.
  45.  
  46.      When `capitalize-region' is called interactively, START and END
  47.      are point and the mark, with the smallest first.
  48.  
  49.           ---------- Buffer: foo ----------
  50.           This is the contents of the 5th foo.
  51.           ---------- Buffer: foo ----------
  52.           
  53.           (capitalize-region 1 44)
  54.           => nil
  55.           
  56.           ---------- Buffer: foo ----------
  57.           This Is The Contents Of The 5th Foo.
  58.           ---------- Buffer: foo ----------
  59.  
  60.  - Command: downcase-region START END
  61.      This function converts all of the letters in the region defined by
  62.      START and END to lower case.  The function returns `nil'.
  63.  
  64.      When `downcase-region' is called interactively, START and END are
  65.      point and the mark, with the smallest first.
  66.  
  67.  - Command: upcase-region START END
  68.      This function converts all of the letters in the region defined by
  69.      START and END to upper case.  The function returns `nil'.
  70.  
  71.      When `upcase-region' is called interactively, START and END are
  72.      point and the mark, with the smallest first.
  73.  
  74.  - Command: capitalize-word COUNT
  75.      This function capitalizes COUNT words after point, moving point
  76.      over as it does.  To capitalize means to convert each word's first
  77.      character to upper case and convert the rest of each word to lower
  78.      case.  If COUNT is negative, the function capitalizes the -COUNT
  79.      previous words but does not move point.  The value is `nil'.
  80.  
  81.      If point is in the middle of a word, the part of word the before
  82.      point (if moving forward) or after point (if operating backward)
  83.      is ignored.  The rest is treated as an entire word.
  84.  
  85.      When `capitalize-word' is called interactively, COUNT is set to
  86.      the numeric prefix argument.
  87.  
  88.  - Command: downcase-word COUNT
  89.      This function converts the COUNT words after point to all lower
  90.      case, moving point over as it does.  If COUNT is negative, it
  91.      converts the -COUNT previous words but does not move point.  The
  92.      value is `nil'.
  93.  
  94.      When `downcase-word' is called interactively, COUNT is set to the
  95.      numeric prefix argument.
  96.  
  97.  - Command: upcase-word COUNT
  98.      This function converts the COUNT words after point to all upper
  99.      case, moving point over as it does.  If COUNT is negative, it
  100.      converts the -COUNT previous words but does not move point.  The
  101.      value is `nil'.
  102.  
  103.      When `upcase-word' is called interactively, COUNT is set to the
  104.      numeric prefix argument.
  105.  
  106. 
  107. File: elisp,  Node: Text Properties,  Next: Substitution,  Prev: Case Changes,  Up: Text
  108.  
  109. Text Properties
  110. ===============
  111.  
  112.    Each character position in a buffer or a string can have a "text
  113. property list", much like the property list of a symbol.  The properties
  114. belong to a particular character at a particular place, such as, the
  115. letter `T' at the beginning of this sentence or the first `o' in
  116. `foo'--if the same character occurs in two different places, the two
  117. occurrences generally have different properties.
  118.  
  119.    Each property has a name, which is usually a symbol, and an
  120. associated value, which can be any Lisp object--just as for properties
  121. of symbols (*note Property Lists::.).
  122.  
  123.    If a character has a `category' property, we call it the "category"
  124. of the character.  It should be a symbol.  The properties of the symbol
  125. serve as defaults for the properties of the character.
  126.  
  127.    Copying text between strings and buffers preserves the properties
  128. along with the characters; this includes such diverse functions as
  129. `substring', `insert', and `buffer-substring'.
  130.  
  131. * Menu:
  132.  
  133. * Examining Properties::    Looking at the properties of one character.
  134. * Changing Properties::        Setting the properties of a range of text.
  135. * Property Search::        Searching for where a property changes value.
  136. * Special Properties::        Particular properties with special meanings.
  137. * Not Intervals::        Why text properties do not use
  138.                   Lisp-visible text intervals.
  139.  
  140. 
  141. File: elisp,  Node: Examining Properties,  Next: Changing Properties,  Up: Text Properties
  142.  
  143. Examining Text Properties
  144. -------------------------
  145.  
  146.    The simplest way to examine text properties is to ask for the value
  147. of a particular property of a particular character.  For that, use
  148. `get-text-property'.  Use `text-properties-at' to get the entire
  149. property list of a character.  *Note Property Search::, for functions
  150. to examine the properties of a number of characters at once.
  151.  
  152.    These functions handle both strings and buffers.  Keep in mind that
  153. positions in a string start from 0, whereas positions in a buffer start
  154. from 1.
  155.  
  156.  - Function: get-text-property POS PROP &optional OBJECT
  157.      This function returns the value of the PROP property of the
  158.      character after position POS in OBJECT (a buffer or string).  The
  159.      argument OBJECT is optional and defaults to the current buffer.
  160.  
  161.      If there is no PROP property strictly speaking, but the character
  162.      has a category which is a symbol, then `get-text-property' returns
  163.      the PROP property of that symbol.
  164.  
  165.  - Function: text-properties-at POSITION &optional OBJECT
  166.      This function returns the list of properties held by the character
  167.      at POSITION in the string or buffer OBJECT.  If OBJECT is `nil',
  168.      it defaults to the current buffer.
  169.  
  170. 
  171. File: elisp,  Node: Changing Properties,  Next: Property Search,  Prev: Examining Properties,  Up: Text Properties
  172.  
  173. Changing Text Properties
  174. ------------------------
  175.  
  176.    The primitives for changing properties apply to a specified range of
  177. text.  The function `set-text-properties' (see end of section) sets the
  178. entire property list of the text in that range; more often, it is
  179. useful to add, change, or delete just certain properties specified by
  180. name.
  181.  
  182.    Since text properties are considered part of the buffer's contents,
  183. and can affect how the buffer looks on the screen, any change in the
  184. text properties is considered a buffer modification.  Buffer text
  185. property changes are undoable.
  186.  
  187.  - Function: add-text-properties START END PROPS &optional OBJECT
  188.      This function modifies the text properties for the text between
  189.      START and END in the string or buffer OBJECT.  If OBJECT is `nil',
  190.      it defaults to the current buffer.
  191.  
  192.      The argument PROPS specifies which properties to change.  It
  193.      should have the form of a property list (*note Property Lists::.):
  194.      a list whose elements include the property names followed
  195.      alternately by the corresponding values.
  196.  
  197.      The return value is `t' if the function actually changed some
  198.      property's value; `nil' otherwise (if PROPS is `nil' or its values
  199.      agree with those in the text).
  200.  
  201.      For example, here is how to set the `comment' property to `t' for
  202.      a range of text:
  203.  
  204.           (add-text-properties (region-beginning)
  205.                                (region-end)
  206.                                (list 'comment t))
  207.  
  208.  - Function: put-text-property START END PROP VALUE &optional OBJECT
  209.      This function sets the PROP property to VALUE for the text between
  210.      START and END in the string or buffer OBJECT.  If OBJECT is `nil',
  211.      it defaults to the current buffer.
  212.  
  213.  - Function: remove-text-properties START END PROPS &optional OBJECT
  214.      This function deletes specified text properties from the text
  215.      between START and END in the string or buffer OBJECT.  If OBJECT
  216.      is `nil', it defaults to the current buffer.
  217.  
  218.      The argument PROPS specifies which properties to delete.  It
  219.      should have the form of a property list (*note Property Lists::.):
  220.      a list whose elements include the property names followed by the
  221.      corresponding values.  The property names mentioned in PROPS are
  222.      the ones deleted from the text.  The values associated in PROPS
  223.      with these names do not matter.
  224.  
  225.      The return value is `t' if the function actually changed some
  226.      property's value; `nil' otherwise (if PROPS is `nil' or if none of
  227.      the text had any of those properties).
  228.  
  229.  - Function: set-text-properties START END PROPS &optional OBJECT
  230.      This function completely replaces the text property list for the
  231.      text between START and END in the string or buffer OBJECT.  If
  232.      OBJECT is `nil', it defaults to the current buffer.
  233.  
  234.      The argument PROPS is the new property list.  It should have the
  235.      form of a list whose elements include the property names followed
  236.      by the corresponding values.
  237.  
  238.      After `set-text-properties' returns, all the characters in the
  239.      specified range have identical properties.
  240.  
  241.      If PROPS is `nil', the effect is to get rid of all properties from
  242.      the specified range of text.  Here's an example:
  243.  
  244.           (set-text-properties (region-beginning)
  245.                                (region-end)
  246.                                nil)
  247.  
  248. 
  249. File: elisp,  Node: Property Search,  Next: Special Properties,  Prev: Changing Properties,  Up: Text Properties
  250.  
  251. Property Search Functions
  252. -------------------------
  253.  
  254.    In typical use of text properties, most of the time several or many
  255. consecutive characters have the same value for a property.  Rather than
  256. writing your programs to examine characters one by one, it is much
  257. faster to process chunks of text that have the same property value.
  258.  
  259.    Here are functions you can use to do this.  In all cases, OBJECT
  260. defaults to the current buffer.
  261.  
  262.  - Function: next-property-change POS &optional OBJECT
  263.      The function scans the text forward from position POS in the
  264.      string or buffer OBJECT till it finds a change in some text
  265.      property, then returns the position of the change.  In other
  266.      words, it returns the position of the first character beyond POS
  267.      whose properties are not identical to those of the character just
  268.      after POS.
  269.  
  270.      The value is `nil' if the properties remain unchanged all the way
  271.      to the end of OBJECT.  If the value is non-`nil', it is a position
  272.      greater than POS, never equal.
  273.  
  274.      Here is an example of how to scan the buffer by chunks of text
  275.      within which all properties are constant:
  276.  
  277.           (while (not (eobp))
  278.             (let ((plist (text-properties-at (point)))
  279.                   (next-change
  280.                    (or (next-property-change (point) (current-buffer))
  281.                        (point-max))))
  282.               PROCESS TEXT FROM POINT TO NEXT-CHANGE...
  283.               (goto-char next-change)))
  284.  
  285.  - Function: next-single-property-change POS PROP &optional OBJECT
  286.      The function scans the text forward from position POS in the
  287.      string or buffer OBJECT till it finds a change in the PROP
  288.      property, then returns the position of the change.  In other
  289.      words, it returns the position of the first character beyond POS
  290.      whose PROP property differs from that of the character just after
  291.      POS.
  292.  
  293.      The value is `nil' if the properties remain unchanged all the way
  294.      to the end of OBJECT.  If the value is non-`nil', it is a position
  295.      greater than POS, never equal.
  296.  
  297.  - Function: previous-property-change POS &optional OBJECT
  298.      This is like `next-property-change', but scans back from POS
  299.      instead of forward.  If the value is non-`nil', it is a position
  300.      always strictly less than POS.
  301.  
  302.  - Function: previous-single-property-change POS PROP &optional OBJECT
  303.      This is like `next-property-change', but scans back from POS
  304.      instead of forward.  If the value is non-`nil', it is a position
  305.      always strictly less than POS.
  306.  
  307. 
  308. File: elisp,  Node: Special Properties,  Next: Not Intervals,  Prev: Property Search,  Up: Text Properties
  309.  
  310. Special Properties
  311. ------------------
  312.  
  313.    If a character has a `category' property, we call it the "category"
  314. of the character.  It should be a symbol.  The properties of the symbol
  315. serve as defaults for the properties of the character.
  316.  
  317.    You can use the property `face' to control the font and color of
  318. text.  *Note Faces::, for more information.  This feature is temporary;
  319. in the future, we may replace it with other ways of specifying how to
  320. display text.
  321.  
  322.    The property `mouse-face' is used instead of `face' when the mouse
  323. is on or near the character.  For this purpose, "near" means that all
  324. text between the character and where the mouse is have the same
  325. `mouse-face' property value.
  326.  
  327.    You can specify a different keymap for a portion of the text by means
  328. of a `local-map' property.  The property's value, for the character
  329. after point, replaces the buffer's local map.  *Note Active Keymaps::.
  330.  
  331.    If a character has the property `read-only', then modifying that
  332. character is not allowed.  Any command that would do so gets an error.
  333.  
  334.    If a character has the property `modification-hooks', then its value
  335. should be a list of functions; modifying that character calls all of
  336. those functions.  Each function receives two arguments: the beginning
  337. and end of the part of the buffer being modified.  Note that if a
  338. particular modification hook function appears on several characters
  339. being modified by a single primitive, you can't predict how many times
  340. the function will be called.
  341.  
  342.    Insertion of text does not, strictly speaking, change any existing
  343. character, so there is a special rule for insertion.  It compares the
  344. `read-only' properties of the two surrounding characters; if they are
  345. non-`nil' and `eq' to each other, then the insertion is not allowed.
  346. Assuming insertion is allowed, it then gets the `modification-hooks'
  347. properties of those characters and calls all the functions in each of
  348. them.  (If a function appears on both characters, it may be called once
  349. or twice.)
  350.  
  351.    See also *Note Change Hooks::, for other hooks that are called when
  352. you change text in a buffer.
  353.  
  354.    The special properties `point-entered' and `point-left' record hook
  355. functions that report motion of point.  Each time point moves, Emacs
  356. compares these two property values:
  357.  
  358.    * the `point-left' property of the character after the old location,
  359.      and
  360.  
  361.    * the `point-entered' property of the character after the new
  362.      location.
  363.  
  364. If these two values differ, each of them is called (if not `nil') with
  365. two arguments: the old value of point, and the new one.
  366.  
  367.    The same comparison is made for the characters before the old and new
  368. locations.  The result may be to execute two `point-left' functions
  369. (which may be the same function) and/or two `point-entered' functions
  370. (which may be the same function).  The `point-left' functions are
  371. always called before the `point-entered' functions.
  372.  
  373.    A primitive function may examine characters at various positions
  374. without moving point to those positions.  Only an actual change in the
  375. value of point runs these hook functions.
  376.  
  377. 
  378. File: elisp,  Node: Not Intervals,  Prev: Special Properties,  Up: Text Properties
  379.  
  380. Why Text Properties are not Intervals
  381. -------------------------------------
  382.  
  383.    Some editors that support adding attributes to text in the buffer do
  384. so by letting the user specify "intervals" within the text, and adding
  385. the properties to the intervals.  Those editors permit the user or the
  386. programmer to determine where individual intervals start and end.  We
  387. deliberately provided a different sort of interface in Emacs Lisp to
  388. avoid certain paradoxical behavior associated with text modification.
  389.  
  390.    If the actual subdivision into intervals is meaningful, that means
  391. you can distinguish between a buffer that is just one interval with a
  392. certain property, and a buffer containing the same text subdivided into
  393. two intervals, both of which have that property.
  394.  
  395.    Suppose you take the buffer with just one interval and kill part of
  396. the text.  The text remaining in the buffer is one interval, and the
  397. copy in the kill ring (and the undo list) becomes a separate interval.
  398. Then if you undo the kill, you get two intervals with the same
  399. properties.  Thus, the distinction can't be preserved when editing
  400. happens.
  401.  
  402.    But suppose we "fix" this problem by coalescing the two intervals
  403. when the text is inserted.  That works fine if the buffer originally was
  404. a single interval.  But if it was two intervals, and the killed text
  405. equals one of them, then undoing the kill yields just one interval.
  406. Again, the distinction can't be preserved.
  407.  
  408.    Insertion of text at the border between intervals also raises
  409. questions that have no satisfactory answer.
  410.  
  411.    However, it is easy to arrange for editing to behave consistently for
  412. questions of the form, "What are the properties of this character?" So
  413. we have decided these are the only questions that make sense; we have
  414. not implemented asking questions about where intervals start or end.
  415.  
  416.    For practical purposes, the property search functions serve in place
  417. of explicit interval boundaries.  You can think of them as finding the
  418. boundaries of intervals, assuming that intervals are always coalesced
  419. whenever possible.  *Note Property Search::.
  420.  
  421.    Emacs also provides explicit intervals as a presentation feature; see
  422. *Note Overlays::.
  423.  
  424. 
  425. File: elisp,  Node: Substitution,  Next: Underlining,  Prev: Text Properties,  Up: Text
  426.  
  427. Substituting for a Character Code
  428. =================================
  429.  
  430.    The following functions replace characters within a specified region
  431. based on their character codes.
  432.  
  433.  - Function: subst-char-in-region START END OLD-CHAR NEW-CHAR &optional
  434.           NOUNDO
  435.      This function replaces all occurrences of the character OLD-CHAR
  436.      with the character NEW-CHAR in the region of the current buffer
  437.      defined by START and END.
  438.  
  439.      If NOUNDO is non-`nil', then `subst-char-in-region' does not
  440.      record the change for undo and does not mark the buffer as
  441.      modified.  This feature is useful for changes which are not
  442.      considered significant, such as when Outline mode changes visible
  443.      lines to invisible lines and vice versa.
  444.  
  445.      `subst-char-in-region' does not move point and returns `nil'.
  446.  
  447.           ---------- Buffer: foo ----------
  448.           This is the contents of the buffer before.
  449.           ---------- Buffer: foo ----------
  450.           
  451.           (subst-char-in-region 1 20 ?i ?X)
  452.                => nil
  453.           
  454.           ---------- Buffer: foo ----------
  455.           ThXs Xs the contents of the buffer before.
  456.           ---------- Buffer: foo ----------
  457.  
  458.  - Function: translate-region START END TABLE
  459.      This function applies a translation table to the characters in the
  460.      buffer between positions START and END.
  461.  
  462.      The translation table TABLE is a string; `(aref TABLE OCHAR)'
  463.      gives the translated character corresponding to OCHAR.  If the
  464.      length of TABLE is less than 256, any characters with codes larger
  465.      than the length of TABLE are not altered by the translation.
  466.  
  467.      The return value of `translate-region' is the number of characters
  468.      which were actually changed by the translation.  This does not
  469.      count characters which were mapped into themselves in the
  470.      translation table.
  471.  
  472.      This function is available in Emacs versions 19 and later.
  473.  
  474. 
  475. File: elisp,  Node: Underlining,  Next: Registers,  Prev: Substitution,  Up: Text
  476.  
  477. Underlining
  478. ===========
  479.  
  480.    The underlining commands are somewhat obsolete.  The
  481. `underline-region' function actually inserts `_^H' before each
  482. appropriate character in the region.  This command provides a minimal
  483. text formatting feature that might work on your printer; however, we
  484. recommend instead that you use more powerful text formatting facilities,
  485. such as Texinfo.
  486.  
  487.  - Command: underline-region START END
  488.      This function underlines all nonblank characters in the region
  489.      defined by START and END.  That is, an underscore character and a
  490.      backspace character are inserted just before each non-whitespace
  491.      character in the region.  The backspace characters are intended to
  492.      cause overstriking, but in Emacs they display as either `\010' or
  493.      `^H', depending on the setting of `ctl-arrow'.  There is no way to
  494.      see the effect of the overstriking within Emacs.  The value is
  495.      `nil'.
  496.  
  497.  - Command: ununderline-region START END
  498.      This function removes all underlining (overstruck underscores) in
  499.      the region defined by START and END.  The value is `nil'.
  500.  
  501. 
  502. File: elisp,  Node: Registers,  Next: Change Hooks,  Prev: Underlining,  Up: Text
  503.  
  504. Registers
  505. =========
  506.  
  507.    A register is a sort of variable used in Emacs editing that can hold
  508. a marker, a string, a rectangle, a window configuration (of one frame),
  509. or a frame configuration (of all frames).  Each register is named by a
  510. single character.  All characters, including control and meta characters
  511. (but with the exception of `C-g'), can be used to name registers.
  512. Thus, there are 255 possible registers.  A register is designated in
  513. Emacs Lisp by a character which is its name.
  514.  
  515.    The functions in this section return unpredictable values unless
  516. otherwise stated.
  517.  
  518.  - Variable: register-alist
  519.      This variable is an alist of elements of the form `(NAME .
  520.      cONTENTS)'.  Normally, there is one element for each Emacs
  521.      register that has been used.
  522.  
  523.      The object NAME is a character (an integer) identifying the
  524.      register.  The object CONTENTS is a string, marker, or list
  525.      representing the register contents.  A string represents text
  526.      stored in the register.  A marker represents a position.  A list
  527.      represents a rectangle; its elements are strings, one per line of
  528.      the rectangle.
  529.  
  530.  - Command: view-register REG
  531.      This command displays what is contained in register REG.
  532.  
  533.  - Function: get-register REG
  534.      This function returns the contents of the register REG, or `nil'
  535.      if it has no contents.
  536.  
  537.  - Function: set-register REG VALUE
  538.      This function sets the contents of register REG to VALUE.  A
  539.      register can be set to any value, but the other register functions
  540.      expect only certain data types.  The return value is VALUE.
  541.  
  542.  - Command: point-to-register REG
  543.      This command stores both the current location of point and the
  544.      current buffer in register REG as a marker.
  545.  
  546.  - Command: jump-to-register REG
  547.  - Command: register-to-point REG
  548.      This command restores the status recorded in register REG.
  549.  
  550.      If REG contains a marker, it moves point to the position stored in
  551.      the marker.  Since both the buffer and the location within the
  552.      buffer are stored by the `point-to-register' function, this
  553.      command can switch you to another buffer.
  554.  
  555.      If REG contains a window configuration or a frame configuration.
  556.      `jump-to-register' restores that configuration.
  557.  
  558.  - Command: insert-register REG &optional BEFOREP
  559.      This command inserts contents of register REG into the current
  560.      buffer.
  561.  
  562.      Normally, this command puts point before the inserted text, and the
  563.      mark after it.  However, if the optional second argument BEFOREP
  564.      is non-`nil', it puts the mark before and point after.  You can
  565.      pass a non-`nil' second argument BEFOREP to this function
  566.      interactively by supplying any prefix argument.
  567.  
  568.      If the register contains a rectangle, then the rectangle is
  569.      inserted with its upper left corner at point.  This means that
  570.      text is inserted in the current line and underneath it on
  571.      successive lines.
  572.  
  573.      If the register contains something other than saved text (a
  574.      string) or a rectangle (a list), currently useless things happen.
  575.      This may be changed in the future.
  576.  
  577.  - Command: copy-to-register REG START END &optional DELETE-FLAG
  578.      This command copies the region from START to END into register
  579.      REG.  If DELETE-FLAG is non-`nil', it deletes the region from the
  580.      buffer after copying it into the register.
  581.  
  582.  - Command: prepend-to-register REG START END &optional DELETE-FLAG
  583.      This command prepends the region from START to END into register
  584.      REG.  If DELETE-FLAG is non-`nil', it deletes the region from the
  585.      buffer after copying it to the register.
  586.  
  587.  - Command: append-to-register REG START END &optional DELETE-FLAG
  588.      This command appends the region from START to END to the text
  589.      already in register REG.  If DELETE-FLAG is non-`nil', it deletes
  590.      the region from the buffer after copying it to the register.
  591.  
  592.  - Command: copy-rectangle-to-register REG START END &optional
  593.           DELETE-FLAG
  594.      This command copies a rectangular region from START to END into
  595.      register REG.  If DELETE-FLAG is non-`nil', it deletes the region
  596.      from the buffer after copying it to the register.
  597.  
  598.  - Command: window-configuration-to-register REG
  599.      This function stores the window configuration of the selected
  600.      frame in register REG.
  601.  
  602.  - Command: frame-configuration-to-register REG
  603.      This function stores the current frame configuration in register
  604.      REG.
  605.  
  606. 
  607. File: elisp,  Node: Change Hooks,  Prev: Registers,  Up: Text
  608.  
  609. Change Hooks
  610. ============
  611.  
  612.    These hook variables let you arrange to take notice of all changes in
  613. all buffers (or in a particular buffer, if you make them buffer-local).
  614. See also *Note Special Properties::, for how to detect changes to
  615. specific parts of the text.
  616.  
  617.  - Variable: before-change-function
  618.      If this variable is non-`nil', then it should be a function; the
  619.      function is called before any buffer modification.  Its arguments
  620.      are the beginning and end of the region that is going to change,
  621.      represented as integers.  The buffer that's about to change is
  622.      always the current buffer.
  623.  
  624.  - Variable: after-change-function
  625.      If this variable is non-`nil', then it should be a function; the
  626.      function is called after any buffer modification.  It receives
  627.      three arguments: the beginning and end of the region just changed,
  628.      and the length of the text that existed before the change.  (To
  629.      get the current length, subtract the region beginning from the
  630.      region end.) All three arguments are integers.  The buffer that's
  631.      about to change is always the current buffer.
  632.  
  633.    Both of these variables are temporarily bound to `nil' during the
  634. time that either of these hooks is running.  This means that if one of
  635. these functions changes the buffer, that change won't run these
  636. functions.  If you do want the hook function to be run recursively,
  637. write your hook functions to bind these variables back to their usual
  638. values.
  639.  
  640.  - Variable: first-change-hook
  641.      This variable is a normal hook; its hook functions are run using
  642.      `run-hooks' whenever a buffer is changed that was previously in
  643.      the unmodified state.
  644.  
  645.    The variables described in this section are meaningful only starting
  646. with Emacs version 19.
  647.  
  648. 
  649. File: elisp,  Node: Searching and Matching,  Next: Syntax Tables,  Prev: Text,  Up: Top
  650.  
  651. Searching and Matching
  652. **********************
  653.  
  654.    GNU Emacs provides two ways to search through a buffer for specified
  655. text: exact string searches and regular expression searches.  After a
  656. regular expression search, you can identify the text matched by parts of
  657. the regular expression by examining the "match data".
  658.  
  659. * Menu:
  660.  
  661. * String Search::         Search for an exact match.
  662. * Regular Expressions::   Describing classes of strings.
  663. * Regexp Search::         Searching for a match for a regexp.
  664. * Replacement::          Internals of `query-replace'.
  665. * Match Data::            Finding out which part of the text matched
  666.                             various parts of a regexp, after regexp search.
  667. * Standard Regexps::      Useful regexps for finding sentences, pages,...
  668. * Searching and Case::    Case-independent or case-significant searching.
  669.  
  670. 
  671. File: elisp,  Node: String Search,  Next: Regular Expressions,  Up: Searching and Matching
  672.  
  673. Searching for Strings
  674. =====================
  675.  
  676.    These are the primitive functions for searching through the text in a
  677. buffer.  They are meant for use in programs, but you may call them
  678. interactively.  If you do so, they prompt for the search string; LIMIT
  679. and NOERROR are set to `nil', and REPEAT is set to 1.
  680.  
  681.  - Command: search-forward STRING &optional LIMIT NOERROR REPEAT
  682.      This function searches forward from point for an exact match for
  683.      STRING.  If successful, it sets point to the end of the occurrence
  684.      found, and returns the new value of point.  If no match is found,
  685.      the value and side effects depend on NOERROR (see below).
  686.  
  687.      In the following example, point is positioned at the beginning of
  688.      the line.  Then `(search-forward "fox")' is evaluated in the
  689.      minibuffer and point is left after the last letter of `fox':
  690.  
  691.           ---------- Buffer: foo ----------
  692.           -!-The quick brown fox jumped over the lazy dog.
  693.           ---------- Buffer: foo ----------
  694.           
  695.           (search-forward "fox")
  696.                => t
  697.           
  698.           ---------- Buffer: foo ----------
  699.           The quick brown fox-!- jumped over the lazy dog.
  700.           ---------- Buffer: foo ----------
  701.  
  702.      The argument LIMIT specifies the upper bound to the search.  (It
  703.      must be a position in the current buffer.)  No match extending
  704.      after that position is accepted.  If LIMIT is omitted or `nil', it
  705.      defaults to the end of the accessible portion of the buffer.
  706.  
  707.      What happens when the search fails depends on the value of
  708.      NOERROR.  If NOERROR is `nil', a `search-failed' error is
  709.      signaled.  If NOERROR is `t', `search-forward' returns `nil' and
  710.      does nothing.  If NOERROR is neither `nil' nor `t', then
  711.      `search-forward' moves point to the upper bound and returns `nil'.
  712.      (It would be more consistent now to return the new position of
  713.      point in that case, but some programs may depend on a value of
  714.      `nil'.)
  715.  
  716.      If REPEAT is non-`nil', then the search is repeated that many
  717.      times.  Point is positioned at the end of the last match.
  718.  
  719.  - Command: search-backward STRING &optional LIMIT NOERROR REPEAT
  720.      This function searches backward from point for STRING.  It is just
  721.      like `search-forward' except that it searches backwards and leaves
  722.      point at the beginning of the match.
  723.  
  724.  - Command: word-search-forward STRING &optional LIMIT NOERROR REPEAT
  725.      This function searches forward from point for a "word" match for
  726.      STRING.  If it finds a match, it sets point to the end of the
  727.      match found, and returns the new value of point.
  728.  
  729.      A word search differs from a simple string search in that a word
  730.      search *requires* that the words it searches for are present as
  731.      entire words (searching for the word `ball' does not match the word
  732.      `balls'), and punctuation and spacing are ignored (searching for
  733.      `ball boy' does match `ball.  Boy!').
  734.  
  735.      In this example, point is first placed at the beginning of the
  736.      buffer; the search leaves it between the `y' and the `!'.
  737.  
  738.           ---------- Buffer: foo ----------
  739.           -!-He said "Please!  Find
  740.           the ball boy!"
  741.           ---------- Buffer: foo ----------
  742.           
  743.           (word-search-forward "Please find the ball, boy.")
  744.                => t
  745.           
  746.           ---------- Buffer: foo ----------
  747.           He said "Please!  Find
  748.           the ball boy-!-!"
  749.           ---------- Buffer: foo ----------
  750.  
  751.      If LIMIT is non-`nil' (it must be a position in the current
  752.      buffer), then it is the upper bound to the search.  The match
  753.      found must not extend after that position.
  754.  
  755.      If NOERROR is `t', then `word-search-forward' returns `nil' when a
  756.      search fails, instead of signaling an error.  If NOERROR is
  757.      neither `nil' nor `t', then `word-search-forward' moves point to
  758.      LIMIT (or the end of the buffer) and returns `nil'.
  759.  
  760.      If REPEAT is non-`nil', then the search is repeated that many
  761.      times.  Point is positioned at the end of the last match.
  762.  
  763.  - Command: word-search-backward STRING &optional LIMIT NOERROR REPEAT
  764.      This function searches backward from point for a word match to
  765.      STRING.  This function is just like `word-search-forward' except
  766.      that it searches backward and normally leaves point at the
  767.      beginning of the match.
  768.  
  769. 
  770. File: elisp,  Node: Regular Expressions,  Next: Regexp Search,  Prev: String Search,  Up: Searching and Matching
  771.  
  772. Regular Expressions
  773. ===================
  774.  
  775.    A "regular expression" ("regexp", for short) is a pattern that
  776. denotes a (possibly infinite) set of strings.  Searching for matches for
  777. a regexp is a very powerful operation.  This section explains how to
  778. write regexps; the following section says how to search for them.
  779.  
  780. * Menu:
  781.  
  782. * Syntax of Regexps::       Rules for writing regular expressions.
  783. * Regexp Example::          Illustrates regular expression syntax.
  784.  
  785. 
  786. File: elisp,  Node: Syntax of Regexps,  Next: Regexp Example,  Up: Regular Expressions
  787.  
  788. Syntax of Regular Expressions
  789. -----------------------------
  790.  
  791.    Regular expressions have a syntax in which a few characters are
  792. special constructs and the rest are "ordinary".  An ordinary character
  793. is a simple regular expression which matches that character and nothing
  794. else.  The special characters are `$', `^', `.', `*', `+', `?', `[',
  795. `]' and `\'; no new special characters will be defined in the future.
  796. Any other character appearing in a regular expression is ordinary,
  797. unless a `\' precedes it.
  798.  
  799.    For example, `f' is not a special character, so it is ordinary, and
  800. therefore `f' is a regular expression that matches the string `f' and
  801. no other string.  (It does *not* match the string `ff'.)  Likewise, `o'
  802. is a regular expression that matches only `o'.
  803.  
  804.    Any two regular expressions A and B can be concatenated.  The result
  805. is a regular expression which matches a string if A matches some amount
  806. of the beginning of that string and B matches the rest of the string.
  807.  
  808.    As a simple example, we can concatenate the regular expressions `f'
  809. and `o' to get the regular expression `fo', which matches only the
  810. string `fo'.  Still trivial.  To do something more powerful, you need
  811. to use one of the special characters.  Here is a list of them:
  812.  
  813. `. (Period)'
  814.      is a special character that matches any single character except a
  815.      newline.  Using concatenation, we can make regular expressions
  816.      like `a.b' which matches any three-character string which begins
  817.      with `a' and ends with `b'.
  818.  
  819. `*'
  820.      is not a construct by itself; it is a suffix that means the
  821.      preceding regular expression is to be repeated as many times as
  822.      possible.  In `fo*', the `*' applies to the `o', so `fo*' matches
  823.      one `f' followed by any number of `o's.  The case of zero `o's is
  824.      allowed: `fo*' does match `f'.
  825.  
  826.      `*' always applies to the *smallest* possible preceding
  827.      expression.  Thus, `fo*' has a repeating `o', not a repeating `fo'.
  828.  
  829.      The matcher processes a `*' construct by matching, immediately, as
  830.      many repetitions as can be found.  Then it continues with the rest
  831.      of the pattern.  If that fails, backtracking occurs, discarding
  832.      some of the matches of the `*'-modified construct in case that
  833.      makes it possible to match the rest of the pattern.  For example,
  834.      matching `ca*ar' against the string `caaar', the `a*' first tries
  835.      to match all three `a's; but the rest of the pattern is `ar' and
  836.      there is only `r' left to match, so this try fails.  The next
  837.      alternative is for `a*' to match only two `a's.  With this choice,
  838.      the rest of the regexp matches successfully.
  839.  
  840. `+'
  841.      is a suffix character similar to `*' except that it must match the
  842.      preceding expression at least once.  So, for example, `ca+r' will
  843.      match the strings `car' and `caaaar' but not the string `cr',
  844.      whereas `ca*r' would match all three strings.
  845.  
  846. `?'
  847.      is a suffix character similar to `*' except that it can match the
  848.      preceding expression either once or not at all.  For example,
  849.      `ca?r' will match `car' or `cr'; nothing else.
  850.  
  851. `[ ... ]'
  852.      `[' begins a "character set", which is terminated by a `]'.  In
  853.      the simplest case, the characters between the two form the set.
  854.      Thus, `[ad]' matches either one `a' or one `d', and `[ad]*'
  855.      matches any string composed of just `a's and `d's (including the
  856.      empty string), from which it follows that `c[ad]*r' matches `cr',
  857.      `car', `cdr', `caddaar', etc.
  858.  
  859.      Character ranges can also be included in a character set, by
  860.      writing two characters with a `-' between them.  Thus, `[a-z]'
  861.      matches any lower case letter.  Ranges may be intermixed freely
  862.      with individual characters, as in `[a-z$%.]', which matches any
  863.      lower case letter or `$', `%' or a period.
  864.  
  865.      Note that the usual special characters are not special any more
  866.      inside a character set.  A completely different set of special
  867.      characters exists inside character sets: `]', `-' and `^'.
  868.  
  869.      To include a `]' in a character set, make it the first character.
  870.      For example, `[]a]' matches `]' or `a'.  To include a `-', write
  871.      `-' as the first or last character in the range.
  872.  
  873.      To include `^', make it other than the first character in the set.
  874.  
  875. `[^ ... ]'
  876.      `[^' begins a "complement character set", which matches any
  877.      character except the ones specified.  Thus, `[^a-z0-9A-Z]' matches
  878.      all characters *except* letters and digits.
  879.  
  880.      `^' is not special in a character set unless it is the first
  881.      character.  The character following the `^' is treated as if it
  882.      were first (thus, `-' and `]' are not special there).
  883.  
  884.      Note that a complement character set can match a newline, unless
  885.      newline is mentioned as one of the characters not to match.
  886.  
  887. `^'
  888.      is a special character that matches the empty string, but only at
  889.      the beginning of a line in the text being matched.  Otherwise it
  890.      fails to match anything.  Thus, `^foo' matches a `foo' which occurs
  891.      at the beginning of a line.
  892.  
  893.      When matching a string, `^' matches at the beginning of the string
  894.      or after a newline character `\n'.
  895.  
  896. `$'
  897.      is similar to `^' but matches only at the end of a line.  Thus,
  898.      `x+$' matches a string of one `x' or more at the end of a line.
  899.  
  900.      When matching a string, `$' matches at the end of the string or
  901.      before a newline character `\n'.
  902.  
  903. `\'
  904.      has two functions: it quotes the special characters (including
  905.      `\'), and it introduces additional special constructs.
  906.  
  907.      Because `\' quotes special characters, `\$' is a regular
  908.      expression which matches only `$', and `\[' is a regular
  909.      expression which matches only `[', and so on.
  910.  
  911.      Note that `\' also has special meaning in the read syntax of Lisp
  912.      strings (*note String Type::.), and must be quoted with `\'.  For
  913.      example, the regular expression that matches the `\' character is
  914.      `\\'.  To write a Lisp string that contains the characters `\\',
  915.      Lisp syntax requires you to quote each `\' with another `\'.
  916.      Therefore, the read syntax for a regular expression matching `\'
  917.      is `"\\\\"'.
  918.  
  919.    *Please note:* for historical compatibility, special characters are
  920. treated as ordinary ones if they are in contexts where their special
  921. meanings make no sense.  For example, `*foo' treats `*' as ordinary
  922. since there is no preceding expression on which the `*' can act.  It is
  923. poor practice to depend on this behavior; better to quote the special
  924. character anyway, regardless of where it appears.
  925.  
  926.    For the most part, `\' followed by any character matches only that
  927. character.  However, there are several exceptions: characters which,
  928. when preceded by `\', are special constructs.  Such characters are
  929. always ordinary when encountered on their own.  Here is a table of `\'
  930. constructs:
  931.  
  932. `\|'
  933.      specifies an alternative.  Two regular expressions A and B with
  934.      `\|' in between form an expression that matches anything that
  935.      either A or B matches.
  936.  
  937.      Thus, `foo\|bar' matches either `foo' or `bar' but no other string.
  938.  
  939.      `\|' applies to the largest possible surrounding expressions.
  940.      Only a surrounding `\( ... \)' grouping can limit the grouping
  941.      power of `\|'.
  942.  
  943.      Full backtracking capability exists to handle multiple uses of
  944.      `\|'.
  945.  
  946. `\( ... \)'
  947.      is a grouping construct that serves three purposes:
  948.  
  949.        1. To enclose a set of `\|' alternatives for other operations.
  950.           Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
  951.  
  952.        2. To enclose a complicated expression for a suffix character
  953.           such as `*' to operate on.  Thus, `ba\(na\)*' matches
  954.           `bananana', etc., with any (zero or more) number of `na'
  955.           strings.
  956.  
  957.        3. To record a matched substring for future reference.
  958.  
  959.      This last application is not a consequence of the idea of a
  960.      parenthetical grouping; it is a separate feature which happens to
  961.      be assigned as a second meaning to the same `\( ... \)' construct
  962.      because there is no conflict in practice between the two meanings.
  963.      Here is an explanation of this feature:
  964.  
  965. `\DIGIT'
  966.      matches the same text which is matched the DIGITth time by a
  967.      previous `\( ... \)' construct.
  968.  
  969.      In other words, after the end of a `\( ... \)' construct.  the
  970.      matcher remembers the beginning and end of the text matched by
  971.      that construct.  Then, later on in the regular expression, you can
  972.      use `\' followed by DIGIT to mean "match the same text matched the
  973.      DIGITth time by the `\( ... \)' construct."
  974.  
  975.      The strings matching the first nine `\( ... \)' constructs
  976.      appearing in a regular expression are assigned numbers 1 through 9
  977.      in the order that the open parentheses appear in the regular
  978.      expression.  So you can use `\1' through `\9' to refer to the text
  979.      matched by the corresponding `\( ... \)' constructs.
  980.  
  981.      For example, `\(.*\)\1' matches any newline-free string that is
  982.      composed of two identical halves.  The `\(.*\)' matches the first
  983.      half, which may be anything, but the `\1' that follows must match
  984.      the same exact text.
  985.  
  986. `\`'
  987.      matches the empty string, provided it is at the beginning of the
  988.      buffer.
  989.  
  990. `\''
  991.      matches the empty string, provided it is at the end of the buffer.
  992.  
  993. `\='
  994.      matches the empty string, provided it is at point.
  995.  
  996. `\b'
  997.      matches the empty string, provided it is at the beginning or end
  998.      of a word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a
  999.      separate word.  `\bballs?\b' matches `ball' or `balls' as a
  1000.      separate word.
  1001.  
  1002. `\B'
  1003.      matches the empty string, provided it is *not* at the beginning or
  1004.      end of a word.
  1005.  
  1006. `\<'
  1007.      matches the empty string, provided it is at the beginning of a
  1008.      word.
  1009.  
  1010. `\>'
  1011.      matches the empty string, provided it is at the end of a word.
  1012.  
  1013. `\w'
  1014.      matches any word-constituent character.  The editor syntax table
  1015.      determines which characters these are.  *Note Syntax Tables::.
  1016.  
  1017. `\W'
  1018.      matches any character that is not a word-constituent.
  1019.  
  1020. `\sCODE'
  1021.      matches any character whose syntax is CODE.  Here CODE is a
  1022.      character which represents a syntax code: thus, `w' for word
  1023.      constituent, `-' for whitespace, `(' for open parenthesis, etc.
  1024.      *Note Syntax Tables::, for a list of the codes.
  1025.  
  1026. `\SCODE'
  1027.      matches any character whose syntax is not CODE.
  1028.  
  1029.    Not every string is a valid regular expression.  For example, any
  1030. string with unbalanced square brackets is invalid, and so is a string
  1031. that ends with a single `\'.  If an invalid regular expression is
  1032. passed to any of the search functions, an `invalid-regexp' error is
  1033. signaled.
  1034.  
  1035.  - Function: regexp-quote STRING
  1036.      This function returns a regular expression string which matches
  1037.      exactly STRING and nothing else.  This allows you to request an
  1038.      exact string match when calling a function that wants a regular
  1039.      expression.
  1040.  
  1041.           (regexp-quote "^The cat$")
  1042.                => "\\^The cat\\$"
  1043.  
  1044.      One use of `regexp-quote' is to combine an exact string match with
  1045.      context described as a regular expression.  For example, this
  1046.      searches for the string which is the value of `string', surrounded
  1047.      by whitespace:
  1048.  
  1049.           (re-search-forward
  1050.            (concat "\\s " (regexp-quote string) "\\s "))
  1051.  
  1052. 
  1053. File: elisp,  Node: Regexp Example,  Prev: Syntax of Regexps,  Up: Regular Expressions
  1054.  
  1055. Complex Regexp Example
  1056. ----------------------
  1057.  
  1058.    Here is a complicated regexp, used by Emacs to recognize the end of a
  1059. sentence together with any whitespace that follows.  It is the value of
  1060. the variable `sentence-end'.
  1061.  
  1062.    First, we show the regexp as a string in Lisp syntax to enable you to
  1063. distinguish the spaces from the tab characters.  The string constant
  1064. begins and ends with a double-quote.  `\"' stands for a double-quote as
  1065. part of the string, `\\' for a backslash as part of the string, `\t'
  1066. for a tab and `\n' for a newline.
  1067.  
  1068.      "[.?!][]\"')}]*\\($\\|\t\\|  \\)[ \t\n]*"
  1069.  
  1070.    In contrast, if you evaluate the variable `sentence-end', you will
  1071. see the following:
  1072.  
  1073.      sentence-end
  1074.      =>
  1075.      "[.?!][]\"')}]*\\($\\|  \\|  \\)[
  1076.      ]*"
  1077.  
  1078. In this case, the tab and carriage return are the actual characters.
  1079.  
  1080.    This regular expression contains four parts in succession and can be
  1081. deciphered as follows:
  1082.  
  1083. `[.?!]'
  1084.      The first part of the pattern consists of three characters, a
  1085.      period, a question mark and an exclamation mark, within square
  1086.      brackets.  The match must begin with one of these three characters.
  1087.  
  1088. `[]\"')}]*'
  1089.      The second part of the pattern matches any closing braces and
  1090.      quotation marks, zero or more of them, that may follow the period,
  1091.      question mark or exclamation mark.  The `\"' is Lisp syntax for a
  1092.      double-quote in a string.  The `*' at the end indicates that the
  1093.      immediately preceding regular expression (a character set, in this
  1094.      case) may be repeated zero or more times.
  1095.  
  1096. `\\($\\|\t\\|  \\)'
  1097.      The third part of the pattern matches the whitespace that follows
  1098.      the end of a sentence: the end of a line, or a tab, or two spaces.
  1099.      The double backslashes are needed to prevent Emacs from reading
  1100.      the parentheses and vertical bars as part of the search pattern;
  1101.      the parentheses are used to mark the group and the vertical bars
  1102.      are used to indicated that the patterns to either side of them are
  1103.      alternatives.  The dollar sign is used to match the end of a line.
  1104.      The tab character is written using `\t' and the two spaces are
  1105.      written as themselves.
  1106.  
  1107. `[ \t\n]*'
  1108.      Finally, the last part of the pattern indicates that the end of
  1109.      the line or the whitespace following the period, question mark or
  1110.      exclamation mark may, but need not, be followed by additional
  1111.      whitespace.
  1112.  
  1113.