home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i16 < prev    next >
Encoding:
GNU Info File  |  1993-06-14  |  47.9 KB  |  1,140 lines

  1. This is Info file elisp, produced by Makeinfo-1.47 from the input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual, for
  7. Emacs Version 18.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  10. Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28. 
  29. File: elisp,  Node: Deleting Windows,  Next: Selecting Windows,  Prev: Splitting Windows,  Up: Windows
  30.  
  31. Deleting Windows
  32. ================
  33.  
  34.    A "deleted window" no longer appears on the screen.  In Emacs
  35. version 18, the space it took up on the screen is divided
  36. proportionally among all siblings; in version 19, the space is given to
  37. one adjacent sibling.
  38.  
  39.  -- Command: delete-window &optional WINDOW
  40.      This function removes WINDOW from the display.  If WINDOW is
  41.      omitted, then the selected window is deleted.  An error is signaled
  42.      if there is only one window when `delete-window' is called.
  43.  
  44.           *Warning:* erroneous information or fatal errors may result
  45.           from using a deleted window.  Use `(window-point WINDOW)' to
  46.           test whether a window has been deleted; it yields `nil' for a
  47.           deleted window.
  48.  
  49.      This function returns `nil'.
  50.  
  51.      When `delete-window' is called interactively, WINDOW defaults to
  52.      the selected window.
  53.  
  54.  
  55.  -- Command: delete-other-windows &optional WINDOW
  56.      This function makes WINDOW the only window on the screen by
  57.      deleting all the other windows.  If WINDOW is omitted or `nil',
  58.      then the selected window is used by default.
  59.  
  60.      The result is `nil'.
  61.  
  62.  -- Command: delete-windows-on BUFFER
  63.      This function deletes all windows showing BUFFER.  If there are no
  64.      windows showing BUFFER, then this function does nothing.  If all
  65.      windows are showing BUFFER (including the case where there is only
  66.      one window), then the screen reverts to having a single window
  67.      showing the buffer chosen by `other-buffer'.  *Note The Buffer
  68.      List::.
  69.  
  70.      If there are several windows showing different buffers, then those
  71.      showing BUFFER are removed, and the others are expanded to fill the
  72.      void.
  73.  
  74.      The result is `nil'.
  75.  
  76. 
  77. File: elisp,  Node: Selecting Windows,  Next: Cyclic Window Ordering,  Prev: Deleting Windows,  Up: Windows
  78.  
  79. Selecting Windows
  80. =================
  81.  
  82.    When a window is selected, the buffer in the window becomes the
  83. current buffer, and the cursor will appear in it.
  84.  
  85.  -- Function: selected-window
  86.      This function returns the selected window.  This is the window in
  87.      which the cursor appears and to which many commands apply.
  88.  
  89.  -- Function: select-window WINDOW
  90.      This function makes WINDOW the selected window.  The cursor then
  91.      appears in WINDOW (on redisplay).  The buffer being displayed in
  92.      WINDOW is immediately designated the current buffer.
  93.  
  94.      The return value is WINDOW.
  95.  
  96.           (setq w (next-window))
  97.           (select-window w)
  98.                => #<window 65 on windows.texi>
  99.  
  100.    The following functions choose one of the windows on the screen,
  101. offering various criteria for the choice.
  102.  
  103.  -- Function: get-lru-window
  104.      This function returns the window least recently "used" (that is,
  105.      selected).  The selected window is always the most recently used
  106.      window.
  107.  
  108.      The selected window can be the least recently used window if it is
  109.      the only window.  A newly created window becomes the least
  110.      recently used window until it is selected.  The minibuffer window
  111.      is not considered a candidate.
  112.  
  113.  -- Function: get-largest-window
  114.      This function returns the window with the largest area (height
  115.      times width).  If there are no side-by-side windows, then this is
  116.      the window with the most lines.  The minibuffer window is not
  117.      considered a candidate.
  118.  
  119.      If there are two windows of the same size, then the function
  120.      returns the window which is first in the cyclic ordering of
  121.      windows (see following section), starting from the selected window.
  122.  
  123. 
  124. File: elisp,  Node: Cyclic Window Ordering,  Next: Buffers and Windows,  Prev: Selecting Windows,  Up: Windows
  125.  
  126. Cycling Ordering of Windows
  127. ===========================
  128.  
  129.    When you use the command `C-x o' (`other-window') to select the next
  130. window, it moves through all the windows on the screen in a specific
  131. cyclic order.  For any given configuration of windows, this order never
  132. varies.  It is called the "cyclic ordering of windows".
  133.  
  134.    This ordering generally goes from top to bottom, and from left to
  135. right.  But it may go down first or go right first, depending on the
  136. order in which the screen, or the windows within the screen, were split.
  137.  
  138.    If the screen was first split vertically (into windows one above each
  139. other), and then the subwindows were split horizontally, then the
  140. ordering is left to right in the top, and then left to right in the next
  141. lower part of the screen, and so on.  If the screen was first split
  142. horizontally, the ordering is top to bottom in the left part, and so on.
  143. In general, within each set of siblings at any level in the window tree,
  144. the order is left to right, or top to bottom.
  145.  
  146.  -- Function: next-window WINDOW &optional MINIBUF
  147.      This function returns the window following WINDOW in the cyclic
  148.      ordering of windows.  This is the window which `C-x o' would select
  149.      if done when WINDOW is selected.  If WINDOW is the only window
  150.      visible, then this function returns WINDOW.
  151.  
  152.      The value of the argument MINIBUF determines whether the
  153.      minibuffer is included in the window order.  Normally, when
  154.      MINIBUF is `nil', the minibuffer is included if it is currently
  155.      active; this is the behavior of `C-x o'.
  156.  
  157.      If MINIBUF is `t', then the cyclic ordering includes the
  158.      minibuffer window even if it is not active.  If MINIBUF is neither
  159.      `t' nor `nil', then the minibuffer window is not included even if
  160.      it is active.  (The minibuffer window is active while the
  161.      minibuffer is in use.  *Note Minibuffers::.)
  162.  
  163.      This example shows two windows, which both happen to be displaying
  164.      the same buffer:
  165.  
  166.           (selected-window)
  167.                => #<window 56 on windows.texi>
  168.           (next-window (selected-window))
  169.                => #<window 52 on windows.texi>
  170.           (next-window (next-window (selected-window)))
  171.                => #<window 56 on windows.texi>
  172.  
  173.  -- Function: previous-window WINDOW
  174.      This function returns the window preceding WINDOW in the cyclic
  175.      ordering of windows.
  176.  
  177.  -- Command: other-window COUNT
  178.      This function selects the COUNTth next window in the cyclic order.
  179.       If count is negative, then it selects the -COUNTth preceding
  180.      window.  It returns `nil'.
  181.  
  182.      In an interactive call, COUNT is the numeric prefix argument.
  183.  
  184. 
  185. File: elisp,  Node: Buffers and Windows,  Next: Displaying Buffers,  Prev: Cyclic Window Ordering,  Up: Windows
  186.  
  187. Buffers and Windows
  188. ===================
  189.  
  190.    This section describes low-level functions to examine windows or to
  191. show buffers in windows in a precisely controlled fashion. *Note
  192. Displaying Buffers::, for related functions that find a window to use
  193. and specify a buffer for it. The functions described there are easier
  194. to use than these, but they employ heuristics in choosing or creating a
  195. window; use these functions when you need complete control.
  196.  
  197.  -- Function: set-window-buffer WINDOW BUFFER-OR-NAME
  198.      This function makes WINDOW display BUFFER-OR-NAME as its contents.
  199.       It returns `nil'.
  200.  
  201.           (set-window-buffer (selected-window) "foo")
  202.                => nil
  203.  
  204.  -- Function: window-buffer &optional WINDOW
  205.      This function returns the buffer that WINDOW is displaying.  If
  206.      WINDOW is omitted, then this function returns the buffer for the
  207.      selected window.
  208.  
  209.           (window-buffer)
  210.                => #<buffer windows.texi>
  211.  
  212.  -- Function: get-buffer-window BUFFER-OR-NAME
  213.      This function returns a window currently displaying
  214.      BUFFER-OR-NAME, or `nil' if there is none.  If there are several
  215.      such windows, then the function returns the first one in the
  216.      cyclic ordering of windows, starting from the selected window.
  217.      *Note Cyclic Window Ordering::.
  218.  
  219.  -- Command: replace-buffer-in-windows BUFFER
  220.      This function replaces BUFFER with some other buffer in all
  221.      windows displaying it.  The other buffer used is chosen with
  222.      `other-buffer'.  In the usual applications of this function, you
  223.      don't care which other buffer is used; you just want to make sure
  224.      that BUFFER is off the screen.
  225.  
  226.      This function returns `nil'.
  227.  
  228. 
  229. File: elisp,  Node: Displaying Buffers,  Next: Window Point,  Prev: Buffers and Windows,  Up: Windows
  230.  
  231. Displaying Buffers in Windows
  232. =============================
  233.  
  234.    In this section we describe convenient functions that choose a window
  235. automatically and use it to display a specified buffer.  These functions
  236. can also split an existing window in certain circumstances.  We also
  237. describe variables that parameterize the heuristics used for choosing a
  238. window. *Note Buffers and Windows::, for low-level functions that give
  239. you more precise control.
  240.  
  241.    Do not use the functions in this section in order to make a buffer
  242. current so that a Lisp program can access or modify it; they are too
  243. drastic for that purpose, since they change the display of buffers on
  244. the screen, which is gratuitous and will surprise the user.  Instead,
  245. use `set-buffer' (*note Current Buffer::.) and `save-excursion' (*note
  246. Excursions::.), which designate buffers as current for programmed
  247. access without affecting the display of buffers in windows.
  248.  
  249.  -- Command: switch-to-buffer BUFFER-OR-NAME &optional NORECORD
  250.      This function makes BUFFER-OR-NAME the current buffer, and also
  251.      displays the buffer in the selected window.  This means that a
  252.      human can see the buffer and subsequent keyboard commands will
  253.      apply to it. Contrast this with `set-buffer', which makes
  254.      BUFFER-OR-NAME the current buffer but does not display it in the
  255.      selected window. *Note Current Buffer::.
  256.  
  257.      If BUFFER-OR-NAME does not identify an existing buffer, then a new
  258.      buffer by that name is created.
  259.  
  260.      Normally the specified buffer is put at the front of the buffer
  261.      list. This affects the operation of `other-buffer'.  However, if
  262.      NORECORD is non-`nil', this is not done.  *Note The Buffer List::.
  263.  
  264.      The `switch-to-buffer' function is often used interactively, as
  265.      the binding of `C-x b'.  It is also used frequently in programs. 
  266.      It always returns `nil'.
  267.  
  268.  -- Command: switch-to-buffer-other-window BUFFER-OR-NAME
  269.      This function makes BUFFER-OR-NAME the current buffer and displays
  270.      it in a window not currently selected.  It then selects that
  271.      window.  The handling of the buffer is the same as in
  272.      `switch-to-buffer'.
  273.  
  274.      The previously selected window is absolutely never used to display
  275.      the buffer.  If it is the only window, then it is split to make a
  276.      distinct window for this purpose.  If the selected window is
  277.      already displaying the buffer, then it continues to do so, but
  278.      another window is nonetheless found to display it in as well.
  279.  
  280.  -- Function: pop-to-buffer BUFFER-OR-NAME &optional OTHER-WINDOW
  281.      This function makes BUFFER-OR-NAME the current buffer and switches
  282.      to it in some window, preferably not the window previously
  283.      selected.  The "popped-to" window becomes the selected window.
  284.  
  285.      If the variable `pop-up-windows' is non-`nil', windows may be
  286.      split to create a new window that is different from the original
  287.      window.
  288.  
  289.      If OTHER-WINDOW is non-`nil', `pop-to-buffer' finds or creates
  290.      another window even if BUFFER-OR-NAME is already visible in the
  291.      selected window.  Thus BUFFER-OR-NAME could end up displayed in
  292.      two windows.  On the other hand, if BUFFER-OR-NAME is already
  293.      displayed in the selected window and OTHER-WINDOW is `nil', then
  294.      the selected window is considered sufficient display for
  295.      BUFFER-OR-NAME, so that nothing needs to be done.
  296.  
  297.      If BUFFER-OR-NAME is a string that does not name an existing
  298.      buffer, a buffer by that name is created.
  299.  
  300.      An example use of this function is found at the end of *Note
  301.      Filter Functions::.
  302.  
  303.  -- Function: display-buffer BUFFER-OR-NAME &optional NOT-THIS-WINDOW
  304.      This function makes BUFFER-OR-NAME appear in some window, like
  305.      `pop-to-buffer', but it does not select that window and does not
  306.      make the buffer current.  The identity of the selected window is
  307.      unaltered by this function.
  308.  
  309.      If NOT-THIS-WINDOW is non-`nil', it means that the specified
  310.      buffer should be displayed in a window other than the selected
  311.      one, even if it is already on display in the selected window. 
  312.      This can cause the buffer to appear in two windows at once. 
  313.      Otherwise, if BUFFER-OR-NAME is already being displayed in any
  314.      window, that is good enough, so this function does nothing.
  315.  
  316.      If the variable `pop-up-windows' is non-`nil', windows can be
  317.      split to display the buffer.  If there are multiple windows,
  318.      `display-buffer' will split the largest window if it has more than
  319.      the number of lines specified by the variable
  320.      `split-height-threshold'.
  321.  
  322.      `display-buffer' returns the window chosen to display
  323.      BUFFER-OR-NAME.
  324.  
  325.  -- User Option: pop-up-windows
  326.      This variable controls whether `display-buffer' makes new windows.
  327.       If it is non-`nil' and there is only one window on the screen,
  328.      then that window is split.  If it is `nil', then `display-buffer'
  329.      does not split the single window, but rather replaces its buffer.
  330.  
  331.      This variable also affects `pop-to-buffer', which uses
  332.      `display-buffer' as a subroutine.
  333.  
  334.  -- User Option: split-height-threshold
  335.      This variable determines when `display-buffer' may split a window,
  336.      if there are multiple windows.  `display-buffer' splits the
  337.      largest window if it has at least this many lines.
  338.  
  339.      If there is only one window, it is split regardless of this value,
  340.      provided `pop-up-windows' is non-`nil'.
  341.  
  342. 
  343. File: elisp,  Node: Window Point,  Next: Window Start,  Prev: Displaying Buffers,  Up: Windows
  344.  
  345. Window Point
  346. ============
  347.  
  348.    Each window has its own value of point, independent of the value of
  349. point in other windows displaying the same buffer.  This makes it useful
  350. to have multiple windows showing one buffer.
  351.  
  352.    * The window point is established when a window is first created; it
  353.      is initialized from the buffer's point, or from the window point
  354.      of another window opened on the buffer if such a window exists.
  355.  
  356.    * Selecting a window sets the value of point in its buffer to the
  357.      window's value of point.  Conversely, deselecting a window copies
  358.      the buffer's value of point into the window.  Thus, when you
  359.      switch between windows that display a given buffer, the point
  360.      value for the selected window is in effect in the buffer, while
  361.      the point values for the other windows are stored in those windows.
  362.  
  363.    * As long as the selected window displays the current buffer, the
  364.      window's point and the buffer's point always move together; they
  365.      remain equal.
  366.  
  367.    * *Note Positions::, for more details on positions.
  368.  
  369.    As far as the user is concerned, point is where the cursor is, and
  370. when the user switches to another buffer, the cursor jumps to the
  371. position of point in that buffer.
  372.  
  373.  -- Function: window-point WINDOW
  374.      This function returns the current position of point in WINDOW. For
  375.      a nonselected window, this is the value point would have (in that
  376.      window's buffer) if that window were selected.
  377.  
  378.      When WINDOW is the selected window and its buffer is also the
  379.      current buffer, the value returned is the same as point in that
  380.      buffer.
  381.  
  382.      Strictly speaking, it would be more correct to return the
  383.      "top-level" value of point, outside of any `save-excursion' forms.
  384.       But that value is hard to find.
  385.  
  386.  -- Function: set-window-point WINDOW POSITION
  387.      This function positions point in WINDOW at position POSITION in
  388.      WINDOW's buffer.
  389.  
  390. 
  391. File: elisp,  Node: Window Start,  Next: Vertical Scrolling,  Prev: Window Point,  Up: Windows
  392.  
  393. The Display-Start Position
  394. ==========================
  395.  
  396.    Each window contains a marker used to keep track of a buffer position
  397. which specifies where in the buffer display should start.  This position
  398. is called the "display-start" position of the window.  The character
  399. after this position is the one that appears at the upper left corner of
  400. the window.  It is usually, but not inevitably, at the beginning of a
  401. text line.
  402.  
  403.  -- Function: window-start &optional WINDOW
  404.      This function returns the display-start position of window WINDOW.
  405.       If WINDOW is `nil', the selected window is used.
  406.  
  407.           (window-start)
  408.                => 7058
  409.  
  410.      For a more complicated example of use, see the description of
  411.      `count-lines' in *Note Text Lines::.
  412.  
  413.  -- Function: set-window-start WINDOW POSITION &optional NOFORCE
  414.      This function sets the display-start position of WINDOW to
  415.      POSITION in WINDOW's buffer.
  416.  
  417.      The display routines insist that the position of point be visible
  418.      when a buffer is displayed.  Normally, they change the
  419.      display-start position (that is, scroll the window) whenever
  420.      necessary to make point visible. However, if you specify the start
  421.      position with this function with `nil' for NOFORCE, it means you
  422.      want display to start at POSITION even if that would put the
  423.      location of point off the screen.  What the display routines do in
  424.      this case is move point instead, to the left margin on the middle
  425.      line in the window.
  426.  
  427.      For example, if point is 1 and you attempt to set the start of the
  428.      window to 2, then the position of point would be "above" the top
  429.      of the window.  The display routines would automatically move
  430.      point if it is still 1 when redisplay occurs.  Here is an example:
  431.  
  432.           ;; Here is what `foo' looks like before executing
  433.           ;; the `set-window-start' expression.
  434.           
  435.           ---------- Buffer: foo ----------
  436.           -!-This is the contents of buffer foo.
  437.           2
  438.           3
  439.           4
  440.           5
  441.           6
  442.           ---------- Buffer: foo ----------
  443.           
  444.           (set-window-start (selected-window) (1+ (window-start)))
  445.           
  446.           ;; Here is what `foo' looks like after executing
  447.           ;; the `set-window-start' expression.
  448.           
  449.           ---------- Buffer: foo ----------
  450.           his is the contents of buffer foo.
  451.           2
  452.           3
  453.           -!-4
  454.           5
  455.           6
  456.           ---------- Buffer: foo ----------
  457.           
  458.                => 2
  459.  
  460.      However, when NOFORCE is non-`nil', `set-window-start' does
  461.      nothing if the specified start position would make point invisible.
  462.  
  463.      This function returns POSITION, regardless of whether the NOFORCE
  464.      option caused that position to be overruled.
  465.  
  466.  -- Function: pos-visible-in-window-p &optional POSITION WINDOW
  467.      This function returns `t' if POSITION is within the range of text
  468.      currently visible on the screen in WINDOW.  It returns `nil' if
  469.      POSITION is scrolled vertically out of view.  The argument
  470.      POSITION defaults to the current position of point; WINDOW, to the
  471.      selected window.  Here is an example:
  472.  
  473.           (or (pos-visible-in-window-p (point) (selected-window))
  474.               (recenter 0))
  475.  
  476.      The `pos-visible-in-window-p' function considers only vertical
  477.      scrolling.  It returns `t' if POSITION is out of view only because
  478.      WINDOW has been scrolled horizontally.  *Note Horizontal
  479.      Scrolling::.
  480.  
  481. 
  482. File: elisp,  Node: Vertical Scrolling,  Next: Horizontal Scrolling,  Prev: Window Start,  Up: Windows
  483.  
  484. Vertical Scrolling
  485. ==================
  486.  
  487.    Vertical scrolling means moving the text up or down in a window.  It
  488. works by changing the value of the window's display-start location.  It
  489. may also change the value of `window-point' to keep it on the screen.
  490.  
  491.    In the commands `scroll-up' and `scroll-down', the directions "up"
  492. and "down" refer to the motion of the text in the buffer at which you
  493. are looking through the window.  Imagine that the text is written on a
  494. long roll of paper and that the scrolling commands move the paper up
  495. and down.  Thus, if you are looking at text in the middle of a buffer
  496. and repeatedly call `scroll-down', you will eventually see the
  497. beginning of the buffer.
  498.  
  499.    Some people have urged that the opposite convention be used: they
  500. imagine that the window moves over text that remains in place.  Then
  501. "down" commands would take you to the end of the buffer.  This view is
  502. more consistent with the actual relationship between windows and the
  503. text in the buffer, but it is less like what the user sees.  The
  504. position of a window on the terminal does not move, and short scrolling
  505. commands clearly move the text up or down on the screen.  We have chosen
  506. names that fit the user's point of view.
  507.  
  508.    The scrolling functions (aside from `scroll-other-window') will have
  509. unpredictable results if the current buffer is different from the
  510. buffer that is displayed in the selected window.  *Note Current
  511. Buffer::.
  512.  
  513.  -- Command: scroll-up &optional COUNT
  514.      This function scrolls the text in the selected window upward COUNT
  515.      lines.  If COUNT is negative, scrolling is actually downward.
  516.  
  517.      If COUNT is `nil' (or omitted), then the length of the scroll is
  518.      `next-screen-context-lines' lines less than the usable height of
  519.      the window (not counting its mode line).
  520.  
  521.      `scroll-up' returns `nil'.
  522.  
  523.  -- Command: scroll-down &optional COUNT
  524.      This function scrolls the text in the selected window downward
  525.      COUNT lines.  If COUNT is negative, scrolling is actually upward.
  526.  
  527.      If COUNT is omitted or `nil', then the length of the scroll is
  528.      `next-screen-context-lines' lines less than the usable height of
  529.      the window.
  530.  
  531.      `scroll-down' returns `nil'.
  532.  
  533.  -- Command: scroll-other-window &optional COUNT
  534.      This function scrolls the text in another window upward COUNT
  535.      lines.  Negative values of COUNT, or `nil', are handled as in
  536.      `scroll-up'.
  537.  
  538.      The window that is scrolled is normally the one following the
  539.      selected window in the cyclic ordering of windows--the window that
  540.      `next-window' would return.  *Note Cyclic Window Ordering::.
  541.  
  542.      If the selected window is the minibuffer, the next window is
  543.      normally the one at the top left corner.  However, you can specify
  544.      the window to scroll by binding the variable
  545.      `minibuffer-scroll-window'.  This variable has no effect when any
  546.      other window is selected. *Note Minibuffer Misc::.
  547.  
  548.      When the minibuffer is active, it is the next window if the
  549.      selected window is the one at the bottom right corner.  In this
  550.      case, `scroll-other-window' will attempt to scroll the minibuffer.
  551.       If the minibuffer contains just one line, that line will be
  552.      redisplayed after the echo area momentarily displays the message
  553.      "Beginning of buffer".
  554.  
  555.  -- User Option: scroll-step
  556.      This variable controls how scrolling is done automatically when
  557.      point moves off the screen.  If the value is zero, then the text
  558.      is scrolled so that point is centered vertically in the window. 
  559.      If the value is a positive integer N, then if it is possible to
  560.      bring point back on screen by scrolling N lines in either
  561.      direction, that is done; otherwise, point is centered vertically
  562.      as usual.  The default value is zero.
  563.  
  564.  -- User Option: next-screen-context-lines
  565.      The value of this variable is the number of lines of continuity to
  566.      retain when scrolling by full screens.  For example, when
  567.      `scroll-up' executes, this many lines that were visible at the
  568.      bottom of the window move to the top of the window.  The default
  569.      value is `2'.
  570.  
  571.  -- Command: recenter &optional COUNT
  572.      This function scrolls the selected window to put the text where
  573.      point is located at a specified screen position.
  574.  
  575.      If COUNT is a nonnegative number, it puts the line containing
  576.      point COUNT lines down from the top of the window.  If COUNT is a
  577.      negative number, then it counts upward from the bottom of the
  578.      window, so that -1 stands for the last usable line in the window.
  579.      If COUNT is a non-`nil' list, then it stands for the line in the
  580.      middle of the window.
  581.  
  582.      If COUNT is `nil', then it puts the line containing point in the
  583.      middle of the window, then clears and redisplays the entire screen.
  584.  
  585.      When `recenter' is called interactively, Emacs sets COUNT to the
  586.      raw prefix argument.  Thus, typing `C-u' as the prefix sets the
  587.      COUNT to a non-`nil' list, while typing `C-u 4' sets COUNT to 4,
  588.      which positions the current line four lines from the top.
  589.  
  590.      Typing `C-u 0 C-l' positions the current line at the top of the
  591.      window.  This action is so handy that some people bind the command
  592.      to a function key.  For example,
  593.  
  594.           (defun line-to-top-of-window ()
  595.             "Scroll the selected window up so current line moves to the top.
  596.           Replaces three keystroke sequence C-u 0 C-l."
  597.             (interactive)
  598.             (recenter 0))
  599.           
  600.           (global-set-key "\C-cl" 'line-to-top-of-window)
  601.  
  602. 
  603. File: elisp,  Node: Horizontal Scrolling,  Next: Size of Window,  Prev: Vertical Scrolling,  Up: Windows
  604.  
  605. Horizontal Scrolling
  606. ====================
  607.  
  608.    Because we read English first from top to bottom and second from left
  609. to right, horizontal scrolling is not like vertical scrolling.  Vertical
  610. scrolling involves selection of a contiguous portion of text to display.
  611. Horizontal scrolling causes part of each line to go off screen.  The
  612. amount of horizontal scrolling is therefore specified as a number of
  613. columns rather than as a position in the buffer.  It has nothing to do
  614. with the display-start position returned by `window-start'.
  615.  
  616.    Usually, no horizontal scrolling is in effect; then the leftmost
  617. column is at the left edge of the window.  In this state, scrolling to
  618. the right is meaningless, since there is no data to the left of the
  619. screen to be revealed by it, so it is not allowed.  Scrolling to the
  620. left is allowed; it causes the first columns of text to go off the edge
  621. of the window and can reveal additional columns on the right that were
  622. truncated before.  Once a window has a nonzero amount of leftward
  623. horizontal scrolling, you can scroll it back to the right, but only so
  624. far as to reduce the net horizontal scroll to zero.  There is no limit
  625. to how far left you can scroll, but eventually all the text will
  626. disappear off the left edge.
  627.  
  628.  -- Command: scroll-left COUNT
  629.      This function scrolls the selected window COUNT columns to the
  630.      left (or to the right if COUNT is negative).  The return value is
  631.      the total amount of leftward horizontal scrolling in effect after
  632.      the change--just like the value returned by `window-hscroll'.
  633.  
  634.  -- Command: scroll-right COUNT
  635.      This function scrolls the selected window COUNT columns to the
  636.      right  (or to the left if COUNT is negative).  The return value is
  637.      the total amount of leftward horizontal scrolling in effect after
  638.      the change--just like the value returned by `window-hscroll'.
  639.  
  640.      Once you scroll a window as far right as it can go, back to its
  641.      normal position where the total leftward scrolling is zero,
  642.      attempts to scroll any farther have no effect.
  643.  
  644.  -- Function: window-hscroll &optional WINDOW
  645.      This function returns the total leftward horizontal scrolling of
  646.      WINDOW--the number of columns by which the text in WINDOW is
  647.      scrolled left past the left margin.
  648.  
  649.      The value is never negative.  It is zero when no horizontal
  650.      scrolling has been done in WINDOW (which is usually the case).
  651.  
  652.      If WINDOW is `nil', the selected window is used.
  653.  
  654.           (window-hscroll)
  655.                => 0
  656.           (scroll-left 5)
  657.                => 5
  658.           (window-hscroll)
  659.                => 5
  660.  
  661.  -- Function: set-window-hscroll WINDOW COLUMNS
  662.      This function sets the number of columns from the left margin that
  663.      WINDOW is scrolled to the value of COLUMNS.  The argument COLUMNS
  664.      should be zero or positive; if not, it is taken as zero.
  665.  
  666.      The value returned is COLUMNS.
  667.  
  668.           (set-window-hscroll (selected-window) 10)
  669.                => 10
  670.  
  671.    Here is how you can determine whether a given position POSITION is
  672. off the screen due to horizontal scrolling:
  673.  
  674.      (save-excursion
  675.        (goto-char POSITION)
  676.        (and
  677.         (>= (- (current-column) (window-hscroll WINDOW)) 0)
  678.         (< (- (current-column) (window-hscroll WINDOW))
  679.            (window-width WINDOW))))
  680.  
  681. 
  682. File: elisp,  Node: Size of Window,  Next: Resizing Windows,  Prev: Horizontal Scrolling,  Up: Windows
  683.  
  684. The Size of a Window
  685. ====================
  686.  
  687.    An Emacs window is rectangular, and its size information consists of
  688. the height (the number of lines) and the width (the number of character
  689. positions in each line).  The mode line is included in the height.  For
  690. a window that does not abut the right hand edge of the screen, the
  691. column of `|' characters that separates it from the window on the right
  692. is included in the width.
  693.  
  694.    The following three functions return size information about a window:
  695.  
  696.  -- Function: window-height &optional WINDOW
  697.      This function returns the number of lines in WINDOW, including its
  698.      mode line.  If WINDOW fills the entire screen, this is one less
  699.      than the value of `(screen-height)' (since the last line is always
  700.      reserved for the minibuffer).
  701.  
  702.      If WINDOW is `nil', the function uses the selected window.
  703.  
  704.           (window-height)
  705.                => 23
  706.           (split-window-vertically)
  707.                => #<window 4 on windows.texi>
  708.           (window-height)
  709.                => 11
  710.  
  711.  -- Function: window-width &optional WINDOW
  712.      This function returns the number of columns in WINDOW.  If WINDOW
  713.      fills the entire screen, this is the same as the value of
  714.      `(screen-width)'.
  715.  
  716.      If WINDOW is `nil', the function uses the selected window.
  717.  
  718.           (window-width)
  719.                => 80
  720.  
  721.  -- Function: window-edges &optional WINDOW
  722.      This function returns a list of the edge coordinates of WINDOW. If
  723.      WINDOW is `nil', the selected window is used.
  724.  
  725.      The order of the list is `(LEFT TOP RIGHT BOTTOM)', all elements
  726.      relative to 0, 0 at the top left corner of the screen.  The
  727.      element RIGHT of the value is one more than the rightmost column
  728.      used by WINDOW, and BOTTOM is one more than the bottommost row
  729.      used by WINDOW and its mode-line.
  730.  
  731.      Here is the result obtained on a typical 24-line terminal with
  732.      just one window:
  733.  
  734.           (window-edges (selected-window))
  735.                => (0 0 80 23)
  736.  
  737.      If WINDOW is at the upper left corner of the screen, RIGHT and
  738.      BOTTOM are the same as the values returned by `(window-width)' and
  739.      `(window-height)' respectively, and TOP and BOTTOM are zero.  For
  740.      example, the edges of the following window are `0 0 5 8'. 
  741.      Assuming that the screen has more than 8 columns, the last column
  742.      of the window (column 7) holds a border rather than text.  The
  743.      last row (row 4) holds the mode line, shown here with `xxxxxxxxx'.
  744.  
  745.                      0
  746.                      _______
  747.                   0 |       |
  748.                     |       |
  749.                     |       |
  750.                     |       |
  751.                     xxxxxxxxx  4
  752.           
  753.                             7
  754.  
  755.      When there are side-by-side windows, any window not at the right
  756.      edge of the screen has a border in its last column.  This border
  757.      counts as one column in the width of the window.  A window never
  758.      includes a border on its left, since the border there belongs to
  759.      the window to the left.
  760.  
  761.      In the following example, let's imagine that the screen is 7
  762.      columns wide.  Then the edges of the left window are `0 0 4 3' and
  763.      the edges of the right window are `4 0 7 3'.
  764.  
  765.                      ___ ___
  766.                     |   |   |
  767.                     |   |   |
  768.                     xxxxxxxxx
  769.           
  770.                      0  34  7
  771.  
  772. 
  773. File: elisp,  Node: Resizing Windows,  Next: Window Configurations,  Prev: Size of Window,  Up: Windows
  774.  
  775. Changing the Size of a Window
  776. =============================
  777.  
  778.    The window size functions fall into two classes: high-level commands
  779. that change the size of windows and low-level functions that access
  780. window size.  Emacs does not permit overlapping windows or gaps between
  781. windows, so resizing one window affects other windows.
  782.  
  783.  -- Command: enlarge-window SIZE &optional HORIZONTAL
  784.      This function makes the selected window SIZE lines bigger,
  785.      stealing lines from neighboring windows.  It generally tries to
  786.      steal equal numbers of lines from the other windows.  If a window
  787.      from which lines are stolen shrinks below `window-min-height',
  788.      then that window disappears.
  789.  
  790.      If HORIZONTAL is non-`nil', then this function makes WINDOW wider
  791.      by SIZE columns, stealing columns as it does lines.  If a window
  792.      from which lines are stolen shrinks below `window-min-width', then
  793.      that window disappears.
  794.  
  795.      If the screen is smaller than SIZE lines (or columns), then the
  796.      function makes the window occupy the entire height (or width) of
  797.      the screen.
  798.  
  799.      If SIZE is negative, this function shrinks the window by -SIZE
  800.      lines.  If it becomes shorter than `window-min-height', it
  801.      disappears.
  802.  
  803.      `enlarge-window' returns `nil'.
  804.  
  805.  -- Command: enlarge-window-horizontally COLUMNS
  806.      This function makes the selected window COLUMNS wider. It could be
  807.      defined as follows:
  808.  
  809.           (defun enlarge-window-horizontally (columns)
  810.             (enlarge-window columns t))
  811.  
  812.  -- Command: shrink-window SIZE &optional HORIZONTAL
  813.      This function is like `enlarge-window' but negates the argument
  814.      SIZE, making the selected window smaller by giving lines (or
  815.      columns) to the other windows.  If the window shrinks below
  816.      `window-min-height' or `window-min-width', then it disappears.
  817.  
  818.      If SIZE is negative, the window is enlarged by -SIZE lines.
  819.  
  820.  -- Command: shrink-window-horizontally COLUMNS
  821.      This function makes the selected window COLUMNS narrower. It could
  822.      be defined as follows:
  823.  
  824.           (defun shrink-window-horizontally (columns)
  825.             (shrink-window columns t))
  826.  
  827.    The following two variables constrain the window size changing
  828. functions to a minimum height and width.
  829.  
  830.  -- User Option: window-min-height
  831.      The value of this variable determines how short a window may become
  832.      before it disappears.  A window disappears when it becomes smaller
  833.      than `window-min-height', and no window may be created that is
  834.      smaller. The absolute minimum height is two (allowing one line for
  835.      the mode line, and one line for the buffer display).  Actions
  836.      which change window sizes reset this variable to two if it is less
  837.      than two.  The default value is 4.
  838.  
  839.  -- User Option: window-min-width
  840.      The value of this variable determines how narrow a window may
  841.      become before it disappears.  A window disappears when it becomes
  842.      narrower than `window-min-width', and no window may be created
  843.      that is narrower. The absolute minimum width is one; any value
  844.      below that is ignored.  The default value is 10.
  845.  
  846. 
  847. File: elisp,  Node: Window Configurations,  Prev: Resizing Windows,  Up: Windows
  848.  
  849. Window Configurations
  850. =====================
  851.  
  852.    "Window configurations" record entire screen layouts--all windows,
  853. their sizes, which buffers they contain, what part of each buffer is
  854. displayed, and the values of point and the mark.  You can bring back an
  855. entire previous screen layout by restoring a window configuration that
  856. you had previously saved.
  857.  
  858.  -- Function: current-window-configuration
  859.      This function returns a new object representing Emacs's current
  860.      window configuration, namely the number of windows, their sizes
  861.      and current buffers, which window is the selected window, and for
  862.      each window the displayed buffer, the display-start position, and
  863.      the positions of point and the mark.  An exception is made for
  864.      point in the current buffer, whose value is not saved.
  865.  
  866.  -- Function: set-window-configuration CONFIGURATION
  867.      This function restores the configuration of Emacs's windows and
  868.      buffers to the state specified by CONFIGURATION.  The argument
  869.      CONFIGURATION must be a value that was previously returned by
  870.      `current-window-configuration'.
  871.  
  872.      Here is a way of using this function to get the same effect as
  873.      `save-window-excursion':
  874.  
  875.           (let ((config (current-window-configuration)))
  876.             (unwind-protect
  877.                 (progn (split-window-vertically nil)
  878.                        ...)
  879.               (set-window-configuration config)))
  880.  
  881.  -- Special Form: save-window-excursion FORMS...
  882.      This special form executes FORMS in sequence, preserving window
  883.      sizes and contents, including the value of point and the portion
  884.      of the buffer which is visible.  However, it does not restore the
  885.      value of point in the current buffer; use `save-excursion' for
  886.      that.
  887.  
  888.      The return value is the value of the final form in FORMS. For
  889.      example:
  890.  
  891.           (split-window)
  892.                => #<window 25 on control.texi>
  893.           (setq w (selected-window))
  894.                => #<window 19 on control.texi>
  895.           (save-window-excursion
  896.             (delete-other-windows w)
  897.             (switch-to-buffer "foo")
  898.             'do-something)
  899.                => do-something
  900.             ;; The screen is now split again.
  901.  
  902.    Primitives to look inside of window configurations would make sense,
  903. but none are implemented.  It is not clear they are useful enough to be
  904. worth implementing.
  905.  
  906. 
  907. File: elisp,  Node: Positions,  Next: Markers,  Prev: Windows,  Up: Top
  908.  
  909. Positions
  910. *********
  911.  
  912.    A "position" is the index of a character in the text of buffer. More
  913. precisely, a position identifies the place between two characters (or
  914. before the first character, or after the last character), so we can
  915. speak of the character before or after a given position.  However, the
  916. character after a position is often said to be "at" that position.
  917.  
  918.    Positions are usually represented as integers starting from 1, but
  919. can also be represented as "markers"--special objects which relocate
  920. automatically when text is inserted or deleted so they stay with the
  921. surrounding characters.  *Note Markers::.
  922.  
  923. * Menu:
  924.  
  925. * Point::         The special position where editing takes place.
  926. * Motion::        Changing point.
  927. * Excursions::    Temporary motion and buffer changes.
  928. * Narrowing::     Restricting editing to a portion of the buffer.
  929.  
  930. 
  931. File: elisp,  Node: Point,  Next: Motion,  Prev: Positions,  Up: Positions
  932.  
  933. Point
  934. =====
  935.  
  936.    "Point" is a special buffer position used by many editing commands,
  937. including the self-inserting typed characters and text insertion
  938. functions.  Other commands move point through the text to allow editing
  939. and insertion at different places.
  940.  
  941.    Like other positions, point designates a place between two characters
  942. (or before the first character, or after the last character), rather
  943. than a particular character.  Many terminals display the cursor over the
  944. character that immediately follows point; on such terminals, point is
  945. actually before the character on which the cursor sits.
  946.  
  947.    The value of point is a number between 1 and the buffer size plus 1.
  948. If narrowing is in effect (*note Narrowing::.), then point is
  949. constrained to fall within the accessible portion of the buffer
  950. (possibly at one end of it).
  951.  
  952.    Each buffer has its own value of point, which is independent of the
  953. value of point in other buffers.  Each window also has a value of point,
  954. which is independent of the value of point in other windows on the same
  955. buffer.  This is why point can have different values in various windows
  956. that display the same buffer.  When a buffer appears in only one window,
  957. the buffer's point and the window's point normally have the same value,
  958. so the distinction is rarely important.  *Note Window Point::, for more
  959. details.
  960.  
  961.  -- Function: point
  962.      This function returns the position of point in the current buffer,
  963.      as an integer.
  964.  
  965.           (point)
  966.                => 175
  967.  
  968.  -- Function: point-min
  969.      This function returns the minimum accessible value of point in the
  970.      current buffer.  This is 1, unless narrowing is in effect, in
  971.      which case it is the position of the start of the region that you
  972.      narrowed to.  (*Note Narrowing::.)
  973.  
  974.  -- Function: point-max
  975.      This function returns the maximum accessible value of point in the
  976.      current buffer.  This is `(1+ (buffer-size))', unless narrowing is
  977.      in effect, in which case it is the position of the end of the
  978.      region that you narrowed to.  (*Note Narrowing::).
  979.  
  980.  -- Function: buffer-end FLAG
  981.      This function returns `(point-min)' if FLAG is less than 1,
  982.      `(point-max)' otherwise.  The argument FLAG must be a number.
  983.  
  984.  -- Function: buffer-size
  985.      This function returns the total number of characters in the current
  986.      buffer.  In the absence of any narrowing (*note Narrowing::.),
  987.      `point-max' returns a value one larger than this.
  988.  
  989.           (buffer-size)
  990.                => 35
  991.           (point-max)
  992.                => 36
  993.  
  994.  -- Variable: buffer-saved-size
  995.      The value of this buffer-local variable is the former length of the
  996.      current buffer, as of the last time it was read in, saved or
  997.      auto-saved.
  998.  
  999. 
  1000. File: elisp,  Node: Motion,  Next: Excursions,  Prev: Point,  Up: Positions
  1001.  
  1002. Motion
  1003. ======
  1004.  
  1005.    Motion functions change the value of point, either relative to the
  1006. current value of point, relative to the beginning or end of the buffer,
  1007. or relative to the edges of the selected window.
  1008.  
  1009. * Menu:
  1010.  
  1011. * Character Motion::       Moving in terms of characters.
  1012. * Word Motion::            Moving in terms of words.
  1013. * Buffer End Motion::      Moving to the beginning or end of the buffer.
  1014. * Text Lines::             Moving in terms of lines of text.
  1015. * Screen Lines::           Moving in terms of lines as displayed.
  1016. * Vertical Motion::        Implementation of `next-line' and
  1017.                              `previous-line'.
  1018. * List Motion::            Moving by parsing lists and sexps.
  1019. * Skipping Characters::    Skipping characters belonging to a certain set.
  1020.  
  1021. 
  1022. File: elisp,  Node: Character Motion,  Next: Word Motion,  Prev: Motion,  Up: Motion
  1023.  
  1024. Motion by Characters
  1025. --------------------
  1026.  
  1027.    These functions move point based on a count of characters.
  1028. `goto-char' is a fundamental primitive because it is the way to move
  1029. point to a specified position.
  1030.  
  1031.  -- Command: goto-char POSITION
  1032.      This function sets point in the current buffer to the value
  1033.      POSITION.  If POSITION is less than 1, then point is set to the
  1034.      beginning of the buffer.  If it is greater than the length of the
  1035.      buffer, then point is set to the end of the buffer.
  1036.  
  1037.      If narrowing is in effect, then the position is still measured
  1038.      from the beginning of the buffer, but point cannot be moved
  1039.      outside of the accessible portion.  Therefore, if POSITION is too
  1040.      small, point is set to the beginning of the accessible portion of
  1041.      the text; if POSITION is too large, point is set to the end.
  1042.  
  1043.      When this function is called interactively, POSITION is the
  1044.      numeric prefix argument, if provided; otherwise it is read from the
  1045.      minibuffer.
  1046.  
  1047.      `goto-char' returns POSITION.
  1048.  
  1049.  -- Command: forward-char &optional COUNT
  1050.      This function moves point forward, towards the end of the buffer,
  1051.      COUNT characters (or backward, towards the beginning of the
  1052.      buffer, if COUNT is negative).  If the function attempts to move
  1053.      point past the beginning or end of the buffer (or the limits of the
  1054.      accessible portion, when narrowing is in effect), an error is
  1055.      signaled with error code `beginning-of-buffer' or `end-of-buffer'.
  1056.  
  1057.      In an interactive call, COUNT is the numeric prefix argument.
  1058.  
  1059.  -- Command: backward-char &optional COUNT
  1060.      This function moves point backward, towards the beginning of the
  1061.      buffer, COUNT characters (or forward, towards the end of the
  1062.      buffer, if COUNT is negative).  If the function attempts to move
  1063.      point past the beginning or end of the buffer (or the limits of
  1064.      the accessible portion, when narrowing is in effect), an error is
  1065.      signaled with error code `beginning-of-buffer' or `end-of-buffer'.
  1066.  
  1067.      In an interactive call, COUNT is the numeric prefix argument.
  1068.  
  1069. 
  1070. File: elisp,  Node: Word Motion,  Next: Buffer End Motion,  Prev: Character Motion,  Up: Motion
  1071.  
  1072. Motion by Words
  1073. ---------------
  1074.  
  1075.    These functions for parsing words use the syntax table to decide
  1076. whether a given character is part of a word.  *Note Syntax Tables::.
  1077.  
  1078.  -- Command: forward-word COUNT
  1079.      This function moves point forward COUNT words (or backward if
  1080.      COUNT is negative).  Normally it returns `t'.  If this motion
  1081.      encounters the beginning or end of the buffer, or the limits of the
  1082.      accessible portion when narrowing is in effect, point stops there
  1083.      and the value is `nil'.
  1084.  
  1085.      In an interactive call, COUNT is set to the numeric prefix
  1086.      argument.
  1087.  
  1088.  -- Command: backward-word COUNT
  1089.      This function just like `forward-word', except that it moves
  1090.      backward until encountering the front of a word, rather than
  1091.      forward.
  1092.  
  1093.      In an interactive call, COUNT is set to the numeric prefix
  1094.      argument.
  1095.  
  1096.      This function is rarely used in programs, as it is more efficient
  1097.      to call `forward-word' with negative argument.
  1098.  
  1099. 
  1100. File: elisp,  Node: Buffer End Motion,  Next: Text Lines,  Prev: Word Motion,  Up: Motion
  1101.  
  1102. Motion to an End of the Buffer
  1103. ------------------------------
  1104.  
  1105.    To move point to the beginning of the buffer, write:
  1106.  
  1107.      (goto-char (point-min))
  1108.  
  1109. Likewise, to move to the end of the buffer, use:
  1110.  
  1111.      (goto-char (point-max))
  1112.  
  1113.    Here are two commands which users use to do these things.  They are
  1114. documented here to warn you not to use them in Lisp programs, because
  1115. they set the mark and display messages in the echo area.
  1116.  
  1117.  -- Command: beginning-of-buffer &optional N
  1118.      This function moves point to the beginning of the buffer (or the
  1119.      limits of the accessible portion, when narrowing is in effect),
  1120.      setting the mark at the previous position.  If N is non-`nil',
  1121.      then it puts point N tenths of the way from the beginning of the
  1122.      buffer.
  1123.  
  1124.      In an interactive call, N is the numeric prefix argument, if
  1125.      provided; otherwise N defaults to `nil'.
  1126.  
  1127.      Don't use this function in Lisp programs!
  1128.  
  1129.  -- Command: end-of-buffer &optional N
  1130.      This function moves point to the end of the buffer (or the limits
  1131.      of the accessible portion, when narrowing is in effect), setting
  1132.      the mark at the previous position.  If N is non-`nil', then it puts
  1133.      point N tenths of the way from the end.
  1134.  
  1135.      In an interactive call, N is the numeric prefix argument, if
  1136.      provided; otherwise N defaults to `nil'.
  1137.  
  1138.      Don't use this function in Lisp programs!
  1139.  
  1140.