*** empty log message ***
[bpt/emacs.git] / lispref / buffers.texi
index 600ff3e..b82c0df 100644 (file)
@@ -1,6 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. 
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
+@c   Free Software Foundation, Inc. 
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/buffers
 @node Buffers, Windows, Backups and Auto-Saving, Top
@@ -10,7 +11,7 @@
   A @dfn{buffer} is a Lisp object containing text to be edited.  Buffers
 are used to hold the contents of files that are being visited; there may
 also be buffers that are not visiting files.  While several buffers may
-exist at one time, exactly one buffer is designated the @dfn{current
+exist at one time, only one buffer is designated the @dfn{current
 buffer} at any time.  Most editing commands act on the contents of the
 current buffer.  Each buffer, including the current buffer, may or may
 not be displayed in any windows.
@@ -18,7 +19,7 @@ not be displayed in any windows.
 @menu
 * Buffer Basics::       What is a buffer?
 * Current Buffer::      Designating a buffer as current
-                          so primitives will access its contents.
+                          so that primitives will access its contents.
 * Buffer Names::        Accessing and changing buffer names.
 * Buffer File Name::    The buffer file name indicates which file is visited.
 * Buffer Modification:: A buffer is @dfn{modified} if it needs to be saved.
@@ -29,27 +30,28 @@ not be displayed in any windows.
 * Creating Buffers::    Functions that create buffers.
 * Killing Buffers::     Buffers exist until explicitly killed.
 * Indirect Buffers::    An indirect buffer shares text with some other buffer.
+* Buffer Gap::          The gap in the buffer.
 @end menu
 
 @node Buffer Basics
 @comment  node-name,  next,  previous,  up
 @section Buffer Basics
 
-@ifinfo
+@ifnottex
   A @dfn{buffer} is a Lisp object containing text to be edited.  Buffers
 are used to hold the contents of files that are being visited; there may
-also be buffers that are not visiting files.  While several buffers may
-exist at one time, exactly one buffer is designated the @dfn{current
+also be buffers that are not visiting files.  Although several buffers
+normally exist, only one buffer is designated the @dfn{current
 buffer} at any time.  Most editing commands act on the contents of the
 current buffer.  Each buffer, including the current buffer, may or may
 not be displayed in any windows.
-@end ifinfo
+@end ifnottex
 
   Buffers in Emacs editing are objects that have distinct names and hold
 text that can be edited.  Buffers appear to Lisp programs as a special
-data type.  You can think of the contents of a buffer as an extendable
-string; insertions and deletions may occur in any part of the buffer.
-@xref{Text}.
+data type.  You can think of the contents of a buffer as a string that
+you can extend; insertions and deletions may occur in any part of the
+buffer.  @xref{Text}.
 
   A Lisp buffer object contains numerous pieces of information.  Some of
 this information is directly accessible to the programmer through
@@ -102,17 +104,17 @@ current, to prevent confusion: the buffer that the cursor is in when
 Emacs reads a command is the buffer that the command will apply to.
 (@xref{Command Loop}.)  Therefore, @code{set-buffer} is not the way to
 switch visibly to a different buffer so that the user can edit it.  For
-this, you must use the functions described in @ref{Displaying Buffers}.
+that, you must use the functions described in @ref{Displaying Buffers}.
 
-  However, Lisp functions that change to a different current buffer
+  @strong{Note:} Lisp functions that change to a different current buffer
 should not depend on the command loop to set it back afterwards.
 Editing commands written in Emacs Lisp can be called from other programs
-as well as from the command loop.  It is convenient for the caller if
+as well as from the command loop; it is convenient for the caller if
 the subroutine does not change which buffer is current (unless, of
 course, that is the subroutine's purpose).  Therefore, you should
 normally use @code{set-buffer} within a @code{save-current-buffer} or
 @code{save-excursion} (@pxref{Excursions}) form that will restore the
-current buffer when your function is done .  Here is an example, the
+current buffer when your function is done.  Here is an example, the
 code for the command @code{append-to-buffer} (with the documentation
 string abridged):
 
@@ -152,9 +154,9 @@ binding.  Otherwise, use @code{save-current-buffer} or
 @code{save-excursion} to make sure that the buffer current at the
 beginning is current again whenever the variable is unbound.
 
-  It is not reliable to change the current buffer back with
-@code{set-buffer}, because that won't do the job if a quit happens while
-the wrong buffer is current.  Here is what @emph{not} to do:
+  Do not rely on using @code{set-buffer} to change the current buffer
+back, because that won't do the job if a quit happens while the wrong
+buffer is current.  Here is what @emph{not} to do:
 
 @example
 @group
@@ -191,18 +193,16 @@ This function returns the current buffer.
 @end defun
 
 @defun set-buffer buffer-or-name
-This function makes @var{buffer-or-name} the current buffer.  It does
-not display the buffer in the currently selected window or in any other
-window, so the user cannot necessarily see the buffer.  But Lisp
-programs can in any case work on it.
+This function makes @var{buffer-or-name} the current buffer.  This does
+not display the buffer in any window, so the user cannot necessarily see
+the buffer.  But Lisp programs will now operate on it.
 
 This function returns the buffer identified by @var{buffer-or-name}.
 An error is signaled if @var{buffer-or-name} does not identify an
 existing buffer.
 @end defun
 
-@tindex save-current-buffer
-@defmac save-current-buffer body...
+@defspec save-current-buffer body...
 The @code{save-current-buffer} macro saves the identity of the current
 buffer, evaluates the @var{body} forms, and finally restores that buffer
 as current.  The return value is the value of the last form in
@@ -213,9 +213,8 @@ If the buffer that used to be current has been killed by the time of
 exit from @code{save-current-buffer}, then it is not made current again,
 of course.  Instead, whichever buffer was current just before exit
 remains current.
-@end defmac
+@end defspec
 
-@tindex with-current-buffer
 @defmac with-current-buffer buffer body...
 The @code{with-current-buffer} macro saves the identity of the current
 buffer, makes @var{buffer} current, evaluates the @var{body} forms, and
@@ -224,7 +223,6 @@ form in @var{body}.  The current buffer is restored even in case of an
 abnormal exit via @code{throw} or error (@pxref{Nonlocal Exits}).
 @end defmac
 
-@tindex with-temp-buffer
 @defmac with-temp-buffer body...
 The @code{with-temp-buffer} macro evaluates the @var{body} forms
 with a temporary buffer as the current buffer.  It saves the identity of
@@ -301,18 +299,15 @@ Ordinarily, @code{rename-buffer} signals an error if @var{newname} is
 already in use.  However, if @var{unique} is non-@code{nil}, it modifies
 @var{newname} to make a name that is not in use.  Interactively, you can
 make @var{unique} non-@code{nil} with a numeric prefix argument.
-
-One application of this command is to rename the @samp{*shell*} buffer
-to some other name, thus making it possible to create a second shell
-buffer under the name @samp{*shell*}.
+(This is how the command @code{rename-uniquely} is implemented.)
 @end deffn
 
 @defun get-buffer buffer-or-name
 This function returns the buffer specified by @var{buffer-or-name}.
 If @var{buffer-or-name} is a string and there is no buffer with that
 name, the value is @code{nil}.  If @var{buffer-or-name} is a buffer, it
-is returned as given.  (That is not very useful, so the argument is usually 
-a name.)  For example:
+is returned as given; that is not very useful, so the argument is usually 
+a name.  For example:
 
 @example
 @group
@@ -333,12 +328,28 @@ See also the function @code{get-buffer-create} in @ref{Creating Buffers}.
 @end defun
 
 @c Emacs 19 feature
-@defun generate-new-buffer-name starting-name
+@defun generate-new-buffer-name starting-name &rest ignore
 This function returns a name that would be unique for a new buffer---but
 does not create the buffer.  It starts with @var{starting-name}, and
 produces a name not currently in use for any buffer by appending a
 number inside of @samp{<@dots{}>}.
 
+If the optional second argument @var{ignore} is non-@code{nil}, it
+should be a string; it makes a difference if it is a name in the
+sequence of names to be tried.  That name will be considered acceptable,
+if it is tried, even if a buffer with that name exists.  Thus, if
+buffers named @samp{foo}, @samp{foo<2>}, @samp{foo<3>} and @samp{foo<4>}
+exist,
+
+@example
+(generate-new-buffer-name "foo")
+     @result{} "foo<5>"
+(generate-new-buffer-name "foo" "foo<3>")
+     @result{} "foo<3>"
+(generate-new-buffer-name "foo" "foo<6>")
+     @result{} "foo<5>"
+@end example
+
 See the related function @code{generate-new-buffer} in @ref{Creating
 Buffers}.
 @end defun
@@ -373,7 +384,8 @@ supplied, it defaults to the current buffer.
 @defvar buffer-file-name
 This buffer-local variable contains the name of the file being visited
 in the current buffer, or @code{nil} if it is not visiting a file.  It
-is a permanent local, unaffected by @code{kill-local-variables}.
+is a permanent local variable, unaffected by
+@code{kill-all-local-variables}.
 
 @example
 @group
@@ -392,14 +404,14 @@ Emacs.
 @defvar buffer-file-truename
 This buffer-local variable holds the truename of the file visited in the
 current buffer, or @code{nil} if no file is visited.  It is a permanent
-local, unaffected by @code{kill-local-variables}.  @xref{Truenames}.
+local, unaffected by @code{kill-all-local-variables}.  @xref{Truenames}.
 @end defvar
 
 @defvar buffer-file-number
 This buffer-local variable holds the file number and directory device
 number of the file visited in the current buffer, or @code{nil} if no
 file or a nonexistent file is visited.  It is a permanent local,
-unaffected by @code{kill-local-variables}.
+unaffected by @code{kill-all-local-variables}.
 
 The value is normally a list of the form @code{(@var{filenum}
 @var{devnum})}.  This pair of numbers uniquely identifies the file among
@@ -427,9 +439,9 @@ the same file name.  In such cases, this function returns the first
 such buffer in the buffer list.
 @end defun
 
-@deffn Command set-visited-file-name filename
+@deffn Command set-visited-file-name filename &optional no-query along-with-file
 If @var{filename} is a non-empty string, this function changes the
-name of the file visited in current buffer to @var{filename}.  (If the
+name of the file visited in the current buffer to @var{filename}.  (If the
 buffer had no visited file, this gives it one.)  The @emph{next time}
 the buffer is saved it will go in the newly-specified file.  This
 command marks the buffer as modified, since it does not (as far as Emacs
@@ -440,6 +452,13 @@ If @var{filename} is @code{nil} or the empty string, that stands for
 ``no visited file''.  In this case, @code{set-visited-file-name} marks
 the buffer as having no visited file.
 
+Normally, this function asks the user for confirmation if the specified
+file already exists.  If @var{no-query} is non-@code{nil}, that prevents
+asking this question.
+
+If @var{along-with-file} is non-@code{nil}, that means to assume that the
+former visited file has been renamed to @var{filename}.
+
 @c Wordy to avoid overfull hbox.  --rjc 16mar92
 When the function @code{set-visited-file-name} is called interactively, it
 prompts for @var{filename} in the minibuffer.
@@ -613,7 +632,7 @@ the read-only flag with @kbd{C-x C-q}.
 
 @item
 Modes such as Dired and Rmail make buffers read-only when altering the
-contents with the usual editing commands is probably a mistake.
+contents with the usual editing commands would probably be a mistake.
 
 The special commands of these modes bind @code{buffer-read-only} to
 @code{nil} (with @code{let}) or bind @code{inhibit-read-only} to
@@ -641,7 +660,7 @@ of the list (comparison is done with @code{eq}).
 
 @deffn Command toggle-read-only
 This command changes whether the current buffer is read-only.  It is
-intended for interactive use; don't use it in programs.  At any given
+intended for interactive use; do not use it in programs.  At any given
 point in a program, you should know whether you want the read-only flag
 on or off; so you can set @code{buffer-read-only} explicitly to the
 proper value, @code{t} or @code{nil}.
@@ -723,21 +742,21 @@ live buffer.
 @code{buffer-list} frame parameter with @code{modify-frame-parameters}
 (@pxref{Parameter Access}).
 
-@defun other-buffer &optional buffer visible-ok
+@defun other-buffer &optional buffer visible-ok frame
 This function returns the first buffer in the buffer list other than
-@var{buffer}.  Usually this is the buffer selected most recently (in the
-currently selected frame), aside from @var{buffer}.  Buffers whose names
-start with a space are not considered at all.
+@var{buffer}.  Usually this is the buffer selected most recently (in
+frame @var{frame} or else the currently selected frame), aside from
+@var{buffer}.  Buffers whose names start with a space are not considered
+at all.
 
 If @var{buffer} is not supplied (or if it is not a buffer), then
 @code{other-buffer} returns the first buffer in the selected frame's
 buffer list that is not now visible in any window in a visible frame.
 
-If the selected frame has a non-@code{nil} @code{buffer-predicate}
-parameter, then @code{other-buffer} uses that predicate to decide which
-buffers to consider.  It calls the predicate once for each buffer, and
-if the value is @code{nil}, that buffer is ignored.  @xref{Window Frame
-Parameters}.
+If @var{frame} has a non-@code{nil} @code{buffer-predicate} parameter,
+then @code{other-buffer} uses that predicate to decide which buffers to
+consider.  It calls the predicate once for each buffer, and if the value
+is @code{nil}, that buffer is ignored.  @xref{Window Frame Parameters}.
 
 @c Emacs 19 feature
 If @var{visible-ok} is @code{nil}, @code{other-buffer} avoids returning
@@ -849,8 +868,8 @@ text space available for other use.
   The buffer object for the buffer that has been killed remains in
 existence as long as anything refers to it, but it is specially marked
 so that you cannot make it current or display it.  Killed buffers retain
-their identity, however; two distinct buffers, when killed, remain
-distinct according to @code{eq}.
+their identity, however; if you kill two distinct buffers, they remain
+distinct according to @code{eq} although both are dead.
 
   If you kill a buffer that is current or displayed in a window, Emacs
 automatically selects or displays some other buffer instead.  This means
@@ -908,9 +927,9 @@ Buffer foo.changed modified; kill anyway? (yes or no) @kbd{yes}
 After confirming unsaved changes, @code{kill-buffer} calls the functions
 in the list @code{kill-buffer-query-functions}, in order of appearance,
 with no arguments.  The buffer being killed is the current buffer when
-they are called.  The idea is that these functions ask for confirmation
-from the user for various nonstandard reasons.  If any of them returns
-@code{nil}, @code{kill-buffer} spares the buffer's life.
+they are called.  The idea of this feature is that these functions will
+ask for confirmation from the user.  If any of them returns @code{nil},
+@code{kill-buffer} spares the buffer's life.
 @end defvar
 
 @defvar kill-buffer-hook
@@ -943,7 +962,7 @@ base buffer; changes made by editing either one are visible immediately
 in the other.  This includes the text properties as well as the characters
 themselves.
 
-  But in all other respects, the indirect buffer and its base buffer are
+  In all other respects, the indirect buffer and its base buffer are
 completely separate.  They have different names, different values of
 point, different narrowing, different markers and overlays (though
 inserting or deleting text in either buffer relocates the markers and
@@ -951,8 +970,8 @@ overlays for both), different major modes, and different buffer-local
 variables.
 
   An indirect buffer cannot visit a file, but its base buffer can.  If
-you try to save the indirect buffer, that actually works by saving the
-base buffer.
+you try to save the indirect buffer, that actually saves the base
+buffer.
 
   Killing an indirect buffer has no effect on its base buffer.  Killing
 the base buffer effectively kills the indirect buffer in that it cannot
@@ -973,3 +992,26 @@ is not indirect, the value is @code{nil}.  Otherwise, the value is
 another buffer, which is never an indirect buffer.
 @end defun
 
+@node Buffer Gap
+@section The Buffer Gap
+
+  Emacs buffers are implemented using an invisible @dfn{gap} to make
+insertion and deletion faster.  Insertion works by filling in part of
+the gap, and deletion adds to the gap.  Of course, this means that the
+gap must first be moved to the locus of the insertion or deletion.
+Emacs moves the gap only when you try to insert or delete.  This is why
+your first editing command in one part of a large buffer, after
+previously editing in another far-away part, sometimes involves a
+noticeable delay.
+
+  This mechanism works invisibly, and Lisp code should never be affected
+by the gap's current location, but these functions are available for
+getting information about the gap status.
+
+@defun gap-position
+This function returns the current gap position in the current buffer.
+@end defun
+
+@defun gap-size
+This function returns the current gap size of the current buffer.
+@end defun