1 This is Info file ../../info/lispref.info, produced by Makeinfo version
2 1.68 from the input file lispref.texi.
4 INFO-DIR-SECTION XEmacs Editor
6 * Lispref: (lispref). XEmacs Lisp Reference Manual.
11 GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
21 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc. Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
25 Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
29 Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
34 Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
39 Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
46 Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
53 File: lispref.info, Node: The Buffer List, Next: Creating Buffers, Prev: Read Only Buffers, Up: Buffers
58 The "buffer list" is a list of all live buffers. Creating a buffer
59 adds it to this list, and killing a buffer deletes it. The order of
60 the buffers in the list is based primarily on how recently each buffer
61 has been displayed in the selected window. Buffers move to the front
62 of the list when they are selected and to the end when they are buried.
63 Several functions, notably `other-buffer', use this ordering. A
64 buffer list displayed for the user also follows this order.
66 Every frame has its own order for the buffer list. Switching to a
67 new buffer inside of a particular frame changes the buffer list order
68 for that frame, but does not affect the buffer list order of any other
69 frames. In addition, there is a global, non-frame buffer list order
70 that is independent of the buffer list orders for any particular frame.
72 Note that the different buffer lists all contain the same elements.
73 It is only the order of those elements that is different.
75 - Function: buffer-list &optional FRAME
76 This function returns a list of all buffers, including those whose
77 names begin with a space. The elements are actual buffers, not
78 their names. The order of the list is specific to FRAME, which
79 defaults to the current frame. If FRAME is `t', the global,
80 non-frame ordering is returned instead.
83 => (#<buffer buffers.texi>
84 #<buffer *Minibuf-1*> #<buffer buffer.c>
85 #<buffer *Help*> #<buffer TAGS>)
87 ;; Note that the name of the minibuffer
88 ;; begins with a space!
89 (mapcar (function buffer-name) (buffer-list))
90 => ("buffers.texi" " *Minibuf-1*"
91 "buffer.c" "*Help*" "TAGS")
93 Buffers appear earlier in the list if they were current more
96 This list is a copy of a list used inside XEmacs; modifying it has
97 no effect on the buffers.
99 - Function: other-buffer &optional BUFFER-OR-NAME FRAME VISIBLE-OK
100 This function returns the first buffer in the buffer list other
101 than BUFFER-OR-NAME, in FRAME's ordering for the buffer list.
102 (FRAME defaults to the current frame. If FRAME is `t', then the
103 global, non-frame ordering is used.) Usually this is the buffer
104 most recently shown in the selected window, aside from
105 BUFFER-OR-NAME. Buffers are moved to the front of the list when
106 they are selected and to the end when they are buried. Buffers
107 whose names start with a space are not considered.
109 If BUFFER-OR-NAME is not supplied (or if it is not a buffer), then
110 `other-buffer' returns the first buffer on the buffer list that is
111 not visible in any window in a visible frame.
113 If the selected frame has a non-`nil' `buffer-predicate' property,
114 then `other-buffer' uses that predicate to decide which buffers to
115 consider. It calls the predicate once for each buffer, and if the
116 value is `nil', that buffer is ignored. *Note X Frame
119 If VISIBLE-OK is `nil', `other-buffer' avoids returning a buffer
120 visible in any window on any visible frame, except as a last
121 resort. If VISIBLE-OK is non-`nil', then it does not matter
122 whether a buffer is displayed somewhere or not.
124 If no suitable buffer exists, the buffer `*scratch*' is returned
125 (and created, if necessary).
127 Note that in FSF Emacs 19, there is no FRAME argument, and
128 VISIBLE-OK is the second argument instead of the third. FSF Emacs
131 - Command: list-buffers &optional FILES-ONLY
132 This function displays a listing of the names of existing buffers.
133 It clears the buffer `*Buffer List*', then inserts the listing
134 into that buffer and displays it in a window. `list-buffers' is
135 intended for interactive use, and is described fully in `The XEmacs
136 Reference Manual'. It returns `nil'.
138 - Command: bury-buffer &optional BUFFER-OR-NAME
139 This function puts BUFFER-OR-NAME at the end of the buffer list
140 without changing the order of any of the other buffers on the list.
141 This buffer therefore becomes the least desirable candidate for
142 `other-buffer' to return.
144 If BUFFER-OR-NAME is `nil' or omitted, this means to bury the
145 current buffer. In addition, if the buffer is displayed in the
146 selected window, this switches to some other buffer (obtained using
147 `other-buffer') in the selected window. But if the buffer is
148 displayed in some other window, it remains displayed there.
150 If you wish to replace a buffer in all the windows that display
151 it, use `replace-buffer-in-windows'. *Note Buffers and Windows::.
154 File: lispref.info, Node: Creating Buffers, Next: Killing Buffers, Prev: The Buffer List, Up: Buffers
159 This section describes the two primitives for creating buffers.
160 `get-buffer-create' creates a buffer if it finds no existing buffer
161 with the specified name; `generate-new-buffer' always creates a new
162 buffer and gives it a unique name.
164 Other functions you can use to create buffers include
165 `with-output-to-temp-buffer' (*note Temporary Displays::.) and
166 `create-file-buffer' (*note Visiting Files::.). Starting a subprocess
167 can also create a buffer (*note Processes::.).
169 - Function: get-buffer-create NAME
170 This function returns a buffer named NAME. It returns an existing
171 buffer with that name, if one exists; otherwise, it creates a new
172 buffer. The buffer does not become the current buffer--this
173 function does not change which buffer is current.
175 An error is signaled if NAME is not a string.
177 (get-buffer-create "foo")
180 The major mode for the new buffer is set to Fundamental mode. The
181 variable `default-major-mode' is handled at a higher level. *Note
184 - Function: generate-new-buffer NAME
185 This function returns a newly created, empty buffer, but does not
186 make it current. If there is no buffer named NAME, then that is
187 the name of the new buffer. If that name is in use, this function
188 adds suffixes of the form `<N>' to NAME, where N is an integer.
189 It tries successive integers starting with 2 until it finds an
192 An error is signaled if NAME is not a string.
194 (generate-new-buffer "bar")
196 (generate-new-buffer "bar")
198 (generate-new-buffer "bar")
201 The major mode for the new buffer is set to Fundamental mode. The
202 variable `default-major-mode' is handled at a higher level. *Note
205 See the related function `generate-new-buffer-name' in *Note
209 File: lispref.info, Node: Killing Buffers, Next: Indirect Buffers, Prev: Creating Buffers, Up: Buffers
214 "Killing a buffer" makes its name unknown to XEmacs and makes its
215 text space available for other use.
217 The buffer object for the buffer that has been killed remains in
218 existence as long as anything refers to it, but it is specially marked
219 so that you cannot make it current or display it. Killed buffers retain
220 their identity, however; two distinct buffers, when killed, remain
221 distinct according to `eq'.
223 If you kill a buffer that is current or displayed in a window, XEmacs
224 automatically selects or displays some other buffer instead. This means
225 that killing a buffer can in general change the current buffer.
226 Therefore, when you kill a buffer, you should also take the precautions
227 associated with changing the current buffer (unless you happen to know
228 that the buffer being killed isn't current). *Note Current Buffer::.
230 If you kill a buffer that is the base buffer of one or more indirect
231 buffers, the indirect buffers are automatically killed as well.
233 The `buffer-name' of a killed buffer is `nil'. To test whether a
234 buffer has been killed, you can either use this feature or the function
237 - Function: buffer-live-p BUFFER
238 This function returns `nil' if BUFFER is deleted, and `t'
241 - Command: kill-buffer BUFFER-OR-NAME
242 This function kills the buffer BUFFER-OR-NAME, freeing all its
243 memory for use as space for other buffers. (Emacs version 18 and
244 older was unable to return the memory to the operating system.)
247 Any processes that have this buffer as the `process-buffer' are
248 sent the `SIGHUP' signal, which normally causes them to terminate.
249 (The basic meaning of `SIGHUP' is that a dialup line has been
250 disconnected.) *Note Deleting Processes::.
252 If the buffer is visiting a file and contains unsaved changes,
253 `kill-buffer' asks the user to confirm before the buffer is killed.
254 It does this even if not called interactively. To prevent the
255 request for confirmation, clear the modified flag before calling
256 `kill-buffer'. *Note Buffer Modification::.
258 Killing a buffer that is already dead has no effect.
260 (kill-buffer "foo.unchanged")
262 (kill-buffer "foo.changed")
264 ---------- Buffer: Minibuffer ----------
265 Buffer foo.changed modified; kill anyway? (yes or no) yes
266 ---------- Buffer: Minibuffer ----------
270 - Variable: kill-buffer-query-functions
271 After confirming unsaved changes, `kill-buffer' calls the functions
272 in the list `kill-buffer-query-functions', in order of appearance,
273 with no arguments. The buffer being killed is the current buffer
274 when they are called. The idea is that these functions ask for
275 confirmation from the user for various nonstandard reasons. If
276 any of them returns `nil', `kill-buffer' spares the buffer's life.
278 - Variable: kill-buffer-hook
279 This is a normal hook run by `kill-buffer' after asking all the
280 questions it is going to ask, just before actually killing the
281 buffer. The buffer to be killed is current when the hook
282 functions run. *Note Hooks::.
284 - Variable: buffer-offer-save
285 This variable, if non-`nil' in a particular buffer, tells
286 `save-buffers-kill-emacs' and `save-some-buffers' to offer to save
287 that buffer, just as they offer to save file-visiting buffers. The
288 variable `buffer-offer-save' automatically becomes buffer-local
289 when set for any reason. *Note Buffer-Local Variables::.
292 File: lispref.info, Node: Indirect Buffers, Prev: Killing Buffers, Up: Buffers
297 An "indirect buffer" shares the text of some other buffer, which is
298 called the "base buffer" of the indirect buffer. In some ways it is
299 the analogue, for buffers, of a symbolic link among files. The base
300 buffer may not itself be an indirect buffer. One base buffer may have
301 several "indirect children".
303 The text of the indirect buffer is always identical to the text of
304 its base buffer; changes made by editing either one are visible
305 immediately in the other.
307 But in all other respects, the indirect buffer and its base buffer
308 are completely separate. They have different names, different values of
309 point and mark, different narrowing, different markers and extents
310 (though inserting or deleting text in either buffer relocates the
311 markers and extents for both), different major modes, and different
312 local variables. Unlike in FSF Emacs, XEmacs indirect buffers do not
313 automatically share text properties among themselves and their base
316 An indirect buffer cannot visit a file, but its base buffer can. If
317 you try to save the indirect buffer, that actually works by saving the
320 Killing an indirect buffer has no effect on its base buffer. Killing
321 the base buffer kills all its indirect children.
323 - Command: make-indirect-buffer BASE-BUFFER NAME
324 This creates an indirect buffer named NAME whose base buffer is
325 BASE-BUFFER. The argument BASE-BUFFER may be a buffer or a string.
327 If BASE-BUFFER is an indirect buffer, its base buffer is used as
328 the base for the new buffer.
330 (make-indirect-buffer "*scratch*" "indirect")
331 => #<buffer "indirect">
333 - Function: buffer-base-buffer &optional BUFFER
334 This function returns the base buffer of BUFFER. If BUFFER is not
335 indirect, the value is `nil'. Otherwise, the value is another
336 buffer, which is never an indirect buffer. If BUFFER is not
337 supplied, it defaults to the current buffer.
339 (buffer-base-buffer (get-buffer "indirect"))
340 => #<buffer "*scratch*">
342 - Function: buffer-indirect-children &optional BUFFER
343 This function returns a list of all indirect buffers whose base
344 buffer is BUFFER. If BUFFER is indirect, the return value will
345 always be nil; see `make-indirect-buffer'. If BUFFER is not
346 supplied, it defaults to the current buffer.
348 (buffer-indirect-children (get-buffer "*scratch*"))
349 => (#<buffer "indirect">)
352 File: lispref.info, Node: Windows, Next: Frames, Prev: Buffers, Up: Top
357 This chapter describes most of the functions and variables related to
358 Emacs windows. See *Note Display::, for information on how text is
359 displayed in windows.
363 * Basic Windows:: Basic information on using windows.
364 * Splitting Windows:: Splitting one window into two windows.
365 * Deleting Windows:: Deleting a window gives its space to other windows.
366 * Selecting Windows:: The selected window is the one that you edit in.
367 * Cyclic Window Ordering:: Moving around the existing windows.
368 * Buffers and Windows:: Each window displays the contents of a buffer.
369 * Displaying Buffers:: Higher-lever functions for displaying a buffer
370 and choosing a window for it.
371 * Choosing Window:: How to choose a window for displaying a buffer.
372 * Window Point:: Each window has its own location of point.
373 * Window Start:: The display-start position controls which text
374 is on-screen in the window.
375 * Vertical Scrolling:: Moving text up and down in the window.
376 * Horizontal Scrolling:: Moving text sideways on the window.
377 * Size of Window:: Accessing the size of a window.
378 * Position of Window:: Accessing the position of a window.
379 * Resizing Windows:: Changing the size of a window.
380 * Window Configurations:: Saving and restoring the state of the screen.
383 File: lispref.info, Node: Basic Windows, Next: Splitting Windows, Up: Windows
385 Basic Concepts of Emacs Windows
386 ===============================
388 A "window" in XEmacs is the physical area of the screen in which a
389 buffer is displayed. The term is also used to refer to a Lisp object
390 that represents that screen area in XEmacs Lisp. It should be clear
391 from the context which is meant.
393 XEmacs groups windows into frames. A frame represents an area of
394 screen available for XEmacs to use. Each frame always contains at least
395 one window, but you can subdivide it vertically or horizontally into
396 multiple nonoverlapping Emacs windows.
398 In each frame, at any time, one and only one window is designated as
399 "selected within the frame". The frame's cursor appears in that
400 window. At ant time, one frame is the selected frame; and the window
401 selected within that frame is "the selected window". The selected
402 window's buffer is usually the current buffer (except when `set-buffer'
403 has been used). *Note Current Buffer::.
405 For practical purposes, a window exists only while it is displayed in
406 a frame. Once removed from the frame, the window is effectively deleted
407 and should not be used, *even though there may still be references to
408 it* from other Lisp objects. Restoring a saved window configuration is
409 the only way for a window no longer on the screen to come back to life.
410 (*Note Deleting Windows::.)
412 Each window has the following attributes:
420 * window edges with respect to the frame or screen
422 * the buffer it displays
424 * position within the buffer at the upper left of the window
426 * amount of horizontal scrolling, in columns
432 * how recently the window was selected
434 Users create multiple windows so they can look at several buffers at
435 once. Lisp libraries use multiple windows for a variety of reasons, but
436 most often to display related information. In Rmail, for example, you
437 can move through a summary buffer in one window while the other window
438 shows messages one at a time as they are reached.
440 The meaning of "window" in XEmacs is similar to what it means in the
441 context of general-purpose window systems such as X, but not identical.
442 The X Window System places X windows on the screen; XEmacs uses one or
443 more X windows as frames, and subdivides them into Emacs windows. When
444 you use XEmacs on a character-only terminal, XEmacs treats the whole
445 terminal screen as one frame.
447 Most window systems support arbitrarily located overlapping windows.
448 In contrast, Emacs windows are "tiled"; they never overlap, and
449 together they fill the whole screen or frame. Because of the way in
450 which XEmacs creates new windows and resizes them, you can't create
451 every conceivable tiling of windows on an Emacs frame. *Note Splitting
452 Windows::, and *Note Size of Window::.
454 *Note Display::, for information on how the contents of the window's
455 buffer are displayed in the window.
457 - Function: windowp OBJECT
458 This function returns `t' if OBJECT is a window.
461 File: lispref.info, Node: Splitting Windows, Next: Deleting Windows, Prev: Basic Windows, Up: Windows
466 The functions described here are the primitives used to split a
467 window into two windows. Two higher level functions sometimes split a
468 window, but not always: `pop-to-buffer' and `display-buffer' (*note
469 Displaying Buffers::.).
471 The functions described here do not accept a buffer as an argument.
472 The two "halves" of the split window initially display the same buffer
473 previously visible in the window that was split.
475 - Function: one-window-p &optional NO-MINI ALL-FRAMES
476 This function returns non-`nil' if there is only one window. The
477 argument NO-MINI, if non-`nil', means don't count the minibuffer
478 even if it is active; otherwise, the minibuffer window is
479 included, if active, in the total number of windows which is
480 compared against one.
482 The argument ALL-FRAME controls which set of windows are counted.
483 * If it is `nil' or omitted, then count only the selected
484 frame, plus the minibuffer it uses (which may be on another
487 * If it is `t', then windows on all frames that currently exist
488 (including invisible and iconified frames) are counted.
490 * If it is the symbol `visible', then windows on all visible
493 * If it is the number 0, then windows on all visible and
494 iconified frames are counted.
496 * If it is any other value, then precisely the windows in
497 WINDOW's frame are counted, excluding the minibuffer in use
498 if it lies in some other frame.
500 - Command: split-window &optional WINDOW SIZE HORIZONTAL
501 This function splits WINDOW into two windows. The original window
502 WINDOW remains the selected window, but occupies only part of its
503 former screen area. The rest is occupied by a newly created
504 window which is returned as the value of this function.
506 If HORIZONTAL is non-`nil', then WINDOW splits into two side by
507 side windows. The original window WINDOW keeps the leftmost SIZE
508 columns, and gives the rest of the columns to the new window.
509 Otherwise, it splits into windows one above the other, and WINDOW
510 keeps the upper SIZE lines and gives the rest of the lines to the
511 new window. The original window is therefore the left-hand or
512 upper of the two, and the new window is the right-hand or lower.
514 If WINDOW is omitted or `nil', then the selected window is split.
515 If SIZE is omitted or `nil', then WINDOW is divided evenly into
516 two parts. (If there is an odd line, it is allocated to the new
517 window.) When `split-window' is called interactively, all its
520 The following example starts with one window on a frame that is 50
521 lines high by 80 columns wide; then the window is split.
523 (setq w (selected-window))
524 => #<window 8 on windows.texi>
525 (window-edges) ; Edges in order:
526 => (0 0 80 50) ; left-top-right-bottom
528 ;; Returns window created
529 (setq w2 (split-window w 15))
530 => #<window 28 on windows.texi>
533 => (0 15 80 50) ; Bottom window;
537 => (0 0 80 15) ; Top window
539 The frame looks like this:
551 Next, the top window is split horizontally:
553 (setq w3 (split-window w 35 t))
554 => #<window 32 on windows.texi>
557 => (35 0 80 15) ; Left edge at column 35
560 => (0 0 35 15) ; Right edge at column 35
563 => (0 15 80 50) ; Bottom window unchanged
565 Now, the screen looks like this:
578 Normally, Emacs indicates the border between two side-by-side
579 windows with a scroll bar (*note Scroll Bars: X Frame Properties.)
580 or `|' characters. The display table can specify alternative
581 border characters; see *Note Display Tables::.
583 - Command: split-window-vertically &optional SIZE
584 This function splits the selected window into two windows, one
585 above the other, leaving the selected window with SIZE lines.
587 This function is simply an interface to `split-windows'. Here is
588 the complete function definition for it:
590 (defun split-window-vertically (&optional arg)
591 "Split current window into two windows, one above the other."
593 (split-window nil (and arg (prefix-numeric-value arg))))
595 - Command: split-window-horizontally &optional SIZE
596 This function splits the selected window into two windows
597 side-by-side, leaving the selected window with SIZE columns.
599 This function is simply an interface to `split-windows'. Here is
600 the complete definition for `split-window-horizontally' (except for
601 part of the documentation string):
603 (defun split-window-horizontally (&optional arg)
604 "Split selected window into two windows, side by side..."
606 (split-window nil (and arg (prefix-numeric-value arg)) t))
608 - Function: one-window-p &optional NO-MINI ALL-FRAMES
609 This function returns non-`nil' if there is only one window. The
610 argument NO-MINI, if non-`nil', means don't count the minibuffer
611 even if it is active; otherwise, the minibuffer window is
612 included, if active, in the total number of windows, which is
613 compared against one.
615 The argument ALL-FRAMES specifies which frames to consider. Here
616 are the possible values and their meanings:
619 Count the windows in the selected frame, plus the minibuffer
620 used by that frame even if it lies in some other frame.
623 Count all windows in all existing frames.
626 Count all windows in all visible frames.
629 Count all windows in all visible or iconified frames.
632 Count precisely the windows in the selected frame, and no
636 File: lispref.info, Node: Deleting Windows, Next: Selecting Windows, Prev: Splitting Windows, Up: Windows
641 A window remains visible on its frame unless you "delete" it by
642 calling certain functions that delete windows. A deleted window cannot
643 appear on the screen, but continues to exist as a Lisp object until
644 there are no references to it. There is no way to cancel the deletion
645 of a window aside from restoring a saved window configuration (*note
646 Window Configurations::.). Restoring a window configuration also
647 deletes any windows that aren't part of that configuration.
649 When you delete a window, the space it took up is given to one
650 adjacent sibling. (In Emacs version 18, the space was divided evenly
651 among all the siblings.)
653 - Function: window-live-p WINDOW
654 This function returns `nil' if WINDOW is deleted, and `t'
657 *Warning:* Erroneous information or fatal errors may result from
658 using a deleted window as if it were live.
660 - Command: delete-window &optional WINDOW
661 This function removes WINDOW from the display. If WINDOW is
662 omitted, then the selected window is deleted. An error is signaled
663 if there is only one window when `delete-window' is called.
665 This function returns `nil'.
667 When `delete-window' is called interactively, WINDOW defaults to
670 - Command: delete-other-windows &optional WINDOW
671 This function makes WINDOW the only window on its frame, by
672 deleting the other windows in that frame. If WINDOW is omitted or
673 `nil', then the selected window is used by default.
677 - Command: delete-windows-on BUFFER &optional FRAME
678 This function deletes all windows showing BUFFER. If there are no
679 windows showing BUFFER, it does nothing.
681 `delete-windows-on' operates frame by frame. If a frame has
682 several windows showing different buffers, then those showing
683 BUFFER are removed, and the others expand to fill the space. If
684 all windows in some frame are showing BUFFER (including the case
685 where there is only one window), then the frame reverts to having a
686 single window showing another buffer chosen with `other-buffer'.
687 *Note The Buffer List::.
689 The argument FRAME controls which frames to operate on:
691 * If it is `nil', operate on the selected frame.
693 * If it is `t', operate on all frames.
695 * If it is `visible', operate on all visible frames.
697 * 0 If it is 0, operate on all visible or iconified frames.
699 * If it is a frame, operate on that frame.
701 This function always returns `nil'.
704 File: lispref.info, Node: Selecting Windows, Next: Cyclic Window Ordering, Prev: Deleting Windows, Up: Windows
709 When a window is selected, the buffer in the window becomes the
710 current buffer, and the cursor will appear in it.
712 - Function: selected-window &optional DEVICE
713 This function returns the selected window. This is the window in
714 which the cursor appears and to which many commands apply. Each
715 separate device can have its own selected window, which is
716 remembered as focus changes from device to device. Optional
717 argument DEVICE specifies which device to return the selected
718 window for, and defaults to the selected device.
720 - Function: select-window WINDOW &optional NORECORD
721 This function makes WINDOW the selected window. The cursor then
722 appears in WINDOW (on redisplay). The buffer being displayed in
723 WINDOW is immediately designated the current buffer.
725 If optional argument NORECORD is non-`nil' then the global and
726 per-frame buffer orderings are not modified, as by the function
729 The return value is WINDOW.
731 (setq w (next-window))
733 => #<window 65 on windows.texi>
735 - Macro: save-selected-window FORMS...
736 This macro records the selected window, executes FORMS in
737 sequence, then restores the earlier selected window. It does not
738 save or restore anything about the sizes, arrangement or contents
739 of windows; therefore, if the FORMS change them, the changes are
742 The following functions choose one of the windows on the screen,
743 offering various criteria for the choice.
745 - Function: get-lru-window &optional FRAME
746 This function returns the window least recently "used" (that is,
747 selected). The selected window is always the most recently used
750 The selected window can be the least recently used window if it is
751 the only window. A newly created window becomes the least
752 recently used window until it is selected. A minibuffer window is
755 The argument FRAME controls which windows are considered.
757 * If it is `nil', consider windows on the selected frame.
759 * If it is `t', consider windows on all frames.
761 * If it is `visible', consider windows on all visible frames.
763 * If it is 0, consider windows on all visible or iconified
766 * If it is a frame, consider windows on that frame.
768 - Function: get-largest-window &optional FRAME
769 This function returns the window with the largest area (height
770 times width). If there are no side-by-side windows, then this is
771 the window with the most lines. A minibuffer window is never a
774 If there are two windows of the same size, then the function
775 returns the window that is first in the cyclic ordering of windows
776 (see following section), starting from the selected window.
778 The argument FRAME controls which set of windows are considered.
779 See `get-lru-window', above.
782 File: lispref.info, Node: Cyclic Window Ordering, Next: Buffers and Windows, Prev: Selecting Windows, Up: Windows
784 Cyclic Ordering of Windows
785 ==========================
787 When you use the command `C-x o' (`other-window') to select the next
788 window, it moves through all the windows on the screen in a specific
789 cyclic order. For any given configuration of windows, this order never
790 varies. It is called the "cyclic ordering of windows".
792 This ordering generally goes from top to bottom, and from left to
793 right. But it may go down first or go right first, depending on the
794 order in which the windows were split.
796 If the first split was vertical (into windows one above each other),
797 and then the subwindows were split horizontally, then the ordering is
798 left to right in the top of the frame, and then left to right in the
799 next lower part of the frame, and so on. If the first split was
800 horizontal, the ordering is top to bottom in the left part, and so on.
801 In general, within each set of siblings at any level in the window tree,
802 the order is left to right, or top to bottom.
804 - Function: next-window &optional WINDOW MINIBUF ALL-FRAMES
805 This function returns the window following WINDOW in the cyclic
806 ordering of windows. This is the window that `C-x o' would select
807 if typed when WINDOW is selected. If WINDOW is the only window
808 visible, then this function returns WINDOW. If omitted, WINDOW
809 defaults to the selected window.
811 The value of the argument MINIBUF determines whether the
812 minibuffer is included in the window order. Normally, when
813 MINIBUF is `nil', the minibuffer is included if it is currently
814 active; this is the behavior of `C-x o'. (The minibuffer window
815 is active while the minibuffer is in use. *Note Minibuffers::.)
817 If MINIBUF is `t', then the cyclic ordering includes the
818 minibuffer window even if it is not active.
820 If MINIBUF is neither `t' nor `nil', then the minibuffer window is
821 not included even if it is active.
823 The argument ALL-FRAMES specifies which frames to consider. Here
824 are the possible values and their meanings:
827 Consider all the windows in WINDOW's frame, plus the
828 minibuffer used by that frame even if it lies in some other
832 Consider all windows in all existing frames.
835 Consider all windows in all visible frames. (To get useful
836 results, you must ensure WINDOW is in a visible frame.)
839 Consider all windows in all visible or iconified frames.
842 Consider precisely the windows in WINDOW's frame, and no
845 This example assumes there are two windows, both displaying the
846 buffer `windows.texi':
849 => #<window 56 on windows.texi>
850 (next-window (selected-window))
851 => #<window 52 on windows.texi>
852 (next-window (next-window (selected-window)))
853 => #<window 56 on windows.texi>
855 - Function: previous-window &optional WINDOW MINIBUF ALL-FRAMES
856 This function returns the window preceding WINDOW in the cyclic
857 ordering of windows. The other arguments specify which windows to
858 include in the cycle, as in `next-window'.
860 - Command: other-window COUNT &optional FRAME
861 This function selects the COUNTth following window in the cyclic
862 order. If count is negative, then it selects the -COUNTth
863 preceding window. It returns `nil'.
865 In an interactive call, COUNT is the numeric prefix argument.
867 The argument FRAME controls which set of windows are considered.
868 * If it is `nil' or omitted, then windows on the selected frame
871 * If it is a frame, then windows on that frame are considered.
873 * If it is `t', then windows on all frames that currently exist
874 (including invisible and iconified frames) are considered.
876 * If it is the symbol `visible', then windows on all visible
877 frames are considered.
879 * If it is the number 0, then windows on all visible and
880 iconified frames are considered.
882 * If it is any other value, then the behavior is undefined.
884 - Function: walk-windows PROC &optional MINIBUF ALL-FRAMES
885 This function cycles through all windows, calling `proc' once for
886 each window with the window as its sole argument.
888 The optional arguments MINIBUF and ALL-FRAMES specify the set of
889 windows to include in the scan. See `next-window', above, for
893 File: lispref.info, Node: Buffers and Windows, Next: Displaying Buffers, Prev: Cyclic Window Ordering, Up: Windows
898 This section describes low-level functions to examine windows or to
899 display buffers in windows in a precisely controlled fashion. *Note
900 Displaying Buffers::, for related functions that find a window to use
901 and specify a buffer for it. The functions described there are easier
902 to use than these, but they employ heuristics in choosing or creating a
903 window; use these functions when you need complete control.
905 - Function: set-window-buffer WINDOW BUFFER-OR-NAME
906 This function makes WINDOW display BUFFER-OR-NAME as its contents.
909 (set-window-buffer (selected-window) "foo")
912 - Function: window-buffer &optional WINDOW
913 This function returns the buffer that WINDOW is displaying. If
914 WINDOW is omitted, this function returns the buffer for the
918 => #<buffer windows.texi>
920 - Function: get-buffer-window BUFFER-OR-NAME &optional FRAME
921 This function returns a window currently displaying
922 BUFFER-OR-NAME, or `nil' if there is none. If there are several
923 such windows, then the function returns the first one in the
924 cyclic ordering of windows, starting from the selected window.
925 *Note Cyclic Window Ordering::.
927 The argument ALL-FRAMES controls which windows to consider.
929 * If it is `nil', consider windows on the selected frame.
931 * If it is `t', consider windows on all frames.
933 * If it is `visible', consider windows on all visible frames.
935 * If it is 0, consider windows on all visible or iconified
938 * If it is a frame, consider windows on that frame.
941 File: lispref.info, Node: Displaying Buffers, Next: Choosing Window, Prev: Buffers and Windows, Up: Windows
943 Displaying Buffers in Windows
944 =============================
946 In this section we describe convenient functions that choose a window
947 automatically and use it to display a specified buffer. These functions
948 can also split an existing window in certain circumstances. We also
949 describe variables that parameterize the heuristics used for choosing a
950 window. *Note Buffers and Windows::, for low-level functions that give
951 you more precise control.
953 Do not use the functions in this section in order to make a buffer
954 current so that a Lisp program can access or modify it; they are too
955 drastic for that purpose, since they change the display of buffers in
956 windows, which is gratuitous and will surprise the user. Instead, use
957 `set-buffer' (*note Current Buffer::.) and `save-excursion' (*note
958 Excursions::.), which designate buffers as current for programmed
959 access without affecting the display of buffers in windows.
961 - Command: switch-to-buffer BUFFER-OR-NAME &optional NORECORD
962 This function makes BUFFER-OR-NAME the current buffer, and also
963 displays the buffer in the selected window. This means that a
964 human can see the buffer and subsequent keyboard commands will
965 apply to it. Contrast this with `set-buffer', which makes
966 BUFFER-OR-NAME the current buffer but does not display it in the
967 selected window. *Note Current Buffer::.
969 If BUFFER-OR-NAME does not identify an existing buffer, then a new
970 buffer by that name is created. The major mode for the new buffer
971 is set according to the variable `default-major-mode'. *Note Auto
974 Normally the specified buffer is put at the front of the buffer
975 list. This affects the operation of `other-buffer'. However, if
976 NORECORD is non-`nil', this is not done. *Note The Buffer List::.
978 The `switch-to-buffer' function is often used interactively, as
979 the binding of `C-x b'. It is also used frequently in programs.
980 It always returns `nil'.
982 - Command: switch-to-buffer-other-window BUFFER-OR-NAME
983 This function makes BUFFER-OR-NAME the current buffer and displays
984 it in a window not currently selected. It then selects that
985 window. The handling of the buffer is the same as in
988 The currently selected window is absolutely never used to do the
989 job. If it is the only window, then it is split to make a
990 distinct window for this purpose. If the selected window is
991 already displaying the buffer, then it continues to do so, but
992 another window is nonetheless found to display it in as well.
994 - Function: pop-to-buffer BUFFER-OR-NAME &optional OTHER-WINDOW
996 This function makes BUFFER-OR-NAME the current buffer and switches
997 to it in some window, preferably not the window previously
998 selected. The "popped-to" window becomes the selected window
1001 If the variable `pop-up-frames' is non-`nil', `pop-to-buffer'
1002 looks for a window in any visible frame already displaying the
1003 buffer; if there is one, it returns that window and makes it be
1004 selected within its frame. If there is none, it creates a new
1005 frame and displays the buffer in it.
1007 If `pop-up-frames' is `nil', then `pop-to-buffer' operates
1008 entirely within the selected frame. (If the selected frame has
1009 just a minibuffer, `pop-to-buffer' operates within the most
1010 recently selected frame that was not just a minibuffer.)
1012 If the variable `pop-up-windows' is non-`nil', windows may be
1013 split to create a new window that is different from the original
1014 window. For details, see *Note Choosing Window::.
1016 If OTHER-WINDOW is non-`nil', `pop-to-buffer' finds or creates
1017 another window even if BUFFER-OR-NAME is already visible in the
1018 selected window. Thus BUFFER-OR-NAME could end up displayed in
1019 two windows. On the other hand, if BUFFER-OR-NAME is already
1020 displayed in the selected window and OTHER-WINDOW is `nil', then
1021 the selected window is considered sufficient display for
1022 BUFFER-OR-NAME, so that nothing needs to be done.
1024 All the variables that affect `display-buffer' affect
1025 `pop-to-buffer' as well. *Note Choosing Window::.
1027 If BUFFER-OR-NAME is a string that does not name an existing
1028 buffer, a buffer by that name is created. The major mode for the
1029 new buffer is set according to the variable `default-major-mode'.
1030 *Note Auto Major Mode::.
1032 If ON-FRAME is non-`nil', it is the frame to pop to this buffer on.
1034 An example use of this function is found at the end of *Note
1037 - Command: replace-buffer-in-windows BUFFER
1038 This function replaces BUFFER with some other buffer in all
1039 windows displaying it. The other buffer used is chosen with
1040 `other-buffer'. In the usual applications of this function, you
1041 don't care which other buffer is used; you just want to make sure
1042 that BUFFER is no longer displayed.
1044 This function returns `nil'.
1047 File: lispref.info, Node: Choosing Window, Next: Window Point, Prev: Displaying Buffers, Up: Windows
1049 Choosing a Window for Display
1050 =============================
1052 This section describes the basic facility that chooses a window to
1053 display a buffer in--`display-buffer'. All the higher-level functions
1054 and commands use this subroutine. Here we describe how to use
1055 `display-buffer' and how to customize it.
1057 - Command: display-buffer BUFFER-OR-NAME &optional NOT-THIS-WINDOW
1058 This command makes BUFFER-OR-NAME appear in some window, like
1059 `pop-to-buffer', but it does not select that window and does not
1060 make the buffer current. The identity of the selected window is
1061 unaltered by this function.
1063 If NOT-THIS-WINDOW is non-`nil', it means to display the specified
1064 buffer in a window other than the selected one, even if it is
1065 already on display in the selected window. This can cause the
1066 buffer to appear in two windows at once. Otherwise, if
1067 BUFFER-OR-NAME is already being displayed in any window, that is
1068 good enough, so this function does nothing.
1070 `display-buffer' returns the window chosen to display
1073 Precisely how `display-buffer' finds or creates a window depends on
1074 the variables described below.
1076 A window can be marked as "dedicated" to a particular buffer. Then
1077 XEmacs will not automatically change which buffer appears in the
1078 window, such as `display-buffer' might normally do.
1080 - Function: window-dedicated-p WINDOW
1081 This function returns WINDOW's dedicated object, usually `t' or
1084 - Function: set-window-buffer-dedicated WINDOW BUFFER
1085 This function makes WINDOW display BUFFER and be dedicated to that
1086 buffer. Then XEmacs will not automatically change which buffer
1087 appears in WINDOW. If BUFFER is `nil', this function makes WINDOW
1088 not be dedicated (but doesn't change which buffer appears in it
1091 - User Option: pop-up-windows
1092 This variable controls whether `display-buffer' makes new windows.
1093 If it is non-`nil' and there is only one window, then that window
1094 is split. If it is `nil', then `display-buffer' does not split
1095 the single window, but uses it whole.
1097 - User Option: split-height-threshold
1098 This variable determines when `display-buffer' may split a window,
1099 if there are multiple windows. `display-buffer' always splits the
1100 largest window if it has at least this many lines. If the largest
1101 window is not this tall, it is split only if it is the sole window
1102 and `pop-up-windows' is non-`nil'.
1104 - User Option: pop-up-frames
1105 This variable controls whether `display-buffer' makes new frames.
1106 If it is non-`nil', `display-buffer' looks for an existing window
1107 already displaying the desired buffer, on any visible frame. If
1108 it finds one, it returns that window. Otherwise it makes a new
1109 frame. The variables `pop-up-windows' and
1110 `split-height-threshold' do not matter if `pop-up-frames' is
1113 If `pop-up-frames' is `nil', then `display-buffer' either splits a
1114 window or reuses one.
1116 *Note Frames::, for more information.
1118 - Variable: pop-up-frame-function
1119 This variable specifies how to make a new frame if `pop-up-frames'
1122 Its value should be a function of no arguments. When
1123 `display-buffer' makes a new frame, it does so by calling that
1124 function, which should return a frame. The default value of the
1125 variable is a function that creates a frame using properties from
1126 `pop-up-frame-plist'.
1128 - Variable: pop-up-frame-plist
1129 This variable holds a plist specifying frame properties used when
1130 `display-buffer' makes a new frame. *Note Frame Properties::, for
1131 more information about frame properties.
1133 - Variable: special-display-buffer-names
1134 A list of buffer names for buffers that should be displayed
1135 specially. If the buffer's name is in this list, `display-buffer'
1136 handles the buffer specially.
1138 By default, special display means to give the buffer a dedicated
1141 If an element is a list, instead of a string, then the CAR of the
1142 list is the buffer name, and the rest of the list says how to
1143 create the frame. There are two possibilities for the rest of the
1144 list. It can be a plist, specifying frame properties, or it can
1145 contain a function and arguments to give to it. (The function's
1146 first argument is always the buffer to be displayed; the arguments
1147 from the list come after that.)
1149 - Variable: special-display-regexps
1150 A list of regular expressions that specify buffers that should be
1151 displayed specially. If the buffer's name matches any of the
1152 regular expressions in this list, `display-buffer' handles the
1155 By default, special display means to give the buffer a dedicated
1158 If an element is a list, instead of a string, then the CAR of the
1159 list is the regular expression, and the rest of the list says how
1160 to create the frame. See above, under
1161 `special-display-buffer-names'.
1163 - Variable: special-display-function
1164 This variable holds the function to call to display a buffer
1165 specially. It receives the buffer as an argument, and should
1166 return the window in which it is displayed.
1168 The default value of this variable is
1169 `special-display-popup-frame'.
1171 - Function: special-display-popup-frame BUFFER
1172 This function makes BUFFER visible in a frame of its own. If
1173 BUFFER is already displayed in a window in some frame, it makes
1174 the frame visible and raises it, to use that window. Otherwise, it
1175 creates a frame that will be dedicated to BUFFER.
1177 This function uses an existing window displaying BUFFER whether or
1178 not it is in a frame of its own; but if you set up the above
1179 variables in your init file, before BUFFER was created, then
1180 presumably the window was previously made by this function.
1182 - User Option: special-display-frame-plist
1183 This variable holds frame properties for
1184 `special-display-popup-frame' to use when it creates a frame.
1186 - Variable: same-window-buffer-names
1187 A list of buffer names for buffers that should be displayed in the
1188 selected window. If the buffer's name is in this list,
1189 `display-buffer' handles the buffer by switching to it in the
1192 - Variable: same-window-regexps
1193 A list of regular expressions that specify buffers that should be
1194 displayed in the selected window. If the buffer's name matches
1195 any of the regular expressions in this list, `display-buffer'
1196 handles the buffer by switching to it in the selected window.
1198 - Variable: display-buffer-function
1199 This variable is the most flexible way to customize the behavior of
1200 `display-buffer'. If it is non-`nil', it should be a function
1201 that `display-buffer' calls to do the work. The function should
1202 accept two arguments, the same two arguments that `display-buffer'
1203 received. It should choose or create a window, display the
1204 specified buffer, and then return the window.
1206 This hook takes precedence over all the other options and hooks
1209 A window can be marked as "dedicated" to its buffer. Then
1210 `display-buffer' does not try to use that window.
1212 - Function: window-dedicated-p WINDOW
1213 This function returns `t' if WINDOW is marked as dedicated;
1216 - Function: set-window-dedicated-p WINDOW FLAG
1217 This function marks WINDOW as dedicated if FLAG is non-`nil', and
1218 nondedicated otherwise.