annotate man/lispref/buffers.texi @ 5384:3889ef128488

Fix misspelled words, and some grammar, across the entire source tree. See xemacs-patches message with ID <AANLkTi=edkEKtK3pZ60ytsG5pTJQy2TjAEVCZCLOa-oA@mail.gmail.com>.
author Jerry James <james@xemacs.org>
date Thu, 24 Mar 2011 11:00:11 -0600
parents 6772ce4d982b
children 9fae6227ede5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/buffers.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Buffers, Windows, Backups and Auto-Saving, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 @cindex buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 A @dfn{buffer} is a Lisp object containing text to be edited. Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 are used to hold the contents of files that are being visited; there may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 also be buffers that are not visiting files. While several buffers may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 exist at one time, exactly one buffer is designated the @dfn{current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 buffer} at any time. Most editing commands act on the contents of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 current buffer. Each buffer, including the current buffer, may or may
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
16 not be displayed in any window.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 * Buffer Basics:: What is a buffer?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 * Current Buffer:: Designating a buffer as current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 so primitives will access its contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 * Buffer Names:: Accessing and changing buffer names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 * Buffer File Name:: The buffer file name indicates which file is visited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 * Buffer Modification:: A buffer is @dfn{modified} if it needs to be saved.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 * Modification Time:: Determining whether the visited file was changed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ``behind XEmacs's back''.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 * Read Only Buffers:: Modifying text is not allowed in a read-only buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 * The Buffer List:: How to look at all the existing buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 * Creating Buffers:: Functions that create buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 * Killing Buffers:: Buffers exist until explicitly killed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 * Indirect Buffers:: An indirect buffer shares text with some other buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 @node Buffer Basics
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 @section Buffer Basics
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 @ifinfo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 A @dfn{buffer} is a Lisp object containing text to be edited. Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 are used to hold the contents of files that are being visited; there may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 also be buffers that are not visiting files. While several buffers may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 exist at one time, exactly one buffer is designated the @dfn{current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 buffer} at any time. Most editing commands act on the contents of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 current buffer. Each buffer, including the current buffer, may or may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 not be displayed in any windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 @end ifinfo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 Buffers in Emacs editing are objects that have distinct names and hold
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 text that can be edited. Buffers appear to Lisp programs as a special
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
49 data type. You can think of the contents of a buffer as an extendible
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 string; insertions and deletions may occur in any part of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 @xref{Text}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 A Lisp buffer object contains numerous pieces of information. Some of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 this information is directly accessible to the programmer through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 variables, while other information is accessible only through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 special-purpose functions. For example, the visited file name is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 directly accessible through a variable, while the value of point is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 accessible only through a primitive function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 Buffer-specific information that is directly accessible is stored in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 @dfn{buffer-local} variable bindings, which are variable values that are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 effective only in a particular buffer. This feature allows each buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 to override the values of certain variables. Most major modes override
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 variables such as @code{fill-column} or @code{comment-column} in this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 way. For more information about buffer-local variables and functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 related to them, see @ref{Buffer-Local Variables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 For functions and variables related to visiting files in buffers, see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 @ref{Visiting Files} and @ref{Saving Buffers}. For functions and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 variables related to the display of buffers in windows, see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 @ref{Buffers and Windows}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 @defun bufferp object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 This function returns @code{t} if @var{object} is a buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 @code{nil} otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 @node Current Buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 @section The Current Buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 @cindex selecting a buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 @cindex changing to another buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 @cindex current buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 There are, in general, many buffers in an Emacs session. At any time,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 one of them is designated as the @dfn{current buffer}. This is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 buffer in which most editing takes place, because most of the primitives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 for examining or changing text in a buffer operate implicitly on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 current buffer (@pxref{Text}). Normally the buffer that is displayed on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 the screen in the selected window is the current buffer, but this is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 always so: a Lisp program can designate any buffer as current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 temporarily in order to operate on its contents, without changing what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 is displayed on the screen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 The way to designate a current buffer in a Lisp program is by calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 @code{set-buffer}. The specified buffer remains current until a new one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 is designated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 When an editing command returns to the editor command loop, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 command loop designates the buffer displayed in the selected window as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 current, to prevent confusion: the buffer that the cursor is in when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 Emacs reads a command is the buffer that the command will apply to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (@xref{Command Loop}.) Therefore, @code{set-buffer} is not the way to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 switch visibly to a different buffer so that the user can edit it. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 this, you must use the functions described in @ref{Displaying Buffers}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 However, Lisp functions that change to a different current buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 should not depend on the command loop to set it back afterwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 Editing commands written in XEmacs Lisp can be called from other programs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 as well as from the command loop. It is convenient for the caller if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 the subroutine does not change which buffer is current (unless, of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 course, that is the subroutine's purpose). Therefore, you should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 normally use @code{set-buffer} within a @code{save-excursion} that will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 restore the current buffer when your function is done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 (@pxref{Excursions}). Here is an example, the code for the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 @code{append-to-buffer} (with the documentation string abridged):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 (defun append-to-buffer (buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 "Append to specified buffer the text of the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 @dots{}"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 (interactive "BAppend to buffer: \nr")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 (let ((oldbuf (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (set-buffer (get-buffer-create buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (insert-buffer-substring oldbuf start end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 This function binds a local variable to the current buffer, and then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 @code{save-excursion} records the values of point, the mark, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 original buffer. Next, @code{set-buffer} makes another buffer current.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 Finally, @code{insert-buffer-substring} copies the string from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 original current buffer to the new current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
137 If the buffer appended to happens to be displayed in some window,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 the next redisplay will show how its text has changed. Otherwise, you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 will not see the change immediately on the screen. The buffer becomes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 current temporarily during the execution of the command, but this does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 not cause it to be displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 If you make local bindings (with @code{let} or function arguments) for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 a variable that may also have buffer-local bindings, make sure that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 same buffer is current at the beginning and at the end of the local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 binding's scope. Otherwise you might bind it in one buffer and unbind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 it in another! There are two ways to do this. In simple cases, you may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 see that nothing ever changes the current buffer within the scope of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 binding. Otherwise, use @code{save-excursion} to make sure that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 buffer current at the beginning is current again whenever the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 is unbound.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 It is not reliable to change the current buffer back with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 @code{set-buffer}, because that won't do the job if a quit happens while
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 the wrong buffer is current. Here is what @emph{not} to do:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (let (buffer-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (obuf (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (set-buffer @dots{})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 @dots{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (set-buffer obuf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 Using @code{save-excursion}, as shown below, handles quitting, errors,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 and @code{throw}, as well as ordinary evaluation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (let (buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (set-buffer @dots{})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 @dots{}))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 @defun current-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 This function returns the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 (current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 @result{} #<buffer buffers.texi>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 @defun set-buffer buffer-or-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 This function makes @var{buffer-or-name} the current buffer. It does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 not display the buffer in the currently selected window or in any other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 window, so the user cannot necessarily see the buffer. But Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 programs can in any case work on it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
197 @var{buffer-or-name} must be a buffer or the name of an existing
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
198 buffer--else an error is signaled. This function returns the buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
199 identified by @var{buffer-or-name}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 @node Buffer Names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 @section Buffer Names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 @cindex buffer names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 Each buffer has a unique name, which is a string. Many of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 functions that work on buffers accept either a buffer or a buffer name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 as an argument. Any argument called @var{buffer-or-name} is of this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 sort, and an error is signaled if it is neither a string nor a buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 Any argument called @var{buffer} must be an actual buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 object, not a name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 Buffers that are ephemeral and generally uninteresting to the user
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 have names starting with a space, so that the @code{list-buffers} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 @code{buffer-menu} commands don't mention them. A name starting with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 space also initially disables recording undo information; see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 @ref{Undo}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 @defun buffer-name &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 This function returns the name of @var{buffer} as a string. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 @var{buffer} is not supplied, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 If @code{buffer-name} returns @code{nil}, it means that @var{buffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 has been killed. @xref{Killing Buffers}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (buffer-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 @result{} "buffers.texi"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (setq foo (get-buffer "temp"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 @result{} #<buffer temp>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (kill-buffer foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (buffer-name foo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 foo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 @result{} #<killed buffer>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 @deffn Command rename-buffer newname &optional unique
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 This function renames the current buffer to @var{newname}. An error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 is signaled if @var{newname} is not a string, or if there is already a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 buffer with that name. The function returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 Ordinarily, @code{rename-buffer} signals an error if @var{newname} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 already in use. However, if @var{unique} is non-@code{nil}, it modifies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 @var{newname} to make a name that is not in use. Interactively, you can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 make @var{unique} non-@code{nil} with a numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 One application of this command is to rename the @samp{*shell*} buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 to some other name, thus making it possible to create a second shell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 buffer under the name @samp{*shell*}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 @defun get-buffer buffer-or-name
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
268 This function returns the buffer named @var{buffer-or-name}. If
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
269 @var{buffer-or-name} is a string and there is no buffer with that name,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
270 the value is @code{nil}. If @var{buffer-or-name} is actually a buffer,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
271 it is returned as given. (That is not very useful, so the argument is
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
272 usually a name.) For example:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (setq b (get-buffer "lewis"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 @result{} #<buffer lewis>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (get-buffer b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 @result{} #<buffer lewis>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (get-buffer "Frazzle-nots")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 See also the function @code{get-buffer-create} in @ref{Creating Buffers}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 @defun generate-new-buffer-name starting-name &optional ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 This function returns a name that would be unique for a new buffer---but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 does not create the buffer. It starts with @var{starting-name}, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 produces a name not currently in use for any buffer by appending a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 number inside of @samp{<@dots{}>}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 If @var{ignore} is given, it specifies a name that is okay to use (if it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 is in the sequence to be tried), even if a buffer with that name exists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 See the related function @code{generate-new-buffer} in @ref{Creating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 Buffers}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 @node Buffer File Name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 @section Buffer File Name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 @cindex visited file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 @cindex buffer file name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 @cindex file name of buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 The @dfn{buffer file name} is the name of the file that is visited in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 that buffer. When a buffer is not visiting a file, its buffer file name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 is @code{nil}. Most of the time, the buffer name is the same as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 nondirectory part of the buffer file name, but the buffer file name and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 the buffer name are distinct and can be set independently.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 @xref{Visiting Files}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 @defun buffer-file-name &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 This function returns the absolute file name of the file that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 @var{buffer} is visiting. If @var{buffer} is not visiting any file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 @code{buffer-file-name} returns @code{nil}. If @var{buffer} is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 supplied, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (buffer-file-name (other-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 @result{} "/usr/user/lewis/manual/files.texi"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 @defvar buffer-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 This buffer-local variable contains the name of the file being visited
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 in the current buffer, or @code{nil} if it is not visiting a file. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 is a permanent local, unaffected by @code{kill-local-variables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 buffer-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 @result{} "/usr/user/lewis/manual/buffers.texi"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 It is risky to change this variable's value without doing various other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 things. See the definition of @code{set-visited-file-name} in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 @file{files.el}; some of the things done there, such as changing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 buffer name, are not strictly necessary, but others are essential to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 avoid confusing XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 @defvar buffer-file-truename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 This buffer-local variable holds the truename of the file visited in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 current buffer, or @code{nil} if no file is visited. It is a permanent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 local, unaffected by @code{kill-local-variables}. @xref{Truenames}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 @defvar buffer-file-number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 This buffer-local variable holds the file number and directory device
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 number of the file visited in the current buffer, or @code{nil} if no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 file or a nonexistent file is visited. It is a permanent local,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 unaffected by @code{kill-local-variables}. @xref{Truenames}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 The value is normally a list of the form @code{(@var{filenum}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 @var{devnum})}. This pair of numbers uniquely identifies the file among
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 all files accessible on the system. See the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 @code{file-attributes}, in @ref{File Attributes}, for more information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 about them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 @defun get-file-buffer filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 This function returns the buffer visiting file @var{filename}. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 there is no such buffer, it returns @code{nil}. The argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 @var{filename}, which must be a string, is expanded (@pxref{File Name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 Expansion}), then compared against the visited file names of all live
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (get-file-buffer "buffers.texi")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 @result{} #<buffer buffers.texi>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 In unusual circumstances, there can be more than one buffer visiting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 the same file name. In such cases, this function returns the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 such buffer in the buffer list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 @deffn Command set-visited-file-name filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 If @var{filename} is a non-empty string, this function changes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 name of the file visited in current buffer to @var{filename}. (If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 buffer had no visited file, this gives it one.) The @emph{next time}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 the buffer is saved it will go in the newly-specified file. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 command marks the buffer as modified, since it does not (as far as XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 knows) match the contents of @var{filename}, even if it matched the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 former visited file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 If @var{filename} is @code{nil} or the empty string, that stands for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 ``no visited file''. In this case, @code{set-visited-file-name} marks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 the buffer as having no visited file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 @c Wordy to avoid overfull hbox. --rjc 16mar92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 When the function @code{set-visited-file-name} is called interactively, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 prompts for @var{filename} in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 See also @code{clear-visited-file-modtime} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 @code{verify-visited-file-modtime} in @ref{Buffer Modification}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 @defvar list-buffers-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 This buffer-local variable records a string to display in a buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 listing in place of the visited file name, for buffers that don't have a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 visited file name. Dired buffers use this variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 @node Buffer Modification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 @section Buffer Modification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 @cindex buffer modification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 @cindex modification flag (of buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 XEmacs keeps a flag called the @dfn{modified flag} for each buffer, to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 record whether you have changed the text of the buffer. This flag is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 set to @code{t} whenever you alter the contents of the buffer, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 cleared to @code{nil} when you save it. Thus, the flag shows whether
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 there are unsaved changes. The flag value is normally shown in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 modeline (@pxref{Modeline Variables}), and controls saving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (@pxref{Saving Buffers}) and auto-saving (@pxref{Auto-Saving}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 Some Lisp programs set the flag explicitly. For example, the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 @code{set-visited-file-name} sets the flag to @code{t}, because the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 does not match the newly-visited file, even if it is unchanged from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 file formerly visited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 The functions that modify the contents of buffers are described in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 @ref{Text}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 @defun buffer-modified-p &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 This function returns @code{t} if the buffer @var{buffer} has been modified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 since it was last read in from a file or saved, or @code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 otherwise. If @var{buffer} is not supplied, the current buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 is tested.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
444 @defun set-buffer-modified-p flag &optional buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
445 This function marks @var{buffer} as modified if @var{flag} is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 non-@code{nil}, or as unmodified if the flag is @code{nil}.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
447 @var{buffer} defaults to the current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 Another effect of calling this function is to cause unconditional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 redisplay of the modeline for the current buffer. In fact, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 function @code{redraw-modeline} works by doing this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (set-buffer-modified-p (buffer-modified-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 @c ARG is only in XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 @deffn Command not-modified &optional arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 This command marks the current buffer as unmodified, and not needing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 to be saved. (If @var{arg} is non-@code{nil}, the buffer is instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 marked as modified.) Don't use this function in programs, since it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 prints a message in the echo area; use @code{set-buffer-modified-p}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (above) instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 @defun buffer-modified-tick &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 This function returns @var{buffer}`s modification-count. This is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 counter that increments every time the buffer is modified. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 @var{buffer} is @code{nil} (or omitted), the current buffer is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 @node Modification Time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 @section Comparison of Modification Time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 @cindex comparison of modification time
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
479 @cindex modification time, comparison of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 Suppose that you visit a file and make changes in its buffer, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 meanwhile the file itself is changed on disk. At this point, saving the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 buffer would overwrite the changes in the file. Occasionally this may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 be what you want, but usually it would lose valuable information. XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 therefore checks the file's modification time using the functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 described below before saving the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 @defun verify-visited-file-modtime buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 This function compares what @var{buffer} has recorded for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 modification time of its visited file against the actual modification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 time of the file as recorded by the operating system. The two should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 the same unless some other process has written the file since XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 visited or saved it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 The function returns @code{t} if the last actual modification time and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 XEmacs's recorded modification time are the same, @code{nil} otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 @defun clear-visited-file-modtime
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 This function clears out the record of the last modification time of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 the file being visited by the current buffer. As a result, the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 attempt to save this buffer will not complain of a discrepancy in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 file modification times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 This function is called in @code{set-visited-file-name} and other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 exceptional places where the usual test to avoid overwriting a changed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 file should not be done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 @defun visited-file-modtime
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 This function returns the buffer's recorded last file modification time,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 as a list of the form @code{(@var{high} . @var{low})}. (This is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 same format that @code{file-attributes} uses to return time values; see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 @ref{File Attributes}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 @defun set-visited-file-modtime &optional time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 This function updates the buffer's record of the last modification time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 of the visited file, to the value specified by @var{time} if @var{time}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 is not @code{nil}, and otherwise to the last modification time of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 visited file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 If @var{time} is not @code{nil}, it should have the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 @code{(@var{high} . @var{low})} or @code{(@var{high} @var{low})}, in
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 444
diff changeset
527 either case containing two fixnums, each of which holds 16 bits of the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 This function is useful if the buffer was not read from the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 normally, or if the file itself has been changed for some known benign
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 reason.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 @defun ask-user-about-supersession-threat filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 @cindex obsolete buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 This function is used to ask a user how to proceed after an attempt to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 modify an obsolete buffer visiting file @var{filename}. An
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 @dfn{obsolete buffer} is an unmodified buffer for which the associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 file on disk is newer than the last save-time of the buffer. This means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 some other program has probably altered the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 @kindex file-supersession
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 Depending on the user's answer, the function may return normally, in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 which case the modification of the buffer proceeds, or it may signal a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 @code{file-supersession} error with data @code{(@var{filename})}, in which
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
547 case the proposed buffer modification is not allowed.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 This function is called automatically by XEmacs on the proper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 occasions. It exists so you can customize XEmacs by redefining it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 See the file @file{userlock.el} for the standard definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 See also the file locking mechanism in @ref{File Locks}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 @node Read Only Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 @section Read-Only Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 @cindex read-only buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 @cindex buffer, read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 If a buffer is @dfn{read-only}, then you cannot change its contents,
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
562 although you may change your view of the contents by scrolling and
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 narrowing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 Read-only buffers are used in two kinds of situations:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 A buffer visiting a write-protected file is normally read-only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 Here, the purpose is to show the user that editing the buffer with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 aim of saving it in the file may be futile or undesirable. The user who
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 wants to change the buffer text despite this can do so after clearing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 the read-only flag with @kbd{C-x C-q}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 Modes such as Dired and Rmail make buffers read-only when altering the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 contents with the usual editing commands is probably a mistake.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 The special commands of these modes bind @code{buffer-read-only} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 @code{nil} (with @code{let}) or bind @code{inhibit-read-only} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 @code{t} around the places where they change the text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 @defvar buffer-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 This buffer-local variable specifies whether the buffer is read-only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 The buffer is read-only if this variable is non-@code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 @defvar inhibit-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 If this variable is non-@code{nil}, then read-only buffers and read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 characters may be modified. Read-only characters in a buffer are those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 that have non-@code{nil} @code{read-only} properties (either text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 properties or extent properties). @xref{Extent Properties}, for more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 information about text properties and extent properties.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 If @code{inhibit-read-only} is @code{t}, all @code{read-only} character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 properties have no effect. If @code{inhibit-read-only} is a list, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 @code{read-only} character properties have no effect if they are members
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 of the list (comparison is done with @code{eq}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
603 @deffn Command toggle-read-only &optional arg
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
604 This command changes whether the current buffer is read-only.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
605 Interactively, if a prefix arg @var{arg} is supplied, set the current
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
606 buffer read only if and only if @var{arg} is positive.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
607
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
608 This command is intended for interactive use only; don't use it in
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
609 programs. At any given point in a program, you should know whether you
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
610 want the read-only flag on or off; so you can set
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
611 @code{buffer-read-only} explicitly to the proper value, @code{t} or
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
612 @code{nil}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
615 @defun barf-if-buffer-read-only &optional buffer start end
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
616 This function signals a @code{buffer-read-only} error if @var{buffer} is
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
617 read-only. @var{buffer} defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
618 @xref{Interactive Call}, for another way to signal an error if the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
619 current buffer is read-only.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
620
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
621 If optional argument @var{start} is non-@code{nil}, all extents in the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
622 buffer which overlap that part of the buffer are checked to ensure none
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
623 has a @code{read-only} property. (Extents that lie completely within the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
624 range, however, are not checked.) @var{end} defaults to the value of
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
625 @var{start}.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
626
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
627 If @var{start} and @var{end} are equal, the range checked is
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
628 [@var{start}, @var{end}] (i.e. closed on both ends); otherwise, the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
629 range checked is (@var{start}, @var{end}) \(open on both ends), except
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
630 that extents that lie completely within [@var{start}, @var{end}] are not
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
631 checked. See @code{extent-in-region-p} for a fuller discussion.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 @node The Buffer List
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 @section The Buffer List
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 @cindex buffer list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 The @dfn{buffer list} is a list of all live buffers. Creating a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 buffer adds it to this list, and killing a buffer deletes it. The order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 of the buffers in the list is based primarily on how recently each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 buffer has been displayed in the selected window. Buffers move to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 front of the list when they are selected and to the end when they are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 buried. Several functions, notably @code{other-buffer}, use this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 ordering. A buffer list displayed for the user also follows this order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 @c XEmacs feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 Every frame has its own order for the buffer list. Switching to a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 new buffer inside of a particular frame changes the buffer list order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 for that frame, but does not affect the buffer list order of any other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 frames. In addition, there is a global, non-frame buffer list order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 that is independent of the buffer list orders for any particular frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 Note that the different buffer lists all contain the same elements. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 is only the order of those elements that is different.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 @defun buffer-list &optional frame
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 This function returns a list of all buffers, including those whose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 names begin with a space. The elements are actual buffers, not their
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 names. The order of the list is specific to @var{frame}, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 defaults to the current frame. If @var{frame} is @code{t}, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 global, non-frame ordering is returned instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (buffer-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 @result{} (#<buffer buffers.texi>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 #<buffer *Minibuf-1*> #<buffer buffer.c>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 #<buffer *Help*> #<buffer TAGS>)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 ;; @r{Note that the name of the minibuffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 ;; @r{begins with a space!}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (mapcar (function buffer-name) (buffer-list))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
675 @result{} ("buffers.texi" " *Minibuf-1*"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 "buffer.c" "*Help*" "TAGS")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 Buffers appear earlier in the list if they were current more recently.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 This list is a copy of a list used inside XEmacs; modifying it has no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 effect on the buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 @defun other-buffer &optional buffer-or-name frame visible-ok
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 This function returns the first buffer in the buffer list other than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 @var{buffer-or-name}, in @var{frame}'s ordering for the buffer list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 (@var{frame} defaults to the current frame. If @var{frame} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 @code{t}, then the global, non-frame ordering is used.) Usually this is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 the buffer most recently shown in the selected window, aside from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 @var{buffer-or-name}. Buffers are moved to the front of the list when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 they are selected and to the end when they are buried. Buffers whose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 names start with a space are not considered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 If @var{buffer-or-name} is not supplied (or if it is not a buffer),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 then @code{other-buffer} returns the first buffer on the buffer list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 that is not visible in any window in a visible frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 If the selected frame has a non-@code{nil} @code{buffer-predicate}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 property, then @code{other-buffer} uses that predicate to decide which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 buffers to consider. It calls the predicate once for each buffer, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 if the value is @code{nil}, that buffer is ignored. @xref{X Frame
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 Properties}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 If @var{visible-ok} is @code{nil}, @code{other-buffer} avoids returning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 a buffer visible in any window on any visible frame, except as a last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 resort. If @var{visible-ok} is non-@code{nil}, then it does not matter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 whether a buffer is displayed somewhere or not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 If no suitable buffer exists, the buffer @samp{*scratch*} is returned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 (and created, if necessary).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 Note that in FSF Emacs 19, there is no @var{frame} argument, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 @var{visible-ok} is the second argument instead of the third.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 @deffn Command list-buffers &optional files-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 This function displays a listing of the names of existing buffers. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 clears the buffer @samp{*Buffer List*}, then inserts the listing into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 that buffer and displays it in a window. @code{list-buffers} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 intended for interactive use, and is described fully in @cite{The XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 Reference Manual}. It returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
727 @deffn Command bury-buffer &optional buffer-or-name before
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 This function puts @var{buffer-or-name} at the end of the buffer list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 without changing the order of any of the other buffers on the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 This buffer therefore becomes the least desirable candidate for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 @code{other-buffer} to return.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 If @var{buffer-or-name} is @code{nil} or omitted, this means to bury the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 current buffer. In addition, if the buffer is displayed in the selected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 window, this switches to some other buffer (obtained using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 @code{other-buffer}) in the selected window. But if the buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 displayed in some other window, it remains displayed there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 If you wish to replace a buffer in all the windows that display it, use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 @code{replace-buffer-in-windows}. @xref{Buffers and Windows}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 @node Creating Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 @section Creating Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 @cindex creating buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 @cindex buffers, creating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 This section describes the two primitives for creating buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 @code{get-buffer-create} creates a buffer if it finds no existing buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 with the specified name; @code{generate-new-buffer} always creates a new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 buffer and gives it a unique name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 Other functions you can use to create buffers include
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 @code{with-output-to-temp-buffer} (@pxref{Temporary Displays}) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 @code{create-file-buffer} (@pxref{Visiting Files}). Starting a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 subprocess can also create a buffer (@pxref{Processes}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 @defun get-buffer-create name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 This function returns a buffer named @var{name}. It returns an existing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 buffer with that name, if one exists; otherwise, it creates a new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 buffer. The buffer does not become the current buffer---this function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 does not change which buffer is current.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 An error is signaled if @var{name} is not a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 (get-buffer-create "foo")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 @result{} #<buffer foo>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 The major mode for the new buffer is set to Fundamental mode. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 variable @code{default-major-mode} is handled at a higher level.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 @xref{Auto Major Mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 @defun generate-new-buffer name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 This function returns a newly created, empty buffer, but does not make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 it current. If there is no buffer named @var{name}, then that is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 name of the new buffer. If that name is in use, this function adds
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 suffixes of the form @samp{<@var{n}>} to @var{name}, where @var{n} is an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 integer. It tries successive integers starting with 2 until it finds an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 available name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 An error is signaled if @var{name} is not a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 (generate-new-buffer "bar")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 @result{} #<buffer bar>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 (generate-new-buffer "bar")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 @result{} #<buffer bar<2>>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 (generate-new-buffer "bar")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 @result{} #<buffer bar<3>>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 The major mode for the new buffer is set to Fundamental mode. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 variable @code{default-major-mode} is handled at a higher level.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 @xref{Auto Major Mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 See the related function @code{generate-new-buffer-name} in @ref{Buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 Names}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 @node Killing Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 @section Killing Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 @cindex killing buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 @cindex buffers, killing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 @dfn{Killing a buffer} makes its name unknown to XEmacs and makes its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 text space available for other use.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 The buffer object for the buffer that has been killed remains in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 existence as long as anything refers to it, but it is specially marked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 so that you cannot make it current or display it. Killed buffers retain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 their identity, however; two distinct buffers, when killed, remain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 distinct according to @code{eq}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 If you kill a buffer that is current or displayed in a window, XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 automatically selects or displays some other buffer instead. This means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 that killing a buffer can in general change the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 Therefore, when you kill a buffer, you should also take the precautions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 associated with changing the current buffer (unless you happen to know
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 that the buffer being killed isn't current). @xref{Current Buffer}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 If you kill a buffer that is the base buffer of one or more indirect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 buffers, the indirect buffers are automatically killed as well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 The @code{buffer-name} of a killed buffer is @code{nil}. To test
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 whether a buffer has been killed, you can either use this feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 or the function @code{buffer-live-p}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
839 @defun buffer-live-p object
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
840 This function returns @code{t} if @var{object} is an editor buffer that
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
841 has not been deleted, @code{nil} otherwise.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 @deffn Command kill-buffer buffer-or-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 This function kills the buffer @var{buffer-or-name}, freeing all its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 memory for use as space for other buffers. (Emacs version 18 and older
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 was unable to return the memory to the operating system.) It returns
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
848 @code{nil}. The argument @var{buffer-or-name} may be a buffer or the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
849 name of one.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 Any processes that have this buffer as the @code{process-buffer} are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 sent the @code{SIGHUP} signal, which normally causes them to terminate.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 (The basic meaning of @code{SIGHUP} is that a dialup line has been
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 disconnected.) @xref{Deleting Processes}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 If the buffer is visiting a file and contains unsaved changes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 @code{kill-buffer} asks the user to confirm before the buffer is killed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 It does this even if not called interactively. To prevent the request
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 for confirmation, clear the modified flag before calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 @code{kill-buffer}. @xref{Buffer Modification}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 Killing a buffer that is already dead has no effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 (kill-buffer "foo.unchanged")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 (kill-buffer "foo.changed")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 Buffer foo.changed modified; kill anyway? (yes or no) @kbd{yes}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 @defvar kill-buffer-query-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 After confirming unsaved changes, @code{kill-buffer} calls the functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 in the list @code{kill-buffer-query-functions}, in order of appearance,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 with no arguments. The buffer being killed is the current buffer when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 they are called. The idea is that these functions ask for confirmation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 from the user for various nonstandard reasons. If any of them returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 @code{nil}, @code{kill-buffer} spares the buffer's life.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 @defvar kill-buffer-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 This is a normal hook run by @code{kill-buffer} after asking all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 questions it is going to ask, just before actually killing the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 The buffer to be killed is current when the hook functions run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 @xref{Hooks}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 @defvar buffer-offer-save
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 This variable, if non-@code{nil} in a particular buffer, tells
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 @code{save-buffers-kill-emacs} and @code{save-some-buffers} to offer to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 save that buffer, just as they offer to save file-visiting buffers. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 variable @code{buffer-offer-save} automatically becomes buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 when set for any reason. @xref{Buffer-Local Variables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 @node Indirect Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 @section Indirect Buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 @cindex indirect buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 @cindex base buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 An @dfn{indirect buffer} shares the text of some other buffer, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 is called the @dfn{base buffer} of the indirect buffer. In some ways it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 is the analogue, for buffers, of a symbolic link among files. The base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 buffer may not itself be an indirect buffer. One base buffer may have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 several @dfn{indirect children}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 The text of the indirect buffer is always identical to the text of its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 base buffer; changes made by editing either one are visible immediately
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 in the other.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 But in all other respects, the indirect buffer and its base buffer are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 completely separate. They have different names, different values of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 point and mark, different narrowing, different markers and extents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (though inserting or deleting text in either buffer relocates the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 markers and extents for both), different major modes, and different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 local variables. Unlike in FSF Emacs, XEmacs indirect buffers do not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 automatically share text properties among themselves and their base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 An indirect buffer cannot visit a file, but its base buffer can. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 you try to save the indirect buffer, that actually works by saving the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 base buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 Killing an indirect buffer has no effect on its base buffer. Killing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 the base buffer kills all its indirect children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 @deffn Command make-indirect-buffer base-buffer name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 This creates an indirect buffer named @var{name} whose base buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 is @var{base-buffer}. The argument @var{base-buffer} may be a buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 or a string.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
936
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 If @var{base-buffer} is an indirect buffer, its base buffer is used as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 the base for the new buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 (make-indirect-buffer "*scratch*" "indirect")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 @result{} #<buffer "indirect">
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 @defun buffer-base-buffer &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 This function returns the base buffer of @var{buffer}. If @var{buffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 is not indirect, the value is @code{nil}. Otherwise, the value is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 another buffer, which is never an indirect buffer. If @var{buffer} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 not supplied, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 (buffer-base-buffer (get-buffer "indirect"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 @result{} #<buffer "*scratch*">
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 @defun buffer-indirect-children &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 This function returns a list of all indirect buffers whose base buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 is @var{buffer}. If @var{buffer} is indirect, the return value will
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
965 always be @code{nil}; see @code{make-indirect-buffer}. If @var{buffer} is not
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 supplied, it defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 (buffer-indirect-children (get-buffer "*scratch*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 @result{} (#<buffer "indirect">)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 @end defun