lisp/progmodes/python.el: Highlight keyword "nonlocal" (bug#8639).
[bpt/emacs.git] / doc / emacs / windows.texi
CommitLineData
6bf7aab6 1@c This is part of the Emacs manual.
b65d8176 2@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001,
5df4f04c 3@c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
6bf7aab6
DL
4@c See file emacs.texi for copying conditions.
5@node Windows, Frames, Buffers, Top
6@chapter Multiple Windows
7@cindex windows in Emacs
8@cindex multiple windows in Emacs
9
10 Emacs can split a frame into two or many windows. Multiple windows
11can display parts of different buffers, or different parts of one
12buffer. Multiple frames always imply multiple windows, because each
13frame has its own set of windows. Each window belongs to one and only
14one frame.
15
16@menu
17* Basic Window:: Introduction to Emacs windows.
18* Split Window:: New windows are made by splitting existing windows.
19* Other Window:: Moving to another window or doing something to it.
20* Pop Up Window:: Finding a file or buffer in another window.
21* Force Same Window:: Forcing certain buffers to appear in the selected
22 window rather than in another window.
23* Change Window:: Deleting windows and changing their sizes.
88968b11 24* Window Convenience:: Convenience functions for window handling.
6bf7aab6
DL
25@end menu
26
27@node Basic Window
28@section Concepts of Emacs Windows
29
30 Each Emacs window displays one Emacs buffer at any time. A single
31buffer may appear in more than one window; if it does, any changes in
3b47541d
RS
32its text are displayed in all the windows where it appears. But these
33windows can show different parts of the buffer, because each window
34has its own value of point.
6bf7aab6
DL
35
36@cindex selected window
3b47541d 37 At any time, one Emacs window is the @dfn{selected window}; the
6bf7aab6
DL
38buffer this window is displaying is the current buffer. The terminal's
39cursor shows the location of point in this window. Each other window
acaa6478
LT
40has a location of point as well. On text-only terminals, there is no
41way to show where those locations are, since the terminal has only one
3b47541d
RS
42cursor. On a graphical display, the location of point in a
43non-selected window is indicated by a hollow box; the cursor in the
acaa6478 44selected window is blinking or solid.
6bf7aab6
DL
45
46 Commands to move point affect the value of point for the selected Emacs
3b47541d
RS
47window only. They do not change the value of point in other Emacs
48windows, even those showing the same buffer. The same is true for commands
49such as @kbd{C-x b} to switch buffers in the selected window;
6bf7aab6
DL
50they do not affect other windows at all. However, there are other commands
51such as @kbd{C-x 4 b} that select a different window and switch buffers in
52it. Also, all commands that display information in a window, including
53(for example) @kbd{C-h f} (@code{describe-function}) and @kbd{C-x C-b}
54(@code{list-buffers}), work by switching buffers in a nonselected window
55without affecting the selected window.
56
57 When multiple windows show the same buffer, they can have different
58regions, because they can have different values of point. However,
59they all have the same value for the mark, because each buffer has
60only one mark position.
61
62 Each window has its own mode line, which displays the buffer name,
63modification status and major and minor modes of the buffer that is
a08ff74c
RS
64displayed in the window. The selected window's mode line appears in a
65different color. @xref{Mode Line}, for full details on the mode line.
6bf7aab6 66
6bf7aab6
DL
67@node Split Window
68@section Splitting Windows
69
70@table @kbd
71@item C-x 2
72Split the selected window into two windows, one above the other
73(@code{split-window-vertically}).
74@item C-x 3
75Split the selected window into two windows positioned side by side
76(@code{split-window-horizontally}).
77@item C-Mouse-2
78In the mode line or scroll bar of a window, split that window.
79@end table
80
81@kindex C-x 2
82@findex split-window-vertically
83 The command @kbd{C-x 2} (@code{split-window-vertically}) breaks the
84selected window into two windows, one above the other. Both windows start
85out displaying the same buffer, with the same value of point. By default
86the two windows each get half the height of the window that was split; a
87numeric argument specifies how many lines to give to the top window.
88
89@kindex C-x 3
90@findex split-window-horizontally
91 @kbd{C-x 3} (@code{split-window-horizontally}) breaks the selected
92window into two side-by-side windows. A numeric argument specifies how
acaa6478 93many columns to give the one on the left. If you are not using
45cfcb43
JL
94scrollbars, a vertical line separates the two windows.
95You can customize its color with the face @code{vertical-border}.
acaa6478
LT
96Windows that are not the full width of the screen have mode lines, but
97they are truncated. On terminals where Emacs does not support
98highlighting, truncated mode lines sometimes do not appear in inverse
99video.
6bf7aab6
DL
100
101@kindex C-Mouse-2 @r{(scroll bar)}
102 You can split a window horizontally or vertically by clicking
acaa6478
LT
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
107your click.
6bf7aab6
DL
108
109@vindex truncate-partial-width-windows
fafeffcf 110 When a window occupies less than the full width of the frame, it may
6cb2ca70
MR
111become too narrow for most of the text lines in its buffer. If most of
112its lines are continued (@pxref{Continuation Lines}), the buffer may
113become difficult to read. Therefore, Emacs automatically truncates
114lines if the window width becomes narrower than 50 columns. This
115truncation occurs regardless of the value of the variable
116@code{truncate-lines} (@pxref{Line Truncation}); it is instead
117controlled by the variable @code{truncate-partial-width-windows}. If
118the value of @code{truncate-partial-width-windows} is a positive integer
119(the default is 50), that specifies the minimum width for a
120partial-width window before automatic line truncation occurs; if the
121value is @code{nil}, automatic line truncation is disabled; and for any
122other non-@code{nil} value, Emacs truncates lines in every partial-width
fafeffcf 123window regardless of its width.
6bf7aab6
DL
124
125 Horizontal scrolling is often used in side-by-side windows.
79c53527 126@xref{Horizontal Scrolling}.
6bf7aab6
DL
127
128@vindex split-window-keep-point
85d6c6e7
RS
129 If @code{split-window-keep-point} is non-@code{nil}, the default,
130both of the windows resulting from @kbd{C-x 2} inherit the value of
131point from the window that was split. This means that scrolling is
6bf7aab6 132inevitable. If this variable is @code{nil}, then @kbd{C-x 2} tries to
85d6c6e7
RS
133avoid scrolling the text currently visible on the screen, by putting
134point in each window at a position already visible in the window. It
0925fc3e 135also selects whichever window contains the screen line that the cursor
3b47541d 136was previously on. Some users prefer that mode on slow terminals.
6bf7aab6
DL
137
138@node Other Window
139@section Using Other Windows
140
141@table @kbd
142@item C-x o
143Select another window (@code{other-window}). That is @kbd{o}, not zero.
144@item C-M-v
145Scroll the next window (@code{scroll-other-window}).
146@item M-x compare-windows
147Find next place where the text in the selected window does not match
148the text in the next window.
149@item Mouse-1
150@kbd{Mouse-1}, in a window's mode line, selects that window
151but does not move point in it (@code{mouse-select-window}).
152@end table
153
154@kindex C-x o
155@findex other-window
156 To select a different window, click with @kbd{Mouse-1} on its mode
157line. With the keyboard, you can switch windows by typing @kbd{C-x o}
2684ed46 158(@code{other-window}). That is an @kbd{o}, for ``other,'' not a zero.
6bf7aab6
DL
159When there are more than two windows, this command moves through all the
160windows in a cyclic order, generally top to bottom and left to right.
161After the rightmost and bottommost window, it goes back to the one at
162the upper left corner. A numeric argument means to move several steps
163in the cyclic order of windows. A negative argument moves around the
164cycle in the opposite order. When the minibuffer is active, the
165minibuffer is the last window in the cycle; you can switch from the
166minibuffer window to one of the other windows, and later switch back and
167finish supplying the minibuffer argument that is requested.
168@xref{Minibuffer Edit}.
169
170@kindex C-M-v
171@findex scroll-other-window
172 The usual scrolling commands (@pxref{Display}) apply to the selected
173window only, but there is one command to scroll the next window.
174@kbd{C-M-v} (@code{scroll-other-window}) scrolls the window that
175@kbd{C-x o} would select. It takes arguments, positive and negative,
176like @kbd{C-v}. (In the minibuffer, @kbd{C-M-v} scrolls the window
177that contains the minibuffer help display, if any, rather than the
178next window in the standard cyclic order.)
179
180 The command @kbd{M-x compare-windows} lets you compare two files or
181buffers visible in two windows, by moving through them to the next
182mismatch. @xref{Comparing Files}, for details.
183
fa8b06c2
RS
184@vindex mouse-autoselect-window
185 If you set @code{mouse-autoselect-window} to a non-@code{nil} value,
186moving the mouse into a different window selects that window. This
187feature is off by default.
188
6bf7aab6
DL
189@node Pop Up Window
190@section Displaying in Another Window
191
192@cindex selecting buffers in other windows
193@kindex C-x 4
194 @kbd{C-x 4} is a prefix key for commands that select another window
195(splitting the window if there is only one) and select a buffer in that
196window. Different @kbd{C-x 4} commands have different ways of finding the
197buffer to select.
198
199@table @kbd
200@item C-x 4 b @var{bufname} @key{RET}
201Select buffer @var{bufname} in another window. This runs
202@code{switch-to-buffer-other-window}.
203@item C-x 4 C-o @var{bufname} @key{RET}
204Display buffer @var{bufname} in another window, but
205don't select that buffer or that window. This runs
206@code{display-buffer}.
207@item C-x 4 f @var{filename} @key{RET}
208Visit file @var{filename} and select its buffer in another window. This
209runs @code{find-file-other-window}. @xref{Visiting}.
210@item C-x 4 d @var{directory} @key{RET}
211Select a Dired buffer for directory @var{directory} in another window.
212This runs @code{dired-other-window}. @xref{Dired}.
213@item C-x 4 m
214Start composing a mail message in another window. This runs
215@code{mail-other-window}; its same-window analogue is @kbd{C-x m}
216(@pxref{Sending Mail}).
217@item C-x 4 .
218Find a tag in the current tags table, in another window. This runs
219@code{find-tag-other-window}, the multiple-window variant of @kbd{M-.}
220(@pxref{Tags}).
221@item C-x 4 r @var{filename} @key{RET}
222Visit file @var{filename} read-only, and select its buffer in another
223window. This runs @code{find-file-read-only-other-window}.
224@xref{Visiting}.
225@end table
226
2a472ee4
MR
227@vindex split-height-threshold
228@vindex split-width-threshold
229 By default, these commands split the window vertically when there is
230only one. You can customize the variables @code{split-height-threshold}
231and @code{split-width-threshold} to split the window horizontally
232instead.
233
234
6bf7aab6
DL
235@node Force Same Window
236@section Forcing Display in the Same Window
237
238 Certain Emacs commands switch to a specific buffer with special
239contents. For example, @kbd{M-x shell} switches to a buffer named
158a07a8 240@samp{*shell*}. By convention, all these commands are written to pop up
6bf7aab6
DL
241the buffer in a separate window. But you can specify that certain of
242these buffers should appear in the selected window.
243
244@vindex same-window-buffer-names
245 If you add a buffer name to the list @code{same-window-buffer-names},
246the effect is that such commands display that particular buffer by
247switching to it in the selected window. For example, if you add the
248element @code{"*grep*"} to the list, the @code{grep} command will
249display its output buffer in the selected window.
250
251 The default value of @code{same-window-buffer-names} is not
252@code{nil}: it specifies buffer names @samp{*info*}, @samp{*mail*} and
253@samp{*shell*} (as well as others used by more obscure Emacs packages).
254This is why @kbd{M-x shell} normally switches to the @samp{*shell*}
255buffer in the selected window. If you delete this element from the
256value of @code{same-window-buffer-names}, the behavior of @kbd{M-x
257shell} will change---it will pop up the buffer in another window
258instead.
259
260@vindex same-window-regexps
261 You can specify these buffers more generally with the variable
262@code{same-window-regexps}. Set it to a list of regular expressions;
263then any buffer whose name matches one of those regular expressions is
264displayed by switching to it in the selected window. (Once again, this
265applies only to buffers that normally get displayed for you in a
266separate window.) The default value of this variable specifies Telnet
267and rlogin buffers.
268
269 An analogous feature lets you specify buffers which should be
270displayed in their own individual frames. @xref{Special Buffer Frames}.
271
272@node Change Window
273@section Deleting and Rearranging Windows
274
275@table @kbd
276@item C-x 0
277Delete the selected window (@code{delete-window}). The last character
278in this key sequence is a zero.
279@item C-x 1
280Delete all windows in the selected frame except the selected window
281(@code{delete-other-windows}).
282@item C-x 4 0
283Delete the selected window and kill the buffer that was showing in it
284(@code{kill-buffer-and-window}). The last character in this key
285sequence is a zero.
286@item C-x ^
287Make selected window taller (@code{enlarge-window}).
288@item C-x @}
289Make selected window wider (@code{enlarge-window-horizontally}).
290@item C-x @{
291Make selected window narrower (@code{shrink-window-horizontally}).
292@item C-x -
293Shrink this window if its buffer doesn't need so many lines
294(@code{shrink-window-if-larger-than-buffer}).
295@item C-x +
296Make all windows the same height (@code{balance-windows}).
6bf7aab6
DL
297@end table
298
299@kindex C-x 0
300@findex delete-window
301 To delete a window, type @kbd{C-x 0} (@code{delete-window}). (That is
302a zero.) The space occupied by the deleted window is given to an
303adjacent window (but not the minibuffer window, even if that is active
304at the time). Once a window is deleted, its attributes are forgotten;
305only restoring a window configuration can bring it back. Deleting the
306window has no effect on the buffer it used to display; the buffer
307continues to exist, and you can select it in any window with @kbd{C-x
308b}.
309
310@findex kill-buffer-and-window
311@kindex C-x 4 0
312 @kbd{C-x 4 0} (@code{kill-buffer-and-window}) is a stronger command
313than @kbd{C-x 0}; it kills the current buffer and then deletes the
314selected window.
315
316@kindex C-x 1
317@findex delete-other-windows
318 @kbd{C-x 1} (@code{delete-other-windows}) is more powerful in a
319different way; it deletes all the windows except the selected one (and
320the minibuffer); the selected window expands to use the whole frame
321except for the echo area.
322
6bf7aab6
DL
323@kindex C-x ^
324@findex enlarge-window
325@kindex C-x @}
326@findex enlarge-window-horizontally
327@vindex window-min-height
328@vindex window-min-width
329 To readjust the division of space among vertically adjacent windows,
330use @kbd{C-x ^} (@code{enlarge-window}). It makes the currently
3b47541d 331selected window one line bigger, or as many lines as is specified
6bf7aab6
DL
332with a numeric argument. With a negative argument, it makes the
333selected window smaller. @kbd{C-x @}}
334(@code{enlarge-window-horizontally}) makes the selected window wider by
335the specified number of columns. @kbd{C-x @{}
336(@code{shrink-window-horizontally}) makes the selected window narrower
337by the specified number of columns.
338
3b47541d
RS
339 When you make a window bigger, the space comes from its peers. If
340this makes any window too small, it is deleted and its space is given
341to an adjacent window. The minimum size is specified by the variables
342@code{window-min-height} and @code{window-min-width}.
6bf7aab6
DL
343
344@kindex C-x -
345@findex shrink-window-if-larger-than-buffer
346 The command @kbd{C-x -} (@code{shrink-window-if-larger-than-buffer})
347reduces the height of the selected window, if it is taller than
348necessary to show the whole text of the buffer it is displaying. It
349gives the extra lines to other windows in the frame.
350
351@kindex C-x +
352@findex balance-windows
353 You can also use @kbd{C-x +} (@code{balance-windows}) to even out the
354heights of all the windows in the selected frame.
355
3b47541d
RS
356 Mouse clicks on the mode line provide another way to change window
357heights and to delete windows. @xref{Mode Line Mouse}.
358
88968b11
DL
359@node Window Convenience
360@section Window Handling Convenience Features and Customization
361
362@findex winner-mode
d683704c
DL
363@cindex Winner mode
364@cindex mode, Winner
88968b11
DL
365@cindex undoing window configuration changes
366@cindex window configuration changes, undoing
74f60775
RS
367 @kbd{M-x winner-mode} is a global minor mode that records the
368changes in the window configuration (i.e. how the frames are
369partitioned into windows), so that you can ``undo'' them. To undo,
acaa6478
LT
370use @kbd{C-c left} (@code{winner-undo}). If you change your mind
371while undoing, you can redo the changes you had undone using @kbd{C-c
74f60775
RS
372right} (@code{M-x winner-redo}). Another way to enable Winner mode is
373by customizing the variable @code{winner-mode}.
88968b11
DL
374
375@cindex Windmove package
376@cindex directional window selection
d683704c
DL
377@findex windmove-right
378@findex windmove-default-keybindings
10886485 379 The Windmove commands move directionally between neighboring windows in
d683704c 380a frame. @kbd{M-x windmove-right} selects the window immediately to the
74f60775
RS
381right of the currently selected one, and similarly for the ``left,'' ``up,''
382and ``down'' counterparts. @kbd{M-x windmove-default-keybindings} binds
383these commands to @kbd{S-right} etc. (Not all terminals support shifted
384arrow keys, however.)
88968b11 385
74f60775
RS
386 Follow minor mode (@kbd{M-x follow-mode}) synchronizes several
387windows on the same buffer so that they always display adjacent
4946337d 388sections of that buffer. @xref{Follow Mode}.
74f60775
RS
389
390@vindex scroll-all-mode
391@cindex scrolling windows together
392@cindex Scroll-all mode
393@cindex mode, Scroll-all
394 @kbd{M-x scroll-all-mode} provides commands to scroll all visible
395windows together. You can also turn it on by customizing the variable
396@code{scroll-all-mode}. The commands provided are @kbd{M-x
397scroll-all-scroll-down-all}, @kbd{M-x scroll-all-page-down-all} and
398their corresponding ``up'' equivalents. To make this mode useful,
399you should bind these commands to appropriate keys.
ab5796a9
MB
400
401@ignore
402 arch-tag: 8bea7453-d4b1-49b1-9bf4-cfe4383e1113
403@end ignore