#
[bpt/emacs.git] / man / windows.texi
CommitLineData
6bf7aab6
DL
1@c This is part of the Emacs manual.
2@c Copyright (C) 1985, 86, 87, 93, 94, 95, 1997 Free Software Foundation, Inc.
3@c See file emacs.texi for copying conditions.
4@node Windows, Frames, Buffers, Top
5@chapter Multiple Windows
6@cindex windows in Emacs
7@cindex multiple windows in Emacs
8
9 Emacs can split a frame into two or many windows. Multiple windows
10can display parts of different buffers, or different parts of one
11buffer. Multiple frames always imply multiple windows, because each
12frame has its own set of windows. Each window belongs to one and only
13one frame.
14
15@menu
16* Basic Window:: Introduction to Emacs windows.
17* Split Window:: New windows are made by splitting existing windows.
18* Other Window:: Moving to another window or doing something to it.
19* Pop Up Window:: Finding a file or buffer in another window.
20* Force Same Window:: Forcing certain buffers to appear in the selected
21 window rather than in another window.
22* Change Window:: Deleting windows and changing their sizes.
23@end menu
24
25@node Basic Window
26@section Concepts of Emacs Windows
27
28 Each Emacs window displays one Emacs buffer at any time. A single
29buffer may appear in more than one window; if it does, any changes in
30its text are displayed in all the windows where it appears. But the
31windows showing the same buffer can show different parts of it, because
32each window has its own value of point.
33
34@cindex selected window
35 At any time, one of the windows is the @dfn{selected window}; the
36buffer this window is displaying is the current buffer. The terminal's
37cursor shows the location of point in this window. Each other window
38has a location of point as well, but since the terminal has only one
39cursor there is no way to show where those locations are. When multiple
40frames are visible in X Windows, each frame has a cursor which appears
41in the frame's selected window. The cursor in the selected frame is
42solid; the cursor in other frames is a hollow box.
43
44 Commands to move point affect the value of point for the selected Emacs
45window only. They do not change the value of point in any other Emacs
46window, even one showing the same buffer. The same is true for commands
47such as @kbd{C-x b} to change the selected buffer in the selected window;
48they do not affect other windows at all. However, there are other commands
49such as @kbd{C-x 4 b} that select a different window and switch buffers in
50it. Also, all commands that display information in a window, including
51(for example) @kbd{C-h f} (@code{describe-function}) and @kbd{C-x C-b}
52(@code{list-buffers}), work by switching buffers in a nonselected window
53without affecting the selected window.
54
55 When multiple windows show the same buffer, they can have different
56regions, because they can have different values of point. However,
57they all have the same value for the mark, because each buffer has
58only one mark position.
59
60 Each window has its own mode line, which displays the buffer name,
61modification status and major and minor modes of the buffer that is
62displayed in the window. @xref{Mode Line}, for full details on the mode
63line.
64
65@iftex
66@break
67@end iftex
68
69@node Split Window
70@section Splitting Windows
71
72@table @kbd
73@item C-x 2
74Split the selected window into two windows, one above the other
75(@code{split-window-vertically}).
76@item C-x 3
77Split the selected window into two windows positioned side by side
78(@code{split-window-horizontally}).
79@item C-Mouse-2
80In the mode line or scroll bar of a window, split that window.
81@end table
82
83@kindex C-x 2
84@findex split-window-vertically
85 The command @kbd{C-x 2} (@code{split-window-vertically}) breaks the
86selected window into two windows, one above the other. Both windows start
87out displaying the same buffer, with the same value of point. By default
88the two windows each get half the height of the window that was split; a
89numeric argument specifies how many lines to give to the top window.
90
91@kindex C-x 3
92@findex split-window-horizontally
93 @kbd{C-x 3} (@code{split-window-horizontally}) breaks the selected
94window into two side-by-side windows. A numeric argument specifies how
95many columns to give the one on the left. A line of vertical bars
96separates the two windows. Windows that are not the full width of the
97screen have mode lines, but they are truncated. On terminals where
98Emacs does not support highlighting, truncated mode lines sometimes do
99not appear in inverse video.
100
101@kindex C-Mouse-2 @r{(scroll bar)}
102 You can split a window horizontally or vertically by clicking
103@kbd{C-Mouse-2} in the mode line or the scroll bar. The line of
104splitting goes through the place where you click: if you click on the
105mode line, the new scroll bar goes above the spot; if you click in the
106scroll bar, the mode line of the split window is side by side with your
107click.
108
109@vindex truncate-partial-width-windows
110 When a window is less than the full width, text lines too long to fit are
111frequent. Continuing all those lines might be confusing. The variable
112@code{truncate-partial-width-windows} can be set non-@code{nil} to force
113truncation in all windows less than the full width of the screen,
114independent of the buffer being displayed and its value for
115@code{truncate-lines}. @xref{Continuation Lines}.@refill
116
117 Horizontal scrolling is often used in side-by-side windows.
118@xref{Display}.
119
120@vindex split-window-keep-point
121 If @code{split-window-keep-point} is non-@code{nil}, the default, both
122of the windows resulting from @kbd{C-x 2} inherit the value of point
123from the window that was split. This means that scrolling is
124inevitable. If this variable is @code{nil}, then @kbd{C-x 2} tries to
125avoid shifting any text the screen, by putting point in each window at a
126position already visible in the window. It also selects whichever
127window contain the screen line that the cursor was previously on. Some
128users prefer the latter mode on slow terminals.
129
130@node Other Window
131@section Using Other Windows
132
133@table @kbd
134@item C-x o
135Select another window (@code{other-window}). That is @kbd{o}, not zero.
136@item C-M-v
137Scroll the next window (@code{scroll-other-window}).
138@item M-x compare-windows
139Find next place where the text in the selected window does not match
140the text in the next window.
141@item Mouse-1
142@kbd{Mouse-1}, in a window's mode line, selects that window
143but does not move point in it (@code{mouse-select-window}).
144@end table
145
146@kindex C-x o
147@findex other-window
148 To select a different window, click with @kbd{Mouse-1} on its mode
149line. With the keyboard, you can switch windows by typing @kbd{C-x o}
150(@code{other-window}). That is an @kbd{o}, for `other', not a zero.
151When there are more than two windows, this command moves through all the
152windows in a cyclic order, generally top to bottom and left to right.
153After the rightmost and bottommost window, it goes back to the one at
154the upper left corner. A numeric argument means to move several steps
155in the cyclic order of windows. A negative argument moves around the
156cycle in the opposite order. When the minibuffer is active, the
157minibuffer is the last window in the cycle; you can switch from the
158minibuffer window to one of the other windows, and later switch back and
159finish supplying the minibuffer argument that is requested.
160@xref{Minibuffer Edit}.
161
162@kindex C-M-v
163@findex scroll-other-window
164 The usual scrolling commands (@pxref{Display}) apply to the selected
165window only, but there is one command to scroll the next window.
166@kbd{C-M-v} (@code{scroll-other-window}) scrolls the window that
167@kbd{C-x o} would select. It takes arguments, positive and negative,
168like @kbd{C-v}. (In the minibuffer, @kbd{C-M-v} scrolls the window
169that contains the minibuffer help display, if any, rather than the
170next window in the standard cyclic order.)
171
172 The command @kbd{M-x compare-windows} lets you compare two files or
173buffers visible in two windows, by moving through them to the next
174mismatch. @xref{Comparing Files}, for details.
175
176@node Pop Up Window
177@section Displaying in Another Window
178
179@cindex selecting buffers in other windows
180@kindex C-x 4
181 @kbd{C-x 4} is a prefix key for commands that select another window
182(splitting the window if there is only one) and select a buffer in that
183window. Different @kbd{C-x 4} commands have different ways of finding the
184buffer to select.
185
186@table @kbd
187@item C-x 4 b @var{bufname} @key{RET}
188Select buffer @var{bufname} in another window. This runs
189@code{switch-to-buffer-other-window}.
190@item C-x 4 C-o @var{bufname} @key{RET}
191Display buffer @var{bufname} in another window, but
192don't select that buffer or that window. This runs
193@code{display-buffer}.
194@item C-x 4 f @var{filename} @key{RET}
195Visit file @var{filename} and select its buffer in another window. This
196runs @code{find-file-other-window}. @xref{Visiting}.
197@item C-x 4 d @var{directory} @key{RET}
198Select a Dired buffer for directory @var{directory} in another window.
199This runs @code{dired-other-window}. @xref{Dired}.
200@item C-x 4 m
201Start composing a mail message in another window. This runs
202@code{mail-other-window}; its same-window analogue is @kbd{C-x m}
203(@pxref{Sending Mail}).
204@item C-x 4 .
205Find a tag in the current tags table, in another window. This runs
206@code{find-tag-other-window}, the multiple-window variant of @kbd{M-.}
207(@pxref{Tags}).
208@item C-x 4 r @var{filename} @key{RET}
209Visit file @var{filename} read-only, and select its buffer in another
210window. This runs @code{find-file-read-only-other-window}.
211@xref{Visiting}.
212@end table
213
214@node Force Same Window
215@section Forcing Display in the Same Window
216
217 Certain Emacs commands switch to a specific buffer with special
218contents. For example, @kbd{M-x shell} switches to a buffer named
219@samp{*Shell*}. By convention, all these commands are written to pop up
220the buffer in a separate window. But you can specify that certain of
221these buffers should appear in the selected window.
222
223@vindex same-window-buffer-names
224 If you add a buffer name to the list @code{same-window-buffer-names},
225the effect is that such commands display that particular buffer by
226switching to it in the selected window. For example, if you add the
227element @code{"*grep*"} to the list, the @code{grep} command will
228display its output buffer in the selected window.
229
230 The default value of @code{same-window-buffer-names} is not
231@code{nil}: it specifies buffer names @samp{*info*}, @samp{*mail*} and
232@samp{*shell*} (as well as others used by more obscure Emacs packages).
233This is why @kbd{M-x shell} normally switches to the @samp{*shell*}
234buffer in the selected window. If you delete this element from the
235value of @code{same-window-buffer-names}, the behavior of @kbd{M-x
236shell} will change---it will pop up the buffer in another window
237instead.
238
239@vindex same-window-regexps
240 You can specify these buffers more generally with the variable
241@code{same-window-regexps}. Set it to a list of regular expressions;
242then any buffer whose name matches one of those regular expressions is
243displayed by switching to it in the selected window. (Once again, this
244applies only to buffers that normally get displayed for you in a
245separate window.) The default value of this variable specifies Telnet
246and rlogin buffers.
247
248 An analogous feature lets you specify buffers which should be
249displayed in their own individual frames. @xref{Special Buffer Frames}.
250
251@node Change Window
252@section Deleting and Rearranging Windows
253
254@table @kbd
255@item C-x 0
256Delete the selected window (@code{delete-window}). The last character
257in this key sequence is a zero.
258@item C-x 1
259Delete all windows in the selected frame except the selected window
260(@code{delete-other-windows}).
261@item C-x 4 0
262Delete the selected window and kill the buffer that was showing in it
263(@code{kill-buffer-and-window}). The last character in this key
264sequence is a zero.
265@item C-x ^
266Make selected window taller (@code{enlarge-window}).
267@item C-x @}
268Make selected window wider (@code{enlarge-window-horizontally}).
269@item C-x @{
270Make selected window narrower (@code{shrink-window-horizontally}).
271@item C-x -
272Shrink this window if its buffer doesn't need so many lines
273(@code{shrink-window-if-larger-than-buffer}).
274@item C-x +
275Make all windows the same height (@code{balance-windows}).
276@item Drag-Mouse-1
277Dragging a window's mode line up or down with @kbd{Mouse-1} changes
278window heights.
279@item Mouse-2
280@kbd{Mouse-2} in a window's mode line deletes all other windows in the frame
281(@code{mouse-delete-other-windows}).
282@item Mouse-3
283@kbd{Mouse-3} in a window's mode line deletes that window
284(@code{mouse-delete-window}).
285@end table
286
287@kindex C-x 0
288@findex delete-window
289 To delete a window, type @kbd{C-x 0} (@code{delete-window}). (That is
290a zero.) The space occupied by the deleted window is given to an
291adjacent window (but not the minibuffer window, even if that is active
292at the time). Once a window is deleted, its attributes are forgotten;
293only restoring a window configuration can bring it back. Deleting the
294window has no effect on the buffer it used to display; the buffer
295continues to exist, and you can select it in any window with @kbd{C-x
296b}.
297
298@findex kill-buffer-and-window
299@kindex C-x 4 0
300 @kbd{C-x 4 0} (@code{kill-buffer-and-window}) is a stronger command
301than @kbd{C-x 0}; it kills the current buffer and then deletes the
302selected window.
303
304@kindex C-x 1
305@findex delete-other-windows
306 @kbd{C-x 1} (@code{delete-other-windows}) is more powerful in a
307different way; it deletes all the windows except the selected one (and
308the minibuffer); the selected window expands to use the whole frame
309except for the echo area.
310
311 You can also delete a window by clicking on its mode line with
312@kbd{Mouse-2}, and delete all the windows in a frame except one window
313by clicking on that window's mode line with @kbd{Mouse-3}.
314
315 The easiest way to adjust window heights is with a mouse. If you
316press @kbd{Mouse-1} on a mode line, you can drag that mode line up or
317down, changing the heights of the windows above and below it.
318
319@kindex C-x ^
320@findex enlarge-window
321@kindex C-x @}
322@findex enlarge-window-horizontally
323@vindex window-min-height
324@vindex window-min-width
325 To readjust the division of space among vertically adjacent windows,
326use @kbd{C-x ^} (@code{enlarge-window}). It makes the currently
327selected window get one line bigger, or as many lines as is specified
328with a numeric argument. With a negative argument, it makes the
329selected window smaller. @kbd{C-x @}}
330(@code{enlarge-window-horizontally}) makes the selected window wider by
331the specified number of columns. @kbd{C-x @{}
332(@code{shrink-window-horizontally}) makes the selected window narrower
333by the specified number of columns.
334
335 When you make a window bigger, the space comes from one of its
336neighbors. If this makes any window too small, it is deleted and its
337space is given to an adjacent window. The minimum size is specified by
338the variables @code{window-min-height} and @code{window-min-width}.
339
340@kindex C-x -
341@findex shrink-window-if-larger-than-buffer
342 The command @kbd{C-x -} (@code{shrink-window-if-larger-than-buffer})
343reduces the height of the selected window, if it is taller than
344necessary to show the whole text of the buffer it is displaying. It
345gives the extra lines to other windows in the frame.
346
347@kindex C-x +
348@findex balance-windows
349 You can also use @kbd{C-x +} (@code{balance-windows}) to even out the
350heights of all the windows in the selected frame.
351
352 @xref{Minibuffer Edit}, for information about the Resize-Minibuffer
353mode, which automatically changes the size of the minibuffer window to
354fit the text in the minibuffer.