]> code.delx.au - gnu-emacs/blob - doc/emacs/windows.texi
Merge from trunk.
[gnu-emacs] / doc / emacs / windows.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2011
3 @c Free Software Foundation, Inc.
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
11 can display parts of different buffers, or different parts of one
12 buffer. Multiple frames always imply multiple windows, because each
13 frame has its own set of windows. Each window belongs to one and only
14 one 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 * Change Window:: Deleting windows and changing their sizes.
22 * Displaying Buffers:: How Emacs picks a window for displaying a buffer.
23 * Window Convenience:: Convenience functions for window handling.
24 @end menu
25
26 @node Basic Window
27 @section Concepts of Emacs Windows
28
29 Each Emacs window displays one Emacs buffer at any time. A single
30 buffer may appear in more than one window; if it does, any changes in
31 its text are displayed in all the windows where it appears. But these
32 windows can show different parts of the buffer, because each window
33 has its own value of point.
34
35 @cindex selected window
36 At any time, one Emacs window is the @dfn{selected window}; the
37 buffer this window is displaying is the current buffer. The terminal's
38 cursor shows the location of point in this window. Each other window
39 has a location of point as well. On text-only terminals, there is no
40 way to show where those locations are, since the terminal has only one
41 cursor. On a graphical display, the location of point in a
42 non-selected window is indicated by a hollow box; the cursor in the
43 selected window is blinking or solid.
44
45 Commands to move point affect the value of point for the selected Emacs
46 window only. They do not change the value of point in other Emacs
47 windows, even those showing the same buffer. The same is true for commands
48 such as @kbd{C-x b} to switch buffers in the selected window;
49 they do not affect other windows at all. However, there are other commands
50 such as @kbd{C-x 4 b} that select a different window and switch buffers in
51 it. Also, all commands that display information in a window, including
52 (for example) @kbd{C-h f} (@code{describe-function}) and @kbd{C-x C-b}
53 (@code{list-buffers}), work by switching buffers in a nonselected window
54 without affecting the selected window.
55
56 When multiple windows show the same buffer, they can have different
57 regions, because they can have different values of point. However,
58 they all have the same value for the mark, because each buffer has
59 only one mark position.
60
61 Each window has its own mode line, which displays the buffer name,
62 modification status and major and minor modes of the buffer that is
63 displayed in the window. The selected window's mode line appears in a
64 different color. @xref{Mode Line}, for full details on the mode line.
65
66 @node Split Window
67 @section Splitting Windows
68
69 @table @kbd
70 @item C-x 2
71 Split the selected window into two windows, one above the other
72 (@code{split-window-vertically}).
73 @item C-x 3
74 Split the selected window into two windows positioned side by side
75 (@code{split-window-horizontally}).
76 @item C-Mouse-2
77 In the mode line or scroll bar of a window, split that window.
78 @end table
79
80 @kindex C-x 2
81 @findex split-window-vertically
82 The command @kbd{C-x 2} (@code{split-window-vertically}) breaks the
83 selected window into two windows, one above the other. Both windows start
84 out displaying the same buffer, with the same value of point. By default
85 the two windows each get half the height of the window that was split; a
86 numeric argument specifies how many lines to give to the top window.
87
88 @kindex C-x 3
89 @findex split-window-horizontally
90 @kbd{C-x 3} (@code{split-window-horizontally}) breaks the selected
91 window into two side-by-side windows. A numeric argument specifies how
92 many columns to give the one on the left. If you are not using
93 scrollbars, a vertical line separates the two windows.
94 You can customize its color with the face @code{vertical-border}.
95 Windows that are not the full width of the screen have mode lines, but
96 they are truncated. On terminals where Emacs does not support
97 highlighting, truncated mode lines sometimes do not appear in inverse
98 video.
99
100 @kindex C-Mouse-2 @r{(scroll bar)}
101 You can split a window horizontally or vertically by clicking
102 @kbd{C-Mouse-2} in the mode line or the scroll bar. The line of
103 splitting goes through the place where you click: if you click on the
104 mode line, the new scroll bar goes above the spot; if you click in the
105 scroll bar, the mode line of the split window is side by side with
106 your click.
107
108 @vindex truncate-partial-width-windows
109 When a window occupies less than the full width of the frame, it may
110 become too narrow for most of the text lines in its buffer. If most of
111 its lines are continued (@pxref{Continuation Lines}), the buffer may
112 become difficult to read. Therefore, Emacs automatically truncates
113 lines if the window width becomes narrower than 50 columns. This
114 truncation occurs regardless of the value of the variable
115 @code{truncate-lines} (@pxref{Line Truncation}); it is instead
116 controlled by the variable @code{truncate-partial-width-windows}. If
117 the value of @code{truncate-partial-width-windows} is a positive integer
118 (the default is 50), that specifies the minimum width for a
119 partial-width window before automatic line truncation occurs; if the
120 value is @code{nil}, automatic line truncation is disabled; and for any
121 other non-@code{nil} value, Emacs truncates lines in every partial-width
122 window regardless of its width.
123
124 Horizontal scrolling is often used in side-by-side windows.
125 @xref{Horizontal Scrolling}.
126
127 @vindex split-window-keep-point
128 If @code{split-window-keep-point} is non-@code{nil}, the default,
129 both of the windows resulting from @kbd{C-x 2} inherit the value of
130 point from the window that was split. This means that scrolling is
131 inevitable. If this variable is @code{nil}, then @kbd{C-x 2} tries to
132 avoid scrolling the text currently visible on the screen, by putting
133 point in each window at a position already visible in the window. It
134 also selects whichever window contains the screen line that the cursor
135 was previously on. Some users prefer that mode on slow terminals.
136
137 @node Other Window
138 @section Using Other Windows
139
140 @table @kbd
141 @item C-x o
142 Select another window (@code{other-window}). That is @kbd{o}, not zero.
143 @item C-M-v
144 Scroll the next window (@code{scroll-other-window}).
145 @item M-x compare-windows
146 Find next place where the text in the selected window does not match
147 the text in the next window.
148 @item Mouse-1
149 @kbd{Mouse-1}, in a window's mode line, selects that window
150 but does not move point in it (@code{mouse-select-window}).
151 @end table
152
153 @kindex C-x o
154 @findex other-window
155 To select a different window, click with @kbd{Mouse-1} on its mode
156 line. With the keyboard, you can switch windows by typing @kbd{C-x o}
157 (@code{other-window}). That is an @kbd{o}, for ``other,'' not a zero.
158 When there are more than two windows, this command moves through all the
159 windows in a cyclic order, generally top to bottom and left to right.
160 After the rightmost and bottommost window, it goes back to the one at
161 the upper left corner. A numeric argument means to move several steps
162 in the cyclic order of windows. A negative argument moves around the
163 cycle in the opposite order. When the minibuffer is active, the
164 minibuffer is the last window in the cycle; you can switch from the
165 minibuffer window to one of the other windows, and later switch back and
166 finish supplying the minibuffer argument that is requested.
167 @xref{Minibuffer Edit}.
168
169 @kindex C-M-v
170 @findex scroll-other-window
171 The usual scrolling commands (@pxref{Display}) apply to the selected
172 window only, but there is one command to scroll the next window.
173 @kbd{C-M-v} (@code{scroll-other-window}) scrolls the window that
174 @kbd{C-x o} would select. It takes arguments, positive and negative,
175 like @kbd{C-v}. (In the minibuffer, @kbd{C-M-v} scrolls the window
176 that contains the minibuffer help display, if any, rather than the
177 next window in the standard cyclic order.)
178
179 The command @kbd{M-x compare-windows} lets you compare two files or
180 buffers visible in two windows, by moving through them to the next
181 mismatch. @xref{Comparing Files}, for details.
182
183 @vindex mouse-autoselect-window
184 If you set @code{mouse-autoselect-window} to a non-@code{nil} value,
185 moving the mouse into a different window selects that window. This
186 feature is off by default.
187
188 @node Pop Up Window
189 @section Displaying in Another Window
190
191 @cindex selecting buffers in other windows
192 @kindex C-x 4
193 @kbd{C-x 4} is a prefix key for a variety of commands that switch to
194 a buffer in a different window---either another existing window, or a
195 new window created by splitting the selected window. @xref{Window
196 Choice}, for how Emacs picks or creates the window to use.
197
198 @table @kbd
199 @findex switch-to-buffer-other-window
200 @item C-x 4 b @var{bufname} @key{RET}
201 Select buffer @var{bufname} in another window
202 (@code{switch-to-buffer-other-window}).
203
204 @findex display-buffer
205 @item C-x 4 C-o @var{bufname} @key{RET}
206 Display buffer @var{bufname} in some window, without trying to select
207 it (@code{display-buffer}). @xref{Displaying Buffers}, for details
208 about how the window is chosen.
209
210 @findex find-file-other-window
211 @item C-x 4 f @var{filename} @key{RET}
212 Visit file @var{filename} and select its buffer in another window
213 (@code{find-file-other-window}). @xref{Visiting}.
214
215 @findex dired-other-window
216 @item C-x 4 d @var{directory} @key{RET}
217 Select a Dired buffer for directory @var{directory} in another window
218 (@code{dired-other-window}). @xref{Dired}.
219
220 @findex mail-other-window
221 @item C-x 4 m
222 Start composing a mail message, similar to @kbd{C-x m} (@pxref{Sending
223 Mail}), but in another window (@code{mail-other-window}).
224
225 @findex find-tag-other-window
226 @item C-x 4 .
227 Find a tag in the current tags table, similar to @kbd{M-.}
228 (@pxref{Tags}), but in another window (@code{find-tag-other-window}).
229 @item C-x 4 r @var{filename} @key{RET}
230 Visit file @var{filename} read-only, and select its buffer in another
231 window (@code{find-file-read-only-other-window}). @xref{Visiting}.
232 @end table
233
234 @node Change Window
235 @section Deleting and Rearranging Windows
236
237 @table @kbd
238 @item C-x 0
239 Delete the selected window (@code{delete-window}). The last character
240 in this key sequence is a zero.
241 @item C-x 1
242 Delete all windows in the selected frame except the selected window
243 (@code{delete-other-windows}).
244 @item C-x 4 0
245 Delete the selected window and kill the buffer that was showing in it
246 (@code{kill-buffer-and-window}). The last character in this key
247 sequence is a zero.
248 @item C-x ^
249 Make selected window taller (@code{enlarge-window}).
250 @item C-x @}
251 Make selected window wider (@code{enlarge-window-horizontally}).
252 @item C-x @{
253 Make selected window narrower (@code{shrink-window-horizontally}).
254 @item C-x -
255 Shrink this window if its buffer doesn't need so many lines
256 (@code{shrink-window-if-larger-than-buffer}).
257 @item C-x +
258 Make all windows the same height (@code{balance-windows}).
259 @end table
260
261 @kindex C-x 0
262 @findex delete-window
263 To delete a window, type @kbd{C-x 0} (@code{delete-window}). (That is
264 a zero.) The space occupied by the deleted window is given to an
265 adjacent window (but not the minibuffer window, even if that is active
266 at the time). Once a window is deleted, its attributes are forgotten;
267 only restoring a window configuration can bring it back. Deleting the
268 window has no effect on the buffer it used to display; the buffer
269 continues to exist, and you can select it in any window with @kbd{C-x
270 b}.
271
272 @findex kill-buffer-and-window
273 @kindex C-x 4 0
274 @kbd{C-x 4 0} (@code{kill-buffer-and-window}) is a stronger command
275 than @kbd{C-x 0}; it kills the current buffer and then deletes the
276 selected window.
277
278 @kindex C-x 1
279 @findex delete-other-windows
280 @kbd{C-x 1} (@code{delete-other-windows}) is more powerful in a
281 different way; it deletes all the windows except the selected one (and
282 the minibuffer); the selected window expands to use the whole frame
283 except for the echo area.
284
285 @kindex C-x ^
286 @findex enlarge-window
287 @kindex C-x @}
288 @findex enlarge-window-horizontally
289 @vindex window-min-height
290 @vindex window-min-width
291 To readjust the division of space among vertically adjacent windows,
292 use @kbd{C-x ^} (@code{enlarge-window}). It makes the currently
293 selected window one line bigger, or as many lines as is specified
294 with a numeric argument. With a negative argument, it makes the
295 selected window smaller. @kbd{C-x @}}
296 (@code{enlarge-window-horizontally}) makes the selected window wider by
297 the specified number of columns. @kbd{C-x @{}
298 (@code{shrink-window-horizontally}) makes the selected window narrower
299 by the specified number of columns.
300
301 When you make a window bigger, the space comes from its peers. If
302 this makes any window too small, it is deleted and its space is given
303 to an adjacent window. The minimum size is specified by the variables
304 @code{window-min-height} and @code{window-min-width}.
305
306 @kindex C-x -
307 @findex shrink-window-if-larger-than-buffer
308 @kbd{C-x -} (@code{shrink-window-if-larger-than-buffer}) reduces the
309 height of the selected window, if it is taller than necessary to show
310 the whole text of the buffer it is displaying. It gives the extra
311 lines to other windows in the frame.
312
313 @kindex C-x +
314 @findex balance-windows
315 You can also use @kbd{C-x +} (@code{balance-windows}) to even out the
316 heights of all the windows in the selected frame.
317
318 Mouse clicks on the mode line provide another way to change window
319 heights and to delete windows. @xref{Mode Line Mouse}.
320
321 @node Displaying Buffers
322 @section Displaying a Buffer in a Window
323
324 It is a common Emacs operation to display or ``pop up'' some buffer
325 in response to a user command. There are several different ways by
326 which commands do this.
327
328 Many commands, like @kbd{C-x C-f} (@code{find-file}), display the
329 buffer by ``taking over'' the selected window, expecting that the
330 user's attention will be diverted to that buffer. These commands
331 usually work by calling @code{switch-to-buffer} internally
332 (@pxref{Select Buffer}).
333
334 @findex display-buffer
335 Some commands try to display ``intelligently'', trying not to take
336 over the selected window, e.g. by splitting the selected window and
337 displaying the desired buffer in the child window. Such commands,
338 which include the various help commands (@pxref{Help}), work by
339 calling @code{display-buffer} internally. @xref{Window Choice}, for
340 details.
341
342 Other commands do the same as @code{display-buffer}, and
343 additionally select the displaying window so that you can begin
344 editing its buffer. The command @kbd{C-x `} (@code{next-error}) is
345 one example (@pxref{Compilation Mode}). Such commands work by calling
346 @code{pop-to-buffer} internally. @xref{Displaying Buffers,,Displaying
347 Buffers in Windows, elisp, The Emacs Lisp Reference Manual}.
348
349 Commands with names ending in @code{-other-window} behave like
350 @code{display-buffer}, except that they never display in the selected
351 window. Several of these commands are bound in the @kbd{C-x 4} prefix
352 key (@pxref{Pop Up Window}).
353
354 Commands with names ending in @code{-other-frame} behave like
355 @code{display-buffer}, except that they (i) never display in the
356 selected window and (ii) prefer to create a new frame to display the
357 desired buffer instead of splitting a window---as though the variable
358 @code{pop-up-frames} is set to @code{t} (@pxref{Window Choice}).
359 Several of these commands are bound in the @kbd{C-x 5} prefix key.
360
361 @menu
362 * Window Choice:: How @code{display-buffer} works.
363 @end menu
364
365 @node Window Choice
366 @subsection How @code{display-buffer} works
367 @findex display-buffer
368
369 The @code{display-buffer} command (as well as commands that call it
370 internally) chooses a window to display using the following steps:
371
372 @itemize
373 @vindex same-window-buffer-names
374 @vindex same-window-regexps
375 @item
376 First, check if the buffer should be displayed in the selected window
377 regardless of other considerations. You can tell Emacs to do this by
378 adding the desired buffer's name to the list
379 @code{same-window-buffer-names}, or adding a matching regular
380 expression to the list @code{same-window-regexps}. By default, these
381 variables are @code{nil}, so this step is skipped.
382
383 @vindex display-buffer-reuse-frames
384 @item
385 Otherwise, if the buffer is already displayed in an existing window,
386 ``reuse'' that window. Normally, only windows on the selected frame
387 are considered, but windows on other frames are also reusable if you
388 change @code{display-buffer-reuse-frames} to @code{t}, or if you
389 change @code{pop-up-frames} (see below) to @code{t}.
390
391 @item
392 Otherwise, if you specified that the buffer should be displayed in a
393 special frame by customizing @code{special-display-buffer-names} or
394 @code{special-display-regexps}, do so. @xref{Special Buffer Frames}.
395
396 @vindex pop-up-frames
397 @item
398 Otherwise, optionally create a new frame and display the buffer there.
399 By default, this step is skipped. To enable it, change the variable
400 @code{pop-up-frames} to a non-@code{nil} value. The special value
401 @code{graphic-only} means to do this only on graphical displays.
402
403 @item
404 Otherwise, try to create a new window by splitting the selected
405 window, and display the buffer in that new window.
406
407 @vindex split-height-threshold
408 @vindex split-width-threshold
409 The split can be either vertical or horizontal, depending on the
410 variables @code{split-height-threshold} and
411 @code{split-width-threshold}. These variables should have integer
412 values. If @code{split-height-threshold} is smaller than the selected
413 window's height, the split puts the new window below. Otherwise, if
414 @code{split-width-threshold} is smaller than the window's width, the
415 split puts the new window on the right. If neither condition holds,
416 Emacs tries to split so that the new window is below---but only if the
417 window was not split before (to avoid excessive splitting).
418
419 @item
420 Otherwise, display the buffer in an existing window on the selected
421 frame.
422
423 @item
424 If all the above methods fail for whatever reason, create a new frame
425 and display the buffer there.
426 @end itemize
427
428 @node Window Convenience
429 @section Window Handling Convenience Features and Customization
430
431 @findex winner-mode
432 @cindex Winner mode
433 @cindex mode, Winner
434 @cindex undoing window configuration changes
435 @cindex window configuration changes, undoing
436 @kbd{M-x winner-mode} is a global minor mode that records the
437 changes in the window configuration (i.e. how the frames are
438 partitioned into windows), so that you can ``undo'' them. To undo,
439 use @kbd{C-c left} (@code{winner-undo}). If you change your mind
440 while undoing, you can redo the changes you had undone using @kbd{C-c
441 right} (@code{M-x winner-redo}). Another way to enable Winner mode is
442 by customizing the variable @code{winner-mode}.
443
444 @cindex Windmove package
445 @cindex directional window selection
446 @findex windmove-right
447 @findex windmove-default-keybindings
448 The Windmove commands move directionally between neighboring windows in
449 a frame. @kbd{M-x windmove-right} selects the window immediately to the
450 right of the currently selected one, and similarly for the ``left,'' ``up,''
451 and ``down'' counterparts. @kbd{M-x windmove-default-keybindings} binds
452 these commands to @kbd{S-right} etc. (Not all terminals support shifted
453 arrow keys, however.)
454
455 Follow minor mode (@kbd{M-x follow-mode}) synchronizes several
456 windows on the same buffer so that they always display adjacent
457 sections of that buffer. @xref{Follow Mode}.
458
459 @vindex scroll-all-mode
460 @cindex scrolling windows together
461 @cindex Scroll-all mode
462 @cindex mode, Scroll-all
463 @kbd{M-x scroll-all-mode} provides commands to scroll all visible
464 windows together. You can also turn it on by customizing the variable
465 @code{scroll-all-mode}. The commands provided are @kbd{M-x
466 scroll-all-scroll-down-all}, @kbd{M-x scroll-all-page-down-all} and
467 their corresponding ``up'' equivalents. To make this mode useful,
468 you should bind these commands to appropriate keys.