home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i17 (.txt) < prev    next >
GNU Info File  |  1993-06-14  |  52KB  |  963 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: Text Lines,  Next: Screen Lines,  Prev: Buffer End Motion,  Up: Motion
  21. Motion by Text Lines
  22. --------------------
  23.    Text lines are portions of the buffer delimited by newline
  24. characters, which are regarded as part of the previous line.  The first
  25. text line begins at the beginning of the buffer, and the last text line
  26. ends at the end of the buffer whether or not the last character is a
  27. newline. The division of the buffer into text lines is not affected by
  28. the width of the window, or by how tabs and control characters are
  29. displayed.
  30.  -- Command: goto-line LINE
  31.      This function moves point to the front of the LINEth line,
  32.      counting from line 1 at beginning of buffer.  If LINE is less than
  33.      1, then point is set to the beginning of the buffer.  If LINE is
  34.      greater than the number of lines in the buffer, then point is set
  35.      to the *end of the last line* of the buffer.
  36.      If narrowing is in effect, then LINE still counts from the
  37.      beginning of the buffer, but point cannot go outside the accessible
  38.      portion.  So point is set at the beginning or end of the accessible
  39.      portion of the text if the line number specifies a position that is
  40.      inaccessible.
  41.      The return value of `goto-line' is the difference between LINE and
  42.      the line number of the line to which point actually was able move
  43.      (before taking account of any narrowing).  Thus, the value is
  44.      positive if the scan encounters the end of the buffer.
  45.      In an interactive call, LINE is the numeric prefix argument if one
  46.      has been provided.  Otherwise LINE is read in the minibuffer.
  47.  -- Command: beginning-of-line &optional COUNT
  48.      This function moves point to the beginning of the current line. 
  49.      With an argument COUNT not `nil' or 1, it moves forward COUNT-1
  50.      lines and then to the beginning of the line.
  51.      If this function reaches the end of the buffer (or of the
  52.      accessible portion, if narrowing is in effect), it positions point
  53.      at the beginning of the last line.  No error is signaled.
  54.  -- Command: end-of-line &optional COUNT
  55.      This function moves point to the end of the current line.  With an
  56.      argument COUNT not `nil' or 1, it moves forward COUNT-1 lines and
  57.      then to the end of the line.
  58.      If this function reaches the end of the buffer (or of the
  59.      accessible portion, if narrowing is in effect), it positions point
  60.      at the end of the last line.  No error is signaled.
  61.  -- Command: forward-line &optional COUNT
  62.      This function moves point forward COUNT lines, to the beginning of
  63.      the line.  If COUNT is negative, it moves point -COUNT lines
  64.      backward, to the beginning of the line.
  65.      If the beginning or end of the buffer (or of the accessible
  66.      portion) is encountered before that many lines are found, then
  67.      point stops at the beginning or end.  No error is signaled.
  68.      `forward-line' returns the difference between COUNT and the number
  69.      of lines actually moved.  If you attempt to move down five lines
  70.      from the beginning of a buffer that has only three lines, point
  71.      will positioned at the end of the last line, and the value will be
  72.      2.
  73.      In an interactive call, COUNT is the numeric prefix argument.
  74.  -- Function: count-lines START END
  75.      This function returns the number of lines between the positions
  76.      START and END in the current buffer.  If START and END are equal,
  77.      then it returns 0.  Otherwise it returns at least 1, even if START
  78.      and END are on the same line.  This is because the text between
  79.      them, considered in isolation, must contain at least one line
  80.      unless it is empty.
  81.      Here is an example of using `count-lines':
  82.           (defun current-line ()
  83.             "Return the vertical position of point in the selected window.
  84.           Top line is 0.  Counts each text line only once, even if it wraps."
  85.             (+ (count-lines (window-start) (point))
  86.                (if (= (current-column) 0) 1 0)
  87.                -1))
  88.    Also see the functions `bolp' and `eolp' in *Note Near Point::.
  89. These functions do not move point, but test whether it is already at the
  90. beginning or end of a line.
  91. File: elisp,  Node: Screen Lines,  Next: Vertical Motion,  Prev: Text Lines,  Up: Motion
  92. Motion by Screen Lines
  93. ----------------------
  94.    The line functions in the previous section count text lines,
  95. delimited only by newline characters.  By contrast, these functions
  96. count screen lines, which are defined by the way the text appears on
  97. the screen.  A text line is a single screen line if it is short enough
  98. to fit the width of the selected window, but otherwise it may occupy
  99. several screen lines.
  100.    In some cases, text lines are truncated on the screen rather than
  101. continued onto additional screen lines.  Then `vertical-motion' moves
  102. point just like `forward-line'.  *Note Truncation::.
  103.    Because the width of a given string depends on the flags which
  104. control the appearance of certain characters, `vertical-motion' will
  105. behave differently on a given piece of text found in different buffers.
  106.  It will even act differently in different windows showing the same
  107. buffer, because the width may differ and so may the truncation flag.
  108. *Note Control Char Display::.
  109.  -- Function: vertical-motion COUNT
  110.      This function moves point to the start of the screen line COUNT
  111.      screen lines down from the screen line containing point.  If COUNT
  112.      is negative, it moves up instead.
  113.      This function returns the number of lines moved.  The value may be
  114.      less in absolute value than COUNT if the beginning or end of the
  115.      buffer was reached.
  116.  -- Command: move-to-window-line COUNT
  117.      This function moves point with respect to the text currently
  118.      displayed in the selected window.  Point is moved to the beginning
  119.      of the screen line COUNT screen lines from the top of the window. 
  120.      If COUNT is negative, point moves either to the beginning of the
  121.      line -COUNT lines from the bottom or else to the last line of the
  122.      buffer if the buffer ends above the specified screen position.
  123.      If COUNT is `nil', then point moves to the beginning of the line
  124.      in the middle of the window.  If the absolute value of COUNT is
  125.      greater than the size of the window, then point moves to the place
  126.      which would appear on that screen line if the window were tall
  127.      enough. This will probably cause the next redisplay to scroll to
  128.      bring that location onto the screen.
  129.      In an interactive call, COUNT is the numeric prefix argument.
  130.      The value returned is the window line number, with the top line in
  131.      the window numbered 0.
  132. File: elisp,  Node: Vertical Motion,  Next: List Motion,  Prev: Screen Lines,  Up: Motion
  133. The User-Level Vertical Motion Commands
  134. ---------------------------------------
  135.    A goal column is useful if you want to edit text such as a table in
  136. which you want to move point to a certain column on each line.  The goal
  137. column affects the vertical text line motion commands, `next-line' and
  138. `previous-line'.  *Note Basic Editing Commands: (emacs)Basic.
  139.  -- User Option: goal-column
  140.      This variable holds an explicitly specified goal column for
  141.      vertical line motion commands.  If it is an integer, it specifies
  142.      a column, and these commands try to move to that column on each
  143.      line.  If it is `nil', then the commands set their own goal
  144.      columns.  Any other value is invalid.
  145.  -- Variable: temporary-goal-column
  146.      This variable holds the temporary goal column during a sequence of
  147.      consecutive vertical line motion commands.  It is overridden by
  148.      `goal-column' if that is non-`nil'.  It is set each time a
  149.      vertical motion command is invoked, unless the previous command
  150.      was also a vertical motion command.
  151.  -- User Option: track-eol
  152.      This variable controls how the vertical line motion commands
  153.      operate when starting at the end of a line.  If `track-eol' is
  154.      non-`nil', then vertical motion starting at the end of a line will
  155.      keep to the ends of lines.  This means moving to the end of each
  156.      line moved onto.  The value of `track-eol' has no effect if point
  157.      is not at the end of a line when the first vertical motion command
  158.      is given.
  159.      `track-eol' has its effect by causing `temporary-goal-column' to
  160.      be set to 9999 instead of to the current column.
  161.  -- Command: set-goal-column UNSET
  162.      This command sets the variable `goal-column' to specify a permanent
  163.      goal column for the vertical line motion commands.  If UNSET is
  164.      `nil', then `goal-column' is set to the current column of point. 
  165.      If UNSET is non-`nil', then `goal-column' is set to `nil'.
  166.      This function is intended for interactive use; and in an
  167.      interactive call, UNSET is the raw prefix argument.
  168. File: elisp,  Node: List Motion,  Next: Skipping Characters,  Prev: Vertical Motion,  Up: Motion
  169. Moving over Lists and Other Balanced Expressions
  170. ------------------------------------------------
  171.    Here are several functions concerned with balanced-parenthesis
  172. expressions (also called "sexps" in connection with moving across them
  173. in Emacs).  The syntax table controls how these functions interpret
  174. various characters; see *Note Syntax Tables::.  *Note Parsing
  175. Expressions::, for lower-level primitives for scanning sexps or parts of
  176. sexps.  For user-level commands, see *Note Lists and Sexps:
  177. (emacs)Lists and Sexps.
  178.  -- Command: forward-list ARG
  179.      Move forward across ARG balanced groups of parentheses. (Other
  180.      syntatic entities such as words or paired string quotes are
  181.      ignored.)
  182.  -- Command: backward-list ARG
  183.      Move backward across ARG balanced groups of parentheses. (Other
  184.      syntatic entities such as words or paired string quotes are
  185.      ignored.)
  186.  -- Command: up-list ARG
  187.      Move forward out of ARG levels of parentheses. A negative argument
  188.      means move backward but still to a less deep spot.
  189.  -- Command: down-list ARG
  190.      Move forward down ARG levels of parentheses.  A negative argument
  191.      means move backward but still go down ARG level.
  192.  -- Command: forward-sexp ARG
  193.      Move forward across ARG balanced expressions. Balanced expressions
  194.      include both those delimited by parentheses and other kinds, such
  195.      as words and string constants.  For example,
  196.           ---------- Buffer: foo ----------
  197.           (concat-!- "foo " (car x) y z)
  198.           ---------- Buffer: foo ----------
  199.           
  200.           (forward-sexp 3)
  201.                => nil
  202.           
  203.           ---------- Buffer: foo ----------
  204.           (concat "foo " (car x) y-!- z)
  205.           ---------- Buffer: foo ----------
  206.  -- Command: backward-sexp ARG
  207.      Move backward across ARG balanced expressions.
  208. File: elisp,  Node: Skipping Characters,  Prev: List Motion,  Up: Motion
  209. Skipping Characters
  210. -------------------
  211.    The following two functions move point over a specified set of
  212. characters.  For example, they are often used to skip whitespace.
  213.  -- Function: skip-chars-forward CHARACTER-SET &optional LIMIT
  214.      This function moves point in the current buffer forward, skipping
  215.      over a given set of characters.  Emacs first examines the
  216.      character following point; if it matches CHARACTER-SET, then point
  217.      is advanced and the next character is examined.  This continues
  218.      until a character is found that does not match.  The function
  219.      returns `nil'.
  220.      The argument CHARACTER-SET is like the inside of a `[...]' in a
  221.      regular expression except that `]' is never special and `\' quotes
  222.      `^', `-' or `\'.  Thus, `"a-zA-Z"' skips over all letters,
  223.      stopping before the first nonletter, and `"^a-zA-Z'" skips
  224.      nonletters stopping before the first letter.  *Note Regular
  225.      Expressions::.
  226.      If LIMIT is supplied (it must be a number or a marker), it
  227.      specifies the maximum position in the buffer that point can be
  228.      skipped to.  Point will stop at or before LIMIT.
  229.      In the following example, point is initially located directly
  230.      before the `T'.  After the form is evaluated, point is located at
  231.      the end of that line (between the `t' of `hat' and the newline). 
  232.      The function skips all letters and spaces, but not newlines.
  233.           ---------- Buffer: foo ----------
  234.           I read "-!-The cat in the hat
  235.           comes back" twice.
  236.           ---------- Buffer: foo ----------
  237.           
  238.           (skip-chars-forward "a-zA-Z ")
  239.                => nil
  240.           
  241.           ---------- Buffer: foo ----------
  242.           I read "The cat in the hat-!-
  243.           comes back" twice.
  244.           ---------- Buffer: foo ----------
  245.  -- Function: skip-chars-backward CHARACTER-SET &optional LIMIT
  246.      This function moves point backward, skipping characters that match
  247.      CHARACTER-SET.  It just like `skip-chars-forward' except for the
  248.      direction of motion.
  249. File: elisp,  Node: Excursions,  Next: Narrowing,  Prev: Motion,  Up: Positions
  250. Excursions
  251. ==========
  252.    It is often useful to move point "temporarily" within a localized
  253. portion of the program, or to switch buffers temporarily.  This is
  254. called an "excursion", and it is done with the `save-excursion' special
  255. form.  This construct saves the current buffer and its values of point
  256. and the mark so they can be restored after the completion of the
  257. excursion.
  258.    The forms for saving and restoring the configuration of windows are
  259. described elsewhere (*note Window Configurations::.).
  260.  -- Special Form: save-excursion FORMS...
  261.      The `save-excursion' special form saves the identity of the current
  262.      buffer and the values of point and the mark in it, evaluates FORMS,
  263.      and finally restores the buffer and its saved values of point and
  264.      the mark. All three saved values are restored even in case of an
  265.      abnormal exit via throw or error (*note Nonlocal Exits::.).
  266.      The `save-excursion' special form is the standard way to switch
  267.      buffers or move point within one part of a program and avoid
  268.      affecting the rest of the program.  It is used more than 500 times
  269.      in the Lisp sources of Emacs.
  270.      The values of point and the mark for other buffers are not saved by
  271.      `save-excursion', so any changes made to point and the mark in the
  272.      other buffers will remain in effect after `save-excursion' exits.
  273.      Likewise, `save-excursion' does not restore window-buffer
  274.      correspondences altered by functions such as `switch-to-buffer'.
  275.      One way to restore these correspondences, and the selected window,
  276.      is to use `save-window-excursion' inside `save-excursion' (*note
  277.      Window Configurations::.).
  278.      The value returned by `save-excursion' is the result of the last of
  279.      FORMS, or `nil' if no FORMS are given.
  280.           (save-excursion
  281.             FORMS)
  282.           ==
  283.           (let ((old-buf (current-buffer))
  284.                 (old-pnt (point-marker))
  285.                 (old-mark (copy-marker (mark-marker))))
  286.             (unwind-protect
  287.                 (progn FORMS)
  288.               (set-buffer old-buf)
  289.               (goto-char old-pnt)
  290.               (set-marker (mark-marker) old-mark)))
  291. File: elisp,  Node: Narrowing,  Prev: Excursions,  Up: Positions
  292. Narrowing
  293. =========
  294.    "Narrowing" means limiting the text addressable by Emacs editing
  295. commands to a limited range of characters in a buffer.  The text that
  296. remains addressable is called the "accessible portion" of the buffer.
  297.    Narrowing is specified with two buffer positions which become the
  298. beginning and end of the accessible portion.  For most editing commands
  299. these positions replace the values of the beginning and end of the
  300. buffer.  While narrowing is in effect, no text outside the accessible
  301. portion is displayed, and point cannot move outside the accessible
  302. portion.
  303.    Values such as positions or line numbers which usually count from the
  304. beginning of the buffer continue to do so, but the functions which use
  305. them will refuse to operate on text that is inaccessible.
  306.    The commands for saving buffers are unaffected by narrowing; the
  307. entire buffer is saved regardless of the any narrowing.
  308.  -- Command: narrow-to-region START END
  309.      This function sets the accessible portion of the current buffer to
  310.      start at START and end at END.  Both arguments should be character
  311.      positions.
  312.      In an interactive call, START and END are set to the bounds of the
  313.      current region (point and the mark, with the smallest first).
  314.  -- Command: narrow-to-page MOVE-COUNT
  315.      This function sets the accessible portion of the current buffer to
  316.      include just the current page.  An optional first argument
  317.      MOVE-COUNT non-`nil' means to move forward or backward by
  318.      MOVE-COUNT pages and then narrow.
  319.      In an interactive call, MOVE-COUNT is set to the numeric prefix
  320.      argument.
  321.  -- Command: widen
  322.      This function cancels any narrowing in the current buffer, so that
  323.      the entire contents are accessible.  This is called "widening". It
  324.      is equivalent to the following expression:
  325.           (narrow-to-region 1 (1+ (buffer-size)))
  326.  -- Special Form: save-restriction FORMS...
  327.      This special form saves the current bounds of the accessible
  328.      portion, evaluates FORMS, and finally restores the saved bounds,
  329.      thus restoring the same state of narrowing (or absence thereof)
  330.      formerly in effect.  The state of narrowing is restored even in
  331.      the event of an abnormal exit via throw or error (*note Nonlocal
  332.      Exits::.).  Therefore, this construct is a clean way to narrow a
  333.      buffer temporarily.
  334.      The value returned by `save-restriction' is that returned by the
  335.      last of FORMS, or `nil' if no forms were given.
  336.      *Note:* it is easy to make a mistake when using
  337.      `save-restriction'.  Read the entire description here before you
  338.      try it.
  339.      Point and the mark are *not* restored by this special form; use
  340.      `save-excursion' for that.  If you use both `save-restriction' and
  341.      `save-excursion' together, `save-excursion' should come first (on
  342.      the outside).  Otherwise, the old point value would be restored
  343.      with temporary narrowing still in effect.  If the old point value
  344.      were outside the limits of the temporary narrowing, this would
  345.      fail to restore it accurately.
  346.      The `save-restriction' special form records the values of the
  347.      beginning and end of the accessible portion as distances from the
  348.      beginning and end of the buffer.  In other words, it records the
  349.      amount of inaccessible text before and after the accessible
  350.      portion.
  351.      This technique yields correct results if the body of the form does
  352.      further narrowing.  However, `save-restriction' can become confused
  353.      if the body widens and then makes changes outside the area of the
  354.      saved narrowing.  When this is what you want to do,
  355.      `save-restriction' is not the right tool for the job.  Here is
  356.      what you must do instead:
  357.           (let ((beg (point-min-marker))
  358.                 (end (point-max-marker)))
  359.             (unwind-protect
  360.                 (progn BODY)
  361.               (narrow-to-region beg end)))
  362.      Here is a simple example of correct use of `save-restriction':
  363.           ---------- Buffer: foo ----------
  364.           This is the contents of foo
  365.           This is the contents of foo
  366.           This is the contents of foo-!-
  367.           ---------- Buffer: foo ----------
  368.           
  369.           (save-excursion
  370.             (save-restriction
  371.               (goto-char 1)
  372.               (forward-line 2)
  373.               (narrow-to-region 1 (point))
  374.               (goto-char (point-min))
  375.               (replace-string "foo" "bar")))
  376.           
  377.           ---------- Buffer: foo ----------
  378.           This is the contents of bar
  379.           This is the contents of bar
  380.           This is the contents of foo-!-
  381.           ---------- Buffer: foo ----------
  382. File: elisp,  Node: Markers,  Next: Text,  Prev: Positions,  Up: Top
  383. Markers
  384. *******
  385.    A "marker" is a Lisp object used to specify a position in a buffer
  386. relative to the surrounding text.  A marker changes its offset from the
  387. beginning of the buffer automatically whenever text is inserted or
  388. deleted, so that it stays with the two characters on either side of it.
  389. * Menu:
  390. * Overview of Markers::      The components of a marker, and how it relocates.
  391. * Predicates on Markers::    Testing whether an object is a marker.
  392. * Creating Markers::         Making empty markers or markers at certain places.
  393. * Information from Markers:: Finding the marker's buffer or character position.
  394. * Changing Markers::         Moving the marker to a new buffer or position.
  395. * The Mark::                 How "the mark" is implemented with a marker.
  396. * The Region::               How to access "the region".
  397. File: elisp,  Node: Overview of Markers,  Next: Predicates on Markers,  Prev: Markers,  Up: Markers
  398. Overview of Markers
  399. ===================
  400.    A marker specifies a buffer and a position in that buffer.  The
  401. marker can be used to represent a position in the functions that
  402. require one, just as an integer could be used.  *Note Positions::, for
  403. a complete description of positions.
  404.    A marker has two attributes: the marker position, and the marker
  405. buffer.  The marker position is an integer which is equivalent (at the
  406. moment) to the marker as a position in that buffer; however, as text is
  407. inserted or deleted in the buffer, the marker is relocated, so that its
  408. integer equivalent changes.  The idea is that a marker positioned
  409. between two characters in a buffer will remain between those two
  410. characters despite any changes made to the contents of the buffer; thus,
  411. a marker's offset from the beginning of a buffer may change often during
  412. the life of the marker.
  413.    If the text around a marker is deleted, the marker is repositioned
  414. between the characters immediately before and after the deleted text. 
  415. If text is inserted at the position of a marker, the marker remains in
  416. front of the new text unless it is inserted with `insert-before-markers'
  417. (*note Insertion::.).  When text is inserted or deleted somewhere
  418. before the marker position (not next to the marker), the marker moves
  419. back and forth with the two neighboring characters.
  420.    When a buffer is modified, all of its markers must be checked so that
  421. they can be relocated if necessary.  This slows processing in a buffer
  422. with a large number of markers.  For this reason, it is a good idea to
  423. make a marker point nowhere if you are sure you don't need it any more.
  424. Unreferenced markers will eventually be garbage collected, but until
  425. then will continue to be updated if they do point somewhere.
  426.    Because it is quite common to perform arithmetic operations on a
  427. marker position, most of the arithmetic operations (including `+' and
  428. `-') accept markers as arguments.  In such cases, the current position
  429. of the marker is used.
  430.    Here are examples of creating markers, setting markers, and moving
  431. point to markers:
  432.      ;; Make a new marker that initially does not point anywhere:
  433.      (setq m1 (make-marker))
  434.           => #<marker in no buffer>
  435.      
  436.      ;; Set `m1' to point between the 100th and 101st characters.
  437.      ;; in the current buffer:
  438.      (set-marker m1 100)
  439.           => #<marker at 100 in markers.texi>
  440.      
  441.      ;; Now insert one character at the beginning of the buffer:
  442.      (goto-char (point-min))
  443.           => 1
  444.      (insert "Q")
  445.           => nil
  446.      
  447.      ;; `m1' is updated appropriately.
  448.      m1
  449.           => #<marker at 101 in markers.texi>
  450.      
  451.      ;; Two markers that point to the same position
  452.      ;; are not `eq', but they are `equal'.
  453.      (setq m2 (copy-marker m1))
  454.           => #<marker at 101 in markers.texi>
  455.      (eq m1 m2)
  456.           => nil
  457.      (equal m1 m2)
  458.           => t
  459.      
  460.      ;; When you are finished using a marker, make it point nowhere.
  461.      (set-marker m1 nil)
  462.           => #<marker in no buffer>
  463. File: elisp,  Node: Predicates on Markers,  Next: Creating Markers,  Prev: Overview of Markers,  Up: Markers
  464. Predicates on Markers
  465. =====================
  466.    You can test an object to see whether it is a marker, or whether it
  467. is either an integer or a marker.  The latter test is useful when you
  468. are using the arithmetic functions that work with both markers and
  469. integers.
  470.  -- Function: markerp OBJECT
  471.      This function returns `t' if OBJECT is a marker, `nil' otherwise. 
  472.      In particular, integers are not markers, even though many
  473.      functions will accept either a marker or an integer.
  474.  -- Function: integer-or-marker-p OBJECT
  475.      This function returns `t' if OBJECT is an integer or a marker,
  476.      `nil' otherwise.
  477. File: elisp,  Node: Creating Markers,  Next: Information from Markers,  Prev: Predicates on Markers,  Up: Markers
  478. Functions That Create Markers
  479. =============================
  480.    When you create a new marker, you can make it point nowhere, or point
  481. to the present position of point, or to the beginning or end of the
  482. accessible portion of the buffer, or to the same place as another given
  483. marker.
  484.  -- Function: make-marker
  485.      This functions returns a newly allocated marker that does not point
  486.      anywhere.
  487.           (make-marker)
  488.                => #<marker in no buffer>
  489.  -- Function: point-marker
  490.      This function returns a new marker that points to the present
  491.      position of point in the current buffer.  *Note Point::.  For an
  492.      example, see `copy-marker', below.
  493.  -- Function: point-min-marker
  494.      This function returns a new marker that points to the beginning of
  495.      the accessible portion of the buffer.  This will be the beginning
  496.      of the buffer unless narrowing is in effect.  *Note Narrowing::.
  497.  -- Function: point-max-marker
  498.      This function returns a new marker that points to the end of the
  499.      accessible portion of the buffer.  This will be the end of the
  500.      buffer unless narrowing is in effect.  *Note Narrowing::.
  501.      Here are examples of this function and `point-min-marker', shown in
  502.      a buffer containing a version of the source file for the text of
  503.      this chapter.
  504.           (point-min-marker)
  505.                => #<marker at 1 in markers.texi>
  506.           (point-max-marker)
  507.                => #<marker at 15573 in markers.texi>
  508.           
  509.           (narrow-to-region 100 200)
  510.                => nil
  511.           (point-min-marker)
  512.                => #<marker at 100 in markers.texi>
  513.           (point-max-marker)
  514.                => #<marker at 200 in markers.texi>
  515.  -- Function: copy-marker MARKER-OR-INTEGER
  516.      If passed a marker as its argument, `copy-marker' returns a new
  517.      marker that points to the same place and the same buffer as does
  518.      MARKER-OR-INTEGER.  If passed an integer as its argument,
  519.      `copy-marker' returns a new marker that points to position
  520.      MARKER-OR-INTEGER in the current buffer.
  521.      If passed an argument that is an integer whose value is less than
  522.      1, `copy-marker' returns a new marker that points to the beginning
  523.      of the current buffer.  If passed an argument that is an integer
  524.      whose value is greater than the length of the buffer, then
  525.      `copy-marker' returns a new marker that points to the end of the
  526.      buffer.
  527.      An error is signaled if MARKER is neither a marker nor an integer.
  528.           (setq p (point-marker))
  529.                => #<marker at 2139 in markers.texi>
  530.           
  531.           (setq q (copy-marker p))
  532.                => #<marker at 2139 in markers.texi>
  533.           
  534.           (eq p q)
  535.                => nil
  536.           
  537.           (equal p q)
  538.                => t
  539.           
  540.           (copy-marker 0)
  541.                => #<marker at 1 in markers.texi>
  542.           
  543.           (copy-marker 20000)
  544.                => #<marker at 7572 in markers.texi>
  545. File: elisp,  Node: Information from Markers,  Next: Changing Markers,  Prev: Creating Markers,  Up: Markers
  546. Information from Markers
  547. ========================
  548.    This section describes the functions for accessing the components of
  549. a marker object.
  550.  -- Function: marker-position MARKER
  551.      This function returns the position that MARKER points to, or `nil'
  552.      if it points nowhere.
  553.  -- Function: marker-buffer MARKER
  554.      This function returns the buffer that MARKER points into, or `nil'
  555.      if it points nowhere.
  556.           (setq m (make-marker))
  557.                => #<marker in no buffer>
  558.           (marker-position m)
  559.                => nil
  560.           (marker-buffer m)
  561.                => nil
  562.           
  563.           (set-marker m 3770 (current-buffer))
  564.                => #<marker at 3770 in markers.texi>
  565.           (marker-buffer m)
  566.                => #<buffer markers.texi>
  567.           (marker-position m)
  568.                => 3770
  569.    Two distinct markers will be found `equal' (even though not `eq') to
  570. each other if they have the same position and buffer, or if they both
  571. point nowhere.
  572. File: elisp,  Node: Changing Markers,  Next: The Mark,  Prev: Information from Markers,  Up: Markers
  573. Changing Markers
  574. ================
  575.    This section describes how to change the position of an existing
  576. marker.  When you do this, be sure you know whether the marker is used
  577. outside of your program, and, if so, what effects will result from
  578. moving it--otherwise, confusing things may happen in other parts of
  579. Emacs.
  580.  -- Function: set-marker MARKER POSITION &optional BUFFER
  581.      This function moves MARKER to POSITION in BUFFER.  If BUFFER is
  582.      not provided, it defaults to the current buffer.
  583.      If POSITION is less than 1, `set-marker' moves marker to the
  584.      beginning of the buffer.  If the value of POSITION is greater than
  585.      the size of the buffer, `set-marker' moves marker to the end of
  586.      the buffer.  If POSITION is `nil' or a marker that points nowhere,
  587.      then MARKER is set to point nowhere.
  588.      The value returned is MARKER.
  589.           (setq m (point-marker))
  590.                => #<marker at 4714 in markers.texi>
  591.           (set-marker m 55)
  592.                => #<marker at 55 in markers.texi>
  593.           (setq b (get-buffer "foo"))
  594.                => #<buffer foo>
  595.           (set-marker m 0 b)
  596.                => #<marker at 1 in foo>
  597.  -- Function: move-marker MARKER POSITION &optional BUFFER
  598.      This is another name for `set-marker'.
  599. File: elisp,  Node: The Mark,  Next: The Region,  Prev: Changing Markers,  Up: Markers
  600. The Mark
  601. ========
  602.    A special marker in each buffer is designated "the mark".  It
  603. records a position for the user for the sake of commands such as `C-w'
  604. and `C-x TAB'.  Lisp programs should set the mark only to values that
  605. have a potential use to the user, and never for their own internal
  606. purposes.  For example, the `replace-regexp' command sets the mark to
  607. the value of point before doing any replacements, because this enables
  608. the user to move back there conveniently after the replace is finished.
  609.    Many commands are designed so that when called interactively they
  610. operate on the text between point and the mark.  If you are writing such
  611. a command, don't examine the mark directly; instead, use `interactive'
  612. with the `r' specification.  This will provide the values of point and
  613. the mark as arguments to the command in an interactive call, but will
  614. permit other Lisp programs to specify arguments explicitly.  *Note
  615. Interactive Codes::.
  616.    Each buffer has its own value of the mark that is independent of the
  617. value of the mark in other buffers.  When a buffer is created, the mark
  618. exists but does not point anywhere.  We consider this state as "the
  619. absence of a mark in that buffer".
  620.    In addition to the mark, each buffer has a "mark ring" which is a
  621. list of markers that are the previous values of the mark.  When editing
  622. commands change the mark, they should normally save the old value of the
  623. mark on the mark ring.  The mark ring may contain no more than the
  624. maximum number of entries specified by the variable `mark-ring-max';
  625. excess entries are discarded on a first-in-first-out basis.
  626.  -- Function: mark
  627.      This function returns the position of the current buffer's mark as
  628.      an integer.  `nil' is returned if the mark is not yet set for this
  629.      buffer.
  630.  -- Function: mark-marker
  631.      This function returns the current buffer's mark.  This the very
  632.      marker which records the mark location inside Emacs, not a copy. 
  633.      Therefore, changing this marker's position will directly affect
  634.      the position of the mark. Don't do it unless that is the effect
  635.      you want.
  636.           (setq m (mark-marker))
  637.                => #<marker at 3420 in markers.texi>
  638.           (set-marker m 100)
  639.                => #<marker at 100 in markers.texi>
  640.           (mark-marker)
  641.                => #<marker at 100 in markers.texi>
  642.      Like any marker, this marker can be set to point at any buffer you
  643.      like. We don't recommend that you make it point at any buffer
  644.      other than the one of which it is the mark.  If you do, it will
  645.      yield perfectly consistent, if rather odd, results.
  646.  -- Command: set-mark-command JUMP
  647.      If JUMP is `nil', this command sets the mark to the value of point
  648.      and pushes the previous value of the mark on the mark ring.  The
  649.      message `Mark set' is also displayed in the echo area.
  650.      If JUMP is not `nil', this command sets point to the value of the
  651.      mark, and sets the mark to the previous saved mark value, which is
  652.      popped off the mark ring.
  653.      This function is *only* intended for interactive use.
  654.  -- Function: set-mark POSITION
  655.      This function sets the mark to POSITION. The old value of the mark
  656.      is *not* pushed onto the mark ring.
  657.      *Note:* use this function only if you want the user to see that
  658.      the mark has moved, and you want the previous mark position to be
  659.      lost. Normally, when a new mark is set, the old one should go on
  660.      the `mark-ring', which is why most applications should use
  661.      `push-mark' and `pop-mark', not `set-mark'.
  662.      Novice Emacs Lisp programmers often try to use the mark for the
  663.      wrong purposes.  The mark saves a location for the user's
  664.      convenience.  An editing command should not alter the mark unless
  665.      altering the mark is part of the user-level functionality of the
  666.      command.  (And, in that case, this effect should be documented.) 
  667.      To remember a location for internal use in the Lisp program, store
  668.      it in a Lisp variable.  For example:
  669.              (let ((beg (point)))
  670.                 (forward-line 1)
  671.                 (delete-region beg (point))).
  672.  -- Variable: mark-ring
  673.      The value of this buffer-local variable is the list of saved former
  674.      marks of the current buffer, most recent first.
  675.           mark-ring
  676.           => (#<marker at 11050 in markers.texi>
  677.               #<marker at 10832 in markers.texi>
  678.               ...)
  679.  -- User Option: mark-ring-max
  680.      The value of this variable is the maximum size of `mark-ring'. If
  681.      more marks than this are pushed onto the `mark-ring', it discards
  682.      marks on a first-in, first-out basis.
  683.  -- Function: push-mark &optional POSITION NOMSG
  684.      This function sets the current buffer's mark to POSITION, and
  685.      pushes a copy of the previous mark onto `mark-ring'.  If POSITION
  686.      is `nil', then the value of point is used. `push-mark' returns
  687.      `nil'.
  688.      A `Mark set' message is displayed unless NOMSG is non-`nil'.
  689.  -- Function: pop-mark
  690.      This function pops off the top element of `mark-ring' and makes
  691.      that mark become the buffer's actual mark.  This does not change
  692.      the buffer's point and does nothing if `mark-ring' is empty.
  693.      The return value is not useful.
  694. File: elisp,  Node: The Region,  Prev: The Mark,  Up: Markers
  695. The Region
  696. ==========
  697.    The text between point and the mark is known as "the region".
  698. Various functions operate on text delimited by point and the mark, but
  699. only those functions specifically related to the region itself are
  700. described here.
  701.  -- Function: region-beginning
  702.      This function returns the position of the beginning of the region
  703.      (as an integer).  This is the position of either point or the mark,
  704.      whichever is smaller.
  705.      If the mark does not point anywhere, an error is signaled.
  706.  -- Function: region-end
  707.      This function returns the position of the end of the region (as an
  708.      integer).  This is the position of either point or the mark,
  709.      whichever is larger.
  710.      If the mark does not point anywhere, an error is signaled.
  711.    Few programs need to use the `region-beginning' and `region-end'
  712. functions.  A command designed to operate on a region should instead
  713. use `interactive' with the `r' specification, so that the same function
  714. can be called with explicit bounds arguments from programs.  (*Note
  715. Interactive Codes::.)
  716. File: elisp,  Node: Text,  Next: Searching and Matching,  Prev: Markers,  Up: Top
  717.    This chapter describes the functions that deal with the text in a
  718. buffer.  Most examine, insert or delete text in the current buffer,
  719. often in the vicinity of point.  Many are interactive.  All the
  720. functions that change the text provide for undoing the changes (*note
  721. Undo::.).
  722.    Many text-related functions operate on a region of text defined by
  723. two buffer positions passed in arguments named START and END. These
  724. arguments should be either markers (*note Markers::.) or or numeric
  725. character positions (*note Positions::.).  The order of these arguments
  726. does not matter; it is all right for START to be the end of the region
  727. and END the beginning.  For example, `(delete-region 1 10)' and
  728. `(delete-region 10 1)' perform identically.  An `args-out-of-range'
  729. error is signaled if either START or END is outside the accessible
  730. portion of the buffer.  In an interactive call, point and the mark are
  731. used for these arguments.
  732.    Throughout this chapter, "text" refers to the characters in the
  733. buffer.
  734. * Menu:
  735. * Near Point::       Examining text in the vicinity of point.
  736. * Buffer Contents::  Examining text in a general fashion.
  737. * Insertion::        Adding new text to a buffer.
  738. * Commands for Insertion::  User-level commands to insert text.
  739. * Deletion::         Removing text from a buffer.
  740. * User-Level Deletion::     User-level commands to delete text.
  741. * The Kill Ring::    Where removed text sometimes is saved for later use.
  742. * Undo::             Undoing changes to the text of a buffer.
  743. * Auto Filling::     How auto-fill mode is implemented to break lines.
  744. * Filling::          Functions for explicit filling.
  745. * Sorting::          Functions for sorting parts of the buffer.
  746. * Indentation::      Functions to insert or adjust indentation.
  747. * Columns::          Computing horizontal positions, and using them.
  748. * Case Changes::     Case conversion of parts of the buffer.
  749. * Substitution::     Replacing a given character wherever it appears.
  750. * Underlining::      Inserting or deleting underlining-by-overstrike.
  751. * Registers::        How registers are implemented.  Accessing the text or
  752.                        position stored in a register.
  753. File: elisp,  Node: Near Point,  Next: Buffer Contents,  Prev: Text,  Up: Text
  754. Examining Text Near Point
  755. =========================
  756.    Many functions are provided to look at the characters around point.
  757. Several simple functions are described here.  See also `looking-at' in
  758. *Note Searching and Matching::.
  759.  -- Function: char-after POSITION
  760.      This function returns the character in the current buffer at (i.e.,
  761.      immediately after) position POSITION.  If POSITION is out of range
  762.      for this purpose, either before the beginning of the buffer, or at
  763.      or beyond the end, than the value is `nil'.
  764.      Remember that point is always between characters, and the terminal
  765.      cursor normally appears over the character following point. 
  766.      Therefore, the character returned by `char-after' is the character
  767.      the cursor is over.
  768.      In the following example, assume that the first character in the
  769.      buffer is `@':
  770.           (char-to-string (char-after 1))
  771.                => "@"
  772.  -- Function: following-char
  773.      This function returns the character following point in the current
  774.      buffer.  This is similar to `(char-after (point))'.  However, point
  775.      is at the end of the buffer, then the result of `following-char' is
  776.      0.
  777.      In this example, point is between the `a' and the `c'.
  778.           ---------- Buffer: foo ----------
  779.           Gentlemen may cry ``Pea-!-ce! Peace!,'' but there is no peace.
  780.           ---------- Buffer: foo ----------
  781.           
  782.           (char-to-string (preceding-char))
  783.                => "a"
  784.           (char-to-string (following-char))
  785.                => "c"
  786.  -- Function: preceding-char
  787.      This function returns the character preceding point in the current
  788.      buffer.  See above, under `following-char', for an example.  If
  789.      point is at the beginning of the buffer, then the result of
  790.      `preceding-char' is 0.
  791.  -- Function: bobp
  792.      This function returns `t' if point is at the beginning of the
  793.      buffer.  If narrowing is in effect, this means the beginning of the
  794.      accessible portion of the text.  See also `point-min' in *Note
  795.      Point::.
  796.  -- Function: eobp
  797.      This function returns `t' if point is at the end of the buffer. If
  798.      narrowing is in effect, this means the end of accessible portion of
  799.      the text.  See also `point-max' in *Note Point::.
  800.  -- Function: bolp
  801.      This function returns `t' if point is at the beginning of a line.
  802.      *Note Text Lines::.
  803.  -- Function: eolp
  804.      This function returns `t' if point is at the end of a line. The
  805.      end of the buffer is always considered the end of a line.
  806. File: elisp,  Node: Buffer Contents,  Next: Insertion,  Prev: Near Point,  Up: Text
  807. Examining Buffer Contents
  808. =========================
  809.    This section describes two functions that allow a Lisp program to
  810. convert any portion of the text in the buffer into a string.
  811.  -- Function: buffer-substring START END
  812.      This function returns a string containing a copy of the text of the
  813.      region defined by positions START and END in the current buffer. 
  814.      If the arguments are not positions in the accessible portion of
  815.      the buffer, Emacs signals an `args-out-of-range' error.
  816.      It is not necessary for START to be less than END; the arguments
  817.      can be given in either order.  But most often the smaller argument
  818.      is written first.
  819.           ---------- Buffer: foo ----------
  820.           This is the contents of buffer foo
  821.           
  822.           ---------- Buffer: foo ----------
  823.           
  824.           (buffer-substring 1 10)
  825.           => "This is t"
  826.           (buffer-substring (point-max) 10)
  827.           => "he contents of buffer foo
  828.           "
  829.  -- Function: buffer-string
  830.      This function returns the contents of the accessible portion of the
  831.      current buffer as a string.  This is the portion between
  832.      `(point-min)' and `(point-max)' (*note Narrowing::.).
  833.           ---------- Buffer: foo ----------
  834.           This is the contents of buffer foo
  835.           
  836.           ---------- Buffer: foo ----------
  837.           
  838.           (buffer-string)
  839.                => "This is the contents of buffer foo
  840.           "
  841. File: elisp,  Node: Insertion,  Next: Commands for Insertion,  Prev: Buffer Contents,  Up: Text
  842. Insertion
  843. =========
  844.    Insertion takes place at point.  Markers pointing at positions after
  845. the insertion point are relocated with the surrounding text (*note
  846. Markers::.).  When a marker points at the place of insertion, it is
  847. normally not relocated, so that it points to the beginning of the
  848. inserted text; however, when `insert-before-markers' is used, all such
  849. markers are relocated to point after the inserted text.
  850.    Point may end up either before or after inserted text, depending on
  851. the function used.  If point is left after the inserted text, we speak
  852. of insertion "before point".
  853.    Each of these functions signals an error if the current buffer is
  854. read-only.
  855.  -- Function: insert &rest ARGS
  856.      This function inserts the strings and/or characters ARGS into the
  857.      current buffer, at point, moving point forward.  An error is
  858.      signaled unless all ARGS are either strings or characters.  The
  859.      value is `nil'.
  860.  -- Function: insert-before-markers &rest ARGS
  861.      This function inserts the strings and/or characters ARGS into the
  862.      current buffer, at point, moving point forward.  An error is
  863.      signaled unless all ARGS are either strings or characters.  The
  864.      value is `nil'.
  865.      This function is unlike the other insertion functions in that a
  866.      marker whose position initially equals point is relocated to come
  867.      after the newly inserted text.
  868.  -- Function: insert-char CHARACTER COUNT
  869.      This function inserts COUNT instances of CHARACTER into the
  870.      current buffer before point.  COUNT must be a number, and
  871.      CHARACTER must be a character.  The value is `nil'.
  872.  -- Function: insert-buffer-substring FROM-BUFFER-OR-NAME START END
  873.      This function inserts a substring of the contents of buffer
  874.      FROM-BUFFER-OR-NAME (which must already exist) into the current
  875.      buffer before point.  The text inserted consists of the characters
  876.      in the region defined by START and END.  The value is `nil'.
  877.      In this example, the form is executed with buffer `bar' as the
  878.      current buffer.  We assume that buffer `bar' is initially empty.
  879.           ---------- Buffer: foo ----------
  880.           We hold these truths to be self-evident, that all
  881.           ---------- Buffer: foo ----------
  882.           
  883.           (insert-buffer-substring "foo" 1 20)
  884.                => nil
  885.           
  886.           ---------- Buffer: bar ----------
  887.           We hold these truth
  888.           ---------- Buffer: bar ----------
  889. File: elisp,  Node: Commands for Insertion,  Next: Deletion,  Prev: Insertion,  Up: Text
  890. User-Level Insertion Commands
  891. =============================
  892.    This section describes higher-level commands for inserting text,
  893. commands intended primarily for the user but useful also in Lisp
  894. programs.
  895.  -- Command: insert-buffer FROM-BUFFER-OR-NAME
  896.      This function inserts the entire contents of FROM-BUFFER-OR-NAME
  897.      (which must exist) into the current buffer after point.  It leaves
  898.      the mark after the inserted text.  The value is unpredictable.
  899.  -- Command: quoted-insert COUNT
  900.      This function reads the next input character verbatim and inserts
  901.      it. It is primarily useful for inserting control characters.  You
  902.      may also type up to 3 octal digits, to insert a character with
  903.      that code.
  904.      The argument COUNT is the number of these characters to insert. An
  905.      error is signaled if COUNT is not a number.
  906.      This function is primarily for interactive use; there is no reason
  907.      to use it in a program except for installing it on a keymap.  It
  908.      returns `nil'.
  909.  -- Command: self-insert-command COUNT
  910.      This function inserts the last character typed COUNT times and
  911.      returns `nil'.  This is the function that most printing characters
  912.      are bound to.  In routine use, `self-insert-command' is the most
  913.      frequently called function in Emacs, but programs rarely use it
  914.      except to install it on a keymap.
  915.      In an interactive call, COUNT is the numeric prefix argument.
  916.      This function calls `auto-fill-hook' if the current column number
  917.      is greater than the value of `fill-column' and the character
  918.      inserted is a space (*note Auto Filling::.).
  919.      This function performs abbrev expansion if Abbrev mode (*note
  920.      Abbrevs::.) is enabled and the inserted character does not have
  921.      word-constituent syntax (*note Syntax Class Table::.).
  922.      This function is also responsible for calling the
  923.      `blink-paren-hook' when the inserted character has close
  924.      parenthesis syntax (*note Blinking::.).
  925.  -- Command: newline &optional NUMBER-OF-NEWLINES
  926.      This function inserts newlines into the current buffer before
  927.      point. If NUMBER-OF-NEWLINES is supplied, that many newline
  928.      characters are inserted.
  929.      In Auto Fill mode, `newline' can break the preceding line if
  930.      NUMBER-OF-NEWLINES is not supplied.  When this happens, it
  931.      actually inserts two newlines at different places: one at point,
  932.      and another earlier in the line.  `newline' does not auto-fill if
  933.      NUMBER-OF-NEWLINES is non-`nil'.
  934.      The value returned is `nil'.  In an interactive call, COUNT is the
  935.      numeric prefix argument.
  936.  -- Command: split-line
  937.      This function splits the current line, moving the portion of the
  938.      line after point down vertically, so that it is on the next line
  939.      directly below where it was before.  Whitespace is inserted as
  940.      needed at the beginning of the lower line, using the `indent-to'
  941.      function. `split-line' returns the position of point.
  942.      Programs hardly ever use this function.
  943.  -- Command: open-line COUNT
  944.      This function inserts COUNT newlines into the current buffer after
  945.      point, leaving point where it was.
  946.      In an interactive call, COUNT is the numeric prefix argument.
  947.      Programs hardly ever use this function.  The value is
  948.      unpredictable.
  949.  -- Command: overwrite-mode ARGUMENT
  950.      This function turns Overwrite mode on or off.  If ARGUMENT is
  951.      `nil' then the mode is toggled.  Otherwise, if ARGUMENT is a
  952.      positive number (greater than zero), then the mode is turned on;
  953.      any other argument turns it off.
  954.      When Overwrite mode is on, self-inserting graphic characters
  955.      replace existing text character for character, and do not push the
  956.      existing text to the right.
  957.      This function affects primarily `self-insert-command'.
  958.      In an interactive call, ARGUMENT is set to the raw prefix
  959.      argument.  The return value of `overwrite-mode' is unpredictable.
  960.  -- Variable: overwrite-mode
  961.      Overwrite mode is in effect when this variable is non-`nil'.  It is
  962.      automatically made buffer-local when set in any fashion.
  963.