Initial git import
[sxemacs] / info / lispref / windows.texi
1 @c -*-texinfo-*-
2 @c This is part of the SXEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 @c Copyright (C) 2005 Sebastian Freundt <hroptatyr@sxemacs.org>
5 @c See the file lispref.texi for copying conditions.
6 @setfilename ../../info/windows.info
7
8 @node Windows, Frames, Buffers, Top
9 @chapter Windows
10
11   This chapter describes most of the functions and variables related to
12 Emacs windows.  See @ref{Display}, for information on how text is
13 displayed in windows.
14
15 @menu
16 * Basic Windows::               Basic information on using windows.
17 * Splitting Windows::           Splitting one window into two windows.
18 * Deleting Windows::            Deleting a window gives its space to other
19                                   windows.
20 * Selecting Windows::           The selected window is the one that you edit
21                                   in.
22 * Cyclic Window Ordering::      Moving around the existing windows.
23 * Buffers and Windows::         Each window displays the contents of a buffer.
24 * Displaying Buffers::          Higher-lever functions for displaying a buffer
25                                   and choosing a window for it.
26 * Choosing Window::             How to choose a window for displaying a buffer.
27 * Window Point::                Each window has its own location of point.
28 * Window Start::                The display-start position controls which text
29                                   is on-screen in the window.
30 * Vertical Scrolling::          Moving text up and down in the window.
31 * Horizontal Scrolling::        Moving text sideways on the window.
32 * Size of Window::              Accessing the size of a window.
33 * Position of Window::          Accessing the position of a window.
34 * Resizing Windows::            Changing the size of a window.
35 * Window Configurations::       Saving and restoring the state of the screen.
36 * Window Configuration Hook::   Running code when the window configuration
37                                   changes.
38 @end menu
39
40
41 @node Basic Windows
42 @section Basic Concepts of Emacs Windows
43 @cindex window
44 @cindex selected window
45
46   A @dfn{window} in SXEmacs is the physical area of the screen in which a
47 buffer is displayed.  The term is also used to refer to a Lisp object that
48 represents that screen area in SXEmacs Lisp.  It should be
49 clear from the context which is meant.
50
51   SXEmacs groups windows into frames.  A frame represents an area of
52 screen available for SXEmacs to use.  Each frame always contains at least
53 one window, but you can subdivide it vertically or horizontally into
54 multiple nonoverlapping SXEmacs windows.
55
56   In each frame, at any time, one and only one window is designated as
57 @dfn{selected within the frame}.  The frame's cursor appears in that
58 window.  At any time, one frame is the selected frame; and the window
59 selected within that frame is @dfn{the selected window}.  The selected
60 window's buffer is usually the current buffer (except when
61 @code{set-buffer} has been used).  @xref{Current Buffer}.
62
63   For practical purposes, a window exists only while it is displayed in
64 a frame.  Once removed from the frame, the window is effectively deleted
65 and should not be used, @emph{even though there may still be references
66 to it} from other Lisp objects.  Restoring a saved window configuration
67 is the only way for a window no longer on the screen to come back to
68 life.  (@xref{Deleting Windows}.)
69
70   Each window has the following attributes:
71
72 @itemize @bullet
73 @item
74 containing frame
75
76 @item
77 window height
78
79 @item
80 window width
81
82 @item
83 window edges with respect to the frame or screen
84
85 @item
86 the buffer it displays
87
88 @item
89 position within the buffer at the upper left of the window
90
91 @item
92 amount of horizontal scrolling, in columns
93
94 @item
95 point
96
97 @item
98 the mark
99
100 @item
101 how recently the window was selected
102 @end itemize
103
104 @cindex multiple windows
105   Users create multiple windows so they can look at several buffers at
106 once.  Lisp libraries use multiple windows for a variety of reasons, but
107 most often to display related information.  In Rmail, for example, you
108 can move through a summary buffer in one window while the other window
109 shows messages one at a time as they are reached.
110
111   The meaning of ``window'' in SXEmacs is similar to what it means in the
112 context of general-purpose window systems such as X, but not identical.
113 The X Window System places X windows on the screen; SXEmacs uses one or
114 more X windows as frames, and subdivides them into
115 SXEmacs windows.  When you use SXEmacs on a character-only terminal, 
116 SXEmacs treats the whole terminal screen as one frame.
117
118 @cindex terminal frame
119 @cindex frame of terminal
120 @cindex tiled windows
121   Most window systems support arbitrarily located overlapping windows.
122 In contrast, SXEmacs windows are @dfn{tiled}; they never overlap, and
123 together they fill the whole screen or frame.  Because of the way
124 in which SXEmacs creates new windows and resizes them, you can't create
125 every conceivable tiling of windows on an SXEmacs frame.  @xref{Splitting
126 Windows}, and @ref{Size of Window}.
127
128   @xref{Display}, for information on how the contents of the
129 window's buffer are displayed in the window.
130
131 @defun windowp object
132   This function returns @code{t} if @var{object} is a window.
133 @end defun
134
135
136 @node Splitting Windows
137 @section Splitting Windows
138 @cindex splitting windows
139 @cindex window splitting
140
141   The functions described here are the primitives used to split a window
142 into two windows.  Two higher level functions sometimes split a window,
143 but not always: @code{pop-to-buffer} and @code{display-buffer}
144 (@pxref{Displaying Buffers}).
145
146   The functions described here do not accept a buffer as an argument.
147 The two ``halves'' of the split window initially display the same buffer
148 previously visible in the window that was split.
149
150 @defun one-window-p &optional nomini which-frames which-devices
151 This function returns non-@code{nil} if there is only one window.  The
152 argument @var{nomini}, if non-@code{nil}, means don't count the
153 minibuffer even if it is active; otherwise, the minibuffer window is
154 included, if active, in the total number of windows which is compared
155 against one.
156
157 The remaining arguments controls which set of windows are counted, as
158 with @code{next-window}.
159 @end defun
160
161 @deffn Command split-window &optional window size horizontal
162 This function splits @var{window} into two windows.  The original
163 window @var{window} remains the selected window, but occupies only
164 part of its former screen area.  The rest is occupied by a newly created
165 window which is returned as the value of this function.
166
167   If @var{horizontal} is non-@code{nil}, then @var{window} splits into
168 two side by side windows.  The original window @var{window} keeps the
169 leftmost @var{size} columns, and gives the rest of the columns to the
170 new window.  Otherwise, it splits into windows one above the other, and
171 @var{window} keeps the upper @var{size} lines and gives the rest of the
172 lines to the new window.  The original window is therefore the
173 left-hand or upper of the two, and the new window is the right-hand or
174 lower.
175
176   If @var{window} is omitted or @code{nil}, then the selected window is
177 split.  If @var{size} is omitted or @code{nil}, then @var{window} is
178 divided evenly into two parts.  (If there is an odd line, it is
179 allocated to the new window.)  When @code{split-window} is called
180 interactively, all its arguments are @code{nil}.
181
182   The following example starts with one window on a frame that is 50
183 lines high by 80 columns wide; then the window is split.
184
185 @smallexample
186 @group
187 (setq w (selected-window))
188      @result{} #<window 8 on windows.texi>
189 (window-edges)          ; @r{Edges in order:}
190      @result{} (0 0 80 50)     ;   @r{left--top--right--bottom}
191 @end group
192
193 @group
194 ;; @r{Returns window created}
195 (setq w2 (split-window w 15))
196      @result{} #<window 28 on windows.texi>
197 @end group
198 @group
199 (window-edges w2)
200      @result{} (0 15 80 50)    ; @r{Bottom window;}
201                         ;   @r{top is line 15}
202 @end group
203 @group
204 (window-edges w)
205      @result{} (0 0 80 15)     ; @r{Top window}
206 @end group
207 @end smallexample
208
209 The frame looks like this:
210
211 @smallexample
212 @group
213          __________
214         |          |  line 0
215         |    w     |
216         |__________|
217         |          |  line 15
218         |    w2    |
219         |__________|
220                       line 50
221  column 0   column 80
222 @end group
223 @end smallexample
224
225 Next, the top window is split horizontally:
226
227 @smallexample
228 @group
229 (setq w3 (split-window w 35 t))
230      @result{} #<window 32 on windows.texi>
231 @end group
232 @group
233 (window-edges w3)
234      @result{} (35 0 80 15)  ; @r{Left edge at column 35}
235 @end group
236 @group
237 (window-edges w)
238      @result{} (0 0 35 15)   ; @r{Right edge at column 35}
239 @end group
240 @group
241 (window-edges w2)
242      @result{} (0 15 80 50)  ; @r{Bottom window unchanged}
243 @end group
244 @end smallexample
245
246 @need 3000
247 Now, the screen looks like this:
248
249 @smallexample
250 @group
251      column 35
252          __________
253         |   |      |  line 0
254         | w |  w3  |
255         |___|______|
256         |          |  line 15
257         |    w2    |
258         |__________|
259                       line 50
260  column 0   column 80
261 @end group
262 @end smallexample
263
264 Normally, SXEmacs indicates the border between two side-by-side windows
265 with a scroll bar (@pxref{X Frame Properties,Scroll Bars}) or @samp{|}
266 characters.  The display table can specify alternative border
267 characters; see @ref{Display Tables}.
268 @end deffn
269
270 @deffn Command split-window-vertically &optional size
271 This function splits the selected window into two windows, one above
272 the other, leaving the selected window with @var{size} lines.
273
274 This function is simply an interface to @code{split-window}.
275 Here is the complete function definition for it:
276
277 @smallexample
278 @group
279 (defun split-window-vertically (&optional arg)
280   "Split current window into two windows, one above the other."
281   (interactive "P")
282   (split-window nil (and arg (prefix-numeric-value arg))))
283 @end group
284 @end smallexample
285 @end deffn
286
287 @deffn Command split-window-horizontally &optional size
288 This function splits the selected window into two windows
289 side-by-side, leaving the selected window with @var{size} columns.
290
291 This function is simply an interface to @code{split-window}.  Here is
292 the complete definition for @code{split-window-horizontally} (except for
293 part of the documentation string):
294
295 @smallexample
296 @group
297 (defun split-window-horizontally (&optional arg)
298   "Split selected window into two windows, side by side..."
299   (interactive "P")
300   (split-window nil (and arg (prefix-numeric-value arg)) t))
301 @end group
302 @end smallexample
303 @end deffn
304
305
306 @node Deleting Windows
307 @section Deleting Windows
308 @cindex deleting windows
309
310 A window remains visible on its frame unless you @dfn{delete} it by
311 calling certain functions that delete windows.  A deleted window cannot
312 appear on the screen, but continues to exist as a Lisp object until
313 there are no references to it.  There is no way to cancel the deletion
314 of a window aside from restoring a saved window configuration
315 (@pxref{Window Configurations}).  Restoring a window configuration also
316 deletes any windows that aren't part of that configuration.
317
318   When you delete a window, the space it took up is given to one
319 adjacent sibling.  (In Emacs version 18, the space was divided evenly
320 among all the siblings.)
321
322 @c Emacs 19 feature
323 @defun window-live-p window
324 This function returns @code{nil} if @var{window} is deleted, and
325 @code{t} otherwise.
326
327 @strong{Warning:} Erroneous information or fatal errors may result from
328 using a deleted window as if it were live.
329 @end defun
330
331 @deffn Command delete-window &optional window force
332 This function removes @var{window} from the display.  If @var{window} is
333 omitted, then the selected window is deleted. If window is the only one
334 on its frame, the frame is deleted as well.
335
336 Normally, you cannot delete the last non-minibuffer-only frame (you must
337 use @code{save-buffers-kill-emacs} or @code{kill-emacs}); an error is
338 signaled instead.  However, if optional second argument @var{force} is
339 non-@code{nil}, you can delete the last frame. (This will automatically
340 call @code{save-buffers-kill-emacs}.)
341
342 This function returns @code{nil}.
343
344 When @code{delete-window} is called interactively, the selected window
345 is deleted.
346 @end deffn
347
348 @deffn Command delete-other-windows &optional window
349 This function makes @var{window} the only window on its frame, by
350 deleting the other windows in that frame.  If @var{window} is omitted or
351 @code{nil}, then the selected window is used by default.
352
353 The result is @code{nil}.
354 @end deffn
355
356 @deffn Command delete-windows-on buffer &optional which-frames which-devices
357 This function deletes all windows showing @var{buffer}.  If there are
358 no windows showing @var{buffer}, it does nothing.
359
360 @code{delete-windows-on} operates frame by frame.  If a frame has
361 several windows showing different buffers, then those showing
362 @var{buffer} are removed, and the others expand to fill the space.  If
363 all windows in some frame are showing @var{buffer} (including the case
364 where there is only one window), then the frame reverts to having a
365 single window showing another buffer chosen with @code{other-buffer}.
366 @xref{The Buffer List}.
367
368 The argument @var{which-frames} controls which frames to operate on:
369
370 @table @asis
371 @item @code{nil}
372 Delete all windows showing @var{buffer} in any frame.
373
374 @item @code{t}
375 Delete only windows showing @var{buffer} in the selected frame.
376
377 @item @code{visible}
378 Delete all windows showing @var{buffer} in any visible frame.
379
380 @item @code{0}
381 Delete all windows showing @var{buffer} in any visible frame.
382
383 @item @var{frame}
384 If it is a frame, delete all windows showing @var{buffer} in that frame.
385 @end table
386
387 @strong{Warning:} This is similar to, but not identical to, the meaning
388 of the @var{which-frames} argument to @code{next-window}; the meanings
389 of @code{nil} and @code{t} are reversed.
390
391 The optional argument @var{which-devices} further clarifies on which
392 devices to search for frames as specified by @var{which-frames}.
393 This value is only meaningful if @var{which-frames} is not @code{t}.
394
395 @table @asis
396 @item @code{nil}
397 Consider all devices on the selected console.
398
399 @item @var{device}
400 Consider only the one device @var{device}.
401
402 @item @var{console}
403 Consider all devices on @var{console}.
404
405 @item @var{device-type}
406 Consider all devices with device type @var{device-type}.
407
408 @item @code{window-system}
409 Consider all devices on window system consoles.
410
411 @item anything else
412 Consider all devices without restriction.
413 @end table
414
415 This function always returns @code{nil}.
416 @end deffn
417
418
419 @node Selecting Windows
420 @section Selecting Windows
421 @cindex selecting windows
422
423   When a window is selected, the buffer in the window becomes the current
424 buffer, and the cursor will appear in it.
425
426 @defun selected-window &optional device
427 This function returns the selected window.  This is the window in
428 which the cursor appears and to which many commands apply.  Each
429 separate device can have its own selected window, which is remembered
430 as focus changes from device to device.  Optional argument @var{device}
431 specifies which device to return the selected window for, and defaults
432 to the selected device.
433 @end defun
434
435 @defun select-window window &optional norecord
436 This function makes @var{window} the selected window.  The cursor then
437 appears in @var{window} (on redisplay).  The buffer being displayed in
438 @var{window} is immediately designated the current buffer.
439
440 If optional argument @var{norecord} is non-@code{nil} then the global
441 and per-frame buffer orderings are not modified, as by the function
442 @code{record-buffer}.
443
444 The return value is @var{window}.
445
446 @example
447 @group
448 (setq w (next-window))
449 (select-window w)
450      @result{} #<window 65 on windows.texi>
451 @end group
452 @end example
453 @end defun
454
455 @defspec save-selected-window forms@dots{}
456 This special form records the selected window, executes @var{forms} in
457 sequence, then restores the earlier selected window.  It does not save
458 or restore anything about the sizes, arrangement or contents of windows;
459 therefore, if the @var{forms} change them, the changes are permanent.
460 @end defspec
461
462 @cindex finding windows
463   The following functions choose one of the windows on the screen,
464 offering various criteria for the choice.
465
466 @defun get-lru-window &optional which-frames which-devices
467 This function returns the window least recently ``used'' (that is,
468 selected).  The selected window is always the most recently used window.
469
470 The selected window can be the least recently used window if it is the
471 only window.  A newly created window becomes the least recently used
472 window until it is selected.  A minibuffer window is never a candidate.
473
474 By default, only the windows in the selected frame are considered.
475 The optional argument @var{which-frames} changes this behavior.
476 Here are the possible values and their meanings:
477
478 @table @asis
479 @item @code{nil}
480 Consider all the windows in the selected windows's frame, plus the
481 minibuffer used by that frame even if it lies in some other frame.
482
483 @item @code{t}
484 Consider all windows in all existing frames.
485
486 @item @code{visible}
487 Consider all windows in all visible frames.  (To get useful results, you
488 must ensure @var{window} is in a visible frame.)
489
490 @item @code{0}
491 Consider all windows in all visible or iconified frames.
492
493 @item @var{frame}
494 Consider all windows on frame @var{frame}.
495
496 @item anything else
497 Consider precisely the windows in the selected window's frame, and no others.
498 @end table
499
500 The optional argument @var{which-devices} further clarifies on which
501 devices to search for frames as specified by @var{which-frames}.
502 This value is only meaningful if @var{which-frames} is non-@code{nil}.
503
504 @table @asis
505 @item @code{nil}
506 Consider all devices on the selected console.
507
508 @item @var{device}
509 Consider only the one device @var{device}.
510
511 @item @var{console}
512 Consider all devices on @var{console}.
513
514 @item @var{device-type}
515 Consider all devices with device type @var{device-type}.
516
517 @item @code{window-system}
518 Consider all devices on window system consoles.
519
520 @item anything else
521 Consider all devices without restriction.
522 @end table
523
524 @end defun
525
526 @defun get-largest-window &optional which-frames which-devices
527 This function returns the window with the largest area (height times
528 width).  If there are no side-by-side windows, then this is the window
529 with the most lines.  A minibuffer window is never a candidate.
530
531 If there are two windows of the same size, then the function returns
532 the window that is first in the cyclic ordering of windows (see
533 following section), starting from the selected window.
534
535 The remaining arguments control which set of windows are considered.
536 See @code{next-window}, above.
537 @end defun
538
539
540 @node Cyclic Window Ordering
541 @section Cyclic Ordering of Windows
542 @cindex cyclic ordering of windows
543 @cindex ordering of windows, cyclic
544 @cindex window ordering, cyclic
545
546   When you use the command @kbd{C-x o} (@code{other-window}) to select
547 the next window, it moves through all the windows on the screen in a
548 specific cyclic order.  For any given configuration of windows, this
549 order never varies.  It is called the @dfn{cyclic ordering of windows}.
550
551   This ordering generally goes from top to bottom, and from left to
552 right.  But it may go down first or go right first, depending on the
553 order in which the windows were split.
554
555   If the first split was vertical (into windows one above each other),
556 and then the subwindows were split horizontally, then the ordering is
557 left to right in the top of the frame, and then left to right in the
558 next lower part of the frame, and so on.  If the first split was
559 horizontal, the ordering is top to bottom in the left part, and so on.
560 In general, within each set of siblings at any level in the window tree,
561 the order is left to right, or top to bottom.
562
563 @defun next-window &optional window minibuf which-frames which-devices
564 @cindex minibuffer window
565 This function returns the window following @var{window} in the cyclic
566 ordering of windows.  This is the window that @kbd{C-x o} would select
567 if typed when @var{window} is selected.  If @var{window} is the only
568 window visible, then this function returns @var{window}.  If omitted,
569 @var{window} defaults to the selected window.
570
571 The value of the argument @var{minibuf} determines whether the
572 minibuffer is included in the window order.  Normally, when
573 @var{minibuf} is @code{nil}, the minibuffer is included if it is
574 currently active; this is the behavior of @kbd{C-x o}.  (The minibuffer
575 window is active while the minibuffer is in use.  @xref{Minibuffers}.)
576
577 If @var{minibuf} is @code{t}, then the cyclic ordering includes the
578 minibuffer window even if it is not active.
579
580 If @var{minibuf} is neither @code{t} nor @code{nil}, then the minibuffer
581 window is not included even if it is active.
582
583 By default, only the windows in the selected frame are considered.
584 The optional argument @var{which-frames} changes this behavior.
585 Here are the possible values and their meanings:
586
587 @table @asis
588 @item @code{nil}
589 Consider all the windows in @var{window}'s frame, plus the minibuffer
590 used by that frame even if it lies in some other frame.
591
592 @item @code{t}
593 Consider all windows in all existing frames.
594
595 @item @code{visible}
596 Consider all windows in all visible frames.  (To get useful results, you
597 must ensure @var{window} is in a visible frame.)
598
599 @item @code{0}
600 Consider all windows in all visible or iconified frames.
601
602 @item @var{frame}
603 Consider all windows on frame @var{frame}.
604
605 @item anything else
606 Consider precisely the windows in @var{window}'s frame, and no others.
607 @end table
608
609 The optional argument @var{which-devices} further clarifies on which
610 devices to search for frames as specified by @var{which-frames}.
611 This value is only meaningful if @var{which-frames} is non-@code{nil}.
612
613 @table @asis
614 @item @code{nil}
615 Consider all devices on the selected console.
616
617 @item @var{device}
618 Consider only the one device @var{device}.
619
620 @item @var{console}
621 Consider all devices on @var{console}.
622
623 @item @var{device-type}
624 Consider all devices with device type @var{device-type}.
625
626 @item @code{window-system}
627 Consider all devices on window system consoles.
628
629 @item anything else
630 Consider all devices without restriction.
631 @end table
632
633 If you use consistent values for @var{minibuf}, @var{which-frames}, and
634 @var{which-devices}, you can use @code{next-window} to iterate through the
635 entire cycle of acceptable windows, eventually ending up back at the
636 window you started with.  @code{previous-window} traverses the same
637 cycle, in the reverse order.
638
639 This example assumes there are two windows, both displaying the
640 buffer @samp{windows.texi}:
641
642 @example
643 @group
644 (selected-window)
645      @result{} #<window 56 on windows.texi>
646 @end group
647 @group
648 (next-window (selected-window))
649      @result{} #<window 52 on windows.texi>
650 @end group
651 @group
652 (next-window (next-window (selected-window)))
653      @result{} #<window 56 on windows.texi>
654 @end group
655 @end example
656 @end defun
657
658 @defun previous-window &optional window minibuf which-frames which-devices
659 This function returns the window preceding @var{window} in the cyclic
660 ordering of windows.  The other arguments specify which windows to
661 include in the cycle, as in @code{next-window}.
662 @end defun
663
664 @deffn Command other-window count &optional which-frames which-devices
665 This function selects the @var{count}th following window in the cyclic order.
666 If @var{count} is negative, then it selects the @minus{}@var{count}th
667 preceding window.  It returns @code{nil}.
668
669 In an interactive call, @var{count} is the numeric prefix argument.
670
671 The other arguments specify which windows to include in the cycle, as in
672 @code{next-window}.
673 @end deffn
674
675 @defun walk-windows function &optional minibuf which-frames which-devices
676 This function cycles through all windows, calling @code{function}
677 once for each window with the window as its sole argument.
678
679 The other arguments specify which windows to cycle through, as in
680 @code{next-window}.
681 @end defun
682
683
684 @node Buffers and Windows
685 @section Buffers and Windows
686 @cindex examining windows
687 @cindex windows, controlling precisely
688 @cindex buffers, controlled in windows
689
690   This section describes low-level functions to examine windows or to
691 display buffers in windows in a precisely controlled fashion.
692 @iftex
693 See the following section for
694 @end iftex
695 @ifinfo
696 @xref{Displaying Buffers}, for
697 @end ifinfo
698 related functions that find a window to use and specify a buffer for it.
699 The functions described there are easier to use than these, but they
700 employ heuristics in choosing or creating a window; use these functions
701 when you need complete control.
702
703 @defun set-window-buffer window buffer-or-name &optional norecord
704 This function makes @var{window} display @var{buffer-or-name} as its
705 contents.  @var{buffer-or-name} can be a buffer or a buffer name.
706
707 With non-@code{nil} optional argument @var{norecord}, do not modify the
708 global or per-frame buffer ordering.
709
710 This function returns @code{nil}.
711
712 @example
713 @group
714 (set-window-buffer (selected-window) "foo")
715      @result{} nil
716 @end group
717 @end example
718 @end defun
719
720 @defun window-buffer &optional window
721 This function returns the buffer that @var{window} is displaying.  If
722 @var{window} is omitted, this function returns the buffer for the
723 selected window.
724
725 @example
726 @group
727 (window-buffer)
728      @result{} #<buffer windows.texi>
729 @end group
730 @end example
731 @end defun
732
733 @defun get-buffer-window buffer-or-name &optional which-frames which-devices
734 This function returns a window currently displaying
735 @var{buffer-or-name}, or @code{nil} if there is none.  If there are
736 several such windows, then the function returns the first one in the
737 cyclic ordering of windows, starting from the selected window.
738 @xref{Cyclic Window Ordering}.
739
740 The remaining arguments control which windows to consider.  They have
741 the same meaning as for @code{next-window}.
742 @end defun
743
744
745 @node Displaying Buffers
746 @section Displaying Buffers in Windows
747 @cindex switching to a buffer
748 @cindex displaying a buffer
749
750   In this section we describe convenient functions that choose a window
751 automatically and use it to display a specified buffer.  These functions
752 can also split an existing window in certain circumstances.  We also
753 describe variables that parameterize the heuristics used for choosing a
754 window.
755 @iftex
756 See the preceding section for
757 @end iftex
758 @ifinfo
759 @xref{Buffers and Windows}, for
760 @end ifinfo
761 low-level functions that give you more precise control.
762
763   Do not use the functions in this section in order to make a buffer
764 current so that a Lisp program can access or modify it; they are too
765 drastic for that purpose, since they change the display of buffers in
766 windows, which is gratuitous and will surprise the user.  Instead, use
767 @code{set-buffer} (@pxref{Current Buffer}) and @code{save-excursion}
768 (@pxref{Excursions}), which designate buffers as current for programmed
769 access without affecting the display of buffers in windows.
770
771 @deffn Command switch-to-buffer buffer-or-name &optional norecord
772 This function makes @var{buffer-or-name} the current buffer, and also
773 displays the buffer in the selected window.  This means that a human can
774 see the buffer and subsequent keyboard commands will apply to it.
775 Contrast this with @code{set-buffer}, which makes @var{buffer-or-name}
776 the current buffer but does not display it in the selected window.
777 @xref{Current Buffer}.
778
779 If @var{buffer-or-name} does not identify an existing buffer, then a new
780 buffer by that name is created.  The major mode for the new buffer is
781 set according to the variable @code{default-major-mode}.  @xref{Auto
782 Major Mode}.
783
784 Normally the specified buffer is put at the front of the buffer list.
785 This affects the operation of @code{other-buffer}.  However, if
786 @var{norecord} is non-@code{nil}, this is not done.  @xref{The Buffer
787 List}.
788
789 The @code{switch-to-buffer} function is often used interactively, as
790 the binding of @kbd{C-x b}.  It is also used frequently in programs.  It
791 always returns @code{nil}.
792 @end deffn
793
794 @deffn Command switch-to-buffer-other-window buffer-or-name
795 This function makes @var{buffer-or-name} the current buffer and
796 displays it in a window not currently selected.  It then selects that
797 window.  The handling of the buffer is the same as in
798 @code{switch-to-buffer}.
799
800 The currently selected window is absolutely never used to do the job.
801 If it is the only window, then it is split to make a distinct window for
802 this purpose.  If the selected window is already displaying the buffer,
803 then it continues to do so, but another window is nonetheless found to
804 display it in as well.
805 @end deffn
806
807 @defun pop-to-buffer buffer-or-name &optional other-window on-frame
808 This function makes @var{buffer-or-name} the current buffer and
809 switches to it in some window, preferably not the window previously
810 selected.  The ``popped-to'' window becomes the selected window within
811 its frame.
812
813 If the variable @code{pop-up-frames} is non-@code{nil},
814 @code{pop-to-buffer} looks for a window in any visible frame already
815 displaying the buffer; if there is one, it returns that window and makes
816 it be selected within its frame.  If there is none, it creates a new
817 frame and displays the buffer in it.
818
819 If @code{pop-up-frames} is @code{nil}, then @code{pop-to-buffer}
820 operates entirely within the selected frame.  (If the selected frame has
821 just a minibuffer, @code{pop-to-buffer} operates within the most
822 recently selected frame that was not just a minibuffer.)
823
824 If the variable @code{pop-up-windows} is non-@code{nil}, windows may
825 be split to create a new window that is different from the original
826 window.  For details, see @ref{Choosing Window}.
827
828 If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or
829 creates another window even if @var{buffer-or-name} is already visible
830 in the selected window.  Thus @var{buffer-or-name} could end up
831 displayed in two windows.  On the other hand, if @var{buffer-or-name} is
832 already displayed in the selected window and @var{other-window} is
833 @code{nil}, then the selected window is considered sufficient display
834 for @var{buffer-or-name}, so that nothing needs to be done.
835
836 All the variables that affect @code{display-buffer} affect
837 @code{pop-to-buffer} as well.  @xref{Choosing Window}.
838
839 If @var{buffer-or-name} is a string that does not name an existing
840 buffer, a buffer by that name is created.  The major mode for the new
841 buffer is set according to the variable @code{default-major-mode}.
842 @xref{Auto Major Mode}.
843
844   If @var{on-frame} is non-@code{nil}, it is the frame to pop to this
845 buffer on.
846
847   An example use of this function is found at the end of @ref{Filter
848 Functions}.
849 @end defun
850
851 @deffn Command replace-buffer-in-windows buffer &optional which-frames which-devices
852 This function replaces @var{buffer} with some other buffer in all
853 windows displaying it.  The other buffer used is chosen with
854 @code{other-buffer}.  In the usual applications of this function, you
855 don't care which other buffer is used; you just want to make sure that
856 @var{buffer} is no longer displayed.
857
858 The optional arguments @var{which-frames} and @var{which-devices} have
859 the same meaning as with @code{delete-windows-on}.
860
861 This function returns @code{nil}.
862 @end deffn
863
864
865 @node Choosing Window
866 @section Choosing a Window for Display
867
868   This section describes the basic facility that chooses a window to
869 display a buffer in---@code{display-buffer}.  All the higher-level
870 functions and commands use this subroutine.  Here we describe how to use
871 @code{display-buffer} and how to customize it.
872
873 @deffn Command display-buffer buffer-or-name &optional not-this-window override-frame
874 This command makes @var{buffer-or-name} appear in some window, like
875 @code{pop-to-buffer}, but it does not select that window and does not
876 make the buffer current.  The identity of the selected window is
877 unaltered by this function.
878
879 @var{buffer-or-name} can be a buffer or the name of one.
880
881 If @var{not-this-window} is non-@code{nil}, it means to display the
882 specified buffer in a window other than the selected one, even if it is
883 already on display in the selected window.  This can cause the buffer to
884 appear in two windows at once.  Otherwise, if @var{buffer-or-name} is
885 already being displayed in any window, that is good enough, so this
886 function does nothing.
887
888 If @var{override-frame} is non-@code{nil}, display on that frame instead
889 of the current frame (or the dedicated frame).
890
891 @code{display-buffer} returns the window chosen to display @var{buffer-or-name}.
892
893 Precisely how @code{display-buffer} finds or creates a window depends on
894 the variables described below.
895 @end deffn
896
897 @c Emacs 19 feature
898 @cindex dedicated window
899 A window can be marked as ``dedicated'' to a particular buffer.
900 Then SXEmacs will not automatically change which buffer appears in the
901 window, such as @code{display-buffer} might normally do.
902
903 @defun window-dedicated-p window
904 This function returns @var{window}'s dedicated object, usually @code{t}
905 or @code{nil}.
906 @end defun
907
908 @defun set-window-buffer-dedicated window buffer
909 This function makes @var{window} display @var{buffer} and be dedicated
910 to that buffer.  Then SXEmacs will not automatically change which buffer
911 appears in @var{window}.  If @var{buffer} is @code{nil}, this function makes
912 @var{window} not be dedicated (but doesn't change which buffer appears
913 in it currently).
914 @end defun
915
916 @defopt pop-up-windows
917 This variable controls whether @code{display-buffer} makes new windows.
918 If it is non-@code{nil} and there is only one window, then that window
919 is split.  If it is @code{nil}, then @code{display-buffer} does not
920 split the single window, but uses it whole.
921 @end defopt
922
923 @defopt split-height-threshold
924 This variable determines when @code{display-buffer} may split a window,
925 if there are multiple windows.  @code{display-buffer} always splits the
926 largest window if it has at least this many lines.  If the largest
927 window is not this tall, it is split only if it is the sole window and
928 @code{pop-up-windows} is non-@code{nil}.
929 @end defopt
930
931 @c Emacs 19 feature
932 @defopt pop-up-frames
933 This variable controls whether @code{display-buffer} makes new frames.
934 If it is non-@code{nil}, @code{display-buffer} looks for an existing
935 window already displaying the desired buffer, on any visible frame.  If
936 it finds one, it returns that window.  Otherwise it makes a new frame.
937 The variables @code{pop-up-windows} and @code{split-height-threshold} do
938 not matter if @code{pop-up-frames} is non-@code{nil}.
939
940 If @code{pop-up-frames} is @code{nil}, then @code{display-buffer} either
941 splits a window or reuses one.
942
943 @xref{Frames}, for more information.
944 @end defopt
945
946 @c Emacs 19 feature
947 @defvar pop-up-frame-function
948 This variable specifies how to make a new frame if @code{pop-up-frames}
949 is non-@code{nil}.
950
951 Its value should be a function of no arguments.  When
952 @code{display-buffer} makes a new frame, it does so by calling that
953 function, which should return a frame.  The default value of the
954 variable is a function that creates a frame using properties from
955 @code{pop-up-frame-plist}.
956 @end defvar
957
958 @defvar pop-up-frame-plist
959 This variable holds a plist specifying frame properties used when
960 @code{display-buffer} makes a new frame.  @xref{Frame Properties}, for
961 more information about frame properties.
962 @end defvar
963
964 @defvar special-display-buffer-names
965 A list of buffer names for buffers that should be displayed specially.
966 If the buffer's name is in this list, @code{display-buffer} handles the
967 buffer specially.
968
969 By default, special display means to give the buffer a dedicated frame.
970
971 If an element is a list, instead of a string, then the @sc{car} of the
972 list is the buffer name, and the rest of the list says how to create the
973 frame.  There are two possibilities for the rest of the list.  It can be
974 a plist, specifying frame properties, or it can contain a function and
975 arguments to give to it.  (The function's first argument is always the
976 buffer to be displayed; the arguments from the list come after that.)
977 @end defvar
978
979 @defvar special-display-regexps
980 A list of regular expressions that specify buffers that should be
981 displayed specially.  If the buffer's name matches any of the regular
982 expressions in this list, @code{display-buffer} handles the buffer
983 specially.
984
985 By default, special display means to give the buffer a dedicated frame.
986
987 If an element is a list, instead of a string, then the @sc{car} of the
988 list is the regular expression, and the rest of the list says how to
989 create the frame.  See above, under @code{special-display-buffer-names}.
990 @end defvar
991
992 @defvar special-display-function
993 This variable holds the function to call to display a buffer specially.
994 It receives the buffer as an argument, and should return the window in
995 which it is displayed.
996
997 The default value of this variable is
998 @code{special-display-popup-frame}.
999 @end defvar
1000
1001 @defun special-display-popup-frame buffer
1002 This function makes @var{buffer} visible in a frame of its own.  If
1003 @var{buffer} is already displayed in a window in some frame, it makes
1004 the frame visible and raises it, to use that window.  Otherwise, it
1005 creates a frame that will be dedicated to @var{buffer}.
1006
1007 This function uses an existing window displaying @var{buffer} whether or
1008 not it is in a frame of its own; but if you set up the above variables
1009 in your init file, before @var{buffer} was created, then presumably the
1010 window was previously made by this function.
1011 @end defun
1012
1013 @defopt special-display-frame-plist
1014 This variable holds frame properties for
1015 @code{special-display-popup-frame} to use when it creates a frame.
1016 @end defopt
1017
1018 @defvar same-window-buffer-names
1019 A list of buffer names for buffers that should be displayed in the
1020 selected window.  If the buffer's name is in this list,
1021 @code{display-buffer} handles the buffer by switching to it in the
1022 selected window.
1023 @end defvar
1024
1025 @defvar same-window-regexps
1026 A list of regular expressions that specify buffers that should be
1027 displayed in the selected window.  If the buffer's name matches any of
1028 the regular expressions in this list, @code{display-buffer} handles the
1029 buffer by switching to it in the selected window.
1030 @end defvar
1031
1032 @c Emacs 19 feature
1033 @defvar display-buffer-function
1034 This variable is the most flexible way to customize the behavior of
1035 @code{display-buffer}.  If it is non-@code{nil}, it should be a function
1036 that @code{display-buffer} calls to do the work.  The function should
1037 accept two arguments, the same two arguments that @code{display-buffer}
1038 received.  It should choose or create a window, display the specified
1039 buffer, and then return the window.
1040
1041 This hook takes precedence over all the other options and hooks
1042 described above.
1043 @end defvar
1044
1045 @c Emacs 19 feature
1046 @cindex dedicated window
1047 A window can be marked as ``dedicated'' to its buffer.  Then
1048 @code{display-buffer} does not try to use that window.
1049
1050 @defun window-dedicated-p window
1051 This function returns @code{t} if @var{window} is marked as dedicated;
1052 otherwise @code{nil}.
1053 @end defun
1054
1055 @defun set-window-dedicated-p window flag
1056 This function marks @var{window} as dedicated if @var{flag} is
1057 non-@code{nil}, and nondedicated otherwise.
1058 @end defun
1059
1060
1061 @node Window Point
1062 @section Windows and Point
1063 @cindex window position
1064 @cindex window point
1065 @cindex position in window
1066 @cindex point in window
1067
1068   Each window has its own value of point, independent of the value of
1069 point in other windows displaying the same buffer.  This makes it useful
1070 to have multiple windows showing one buffer.
1071
1072 @itemize @bullet
1073 @item
1074 The window point is established when a window is first created; it is
1075 initialized from the buffer's point, or from the window point of another
1076 window opened on the buffer if such a window exists.
1077
1078 @item
1079 Selecting a window sets the value of point in its buffer to the window's
1080 value of point.  Conversely, deselecting a window sets the window's
1081 value of point from that of the buffer.  Thus, when you switch between
1082 windows that display a given buffer, the point value for the selected
1083 window is in effect in the buffer, while the point values for the other
1084 windows are stored in those windows.
1085
1086 @item
1087 As long as the selected window displays the current buffer, the window's
1088 point and the buffer's point always move together; they remain equal.
1089
1090 @item
1091 @xref{Positions}, for more details on buffer positions.
1092 @end itemize
1093
1094   As far as the user is concerned, point is where the cursor is, and
1095 when the user switches to another buffer, the cursor jumps to the
1096 position of point in that buffer.
1097
1098 @defun window-point &optional window
1099 This function returns the current position of point in @var{window}.
1100 For a non-selected window, this is the value point would have (in that
1101 window's buffer) if that window were selected.
1102
1103 When @var{window} is the selected window and its buffer is also the
1104 current buffer, the value returned is the same as the value of point in
1105 that buffer.
1106
1107 Strictly speaking, it would be more correct to return the
1108 ``top-level'' value of point, outside of any @code{save-excursion}
1109 forms.  But that value is hard to find.
1110 @end defun
1111
1112 @defun set-window-point window position
1113 This function positions point in @var{window} at position
1114 @var{position} in @var{window}'s buffer.
1115 @end defun
1116
1117
1118 @node Window Start
1119 @section The Window Start Position
1120
1121   Each window contains a marker used to keep track of a buffer position
1122 that specifies where in the buffer display should start.  This position
1123 is called the @dfn{display-start} position of the window (or just the
1124 @dfn{start}).  The character after this position is the one that appears
1125 at the upper left corner of the window.  It is usually, but not
1126 inevitably, at the beginning of a text line.
1127
1128 @defun window-start &optional window
1129 @cindex window top line
1130 This function returns the display-start position of window
1131 @var{window}.  If @var{window} is @code{nil}, the selected window is
1132 used.  For example,
1133
1134 @example
1135 @group
1136 (window-start)
1137      @result{} 7058
1138 @end group
1139 @end example
1140
1141 When you create a window, or display a different buffer in it, the
1142 display-start position is set to a display-start position recently used
1143 for the same buffer, or 1 if the buffer doesn't have any.
1144
1145 For a realistic example, see the description of @code{count-lines} in
1146 @ref{Text Lines}.
1147 @end defun
1148
1149 @defun window-end &optional window guarantee
1150 This function returns the position of the end of the display in window
1151 @var{window}.  If @var{window} is @code{nil}, the selected window is
1152 used.
1153
1154 Simply changing the buffer text or setting @code{window-start} does not
1155 update the value that @code{window-end} returns.  The value is updated
1156 only when SXEmacs redisplays and redisplay actually finishes.
1157
1158 If the last redisplay of @var{window} was preempted, and did not finish,
1159 SXEmacs does not know the position of the end of display in that window.
1160 In that case, this function returns a value that is not correct.  In a
1161 future version, @code{window-end} will return @code{nil} in that case.
1162
1163 If optional arg @var{guarantee} is non-@code{nil}, the return value is
1164 guaranteed to be the same as @code{window-end} would return at the end
1165 of the next full redisplay assuming nothing else changes in the
1166 meantime.  This function is potentially much slower with this flag set.
1167
1168 @ignore
1169 in that case, this function returns @code{nil}.  You can compute where
1170 the end of the window @emph{would} have been, if redisplay had finished,
1171 like this:
1172
1173 @example
1174 (save-excursion
1175   (goto-char (window-start window))
1176   (vertical-motion (1- (window-height window))
1177                    window)
1178   (point))
1179 @end example
1180 @end ignore
1181 @end defun
1182
1183 @defun set-window-start window position &optional noforce
1184 This function sets the display-start position of @var{window} to
1185 @var{position} in @var{window}'s buffer.  It returns @var{position}.
1186
1187 The display routines insist that the position of point be visible when a
1188 buffer is displayed.  Normally, they change the display-start position
1189 (that is, scroll the window) whenever necessary to make point visible.
1190 However, if you specify the start position with this function using
1191 @code{nil} for @var{noforce}, it means you want display to start at
1192 @var{position} even if that would put the location of point off the
1193 screen.  If this does place point off screen, the display routines move
1194 point to the left margin on the middle line in the window.
1195
1196 For example, if point @w{is 1} and you set the start of the window @w{to
1197 2}, then point would be ``above'' the top of the window.  The display
1198 routines will automatically move point if it is still 1 when redisplay
1199 occurs.  Here is an example:
1200
1201 @example
1202 @group
1203 ;; @r{Here is what @samp{foo} looks like before executing}
1204 ;;   @r{the @code{set-window-start} expression.}
1205 @end group
1206
1207 @group
1208 ---------- Buffer: foo ----------
1209 @point{}This is the contents of buffer foo.
1210 2
1211 3
1212 4
1213 5
1214 6
1215 ---------- Buffer: foo ----------
1216 @end group
1217
1218 @group
1219 (set-window-start
1220  (selected-window)
1221  (1+ (window-start)))
1222 @result{} 2
1223 @end group
1224
1225 @group
1226 ;; @r{Here is what @samp{foo} looks like after executing}
1227 ;;   @r{the @code{set-window-start} expression.}
1228 ---------- Buffer: foo ----------
1229 his is the contents of buffer foo.
1230 2
1231 3
1232 @point{}4
1233 5
1234 6
1235 ---------- Buffer: foo ----------
1236 @end group
1237 @end example
1238
1239 If @var{noforce} is non-@code{nil}, and @var{position} would place point
1240 off screen at the next redisplay, then redisplay computes a new window-start
1241 position that works well with point, and thus @var{position} is not used.
1242 @end defun
1243
1244 @defun pos-visible-in-window-p &optional position window
1245 This function returns @code{t} if @var{position} is within the range
1246 of text currently visible on the screen in @var{window}.  It returns
1247 @code{nil} if @var{position} is scrolled vertically out of view.  The
1248 argument @var{position} defaults to the current position of point;
1249 @var{window}, to the selected window.  Here is an example:
1250
1251 @example
1252 @group
1253 (or (pos-visible-in-window-p
1254      (point) (selected-window))
1255     (recenter 0))
1256 @end group
1257 @end example
1258
1259 The @code{pos-visible-in-window-p} function considers only vertical
1260 scrolling.  If @var{position} is out of view only because @var{window}
1261 has been scrolled horizontally, @code{pos-visible-in-window-p} returns
1262 @code{t}.  @xref{Horizontal Scrolling}.
1263 @end defun
1264
1265
1266 @node Vertical Scrolling
1267 @section Vertical Scrolling
1268 @cindex vertical scrolling
1269 @cindex scrolling vertically
1270
1271   Vertical scrolling means moving the text up or down in a window.  It
1272 works by changing the value of the window's display-start location.  It
1273 may also change the value of @code{window-point} to keep it on the
1274 screen.
1275
1276   In the commands @code{scroll-up} and @code{scroll-down}, the directions
1277 ``up'' and ``down'' refer to the motion of the text in the buffer at which
1278 you are looking through the window.  Imagine that the text is
1279 written on a long roll of paper and that the scrolling commands move the
1280 paper up and down.  Thus, if you are looking at text in the middle of a
1281 buffer and repeatedly call @code{scroll-down}, you will eventually see
1282 the beginning of the buffer.
1283
1284   Some people have urged that the opposite convention be used: they
1285 imagine that the window moves over text that remains in place.  Then
1286 ``down'' commands would take you to the end of the buffer.  This view is
1287 more consistent with the actual relationship between windows and the
1288 text in the buffer, but it is less like what the user sees.  The
1289 position of a window on the terminal does not move, and short scrolling
1290 commands clearly move the text up or down on the screen.  We have chosen
1291 names that fit the user's point of view.
1292
1293   The scrolling functions (aside from @code{scroll-other-window}) have
1294 unpredictable results if the current buffer is different from the buffer
1295 that is displayed in the selected window.  @xref{Current Buffer}.
1296
1297 @deffn Command scroll-up &optional lines
1298 This function scrolls the text in the selected window upward
1299 @var{lines} lines.  If @var{lines} is negative, scrolling is actually
1300 downward.
1301
1302 If @var{lines} is @code{nil} (or omitted), then the length of scroll
1303 is @code{next-screen-context-lines} lines less than the usable height of
1304 the window (not counting its modeline).
1305
1306 @code{scroll-up} returns @code{nil}.
1307 @end deffn
1308
1309 @deffn Command scroll-down &optional lines
1310 This function scrolls the text in the selected window downward
1311 @var{lines} lines.  If @var{lines} is negative, scrolling is actually
1312 upward.
1313
1314 If @var{lines} is omitted or @code{nil}, then the length of the scroll
1315 is @code{next-screen-context-lines} lines less than the usable height of
1316 the window (not counting its mode line).
1317
1318 @code{scroll-down} returns @code{nil}.
1319 @end deffn
1320
1321 @deffn Command scroll-other-window &optional lines
1322 This function scrolls the text in another window upward @var{lines}
1323 lines.  Negative values of @var{lines}, or @code{nil}, are handled
1324 as in @code{scroll-up}.
1325
1326 You can specify a buffer to scroll with the variable
1327 @code{other-window-scroll-buffer}.  When the selected window is the
1328 minibuffer, the next window is normally the one at the top left corner.
1329 You can specify a different window to scroll with the variable
1330 @code{minibuffer-scroll-window}.  This variable has no effect when any
1331 other window is selected.  @xref{Minibuffer Misc}.
1332
1333 When the minibuffer is active, it is the next window if the selected
1334 window is the one at the bottom right corner.  In this case,
1335 @code{scroll-other-window} attempts to scroll the minibuffer.  If the
1336 minibuffer contains just one line, it has nowhere to scroll to, so the
1337 line reappears after the echo area momentarily displays the message
1338 ``Beginning of buffer''.
1339 @end deffn
1340
1341 @c Emacs 19 feature
1342 @defvar other-window-scroll-buffer
1343 If this variable is non-@code{nil}, it tells @code{scroll-other-window}
1344 which buffer to scroll.
1345 @end defvar
1346
1347 @defopt scroll-step
1348 This variable controls how scrolling is done automatically when point
1349 moves off the screen.  If the value is zero, then redisplay scrolls the
1350 text to center point vertically in the window.  If the value is a
1351 positive integer @var{n}, then redisplay brings point back on screen by
1352 scrolling @var{n} lines in either direction, if possible; otherwise, it
1353 centers point.  The default value is zero.
1354 @end defopt
1355
1356 @defopt scroll-conservatively
1357 This variable controls how many lines SXEmacs tries to scroll before
1358 recentering.  If you set it to a small number, then when you move point
1359 a short distance off the screen, SXEmacs will scroll the screen just far
1360 enough to bring point back on screen, provided that does not exceed
1361 @code{scroll-conservatively} lines.  This variable overrides the
1362 redisplay preemption.
1363 @end defopt
1364
1365 @defopt next-screen-context-lines
1366 The value of this variable is the number of lines of continuity to
1367 retain when scrolling by full screens.  For example, @code{scroll-up}
1368 with an argument of @code{nil} scrolls so that this many lines at the
1369 bottom of the window appear instead at the top.  The default value is
1370 @code{2}.
1371 @end defopt
1372
1373 @deffn Command recenter &optional location window
1374 @cindex centering point
1375 This function scrolls @var{window} (which defaults to the selected
1376 window) to put the text where point is located at a specified vertical
1377 position within the window.
1378
1379 If @var{location} is a nonnegative number, it puts the line containing
1380 point @var{location} lines down from the top of the window.  If @var{location}
1381 is a negative number, then it counts upward from the bottom of the
1382 window, so that @minus{}1 stands for the last usable line in the window.
1383 If @var{location} is a non-@code{nil} list, then it stands for the line in
1384 the middle of the window.
1385
1386 If @var{location} is @code{nil}, @code{recenter} puts the line containing
1387 point in the middle of the window, then clears and redisplays the entire
1388 selected frame.
1389
1390 When @code{recenter} is called interactively, @var{location} is the raw
1391 prefix argument.  Thus, typing @kbd{C-u} as the prefix sets the
1392 @var{location} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
1393 @var{location} to 4, which positions the current line four lines from the
1394 top.
1395
1396 With an argument of zero, @code{recenter} positions the current line at
1397 the top of the window.  This action is so handy that some people make a
1398 separate key binding to do this.  For example,
1399
1400 @example
1401 @group
1402 (defun line-to-top-of-window ()
1403   "Scroll current line to top of window.
1404 Replaces three keystroke sequence C-u 0 C-l."
1405   (interactive)
1406   (recenter 0))
1407
1408 (global-set-key [kp-multiply] 'line-to-top-of-window)
1409 @end group
1410 @end example
1411 @end deffn
1412
1413
1414 @node Horizontal Scrolling
1415 @section Horizontal Scrolling
1416 @cindex horizontal scrolling
1417
1418   Because we read English first from top to bottom and second from left
1419 to right, horizontal scrolling is not like vertical scrolling.  Vertical
1420 scrolling involves selection of a contiguous portion of text to display.
1421 Horizontal scrolling causes part of each line to go off screen.  The
1422 amount of horizontal scrolling is therefore specified as a number of
1423 columns rather than as a position in the buffer.  It has nothing to do
1424 with the display-start position returned by @code{window-start}.
1425
1426   Usually, no horizontal scrolling is in effect; then the leftmost
1427 column is at the left edge of the window.  In this state, scrolling to
1428 the right is meaningless, since there is no data to the left of the
1429 screen to be revealed by it; so this is not allowed.  Scrolling to the
1430 left is allowed; it scrolls the first columns of text off the edge of
1431 the window and can reveal additional columns on the right that were
1432 truncated before.  Once a window has a nonzero amount of leftward
1433 horizontal scrolling, you can scroll it back to the right, but only so
1434 far as to reduce the net horizontal scroll to zero.  There is no limit
1435 to how far left you can scroll, but eventually all the text will
1436 disappear off the left edge.
1437
1438 @deffn Command scroll-left &optional count
1439 This function scrolls the selected window @var{count} columns to the
1440 left (or to the right if @var{count} is negative).  The return value is
1441 the total amount of leftward horizontal scrolling in effect after the
1442 change---just like the value returned by @code{window-hscroll} (below).
1443 @end deffn
1444
1445 @deffn Command scroll-right &optional count
1446 This function scrolls the selected window @var{count} columns to the
1447 right (or to the left if @var{count} is negative).  The return value is
1448 the total amount of leftward horizontal scrolling in effect after the
1449 change---just like the value returned by @code{window-hscroll} (below).
1450
1451 Once you scroll a window as far right as it can go, back to its normal
1452 position where the total leftward scrolling is zero, attempts to scroll
1453 any farther right have no effect.
1454 @end deffn
1455
1456 @defun window-hscroll &optional window
1457 This function returns the total leftward horizontal scrolling of
1458 @var{window}---the number of columns by which the text in @var{window}
1459 is scrolled left past the left margin.
1460
1461 The value is never negative.  It is zero when no horizontal scrolling
1462 has been done in @var{window} (which is usually the case).
1463
1464 If @var{window} is @code{nil}, the selected window is used.
1465
1466 @example
1467 @group
1468 (window-hscroll)
1469      @result{} 0
1470 @end group
1471 @group
1472 (scroll-left 5)
1473      @result{} 5
1474 @end group
1475 @group
1476 (window-hscroll)
1477      @result{} 5
1478 @end group
1479 @end example
1480 @end defun
1481
1482 @defun set-window-hscroll window columns
1483 This function sets the number of columns from the left margin that
1484 @var{window} is scrolled to the value of @var{columns}.  The argument
1485 @var{columns} should be zero or positive; if not, it is taken as zero.
1486
1487 The value returned is @var{columns}.
1488
1489 @example
1490 @group
1491 (set-window-hscroll (selected-window) 10)
1492      @result{} 10
1493 @end group
1494 @end example
1495 @end defun
1496
1497   Here is how you can determine whether a given position @var{position}
1498 is off the screen due to horizontal scrolling:
1499
1500 @example
1501 @group
1502 (defun hscroll-on-screen (window position)
1503   (save-excursion
1504     (goto-char position)
1505     (and
1506      (>= (- (current-column) (window-hscroll window)) 0)
1507      (< (- (current-column) (window-hscroll window))
1508         (window-width window)))))
1509 @end group
1510 @end example
1511
1512
1513 @node Size of Window
1514 @section The Size of a Window
1515 @cindex window size
1516 @cindex size of window
1517
1518 A SXEmacs window is rectangular, and its size information consists of
1519 the height (in lines or pixels) and the width (in character positions
1520 or pixels).  The modeline is included in the height.  The pixel
1521 width and height values include scrollbars and margins, while the
1522 line/character-position values do not.
1523
1524 Note that the height in lines, and the width in characters, are
1525 determined by dividing the corresponding pixel value by the height or
1526 width of the default font in that window (if this is a variable-width
1527 font, the average width is used).  The resulting values may or may not
1528 represent the actual number of lines in the window, or the actual number
1529 of character positions in any particular line, esp. if there are pixmaps
1530 or various different fonts in the window.
1531
1532   The following functions return size information about a window:
1533
1534 @defun window-height &optional window
1535 This function returns the number of lines in @var{window}, including
1536 its modeline but not including the horizontal scrollbar, if any (this
1537 is different from @code{window-pixel-height}).  If @var{window} is
1538 @code{nil}, the function uses the selected window.
1539
1540 @example
1541 @group
1542 (window-height)
1543      @result{} 40
1544 @end group
1545 @group
1546 (split-window-vertically)
1547      @result{} #<window on "windows.texi" 0x679b>
1548 @end group
1549 @group
1550 (window-height)
1551      @result{} 20
1552 @end group
1553 @end example
1554 @end defun
1555
1556 @defun window-width &optional window
1557 This function returns the number of columns in @var{window}, not
1558 including any left margin, right margin, or vertical scrollbar (this is
1559 different from @code{window-pixel-width}).  If @var{window} is
1560 @code{nil}, the function uses the selected window.
1561
1562 @example
1563 @group
1564 (window-width)
1565      @result{} 80
1566 @end group
1567 @group
1568 (window-height)
1569      @result{} 40
1570 @end group
1571 @group
1572 (split-window-horizontally)
1573      @result{} #<window on "windows.texi" 0x7538>
1574 @end group
1575 @group
1576 (window-width)
1577      @result{} 39
1578 @end group
1579 @end example
1580 @end defun
1581
1582 Note that after splitting the window into two side-by-side windows,
1583 the width of each window is less the half the width of the original
1584 window because a vertical scrollbar appeared between the windows,
1585 occupying two columns worth of space.  Also, the height shrunk by
1586 one because horizontal scrollbars appeared that weren't there
1587 before. (Horizontal scrollbars appear only when lines are
1588 truncated, not when they wrap.  This is usually the case for
1589 horizontally split windows but not for full-frame windows.  You
1590 can change this using the variables @code{truncate-lines} and
1591 @code{truncate-partial-width-windows}.)
1592
1593 @defun window-pixel-height &optional window
1594 This function returns the height of @var{window} in pixels, including
1595 its modeline and horizontal scrollbar, if any.  If @var{window} is
1596 @code{nil}, the function uses the selected window.
1597
1598 @example
1599 @group
1600 (window-pixel-height)
1601      @result{} 600
1602 @end group
1603 @group
1604 (split-window-vertically)
1605      @result{} #<window on "windows.texi" 0x68a6>
1606 @end group
1607 @group
1608 (window-pixel-height)
1609      @result{} 300
1610 @end group
1611 @end example
1612 @end defun
1613
1614 @defun window-pixel-width &optional window
1615   This function returns the width of @var{window} in pixels, including
1616 any left margin, right margin, or vertical scrollbar that may be
1617 displayed alongside it.  If @var{window} is @code{nil}, the function
1618 uses the selected window.
1619
1620 @example
1621 @group
1622 (window-pixel-width)
1623      @result{} 735
1624 @end group
1625 @group
1626 (window-pixel-height)
1627      @result{} 600
1628 @end group
1629 @group
1630 (split-window-horizontally)
1631      @result{} #<window on "windows.texi" 0x7538>
1632 @end group
1633 @group
1634 (window-pixel-width)
1635      @result{} 367
1636 @end group
1637 @group
1638 (window-pixel-height)
1639      @result{} 600
1640 @end group
1641 @end example
1642 @end defun
1643
1644 @defun window-text-area-pixel-height &optional window
1645 This function returns the height in pixels of the text displaying
1646 portion of @var{window}, which defaults to the selected window.  Unlike
1647 @code{window-pixel-height}, the space occupied by the modeline and
1648 horizontal scrollbar, if any, is not counted.
1649 @end defun
1650
1651 @defun window-text-area-pixel-width &optional window
1652 This function returns the width in pixels of the text displaying
1653 portion of @var{window}, which defaults to the selected window.  Unlike
1654 @code{window-pixel-width}, the space occupied by the vertical scrollbar
1655 and divider, if any, is not counted.
1656 @end defun
1657
1658 @defun window-displayed-text-pixel-height &optional window noclipped
1659 This function returns the height in pixels of the text displayed in
1660 @var{window}, which defaults to the selected window.  Unlike
1661 @code{window-text-area-pixel-height}, any blank space below the
1662 end of the buffer is not included.  If optional argument @var{noclipped}
1663 is non-@code{nil}, any space occupied by clipped lines will not be
1664 included.
1665 @end defun
1666
1667
1668 @node Position of Window
1669 @section The Position of a Window
1670 @cindex window position
1671 @cindex position of window
1672
1673 SXEmacs provides functions to determine the absolute location of windows
1674 within a frame, and the relative location of a window in comparison to
1675 other windows in the same frame.
1676
1677 @defun window-pixel-edges &optional window
1678   This function returns a list of the pixel edge coordinates of
1679 @var{window}.  If @var{window} is @code{nil}, the selected window is
1680 used.
1681
1682   The order of the list is @code{(@var{left} @var{top} @var{right}
1683 @var{bottom})}, all elements relative to 0, 0 at the top left corner of
1684 @var{window}'s frame.  The element @var{right} of the value is one more
1685 than the rightmost pixel used by @var{window} (including any left
1686 margin, right margin, or vertical scrollbar displayed alongside it), and
1687 @var{bottom} is one more than the bottommost pixel used by @var{window}
1688 (including any modeline or horizontal scrollbar displayed above or below
1689 it).  The frame area does not include any frame menubars, toolbars, or
1690 gutters that may be displayed; thus, for example, if there is only one
1691 window on the frame, the values for @var{left} and @var{top} will always
1692 be 0.
1693
1694   If @var{window} is at the upper left corner of its frame, @var{right}
1695 and @var{bottom} are the same as the values returned by
1696 @code{(window-pixel-width)} and @code{(window-pixel-height)}
1697 respectively, and @var{left} and @var{top} are zero.
1698 @end defun
1699
1700   There is no longer a function @code{window-edges} because it does not
1701 make sense in a world with variable-width and variable-height lines,
1702 as are allowed in SXEmacs.
1703
1704 @defun window-highest-p window
1705   This function returns non-@code{nil} if @var{window} is along the
1706 top of its frame.
1707 @end defun
1708
1709 @defun window-lowest-p window
1710   This function returns non-@code{nil} if @var{window} is along the
1711 bottom of its frame.
1712 @end defun
1713
1714 @defun window-text-area-pixel-edges &optional window
1715 This function allows one to determine the location of the
1716 text-displaying portion of @var{window}, which defaults to the selected
1717 window, with respect to the top left corner of the window.  It returns
1718 a list of integer pixel positions @code{(left top right bottom)}, all
1719 relative to @code{(0,0)} at the top left corner of the window.
1720 @end defun
1721
1722
1723 @node Resizing Windows
1724 @section Changing the Size of a Window
1725 @cindex window resizing
1726 @cindex changing window size
1727 @cindex window size, changing
1728
1729   The window size functions fall into two classes: high-level commands
1730 that change the size of windows and low-level functions that access
1731 window size.  SXEmacs does not permit overlapping windows or gaps between
1732 windows, so resizing one window affects other windows.
1733
1734 @deffn Command enlarge-window count &optional horizontal window
1735 This function makes the selected window @var{count} lines taller,
1736 stealing lines from neighboring windows.  It takes the lines from one
1737 window at a time until that window is used up, then takes from another.
1738 If a window from which lines are stolen shrinks below
1739 @code{window-min-height} lines, that window disappears.
1740
1741 If @var{horizontal} is non-@code{nil}, this function makes
1742 @var{window} wider by @var{count} columns, stealing columns instead of
1743 lines.  If a window from which columns are stolen shrinks below
1744 @code{window-min-width} columns, that window disappears.
1745
1746 If the requested size would exceed that of the window's frame, then the
1747 function makes the window occupy the entire height (or width) of the
1748 frame.
1749
1750 If @var{count} is negative, this function shrinks the window by
1751 @minus{}@var{count} lines or columns.  If that makes the window smaller
1752 than the minimum size (@code{window-min-height} and
1753 @code{window-min-width}), @code{enlarge-window} deletes the window.
1754
1755 If @var{window} is non-@code{nil}, it specifies a window to change
1756 instead of the selected window.
1757
1758 @code{enlarge-window} returns @code{nil}.
1759 @end deffn
1760
1761 @deffn Command enlarge-window-horizontally columns
1762 This function makes the selected window @var{columns} wider.
1763 It could be defined as follows:
1764
1765 @example
1766 @group
1767 (defun enlarge-window-horizontally (columns)
1768   (enlarge-window columns t))
1769 @end group
1770 @end example
1771 @end deffn
1772
1773 @deffn Command enlarge-window-pixels count &optional side window
1774 This function makes the selected window @var{count} pixels larger.  
1775 When called from Lisp, optional second argument @var{side}
1776 non-@code{nil} means to grow sideways @var{count} pixels, and optional
1777 third argument @var{window} specifies the window to change instead of
1778 the selected window.
1779 @end deffn
1780
1781 @deffn Command shrink-window count &optional horizontal window
1782 This function is like @code{enlarge-window} but negates the argument
1783 @var{count}, making the selected window smaller by giving lines (or
1784 columns) to the other windows.  If the window shrinks below
1785 @code{window-min-height} or @code{window-min-width}, then it disappears.
1786
1787 If @var{count} is negative, the window is enlarged by @minus{}@var{count}
1788 lines or columns.
1789
1790 If @var{window} is non-@code{nil}, it specifies a window to change
1791 instead of the selected window.
1792 @end deffn
1793
1794 @deffn Command shrink-window-horizontally columns
1795 This function makes the selected window @var{columns} narrower.
1796 It could be defined as follows:
1797
1798 @example
1799 @group
1800 (defun shrink-window-horizontally (columns)
1801   (shrink-window columns t))
1802 @end group
1803 @end example
1804 @end deffn
1805
1806 @deffn Command shrink-window-pixels count &optional side window
1807 This function makes the selected window @var{count} pixels smaller.
1808 When called from Lisp, optional second argument @var{side}
1809 non-@code{nil} means to shrink sideways @var{count} pixels, and optional
1810 third argument @var{window} specifies the window to change instead of
1811 the selected window.
1812 @end deffn
1813
1814 @cindex minimum window size
1815   The following two variables constrain the window-size-changing
1816 functions to a minimum height and width.
1817
1818 @defopt window-min-height
1819 The value of this variable determines how short a window may become
1820 before it is automatically deleted.  Making a window smaller than
1821 @code{window-min-height} automatically deletes it, and no window may be
1822 created shorter than this.  The absolute minimum height is two (allowing
1823 one line for the mode line, and one line for the buffer display).
1824 Actions that change window sizes reset this variable to two if it is
1825 less than two.  The default value is 4.
1826 @end defopt
1827
1828 @defopt window-min-width
1829 The value of this variable determines how narrow a window may become
1830 before it automatically deleted.  Making a window smaller than
1831 @code{window-min-width} automatically deletes it, and no window may be
1832 created narrower than this.  The absolute minimum width is one; any
1833 value below that is ignored.  The default value is 10.
1834 @end defopt
1835
1836 @c This is not yet implemented.  Why is it "documented"?
1837 @defvar window-size-change-functions
1838 This variable holds a list of functions to be called if the size of any
1839 window changes for any reason.  The functions are called just once per
1840 redisplay, and just once for each frame on which size changes have
1841 occurred.
1842
1843 Each function receives the frame as its sole argument.  There is no
1844 direct way to find out which windows changed size, or precisely how;
1845 however, if your size-change function keeps track, after each change, of
1846 the windows that interest you, you can figure out what has changed by
1847 comparing the old size data with the new.
1848
1849 Creating or deleting windows counts as a size change, and therefore
1850 causes these functions to be called.  Changing the frame size also
1851 counts, because it changes the sizes of the existing windows.
1852
1853 It is not a good idea to use @code{save-window-excursion} in these
1854 functions, because that always counts as a size change, and it would
1855 cause these functions to be called over and over.  In most cases,
1856 @code{save-selected-window} is what you need here.
1857 @end defvar
1858
1859
1860 @node Window Configurations
1861 @section Window Configurations
1862 @cindex window configurations
1863 @cindex saving window information
1864
1865   A @dfn{window configuration} records the entire layout of a
1866 frame---all windows, their sizes, which buffers they contain, what part
1867 of each buffer is displayed, and the values of point and the mark.  You
1868 can bring back an entire previous layout by restoring a window
1869 configuration previously saved.
1870
1871   If you want to record all frames instead of just one, use a frame
1872 configuration instead of a window configuration.  @xref{Frame
1873 Configurations}.
1874
1875   Use the window configuration hook whenever you need to dynamicly
1876 adapt to window configuration changes.  @xref{Window Configuration
1877 Hook}.
1878
1879 @defun current-window-configuration &optional frame
1880 This function returns a new object representing the current window
1881 configuration of @var{frame}, namely the number of windows, their sizes
1882 and current buffers, which window is the selected window, and for each
1883 window the displayed buffer, the display-start position, and the
1884 positions of point and the mark.  An exception is made for point in the
1885 current buffer, whose value is not saved.
1886
1887 @var{frame} defaults to the selected frame.
1888 @end defun
1889
1890 @defun set-window-configuration configuration
1891 This function restores the configuration of SXEmacs's windows and
1892 buffers to the state specified by @var{configuration}.  The argument
1893 @var{configuration} must be a value that was previously returned by
1894 @code{current-window-configuration}.
1895
1896 This function always counts as a window size change and triggers
1897 execution of the @code{window-size-change-functions}.  (It doesn't know
1898 how to tell whether the new configuration actually differs from the old
1899 one.)
1900
1901 Here is a way of using this function to get the same effect
1902 as @code{save-window-excursion}:
1903
1904 @example
1905 @group
1906 (let ((config (current-window-configuration)))
1907   (unwind-protect
1908       (progn (split-window-vertically nil)
1909              @dots{})
1910     (set-window-configuration config)))
1911 @end group
1912 @end example
1913 @end defun
1914
1915 @defspec save-window-excursion forms@dots{}
1916 This special form records the window configuration, executes @var{forms}
1917 in sequence, then restores the earlier window configuration.  The window
1918 configuration includes the value of point and the portion of the buffer
1919 that is visible.  It also includes the choice of selected window.
1920 However, it does not include the value of point in the current buffer;
1921 use @code{save-excursion} if you wish to preserve that.
1922
1923 Don't use this construct when @code{save-selected-window} is all you need.
1924
1925 Exit from @code{save-window-excursion} always triggers execution of the
1926 @code{window-size-change-functions}.  (It doesn't know how to tell
1927 whether the restored configuration actually differs from the one in
1928 effect at the end of the @var{forms}.)
1929
1930 The return value is the value of the final form in @var{forms}.
1931 For example:
1932
1933 @example
1934 @group
1935 (split-window)
1936      @result{} #<window 25 on control.texi>
1937 @end group
1938 @group
1939 (setq w (selected-window))
1940      @result{} #<window 19 on control.texi>
1941 @end group
1942 @group
1943 (save-window-excursion
1944   (delete-other-windows w)
1945   (switch-to-buffer "foo")
1946   'do-something)
1947      @result{} do-something
1948      ;; @r{The frame is now split again.}
1949 @end group
1950 @end example
1951 @end defspec
1952
1953 @defun window-configuration-p object
1954 This function returns @code{t} if @var{object} is a window configuration.
1955 @end defun
1956
1957   Primitives to look inside of window configurations would make sense,
1958 but none are implemented.  It is not clear they are useful enough to be
1959 worth implementing.
1960
1961
1962 @node Window Configuration Hook
1963 @section Window Configuration Hook
1964 @cindex window configuration hook
1965
1966 The @var{window-configuration-hook}, is a list of functions run whenever
1967 the window configuration of a frame changes; such as when a window is
1968 deleted, split or resized.
1969
1970 Each function is called with a window as argument, which window depends
1971 on what function runs the hook.
1972
1973 When a new frame is created, this hook is not run on the newly created
1974 window, please use the @var{create-frame-hook} instead, where each
1975 function recieves the frame as argument.
1976
1977 There is no guarantee that this will only be run at the end of some
1978 function that changes the window configuration (read layout), in fact it
1979 can be run several times while the window layout changes.
1980
1981 The core functions that run this hook try to ensure that it does not
1982 cause infinite loops, but if you run some functions that change the
1983 layout @strong{expect trouble}.
1984
1985 Here is a complete list of core functions, running the hook.  All other
1986 window manipulating functions call these and therefore run the hook at
1987 some point in time.  If not, that's a bug, and you should report it as
1988 such.
1989
1990 @table @asis
1991 @c deleting windows
1992 @item @code{delete-window} @xref{Deleting Windows}.
1993 The window that takes the space of the deleted window is recieved as the
1994 argument.  If this command deletes the frame, the hook is not run.
1995 @item @code{delete-other-windows} @xref{Deleting Windows}.
1996 The window that is left behind is recieved as argument.
1997 @c buffers and windows
1998 @item @code{set-window-buffer} @xref{Buffers and Windows}.
1999 The window recievied as argument is passed on to the hook.
2000 @c splitting windows
2001 @item @code{split-window} @xref{Splitting Windows}.
2002 The window recievied as argument is passed on to the hook.
2003 @c resising windows
2004 @item @code{enlarge-window} @xref{Resizing Windows}.
2005 The window recievied as argument is passed on to the hook.
2006 @item @code{enlarge-window-pixels} @xref{Resizing Windows}.
2007 The window recievied as argument is passed on to the hook..
2008 @item @code{shrink-window} @xref{Resizing Windows}.
2009 The window recievied as argument is passed on to the hook.
2010 @item @code{shrink-window-pixels} @xref{Resizing Windows}.
2011 The window recievied as argument is passed on to the hook.
2012 @end table