home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i15 (.txt) < prev    next >
GNU Info File  |  1993-06-14  |  51KB  |  893 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: Numbered Backups,  Next: Backup Names,  Prev: Rename or Copy,  Up: Backup Files
  21. Making and Deleting Numbered Backup Files
  22. -----------------------------------------
  23.    If a file's name is `foo', the names of its numbered backup versions
  24. are `foo.~V~', for various integers V, like this: `foo.~1~', `foo.~2~',
  25. `foo.~3~', ..., `foo.~259~', and so on.
  26.  -- User Option: version-control
  27.      This variable controls whether to make a single non-numbered backup
  28.      file or multiple numbered backups.
  29.     `nil'
  30.           Make numbered backups if the visited file already has
  31.           numbered backups; otherwise, do not.
  32.     `never'
  33.           Do not make numbered backups.
  34.     ANYTHING ELSE
  35.           Do make numbered backups.
  36.    The use of numbered backups ultimately leads to a large number of
  37. backup versions, which must then be deleted.  Emacs can do this
  38. automatically.
  39.  -- User Option: kept-new-versions
  40.      The value of this variable is the number of oldest versions to keep
  41.      when a new numbered backup is made.  The newly made backup is
  42.      included in the count.  The default value is 2.
  43.  -- User Option: kept-old-versions
  44.      The value of this variable is the number of oldest versions to keep
  45.      when a new numbered backup is made.  The default value is 2.
  46.  -- User Option: dired-kept-versions
  47.      This variable plays a role in Dired's `dired-clean-directory'
  48.      (`.') command like that played by `kept-old-versions' when a
  49.      backup file is made.  The default value is 2.
  50.    If there are backups numbered 1, 2, 3, 5, and 7, and both of these
  51. variables have the value 2, then the backups numbered 1 and 2 will be
  52. kept as old versions and those numbered 5 and 7 will be kept as new
  53. versions; backup version 3 will be deleted.  The function
  54. `find-backup-file-name' is responsible for determining which backup
  55. versions to delete, but does not delete them itself.
  56.  -- User Option: trim-versions-without-asking
  57.      If this variable is non-`nil', then excess backup versions are
  58.      deleted silently.  Otherwise, the user is asked whether to delete
  59.      them.
  60. File: elisp,  Node: Backup Names,  Prev: Numbered Backups,  Up: Backup Files
  61. Naming Backup Files
  62. -------------------
  63.    The functions in this section are documented mainly because you can
  64. customize the naming conventions for backup files by redefining them.
  65.  -- Function: backup-file-name-p FILENAME
  66.      This function returns a non-`nil' value if FILENAME is a possible
  67.      name for a backup file.  A file with the name FILENAME need not
  68.      exist; the function just checks the name.
  69.           (backup-file-name-p "foo")
  70.                => nil
  71.           (backup-file-name-p "foo~")
  72.                => 3
  73.      The standard definition of this function is as follows:
  74.           (defun backup-file-name-p (file)
  75.             "Return non-nil if FILE is a backup file name (numeric or not)..."
  76.             (string-match "~$" file))
  77.      Thus, the function returns a non-`nil' value if the file name ends
  78.      with a `~'
  79.      This simple expression is placed in a separate function to make it
  80.      easy to redefine for customization.
  81.  -- Function: make-backup-file-name FILENAME
  82.      This function returns a string which is the name to use for a
  83.      non-numbered backup file for file FILENAME.  On Unix, this is just
  84.      FILENAME with a tilde appended.
  85.      The standard definition of this function is as follows:
  86.           (defun make-backup-file-name (file)
  87.             "Create the non-numeric backup file name for FILE..."
  88.             (concat file "~"))
  89.      You can change the backup file naming convention by redefining this
  90.      function.  In the following example, `make-backup-file-name' is
  91.      redefined to prepend a `.' as well as to append a tilde.
  92.           (defun make-backup-file-name (filename)
  93.             (concat "." filename "~"))
  94.           
  95.           (make-backup-file-name "backups.texi")
  96.                => ".backups.texi~"
  97.      If you do redefine `make-backup-file-name', be sure to redefine
  98.      `backup-file-name-p' and `find-backup-file-name' as well.
  99.  -- Function: find-backup-file-name FILENAME
  100.      This function computes the file name for a new backup file for
  101.      FILENAME.  It may also propose certain existing backup files for
  102.      deletion.  `find-backup-file-name' returns a list whose CAR is the
  103.      name for the new backup file and whose CDR is a list of backup
  104.      files whose deletion is proposed.
  105.      Two variables called `kept-old-versions' and `kept-new-versions'
  106.      determine which old backup versions will be kept (by excluding
  107.      them from the list of backup files ripe for deletion).  *Note
  108.      Numbered Backups::.
  109.      In this example, `~rms/foo.~5~' is the name to use for the new
  110.      backup file, and `~rms/foo.~3~' is an "excess" version that the
  111.      caller should consider deleting now.
  112.           (find-backup-file-name "~rms/foo")
  113.                => ("~rms/foo.~5~" "~rms/foo.~3~")
  114. File: elisp,  Node: Auto-Saving,  Next: Reverting,  Prev: Backup Files,  Up: Backups and Auto-Saving
  115. Auto-Saving
  116. ===========
  117.    Emacs periodically saves all files that you are visiting; this is
  118. called "auto-saving".  Auto-saving prevents you from losing more than a
  119. limited amount of work if the system crashes.  By default, auto-saves
  120. happen every 300 keystrokes.  *Note Auto-Save: (emacs)Auto-Save, for
  121. information on auto-save for users.  Here we describe the functions
  122. used to implement auto-saving and the variables that control them.
  123.  -- Variable: buffer-auto-save-file-name
  124.      This buffer-local variable is the name of the file used for
  125.      auto-saving the current buffer.  It is `nil' if the buffer should
  126.      not be auto-saved.
  127.           buffer-auto-save-file-name
  128.           => "/xcssun/users/rms/lewis/#files.texi#"
  129.  -- Command: auto-save-mode ARG
  130.      When used interactively without an argument, this command is a
  131.      toggle switch: it turns on auto-saving of the current buffer if it
  132.      is off, and vice-versa.  With an argument ARG, the command turns
  133.      auto-saving on if the value of ARG is `t', a nonempty list, or a
  134.      positive integer.  Otherwise, it turns auto-saving off.
  135.  -- Function: auto-save-file-name-p FILENAME
  136.      This function returns a non-`nil' value if FILENAME is a string
  137.      that could be the name of an auto-save file.  It works based on
  138.      knowledge of the naming convention for auto-save files: a name that
  139.      begins and ends with hash marks (`#') is a possible auto-save file
  140.      name.  The argument FILENAME should not contain a directory part.
  141.           (make-auto-save-file-name)
  142.                => "/xcssun/users/rms/lewis/#files.texi#"
  143.           (auto-save-file-name-p "#files.texi#")
  144.                => 0
  145.           (auto-save-file-name-p "files.texi")
  146.                => nil
  147.      The standard definition of this function is as follows:
  148.           (defun auto-save-file-name-p (filename)
  149.             "Return non-nil if FILENAME can be yielded by..."
  150.             (string-match "^#.*#$" filename))
  151.      This function exists so that you can customize it if you wish to
  152.      change the naming convention for auto-save files.  If you redefine
  153.      it, be sure to redefine `make-auto-save-file-name' correspondingly.
  154.  -- Function: make-auto-save-file-name
  155.      This function returns the file name to use for auto-saving the
  156.      current buffer.  This is just the file name with hash marks (`#')
  157.      appended and prepended to it.  This function does not look at the
  158.      variable `auto-save-visited-file-name'; that should be checked
  159.      before this function is called.
  160.           (make-auto-save-file-name)
  161.                => "/xcssun/users/rms/lewis/#backup.texi#"
  162.      The standard definition of this function is as follows:
  163.           (defun make-auto-save-file-name ()
  164.             "Return file name to use for auto-saves of current buffer..."
  165.             (if buffer-file-name
  166.                 (concat (file-name-directory buffer-file-name)
  167.                         "#"
  168.                         (file-name-nondirectory buffer-file-name)
  169.                         "#")
  170.               (expand-file-name (concat "#%" (buffer-name) "#"))))
  171.      This exists as a separate function so that you can redefine it to
  172.      customize the naming convention for auto-save files.  Be sure to
  173.      change `auto-save-file-name-p' in a corresponding way.
  174.  -- Variable: auto-save-visited-file-name
  175.      If this variable is non-`nil', Emacs will auto-save buffers in the
  176.      files they are visiting.  That is, the auto-save is done in the
  177.      same file which you are editing.  Normally, this variable is
  178.      `nil', so auto-save files have distinct names that are created by
  179.      `make-auto-save-file-name'.
  180.      When you change the value of this variable, the value does not take
  181.      effect until the next time auto-save mode is reenabled in any given
  182.      buffer.  If auto-save mode is already enabled, auto-saves continue
  183.      to go in the same file name until `auto-save-mode' is called again.
  184.  -- Function: recent-auto-save-p
  185.      This function returns `t' if the current buffer has been
  186.      auto-saved since the last time it was read in or saved.
  187.  -- Function: set-buffer-auto-saved
  188.      This function marks the current buffer as auto-saved.  The buffer
  189.      will not be auto-saved again until the buffer text is changed
  190.      again.  The function returns `nil'.
  191.  -- User Option: auto-save-interval
  192.      The value of this variable is the number of characters that Emacs
  193.      reads from the keyboard between auto-saves.  Each time this many
  194.      more characters are read, auto-saving is done for all buffers in
  195.      which it is enabled.
  196.  -- User Option: auto-save-default
  197.      If this variable is non-`nil', buffers that are visiting files
  198.      have auto-saving enabled by default.  Otherwise, they do not.
  199.  -- Command: do-auto-save &optional NO-MESSAGE
  200.      This function auto-saves all buffers that need to be auto-saved.
  201.      This is all buffers for which auto-saving is enabled and that have
  202.      been changed since the last time they were auto-saved.
  203.      Normally, if any buffers are auto-saved, a message
  204.      `Auto-saving...' is displayed in the echo area while auto-saving is
  205.      going on.  However, if NO-MESSAGE is non-`nil', the message is
  206.      inhibited.
  207.  -- Function: delete-auto-save-file-if-necessary
  208.      This function deletes the auto-save file for the current buffer if
  209.      variable `delete-auto-save-files' is non-`nil'.  It is called
  210.      every time a buffer is saved.
  211.  -- Variable: delete-auto-save-files
  212.      This variable is used by the function
  213.      `delete-auto-save-file-if-necessary'.  If it is non-`nil', Emacs
  214.      will delete auto-save files when a true save is done (in the
  215.      visited file).  This saves on disk space and unclutters your
  216.      directory.
  217.  -- Function: rename-auto-save-file
  218.      This function adjusts the current buffer's auto-save file name if
  219.      the visited file name has changed.  It also renames an existing
  220.      auto-save file.  If the visited file name has not changed, this
  221.      function does nothing.
  222. File: elisp,  Node: Reverting,  Prev: Auto-Saving,  Up: Backups and Auto-Saving
  223. Reverting
  224. =========
  225.    If you have made extensive changes to a file and then change your
  226. mind about them, you can get rid of them by reading in the previous
  227. version of the file with the `revert-buffer' command.  *Note  Reverting
  228. a Buffer: (emacs)Reverting.
  229.  -- Command: revert-buffer &optional NO-AUTO-SAVE-OFFER-P NOCONFIRM
  230.      This command replaces the buffer text with the text of the visited
  231.      file on disk.  This action undoes all changes since the file was
  232.      visited or saved.
  233.      When the value of the NO-AUTO-SAVE-OFFER-P argument is `nil', and
  234.      the latest auto-save file is more recent than the visited file,
  235.      `revert-buffer' asks the user whether to use that instead. 
  236.      Otherwise, it always uses the latest backup file.  This argument
  237.      is the numeric prefix argument when the function is called
  238.      interactively.
  239.      When the value of the NOCONFIRM argument is non-`nil',
  240.      `revert-buffer' does not ask for confirmation for the reversion
  241.      action.  This means that the buffer contents are deleted and
  242.      replaced by the text from the file on the disk, with no further
  243.      opportunities for the user to prevent it.
  244.      Since reverting works by deleting the entire text of the buffer and
  245.      inserting the file contents, all the buffer's markers are
  246.      relocated to point at the beginning of the buffer.  This is not
  247.      "correct", but then, there is no way to determine what would be
  248.      correct.  It is not possible to determine, from the text before
  249.      and after, which characters after reversion correspond to which
  250.      characters before.
  251.      If the value of the `revert-buffer-function' variable is
  252.      non-`nil', it is called as a function with no arguments to do the
  253.      work.
  254.  -- Variable: revert-buffer-function
  255.      The value of this variable is the function to use to revert this
  256.      buffer; but if the value of this variable is `nil', then the
  257.      `revert-buffer' function carries out its default action.  Modes
  258.      such as Dired mode, in which the text being edited does not
  259.      consist of a file's contents but can be regenerated in some other
  260.      fashion, give this variable a buffer-local value that is a
  261.      function to regenerate the contents.
  262.  -- Command: recover-file FILENAME
  263.      This function visits FILENAME, but gets the contents from its last
  264.      auto-save file.  This is useful after the system has crashed, to
  265.      resume editing the same file without losing all the work done in
  266.      the previous session.
  267.      An error is signaled if there is no auto-save file for FILENAME,
  268.      or if FILENAME is newer than its auto-save file.  If FILENAME does
  269.      not exist, but its auto-save file does, then the auto-save file is
  270.      read as usual.  This last situation may occur if you visited a
  271.      nonexistent file and never actually saved it.
  272. File: elisp,  Node: Buffers,  Next: Windows,  Prev: Backups and Auto-Saving,  Up: Top
  273. Buffers
  274. *******
  275.    A "buffer" is a Lisp object containing text to be edited.  Buffers
  276. are used to hold the contents of files that are being visited; there may
  277. also be buffers which are not visiting files.  While several buffers may
  278. exist at one time, exactly one buffer is designated the "current
  279. buffer" at any time.  Most editing commands act on the contents of the
  280. current buffer.  Each buffer, including the current buffer, may or may
  281. not be displayed in any windows.
  282. * Menu:
  283. * Buffer Basics::       What is a buffer?
  284. * Buffer Names::        Accessing and changing buffer names.
  285. * Buffer File Name::    The buffer file name indicates which file is visited.
  286. * Buffer Modification:: A buffer is "modified" if it needs to be saved.
  287. * Modification Time::   Determining whether the visited file was changed
  288.                          "behind Emacs's back".
  289. * Read Only Buffers::   Modifying text is not allowed in a read-only buffer.
  290. * The Buffer List::     How to look at all the existing buffers.
  291. * Creating Buffers::    Functions that create buffers.
  292. * Killing Buffers::     Buffers exist until explicitly killed.
  293. * Current Buffer::      Designating a buffer as current
  294.                           so primitives will access its contents.
  295. File: elisp,  Node: Buffer Basics,  Next: Buffer Names,  Prev: Buffers,  Up: Buffers
  296. Buffer Basics
  297. =============
  298.    A "buffer" is a Lisp object containing text to be edited.  Buffers
  299. are used to hold the contents of files that are being visited; there may
  300. also be buffers which are not visiting files.  While several buffers may
  301. exist at one time, exactly one buffer is designated the "current
  302. buffer" at any time.  Most editing commands act on the contents of the
  303. current buffer.  Each buffer, including the current buffer, may or may
  304. not be displayed in any windows.
  305.    Buffers in Emacs editing are objects which have distinct names and
  306. hold text that can be edited.  Buffers appear to Lisp programs as a
  307. special data type.  The contents of a buffer may be viewed as an
  308. extendible string; insertions and deletions may occur in any part of the
  309. buffer.  *Note Text::.
  310.    A Lisp buffer object contains numerous pieces of information.  Some
  311. of this information is directly accessible to the programmer through
  312. variables, while other information is only accessible through
  313. special-purpose functions.  For example, the width of a tab character is
  314. directly accessible through a variable, while the value of point is
  315. accessible only through a primitive function.
  316.    Buffer-specific information that is directly accessible is stored in
  317. "buffer-local" variable bindings, which are variable values that are
  318. effective only in a particular buffer.  This feature allows each buffer
  319. to override the values of certain variables.  Most major modes override
  320. variables such as `fill-column' or `comment-column' in this way.  For
  321. more information about buffer-local variables and functions related to
  322. them, see *Note Buffer-Local Variables::.
  323.    For functions and variables related to visiting files in buffers, see
  324. *Note Visiting Files:: and *Note Saving Buffers::.  For functions and
  325. variables related to the display of buffers in windows, see *Note
  326. Buffers and Windows::.
  327.  -- Function: bufferp OBJECT
  328.      This function returns `t' if OBJECT is a buffer, `nil' otherwise.
  329. File: elisp,  Node: Buffer Names,  Next: Buffer File Name,  Prev: Buffer Basics,  Up: Buffers
  330. Buffer Names
  331. ============
  332.    Each buffer has a unique name, which is a string.  The buffer name
  333. may be used in place of the buffer object in many functions that
  334. operate on buffers.  Buffers that are generally ephemeral and
  335. uninteresting to the user have names starting with a space, which
  336. prevents them from being listed by the `list-buffers' or `buffer-menu'
  337. commands.
  338.    Many of the following functions accept either a buffer or a buffer
  339. name (a string) as an argument.  Any argument called BUFFER-OR-NAME is
  340. of this sort, and an error is signaled if it is neither a string nor a
  341. buffer.  Any argument called BUFFER is required to be an actual buffer
  342. object, not a name.
  343.  -- Function: buffer-name &optional BUFFER
  344.      This function returns the name of BUFFER as a string.  If BUFFER
  345.      is not supplied, it defaults to the current buffer.
  346.      If `buffer-name' returns `nil', it means that BUFFER has been
  347.      killed.  *Note Killing Buffers::.
  348.           (buffer-name)
  349.                => "buffers.texi"
  350.           
  351.           (setq foo (get-buffer "temp"))
  352.                => #<buffer temp>
  353.           (kill-buffer foo)
  354.                => nil
  355.           (buffer-name foo)
  356.                => nil
  357.           foo
  358.                => #<killed buffer>
  359.  -- Command: rename-buffer NEWNAME
  360.      This function renames the current buffer to NEWNAME.  An error is
  361.      signaled if NEWNAME is not a string, or if there is already a
  362.      buffer with that name.  The function returns `nil'.
  363.      One application of this command is to rename the `*shell*' buffer
  364.      to some other name, thus making it possible to create a second
  365.      shell buffer under the name `*shell*'.
  366.  -- Function: get-buffer BUFFER-OR-NAME
  367.      This function returns the buffer specified by BUFFER-OR-NAME. If
  368.      BUFFER-OR-NAME is a string and there is no buffer with that name,
  369.      the value is `nil'.  If BUFFER-OR-NAME is a buffer, it is returned
  370.      as given.  (That is not very useful, so the argument is usually a
  371.      name.)  For example:
  372.           (setq b (get-buffer "lewis"))
  373.                => #<buffer lewis>
  374.           (get-buffer b)
  375.                => #<buffer lewis>
  376.           (get-buffer "Frazzle-nots")
  377.                => nil
  378. File: elisp,  Node: Buffer File Name,  Next: Buffer Modification,  Prev: Buffer Names,  Up: Buffers
  379. Buffer File Name
  380. ================
  381.    The "buffer file name" is the name of the file that is visited in
  382. that buffer.  When a buffer is not visiting a file, its buffer file name
  383. is `nil'.  Most of the time, the buffer name is the same as the
  384. nondirectory part of the buffer file name, but the buffer file name and
  385. the buffer name are distinct and can be set independently. *Note
  386. Visiting Files::.
  387.  -- Function: buffer-file-name &optional BUFFER
  388.      This function returns the absolute file name of the file that
  389.      BUFFER is visiting.  If BUFFER is not visiting any file,
  390.      `buffer-file-name' returns `nil'.  If BUFFER is not supplied, it
  391.      defaults to the current buffer.
  392.           (buffer-file-name (other-buffer))
  393.                => "/usr/user/lewis/manual/files.texi"
  394.  -- Variable: buffer-file-name
  395.      This buffer-local variable contains the name of the file being
  396.      visited in the current buffer, or `nil' if it is not visiting a
  397.      file.
  398.           buffer-file-name
  399.                => "/usr/user/lewis/manual/buffers.texi"
  400.      It is risky to change this variable's value without doing various
  401.      other things.  See the definition of `set-visited-file-name' in
  402.      `files.el'; some of the things done there, such as changing the
  403.      buffer name, are not necessary, but others are essential to avoid
  404.      confusing Emacs.
  405.  -- Function: get-file-buffer FILENAME
  406.      This function returns the buffer visiting file FILENAME.  If there
  407.      is no such buffer, it returns `nil'.  The argument FILENAME, which
  408.      must be a string, is expanded (*note File Name Expansion::.), then
  409.      compared against the visited file names of all live buffers.
  410.           (get-file-buffer "buffers.texi")
  411.           => #<buffer buffers.texi>
  412.      In unusual circumstances, there can be more than one buffer
  413.      visiting the same file name.  In such cases, this function returns
  414.      the first such buffer in the buffer list.
  415.  -- Command: set-visited-file-name FILENAME
  416.      If FILENAME is a non-empty string, this function changes the name
  417.      of the file visited in current buffer to FILENAME.  (If the buffer
  418.      had no visited file, this gives it one.)  The *next time* the
  419.      buffer is saved it will go in the newly-specified file.  The buffer
  420.      is always marked as modified, since it does not (as far as Emacs
  421.      knows) match the contents of FILENAME, even if it matched the
  422.      former visited file.
  423.      If FILENAME is `nil' or the empty string, that stands for "no
  424.      visited file".  In this case, `set-visited-file-name' marks the
  425.      buffer as having no visited file.
  426.      When `set-visited-file-name' is called interactively, it prompts
  427.      for FILENAME in the minibuffer.
  428.      See also `clear-visited-file-modtime' and
  429.      `verify-visited-file-modtime' in *Note Buffer Modification::.
  430. File: elisp,  Node: Buffer Modification,  Next: Modification Time,  Prev: Buffer File Name,  Up: Buffers
  431. Buffer Modification
  432. ===================
  433.    Emacs keeps a flag called the "modified flag" for each buffer, to
  434. record whether you have changed the text of the buffer.  This flag is
  435. set to `t' whenever you alter the contents of the buffer, and cleared
  436. to `nil' when you save it.  Thus, the flag shows whether there are
  437. unsaved changes.  The flag value is normally shown in the mode line
  438. (*note Mode Line Variables::.), and controls saving (*note Saving
  439. Buffers::.) and auto-saving (*note Auto-Saving::.).
  440.    Some Lisp programs set the flag explicitly.  For example, the Lisp
  441. function `set-visited-file-name' sets the flag to `t', because the text
  442. does not match the newly-visited file, even if it is unchanged from the
  443. file formerly visited.
  444.    The functions that modify the contents of buffers are described in
  445. *Note Text::.
  446.  -- Function: buffer-modified-p &optional BUFFER
  447.      This function returns `t' if the buffer BUFFER has been modified
  448.      since it was last read in from a file or saved, or `nil'
  449.      otherwise.  If BUFFER is not supplied, the current buffer is
  450.      tested.
  451.  -- Function: set-buffer-modified-p FLAG
  452.      This function marks the current buffer as modified if FLAG is
  453.      non-`nil', or as unmodified if the flag is `nil'.
  454.      Another effect of calling this function is to cause unconditional
  455.      redisplay of the mode line for the current buffer.  In fact, the
  456.      standard way to force redisplay of the mode line is as follows:
  457.           (set-buffer-modified-p (buffer-modified-p))
  458.  -- Command: not-modified
  459.      This command marks the current buffer as unmodified, and not
  460.      needing to be saved.  Don't use this function in programs, since
  461.      it prints a message; use `set-buffer-modified-p' (above) instead.
  462. File: elisp,  Node: Modification Time,  Next: Read Only Buffers,  Prev: Buffer Modification,  Up: Buffers
  463. Comparison of Modification Time
  464. ===============================
  465.    Suppose that you visit a file and make changes in its buffer, and
  466. meanwhile the file itself is changed on disk.  At this point, saving the
  467. buffer would overwrite the changes in the file.  Occasionally this may
  468. be what you want, but usually it would lose valuable information.  Emacs
  469. therefore checks the file's modification time using the functions
  470. described below before saving the file.
  471.  -- Function: verify-visited-file-modtime BUFFER
  472.      This function compares Emacs's record of the modification time for
  473.      the file that the buffer is visiting against the actual
  474.      modification time of the file as recorded by the operating system.
  475.       The two will be the same unless some other process has written
  476.      the file since Emacs visited or saved it.
  477.      The function returns `t' if the last actual modification time and
  478.      Emacs's recorded modification time are the same, `nil' otherwise.
  479.  -- Function: clear-visited-file-modtime
  480.      This function clears out the record of the last modification time
  481.      of the file being visited by the current buffer.  As a result, the
  482.      next attempt to save this buffer will not complain of a
  483.      discrepancy in file modification times.
  484.      This function is called in `set-visited-file-name' and other
  485.      exceptional places where the usual test to avoid overwriting a
  486.      changed file should not be done.
  487.  -- Function: ask-user-about-supersession-threat FN
  488.      This function is used to ask a user how to proceed after an
  489.      attempt to modify an obsolete buffer.  An "obsolete buffer" is an
  490.      unmodified buffer for which the associated file on disk is newer
  491.      than the last save-time of the buffer.  This means some other
  492.      program has probably altered the file.
  493.      This function is called automatically by Emacs on the proper
  494.      occasions.  It exists so you can customize Emacs by redefining it.
  495.      See the file `userlock.el' for the standard definition.
  496.      Depending on the user's answer, the function may return normally,
  497.      in which case the modification of the buffer proceeds, or it may
  498.      signal a `file-supersession' error with data `(FN)', in which case
  499.      the proposed buffer modification is not allowed.
  500.      See also the file locking mechanism in *Note File Locks::.
  501. File: elisp,  Node: Read Only Buffers,  Next: The Buffer List,  Prev: Modification Time,  Up: Buffers
  502. Read-Only Buffers
  503. =================
  504.    A buffer may be designated as "read-only".  This means that the
  505. buffer's contents may not be modified, although you may change your view
  506. of the contents by scrolling, narrowing, or widening, etc.
  507.    Read-only buffers are used in two kinds of situations:
  508.    * A buffer visiting a file is made read-only if the file is
  509.      write-protected.
  510.      Here, the purpose is to show the user that editing the buffer with
  511.      the aim of saving it in the file may be futile or undesirable. 
  512.      The user who wants to change the buffer text despite this can do
  513.      so after clearing the read-only flag with the function
  514.      `toggle-read-only'.
  515.    * Modes such as Dired and Rmail make buffers read-only when altering
  516.      the contents with the usual editing commands is probably a mistake.
  517.      The special commands of the mode in question bind
  518.      `buffer-read-only' to `nil' (with `let') around the places where
  519.      they change the text.
  520.  -- Variable: buffer-read-only
  521.      This buffer-local variable specifies whether the buffer is
  522.      read-only. The buffer is read-only if this variable is non-`nil'.
  523.  -- Command: toggle-read-only
  524.      This command changes whether the current buffer is read-only.  It
  525.      is intended for interactive use; don't use it in programs.  At any
  526.      given point in a program, you should know whether you want the
  527.      read-only flag on or off; so you can set `buffer-read-only'
  528.      explicitly to the proper value, `t' or `nil'.
  529.  -- Function: barf-if-buffer-read-only
  530.      This function signals a `buffer-read-only' error if the current
  531.      buffer is read-only.  *Note Interactive Call::, for another way to
  532.      signal an error if the current buffer is read-only.
  533. File: elisp,  Node: The Buffer List,  Next: Creating Buffers,  Prev: Read Only Buffers,  Up: Buffers
  534. The Buffer List
  535. ===============
  536.    The "buffer list" is a list of all buffers that have not been
  537. killed.  The order of the buffers in the list is based primarily on how
  538. recently each buffer has been displayed in the selected window.  Several
  539. functions, notably `other-buffer', make use of this ordering.
  540.  -- Function: buffer-list
  541.      This function returns a list of all buffers, including those whose
  542.      names begin with a space.  The elements are actual buffers, not
  543.      their names.
  544.           (buffer-list)
  545.                => (#<buffer buffers.texi> #<buffer  *Minibuf-1*>
  546.                    #<buffer buffer.c>  #<buffer *Help*> #<buffer TAGS>)
  547.           
  548.           ;; Note that the name of the minibuffer begins with a space!
  549.           
  550.           (mapcar (function buffer-name) (buffer-list))
  551.           => ("buffers.texi" " *Minibuf-1*" "buffer.c" "*Help*" "TAGS")
  552.      This list is a copy of a list used inside Emacs; modifying it has
  553.      no effect on the buffers.
  554.  -- Function: other-buffer &optional BUFFER-OR-NAME
  555.      This function returns the first buffer in the buffer list other
  556.      than BUFFER-OR-NAME.  Usually this is the buffer most recently
  557.      shown in the selected window, aside from BUFFER-OR-NAME.  Buffers
  558.      are moved to the front of the list when they are selected and to
  559.      the end when they are buried.  Buffers whose names start with a
  560.      space are not even considered.
  561.      If BUFFER-OR-NAME is not supplied (or if it is not a buffer), then
  562.      `other-buffer' returns the first buffer on the buffer list that is
  563.      not visible in any window.
  564.      If no suitable buffer exists, the buffer `*scratch*' is returned
  565.      (and created, if necessary).
  566.  -- Command: list-buffers &optional FILES-ONLY
  567.      This function displays a listing of the names of existing buffers.
  568.       It clears the buffer `*Buffer List*', then inserts the listing
  569.      into that buffer and displays it in a window.  `list-buffers' is
  570.      intended for interactive use, and is described fully in `The GNU
  571.      Emacs Manual'.  It returns `nil'.
  572.  -- Command: bury-buffer &optional BUFFER-OR-NAME
  573.      This function puts BUFFER-OR-NAME at the end of the buffer list
  574.      without changing the order of any of the other buffers on the list.
  575.      This buffer therefore becomes the least desirable candidate for
  576.      `other-buffer' to return, and appears last in the list displayed by
  577.      `list-buffers'.
  578.      If BUFFER-OR-NAME is the current buffer, then it is replaced in
  579.      the selected window by the buffer chosen using `other-buffer'.  If
  580.      the buffer is displayed in a window other than the selected one, it
  581.      remains there.
  582.      If BUFFER-OR-NAME is not supplied, it defaults to the current
  583.      buffer.  This is what happens in an interactive call.
  584. File: elisp,  Node: Creating Buffers,  Next: Killing Buffers,  Prev: The Buffer List,  Up: Buffers
  585. Creating Buffers
  586. ================
  587.    This section describes the two primitives for creating buffers.
  588. `get-buffer-create' creates a buffer if it finds no existing buffer;
  589. `generate-new-buffer' always creates a new buffer, and gives it a
  590. unique name.
  591.    Two other functions to create buffers are
  592. `with-output-to-temp-buffer' (*note Temporary Displays::.) and
  593. `create-file-buffer' (*note Visiting Files::.).
  594.  -- Function: get-buffer-create NAME
  595.      This function returns a buffer named NAME.  If such a buffer
  596.      already exists, it is returned.  If such a buffer does not exist,
  597.      one is created and returned.  The buffer does not become the
  598.      current buffer--this function does not change which buffer is
  599.      current.
  600.      An error is signaled if NAME is not a string.
  601.           (get-buffer-create "foo")
  602.                => #<buffer foo>
  603.      The major mode for the new buffer is chosen according to the value
  604.      of `default-major-mode'.  *Note Auto Major Mode::.
  605.  -- Function: generate-new-buffer NAME
  606.      This function returns a newly created, empty buffer.  If there is
  607.      no buffer named NAME, then that is the name of the new buffer.  If
  608.      there is a buffer with that name, then suffixes of the form `<N>'
  609.      are added to NAME, where N stands for successive integers starting
  610.      with 2.  New suffixes are tried until an unused name is found.
  611.      An error is signaled if NAME is not a string.
  612.           (generate-new-buffer "bar")
  613.                => #<buffer bar>
  614.           (generate-new-buffer "bar")
  615.                => #<buffer bar<2>>
  616.           (generate-new-buffer "bar")
  617.                => #<buffer bar<3>>
  618.      The major mode for the new buffer is chosen according to the value
  619.      of `default-major-mode'.  *Note Auto Major Mode::.
  620. File: elisp,  Node: Killing Buffers,  Next: Current Buffer,  Prev: Creating Buffers,  Up: Buffers
  621. Killing Buffers
  622. ===============
  623.    "Killing a buffer" makes its name unknown to Emacs and makes its
  624. space available for other use.
  625.    The buffer object for the buffer which has been killed remains in
  626. existence as long as anything refers to it, but it is specially marked
  627. so that you cannot make it current or display it.  Killed buffers retain
  628. their identity, however; two distinct buffers, when killed, remain
  629. distinct according to `eq'.
  630.    The `buffer-name' of a killed buffer is `nil'.  You can use this
  631. feature to test whether a buffer has been killed:
  632.      (defun killed-buffer-p (buffer)
  633.        "Return t if BUFFER is killed."
  634.        (not (buffer-name buffer)))
  635.  -- Command: kill-buffer BUFFER-OR-NAME
  636.      This function kills the buffer BUFFER-OR-NAME, freeing all its
  637.      memory for use as space for other buffers.  (In Emacs version 18,
  638.      the memory is not returned to the operating system.)  It returns
  639.      `nil'.
  640.      Any processes that have this buffer as the `process-buffer' are
  641.      sent the `SIGHUP' signal, which normally causes them to terminate.
  642.      (The usual meaning of `SIGHUP' is that a dialup line has been
  643.      disconnected.)  *Note Deleting Processes::.
  644.      If the buffer is visiting a file when `kill-buffer' is called and
  645.      the buffer has not been saved since it was last modified, the user
  646.      is asked to confirm before the buffer is killed.  This is done
  647.      even if `kill-buffer' is not called interactively.  To prevent the
  648.      request for confirmation, clear the modified flag before calling
  649.      `kill-buffer'.  *Note Buffer Modification::.
  650.           (kill-buffer "foo.unchanged")
  651.                => nil
  652.           (kill-buffer "foo.changed")
  653.           
  654.           ---------- Buffer: Minibuffer ----------
  655.           Buffer foo.changed modified; kill anyway? (yes or no) `yes'
  656.           ---------- Buffer: Minibuffer ----------
  657.           
  658.                => nil
  659. File: elisp,  Node: Current Buffer,  Prev: Killing Buffers,  Up: Buffers
  660. The Current Buffer
  661. ==================
  662.    There are in general many buffers in an Emacs session.  At any time,
  663. one of them is designated as the "current buffer".  This is the buffer
  664. in which most editing takes place, because most of the primitives for
  665. examining or changing text in a buffer operate implicitly on the
  666. current buffer (*note Text::.).  Normally the buffer that is displayed
  667. on the screen in the selected window is the current buffer, but this is
  668. not always so: a Lisp program can designate any buffer as current
  669. temporarily in order to operate on its contents, without changing what
  670. is displayed on the screen.
  671.    The way to designate a current buffer in a Lisp program is by calling
  672. `set-buffer'.  The specified buffer remains current until a new one is
  673. designated.
  674.    When an editing command returns to the editor command loop, the
  675. command loop designates the buffer displayed in the selected window as
  676. current, to prevent confusion: the buffer that the cursor is in, when
  677. Emacs reads a command, is the one to which the command will apply.
  678. (*Note Command Loop::.)  Therefore, `set-buffer' is not usable for
  679. switching visibly to a different buffer so that the user can edit it.
  680. For this, you must use the functions described in *Note Displaying
  681. Buffers::.
  682.    However, Lisp functions that change to a different current buffer
  683. should not rely on the command loop to set it back afterwards.  Editing
  684. commands written in Emacs Lisp can be called from other programs as well
  685. as from the command loop.  It is convenient for the caller if the
  686. subroutine does not change which buffer is current (unless, of course,
  687. that is the subroutine's purpose).  Therefore, you should normally use
  688. `set-buffer' within a `save-excursion' that will restore the current
  689. buffer when your program is done (*note Excursions::.).  Here is an
  690. example, the code for the command `append-to-buffer' (with the
  691. documentation string abridged):
  692.      (defun append-to-buffer (buffer start end)
  693.        "Append to specified buffer the text of the region..."
  694.        (interactive "BAppend to buffer: \nr")
  695.        (let ((oldbuf (current-buffer)))
  696.          (save-excursion
  697.            (set-buffer (get-buffer-create buffer))
  698.            (insert-buffer-substring oldbuf start end))))
  699. In this function, a local variable is bound to the current buffer, and
  700. then `save-excursion' records the values of point, the mark, and the
  701. original buffer.  Next, `set-buffer' makes another buffer current.
  702. Finally, `insert-buffer-substring' copies the string from the original
  703. current buffer to the new current buffer.
  704.    If the buffer appended to happens to be displayed in some window,
  705. then the next redisplay will show how its text has changed.  Otherwise,
  706. you will not see the change immediately on the screen.  The buffer
  707. becomes current temporarily during the execution of the command, but
  708. this does not cause it to be displayed.
  709.  -- Function: current-buffer
  710.      This function returns the current buffer.
  711.           (current-buffer)
  712.                => #<buffer buffers.texi>
  713.  -- Function: set-buffer BUFFER-OR-NAME
  714.      This function makes BUFFER-OR-NAME the current buffer.  However,
  715.      it does not display the buffer in the currently selected window or
  716.      in any other window.  This means that the user cannot necessarily
  717.      see the buffer, but Lisp programs can in any case work on it.
  718.      This function returns the buffer identified by BUFFER-OR-NAME. An
  719.      error is signaled if BUFFER-OR-NAME does not identify an existing
  720.      buffer.
  721. File: elisp,  Node: Windows,  Next: Positions,  Prev: Buffers,  Up: Top
  722. Windows
  723. *******
  724.    This chapter describes most of the functions and variables related to
  725. Emacs windows.  See *Note Emacs Display::, for information on how text
  726. is displayed in windows.
  727. * Menu:
  728. * Basic Windows::          Basic information on using windows.
  729. * Splitting Windows::      Splitting one window into two windows.
  730. * Deleting Windows::       Deleting a window gives its space to other windows.
  731. * Selecting Windows::      The selected window is the one that you edit in.
  732. * Cyclic Window Ordering:: Moving around the existing windows.
  733. * Buffers and Windows::    Each window displays the contents of a buffer.
  734. * Displaying Buffers::     Higher-lever functions for displaying a buffer
  735.                              and choosing a window for it.
  736. * Window Point::           Each window has its own location of point.
  737. * Window Start::           The display-start position controls which text
  738.                              is on-screen in the window.
  739. * Vertical Scrolling::     Moving text up and down in the window.
  740. * Horizontal Scrolling::   Moving text sideways on the window.
  741. * Size of Window::         Accessing the size of a window.
  742. * Resizing Windows::       Changing the size of a window.
  743. * Window Configurations::  Saving and restoring the state of the screen.
  744. File: elisp,  Node: Basic Windows,  Next: Splitting Windows,  Prev: Windows,  Up: Windows
  745. Basic Concepts of Emacs Windows
  746. ===============================
  747.    A "window" is the physical area of the screen in which a buffer is
  748. displayed.  The term is also used to refer to a Lisp object which
  749. represents that screen area in Emacs Lisp.  It should be clear from the
  750. context which is meant.
  751.    There is always at least one window displayed on the screen, and
  752. there is exactly one window that we call the "selected window".  The
  753. cursor is in the selected window.  The selected window's buffer is
  754. usually the current buffer (except when `set-buffer' has been used.) 
  755. *Note Current Buffer::.
  756.    For all intents, a window only exists while it is displayed on the
  757. terminal.  Once removed from the display, the window is effectively
  758. deleted and should not be used, *even though there may still be
  759. references to it* from other Lisp objects.  (*Note Deleting Windows::.)
  760.    Each window has the following attributes:
  761.    * window height
  762.    * window width
  763.    * window edges with respect to the screen
  764.    * the buffer it displays
  765.    * position within the buffer at the upper left of the window
  766.    * the amount of horizontal scrolling, in columns
  767.    * point
  768.    * the mark
  769.    * how recently the window was selected
  770.    Applications use multiple windows for a variety of reasons, but most
  771. often to give different views of the same information.  In Rmail, for
  772. example, you can move through a summary buffer in one window while the
  773. other window shows messages one at a time as they are reached.
  774.    Use of the word "window" to refer to a view of a buffer was
  775. established long ago in Emacs.  The metaphor was inspired by how you
  776. look out a house window--at part (or sometimes all) of an overall view.
  777. You see part (or sometimes all) of a buffer through an Emacs window.  In
  778. Emacs, each window may look on a different view, like different windows
  779. of a house.
  780.    The term "window" as used in this manual means something different
  781. from the term as used in a window system like X Windows.  In this
  782. manual, the term "window" refers to the nonoverlapping subdivisions of
  783. the Emacs display.  If Emacs is displaying on a window system, the Emacs
  784. display may itself be one X window among many on the screen.  But Emacs
  785. version 18 knows nothing of this.
  786.    For those familiar with windowing systems, Emacs's windows are
  787. rectangles tiled onto the rectangle of the screen, and every portion of
  788. the screen is part of some window, except (sometimes) the minibuffer
  789. area.  This limitation helps avoid wasting the historically scarce
  790. resource of screen space.  It also works well with character-only
  791. terminals.  Because of the way in which Emacs creates new windows and
  792. resizes them, you can't create every conceivable tiling on an Emacs
  793. screen.  *Note Splitting Windows::.  Also, see *Note Size of Window::.
  794.    *Note Emacs Display::, for information on how the contents of the
  795. window's buffer are displayed in the window.
  796.  -- Function: windowp OBJECT
  797.      This function returns `t' if OBJECT is a window.
  798. File: elisp,  Node: Splitting Windows,  Next: Deleting Windows,  Prev: Basic Windows,  Up: Windows
  799. Splitting Windows
  800. =================
  801.    The functions described here are the primitives used to split a
  802. window into two windows.  Two higher level functions sometimes split a
  803. window, but not always: `pop-to-buffer' and `display-buffer' (*note
  804. Displaying Buffers::.).
  805.    The functions described here do not accept a buffer as an argument.
  806. They let the two "halves" of the split window display the same buffer
  807. previously visible in the window that was split.
  808.  -- Function: one-window-p &optional NO-MINI
  809.      This function returns non-`nil' if there is only one window.  The
  810.      argument NO-MINI, if non-`nil', means don't count the minibuffer
  811.      even if it is active; otherwise, the minibuffer window is
  812.      included, if active, in the total number of windows which is
  813.      compared against one.
  814.  -- Command: split-window &optional WINDOW SIZE HORIZONTAL
  815.      This function splits WINDOW into two windows.  The original window
  816.      WINDOW remains the selected window, but occupies only part of its
  817.      former screen area.  The rest is occupied by a newly created
  818.      window which is returned as the value of this function.
  819.      If HORIZONTAL is non-`nil', then WINDOW splits side by side,
  820.      keeping the leftmost SIZE columns and giving the rest of the
  821.      columns to the new window.  Otherwise, it splits into halves one
  822.      above the other, keeping the upper SIZE lines and giving the rest
  823.      of the lines to the new window.  The original window is therefore
  824.      the right-hand or upper of the two, and the new window is the
  825.      left-hand or lower.
  826.      If WINDOW is omitted or `nil', then the selected window is split. 
  827.      If SIZE is omitted or `nil', then WINDOW is divided evenly into
  828.      two parts.  (If there is an odd line, it is allocated to the new
  829.      window.)  When `split-window' is called interactively, all its
  830.      arguments are `nil'.
  831.      The following example starts with one window on a screen that is 50
  832.      lines high by 80 columns wide; then the window is split.
  833.           (setq w (selected-window))
  834.                => #<window 8 on windows.texi>
  835.           (window-edges)                  ; Edges in order: left--top--right--bottom
  836.                => (0 0 80 50)
  837.           
  838.           (setq w2 (split-window w 15))   ; Returns window created
  839.                => #<window 28 on windows.texi>
  840.           (window-edges w2)
  841.                => (0 15 80 50)            ; Bottom window; top is line 15
  842.           (window-edges w)
  843.                => (0 0 80 15)             ; Top window
  844.      The screen looks like this:
  845.                    __________
  846.                   |          |  line 0
  847.                   |    w     |
  848.                   |__________|
  849.                   |          |  line 15
  850.                   |    w2    |
  851.                   |__________|
  852.                                 line 50
  853.            column 0   column 80
  854.      Next, the top window is split horizontally:
  855.           (setq w3 (split-window w 35 t))
  856.                => #<window 32 on windows.texi>
  857.           (window-edges w3)
  858.                => (35 0 80 15)  ; Left edge at column 35
  859.           (window-edges w)
  860.                => (0 0 35 15)   ; Right edge at column 35
  861.           (window-edges w2)
  862.                => (0 15 80 50)  ; Bottom window unchanged
  863.      Now, the screen looks like this:
  864.                column 35
  865.                    __________
  866.                   |   |      |  line 0
  867.                   | w |  w3  |
  868.                   |___|______|
  869.                   |          |  line 15
  870.                   |    w2    |
  871.                   |__________|
  872.                                 line 50
  873.            column 0   column 80
  874.  -- Command: split-window-vertically SIZE
  875.      This function splits the selected window into two windows, one
  876.      above the other, leaving the selected window with SIZE lines.
  877.      This function is simply an interface to `split-windows'. Here is
  878.      the complete function definition for it:
  879.           (defun split-window-vertically (&optional arg)
  880.             "Split selected window into two windows, one above the other..."
  881.             (interactive "P")
  882.             (split-window nil (and arg (prefix-numeric-value arg))))
  883.  -- Command: split-window-horizontally SIZE
  884.      This function splits the selected window into two windows
  885.      side-by-side, leaving the selected window with SIZE columns.
  886.      This function is simply an interface to `split-windows'.  Here is
  887.      the complete definition for `split-window-horizontally' (except for
  888.      part of the documentation string):
  889.           (defun split-window-horizontally (&optional arg)
  890.             "Split selected window into two windows side by side..."
  891.             (interactive "P")
  892.             (split-window nil (and arg (prefix-numeric-value arg)) t))
  893.