1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
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: Current Buffer, Next: Buffer Names, Prev: Buffer Basics, Up: Buffers
58 There are, in general, many buffers in an Emacs session. At any
59 time, one of them is designated as the "current buffer". This is the
60 buffer in which most editing takes place, because most of the primitives
61 for examining or changing text in a buffer operate implicitly on the
62 current buffer (*note Text::). Normally the buffer that is displayed on
63 the screen in the selected window is the current buffer, but this is not
64 always so: a Lisp program can designate any buffer as current
65 temporarily in order to operate on its contents, without changing what
66 is displayed on the screen.
68 The way to designate a current buffer in a Lisp program is by calling
69 `set-buffer'. The specified buffer remains current until a new one is
72 When an editing command returns to the editor command loop, the
73 command loop designates the buffer displayed in the selected window as
74 current, to prevent confusion: the buffer that the cursor is in when
75 Emacs reads a command is the buffer that the command will apply to.
76 (*Note Command Loop::.) Therefore, `set-buffer' is not the way to
77 switch visibly to a different buffer so that the user can edit it. For
78 this, you must use the functions described in *Note Displaying
81 However, Lisp functions that change to a different current buffer
82 should not depend on the command loop to set it back afterwards.
83 Editing commands written in XEmacs Lisp can be called from other
84 programs as well as from the command loop. It is convenient for the
85 caller if the subroutine does not change which buffer is current
86 (unless, of course, that is the subroutine's purpose). Therefore, you
87 should normally use `set-buffer' within a `save-excursion' that will
88 restore the current buffer when your function is done (*note
89 Excursions::). Here is an example, the code for the command
90 `append-to-buffer' (with the documentation string abridged):
92 (defun append-to-buffer (buffer start end)
93 "Append to specified buffer the text of the region.
95 (interactive "BAppend to buffer: \nr")
96 (let ((oldbuf (current-buffer)))
98 (set-buffer (get-buffer-create buffer))
99 (insert-buffer-substring oldbuf start end))))
101 This function binds a local variable to the current buffer, and then
102 `save-excursion' records the values of point, the mark, and the
103 original buffer. Next, `set-buffer' makes another buffer current.
104 Finally, `insert-buffer-substring' copies the string from the original
105 current buffer to the new current buffer.
107 If the buffer appended to happens to be displayed in some window,
108 the next redisplay will show how its text has changed. Otherwise, you
109 will not see the change immediately on the screen. The buffer becomes
110 current temporarily during the execution of the command, but this does
111 not cause it to be displayed.
113 If you make local bindings (with `let' or function arguments) for a
114 variable that may also have buffer-local bindings, make sure that the
115 same buffer is current at the beginning and at the end of the local
116 binding's scope. Otherwise you might bind it in one buffer and unbind
117 it in another! There are two ways to do this. In simple cases, you may
118 see that nothing ever changes the current buffer within the scope of the
119 binding. Otherwise, use `save-excursion' to make sure that the buffer
120 current at the beginning is current again whenever the variable is
123 It is not reliable to change the current buffer back with
124 `set-buffer', because that won't do the job if a quit happens while the
125 wrong buffer is current. Here is what _not_ to do:
127 (let (buffer-read-only
128 (obuf (current-buffer)))
133 Using `save-excursion', as shown below, handles quitting, errors, and
134 `throw', as well as ordinary evaluation.
136 (let (buffer-read-only)
141 - Function: current-buffer
142 This function returns the current buffer.
145 => #<buffer buffers.texi>
147 - Function: set-buffer buffer-or-name
148 This function makes BUFFER-OR-NAME the current buffer. It does
149 not display the buffer in the currently selected window or in any
150 other window, so the user cannot necessarily see the buffer. But
151 Lisp programs can in any case work on it.
153 This function returns the buffer identified by BUFFER-OR-NAME. An
154 error is signaled if BUFFER-OR-NAME does not identify an existing
158 File: lispref.info, Node: Buffer Names, Next: Buffer File Name, Prev: Current Buffer, Up: Buffers
163 Each buffer has a unique name, which is a string. Many of the
164 functions that work on buffers accept either a buffer or a buffer name
165 as an argument. Any argument called BUFFER-OR-NAME is of this sort,
166 and an error is signaled if it is neither a string nor a buffer. Any
167 argument called BUFFER must be an actual buffer object, not a name.
169 Buffers that are ephemeral and generally uninteresting to the user
170 have names starting with a space, so that the `list-buffers' and
171 `buffer-menu' commands don't mention them. A name starting with space
172 also initially disables recording undo information; see *Note Undo::.
174 - Function: buffer-name &optional buffer
175 This function returns the name of BUFFER as a string. If BUFFER
176 is not supplied, it defaults to the current buffer.
178 If `buffer-name' returns `nil', it means that BUFFER has been
179 killed. *Note Killing Buffers::.
184 (setq foo (get-buffer "temp"))
193 - Command: rename-buffer newname &optional unique
194 This function renames the current buffer to NEWNAME. An error is
195 signaled if NEWNAME is not a string, or if there is already a
196 buffer with that name. The function returns `nil'.
198 Ordinarily, `rename-buffer' signals an error if NEWNAME is already
199 in use. However, if UNIQUE is non-`nil', it modifies NEWNAME to
200 make a name that is not in use. Interactively, you can make
201 UNIQUE non-`nil' with a numeric prefix argument.
203 One application of this command is to rename the `*shell*' buffer
204 to some other name, thus making it possible to create a second
205 shell buffer under the name `*shell*'.
207 - Function: get-buffer buffer-or-name
208 This function returns the buffer specified by BUFFER-OR-NAME. If
209 BUFFER-OR-NAME is a string and there is no buffer with that name,
210 the value is `nil'. If BUFFER-OR-NAME is a buffer, it is returned
211 as given. (That is not very useful, so the argument is usually a
214 (setq b (get-buffer "lewis"))
218 (get-buffer "Frazzle-nots")
221 See also the function `get-buffer-create' in *Note Creating
224 - Function: generate-new-buffer-name starting-name &optional ignore
225 This function returns a name that would be unique for a new
226 buffer--but does not create the buffer. It starts with
227 STARTING-NAME, and produces a name not currently in use for any
228 buffer by appending a number inside of `<...>'.
230 If IGNORE is given, it specifies a name that is okay to use (if it
231 is in the sequence to be tried), even if a buffer with that name
234 See the related function `generate-new-buffer' in *Note Creating
238 File: lispref.info, Node: Buffer File Name, Next: Buffer Modification, Prev: Buffer Names, Up: Buffers
243 The "buffer file name" is the name of the file that is visited in
244 that buffer. When a buffer is not visiting a file, its buffer file name
245 is `nil'. Most of the time, the buffer name is the same as the
246 nondirectory part of the buffer file name, but the buffer file name and
247 the buffer name are distinct and can be set independently. *Note
250 - Function: buffer-file-name &optional buffer
251 This function returns the absolute file name of the file that
252 BUFFER is visiting. If BUFFER is not visiting any file,
253 `buffer-file-name' returns `nil'. If BUFFER is not supplied, it
254 defaults to the current buffer.
256 (buffer-file-name (other-buffer))
257 => "/usr/user/lewis/manual/files.texi"
259 - Variable: buffer-file-name
260 This buffer-local variable contains the name of the file being
261 visited in the current buffer, or `nil' if it is not visiting a
262 file. It is a permanent local, unaffected by
263 `kill-local-variables'.
266 => "/usr/user/lewis/manual/buffers.texi"
268 It is risky to change this variable's value without doing various
269 other things. See the definition of `set-visited-file-name' in
270 `files.el'; some of the things done there, such as changing the
271 buffer name, are not strictly necessary, but others are essential
272 to avoid confusing XEmacs.
274 - Variable: buffer-file-truename
275 This buffer-local variable holds the truename of the file visited
276 in the current buffer, or `nil' if no file is visited. It is a
277 permanent local, unaffected by `kill-local-variables'. *Note
280 - Variable: buffer-file-number
281 This buffer-local variable holds the file number and directory
282 device number of the file visited in the current buffer, or `nil'
283 if no file or a nonexistent file is visited. It is a permanent
284 local, unaffected by `kill-local-variables'. *Note Truenames::.
286 The value is normally a list of the form `(FILENUM DEVNUM)'. This
287 pair of numbers uniquely identifies the file among all files
288 accessible on the system. See the function `file-attributes', in
289 *Note File Attributes::, for more information about them.
291 - Function: get-file-buffer filename
292 This function returns the buffer visiting file FILENAME. If there
293 is no such buffer, it returns `nil'. The argument FILENAME, which
294 must be a string, is expanded (*note File Name Expansion::), then
295 compared against the visited file names of all live buffers.
297 (get-file-buffer "buffers.texi")
298 => #<buffer buffers.texi>
300 In unusual circumstances, there can be more than one buffer
301 visiting the same file name. In such cases, this function returns
302 the first such buffer in the buffer list.
304 - Command: set-visited-file-name filename
305 If FILENAME is a non-empty string, this function changes the name
306 of the file visited in current buffer to FILENAME. (If the buffer
307 had no visited file, this gives it one.) The _next time_ the
308 buffer is saved it will go in the newly-specified file. This
309 command marks the buffer as modified, since it does not (as far as
310 XEmacs knows) match the contents of FILENAME, even if it matched
311 the former visited file.
313 If FILENAME is `nil' or the empty string, that stands for "no
314 visited file". In this case, `set-visited-file-name' marks the
315 buffer as having no visited file.
317 When the function `set-visited-file-name' is called interactively,
318 it prompts for FILENAME in the minibuffer.
320 See also `clear-visited-file-modtime' and
321 `verify-visited-file-modtime' in *Note Buffer Modification::.
323 - Variable: list-buffers-directory
324 This buffer-local variable records a string to display in a buffer
325 listing in place of the visited file name, for buffers that don't
326 have a visited file name. Dired buffers use this variable.
329 File: lispref.info, Node: Buffer Modification, Next: Modification Time, Prev: Buffer File Name, Up: Buffers
334 XEmacs keeps a flag called the "modified flag" for each buffer, to
335 record whether you have changed the text of the buffer. This flag is
336 set to `t' whenever you alter the contents of the buffer, and cleared
337 to `nil' when you save it. Thus, the flag shows whether there are
338 unsaved changes. The flag value is normally shown in the modeline
339 (*note Modeline Variables::), and controls saving (*note Saving
340 Buffers::) and auto-saving (*note Auto-Saving::).
342 Some Lisp programs set the flag explicitly. For example, the
343 function `set-visited-file-name' sets the flag to `t', because the text
344 does not match the newly-visited file, even if it is unchanged from the
345 file formerly visited.
347 The functions that modify the contents of buffers are described in
350 - Function: buffer-modified-p &optional buffer
351 This function returns `t' if the buffer BUFFER has been modified
352 since it was last read in from a file or saved, or `nil'
353 otherwise. If BUFFER is not supplied, the current buffer is
356 - Function: set-buffer-modified-p flag
357 This function marks the current buffer as modified if FLAG is
358 non-`nil', or as unmodified if the flag is `nil'.
360 Another effect of calling this function is to cause unconditional
361 redisplay of the modeline for the current buffer. In fact, the
362 function `redraw-modeline' works by doing this:
364 (set-buffer-modified-p (buffer-modified-p))
366 - Command: not-modified &optional arg
367 This command marks the current buffer as unmodified, and not
368 needing to be saved. (If ARG is non-`nil', the buffer is instead
369 marked as modified.) Don't use this function in programs, since it
370 prints a message in the echo area; use `set-buffer-modified-p'
373 - Function: buffer-modified-tick &optional buffer
374 This function returns BUFFER`s modification-count. This is a
375 counter that increments every time the buffer is modified. If
376 BUFFER is `nil' (or omitted), the current buffer is used.
379 File: lispref.info, Node: Modification Time, Next: Read Only Buffers, Prev: Buffer Modification, Up: Buffers
381 Comparison of Modification Time
382 ===============================
384 Suppose that you visit a file and make changes in its buffer, and
385 meanwhile the file itself is changed on disk. At this point, saving the
386 buffer would overwrite the changes in the file. Occasionally this may
387 be what you want, but usually it would lose valuable information.
388 XEmacs therefore checks the file's modification time using the functions
389 described below before saving the file.
391 - Function: verify-visited-file-modtime buffer
392 This function compares what BUFFER has recorded for the
393 modification time of its visited file against the actual
394 modification time of the file as recorded by the operating system.
395 The two should be the same unless some other process has written
396 the file since XEmacs visited or saved it.
398 The function returns `t' if the last actual modification time and
399 XEmacs's recorded modification time are the same, `nil' otherwise.
401 - Function: clear-visited-file-modtime
402 This function clears out the record of the last modification time
403 of the file being visited by the current buffer. As a result, the
404 next attempt to save this buffer will not complain of a
405 discrepancy in file modification times.
407 This function is called in `set-visited-file-name' and other
408 exceptional places where the usual test to avoid overwriting a
409 changed file should not be done.
411 - Function: visited-file-modtime
412 This function returns the buffer's recorded last file modification
413 time, as a list of the form `(HIGH . LOW)'. (This is the same
414 format that `file-attributes' uses to return time values; see
415 *Note File Attributes::.)
417 - Function: set-visited-file-modtime &optional time
418 This function updates the buffer's record of the last modification
419 time of the visited file, to the value specified by TIME if TIME
420 is not `nil', and otherwise to the last modification time of the
423 If TIME is not `nil', it should have the form `(HIGH . LOW)' or
424 `(HIGH LOW)', in either case containing two integers, each of
425 which holds 16 bits of the time.
427 This function is useful if the buffer was not read from the file
428 normally, or if the file itself has been changed for some known
431 - Function: ask-user-about-supersession-threat filename
432 This function is used to ask a user how to proceed after an
433 attempt to modify an obsolete buffer visiting file FILENAME. An
434 "obsolete buffer" is an unmodified buffer for which the associated
435 file on disk is newer than the last save-time of the buffer. This
436 means some other program has probably altered the file.
438 Depending on the user's answer, the function may return normally,
439 in which case the modification of the buffer proceeds, or it may
440 signal a `file-supersession' error with data `(FILENAME)', in which
441 case the proposed buffer modification is not allowed.
443 This function is called automatically by XEmacs on the proper
444 occasions. It exists so you can customize XEmacs by redefining it.
445 See the file `userlock.el' for the standard definition.
447 See also the file locking mechanism in *Note File Locks::.
450 File: lispref.info, Node: Read Only Buffers, Next: The Buffer List, Prev: Modification Time, Up: Buffers
455 If a buffer is "read-only", then you cannot change its contents,
456 although you may change your view of the contents by scrolling and
459 Read-only buffers are used in two kinds of situations:
461 * A buffer visiting a write-protected file is normally read-only.
463 Here, the purpose is to show the user that editing the buffer with
464 the aim of saving it in the file may be futile or undesirable.
465 The user who wants to change the buffer text despite this can do
466 so after clearing the read-only flag with `C-x C-q'.
468 * Modes such as Dired and Rmail make buffers read-only when altering
469 the contents with the usual editing commands is probably a mistake.
471 The special commands of these modes bind `buffer-read-only' to
472 `nil' (with `let') or bind `inhibit-read-only' to `t' around the
473 places where they change the text.
475 - Variable: buffer-read-only
476 This buffer-local variable specifies whether the buffer is
477 read-only. The buffer is read-only if this variable is non-`nil'.
479 - Variable: inhibit-read-only
480 If this variable is non-`nil', then read-only buffers and read-only
481 characters may be modified. Read-only characters in a buffer are
482 those that have non-`nil' `read-only' properties (either text
483 properties or extent properties). *Note Extent Properties::, for
484 more information about text properties and extent properties.
486 If `inhibit-read-only' is `t', all `read-only' character
487 properties have no effect. If `inhibit-read-only' is a list, then
488 `read-only' character properties have no effect if they are members
489 of the list (comparison is done with `eq').
491 - Command: toggle-read-only
492 This command changes whether the current buffer is read-only. It
493 is intended for interactive use; don't use it in programs. At any
494 given point in a program, you should know whether you want the
495 read-only flag on or off; so you can set `buffer-read-only'
496 explicitly to the proper value, `t' or `nil'.
498 - Function: barf-if-buffer-read-only
499 This function signals a `buffer-read-only' error if the current
500 buffer is read-only. *Note Interactive Call::, for another way to
501 signal an error if the current buffer is read-only.
504 File: lispref.info, Node: The Buffer List, Next: Creating Buffers, Prev: Read Only Buffers, Up: Buffers
509 The "buffer list" is a list of all live buffers. Creating a buffer
510 adds it to this list, and killing a buffer deletes it. The order of
511 the buffers in the list is based primarily on how recently each buffer
512 has been displayed in the selected window. Buffers move to the front
513 of the list when they are selected and to the end when they are buried.
514 Several functions, notably `other-buffer', use this ordering. A
515 buffer list displayed for the user also follows this order.
517 Every frame has its own order for the buffer list. Switching to a
518 new buffer inside of a particular frame changes the buffer list order
519 for that frame, but does not affect the buffer list order of any other
520 frames. In addition, there is a global, non-frame buffer list order
521 that is independent of the buffer list orders for any particular frame.
523 Note that the different buffer lists all contain the same elements.
524 It is only the order of those elements that is different.
526 - Function: buffer-list &optional frame
527 This function returns a list of all buffers, including those whose
528 names begin with a space. The elements are actual buffers, not
529 their names. The order of the list is specific to FRAME, which
530 defaults to the current frame. If FRAME is `t', the global,
531 non-frame ordering is returned instead.
534 => (#<buffer buffers.texi>
535 #<buffer *Minibuf-1*> #<buffer buffer.c>
536 #<buffer *Help*> #<buffer TAGS>)
538 ;; Note that the name of the minibuffer
539 ;; begins with a space!
540 (mapcar (function buffer-name) (buffer-list))
541 => ("buffers.texi" " *Minibuf-1*"
542 "buffer.c" "*Help*" "TAGS")
544 Buffers appear earlier in the list if they were current more
547 This list is a copy of a list used inside XEmacs; modifying it has
548 no effect on the buffers.
550 - Function: other-buffer &optional buffer-or-name frame visible-ok
551 This function returns the first buffer in the buffer list other
552 than BUFFER-OR-NAME, in FRAME's ordering for the buffer list.
553 (FRAME defaults to the current frame. If FRAME is `t', then the
554 global, non-frame ordering is used.) Usually this is the buffer
555 most recently shown in the selected window, aside from
556 BUFFER-OR-NAME. Buffers are moved to the front of the list when
557 they are selected and to the end when they are buried. Buffers
558 whose names start with a space are not considered.
560 If BUFFER-OR-NAME is not supplied (or if it is not a buffer), then
561 `other-buffer' returns the first buffer on the buffer list that is
562 not visible in any window in a visible frame.
564 If the selected frame has a non-`nil' `buffer-predicate' property,
565 then `other-buffer' uses that predicate to decide which buffers to
566 consider. It calls the predicate once for each buffer, and if the
567 value is `nil', that buffer is ignored. *Note X Frame
570 If VISIBLE-OK is `nil', `other-buffer' avoids returning a buffer
571 visible in any window on any visible frame, except as a last
572 resort. If VISIBLE-OK is non-`nil', then it does not matter
573 whether a buffer is displayed somewhere or not.
575 If no suitable buffer exists, the buffer `*scratch*' is returned
576 (and created, if necessary).
578 Note that in FSF Emacs 19, there is no FRAME argument, and
579 VISIBLE-OK is the second argument instead of the third. FSF Emacs
582 - Command: list-buffers &optional files-only
583 This function displays a listing of the names of existing buffers.
584 It clears the buffer `*Buffer List*', then inserts the listing
585 into that buffer and displays it in a window. `list-buffers' is
586 intended for interactive use, and is described fully in `The XEmacs
587 Reference Manual'. It returns `nil'.
589 - Command: bury-buffer &optional buffer-or-name
590 This function puts BUFFER-OR-NAME at the end of the buffer list
591 without changing the order of any of the other buffers on the list.
592 This buffer therefore becomes the least desirable candidate for
593 `other-buffer' to return.
595 If BUFFER-OR-NAME is `nil' or omitted, this means to bury the
596 current buffer. In addition, if the buffer is displayed in the
597 selected window, this switches to some other buffer (obtained using
598 `other-buffer') in the selected window. But if the buffer is
599 displayed in some other window, it remains displayed there.
601 If you wish to replace a buffer in all the windows that display
602 it, use `replace-buffer-in-windows'. *Note Buffers and Windows::.
605 File: lispref.info, Node: Creating Buffers, Next: Killing Buffers, Prev: The Buffer List, Up: Buffers
610 This section describes the two primitives for creating buffers.
611 `get-buffer-create' creates a buffer if it finds no existing buffer
612 with the specified name; `generate-new-buffer' always creates a new
613 buffer and gives it a unique name.
615 Other functions you can use to create buffers include
616 `with-output-to-temp-buffer' (*note Temporary Displays::) and
617 `create-file-buffer' (*note Visiting Files::). Starting a subprocess
618 can also create a buffer (*note Processes::).
620 - Function: get-buffer-create name
621 This function returns a buffer named NAME. It returns an existing
622 buffer with that name, if one exists; otherwise, it creates a new
623 buffer. The buffer does not become the current buffer--this
624 function does not change which buffer is current.
626 An error is signaled if NAME is not a string.
628 (get-buffer-create "foo")
631 The major mode for the new buffer is set to Fundamental mode. The
632 variable `default-major-mode' is handled at a higher level. *Note
635 - Function: generate-new-buffer name
636 This function returns a newly created, empty buffer, but does not
637 make it current. If there is no buffer named NAME, then that is
638 the name of the new buffer. If that name is in use, this function
639 adds suffixes of the form `<N>' to NAME, where N is an integer.
640 It tries successive integers starting with 2 until it finds an
643 An error is signaled if NAME is not a string.
645 (generate-new-buffer "bar")
647 (generate-new-buffer "bar")
649 (generate-new-buffer "bar")
652 The major mode for the new buffer is set to Fundamental mode. The
653 variable `default-major-mode' is handled at a higher level. *Note
656 See the related function `generate-new-buffer-name' in *Note
660 File: lispref.info, Node: Killing Buffers, Next: Indirect Buffers, Prev: Creating Buffers, Up: Buffers
665 "Killing a buffer" makes its name unknown to XEmacs and makes its
666 text space available for other use.
668 The buffer object for the buffer that has been killed remains in
669 existence as long as anything refers to it, but it is specially marked
670 so that you cannot make it current or display it. Killed buffers retain
671 their identity, however; two distinct buffers, when killed, remain
672 distinct according to `eq'.
674 If you kill a buffer that is current or displayed in a window, XEmacs
675 automatically selects or displays some other buffer instead. This means
676 that killing a buffer can in general change the current buffer.
677 Therefore, when you kill a buffer, you should also take the precautions
678 associated with changing the current buffer (unless you happen to know
679 that the buffer being killed isn't current). *Note Current Buffer::.
681 If you kill a buffer that is the base buffer of one or more indirect
682 buffers, the indirect buffers are automatically killed as well.
684 The `buffer-name' of a killed buffer is `nil'. To test whether a
685 buffer has been killed, you can either use this feature or the function
688 - Function: buffer-live-p buffer
689 This function returns `nil' if BUFFER is deleted, and `t'
692 - Command: kill-buffer buffer-or-name
693 This function kills the buffer BUFFER-OR-NAME, freeing all its
694 memory for use as space for other buffers. (Emacs version 18 and
695 older was unable to return the memory to the operating system.)
698 Any processes that have this buffer as the `process-buffer' are
699 sent the `SIGHUP' signal, which normally causes them to terminate.
700 (The basic meaning of `SIGHUP' is that a dialup line has been
701 disconnected.) *Note Deleting Processes::.
703 If the buffer is visiting a file and contains unsaved changes,
704 `kill-buffer' asks the user to confirm before the buffer is killed.
705 It does this even if not called interactively. To prevent the
706 request for confirmation, clear the modified flag before calling
707 `kill-buffer'. *Note Buffer Modification::.
709 Killing a buffer that is already dead has no effect.
711 (kill-buffer "foo.unchanged")
713 (kill-buffer "foo.changed")
715 ---------- Buffer: Minibuffer ----------
716 Buffer foo.changed modified; kill anyway? (yes or no) yes
717 ---------- Buffer: Minibuffer ----------
721 - Variable: kill-buffer-query-functions
722 After confirming unsaved changes, `kill-buffer' calls the functions
723 in the list `kill-buffer-query-functions', in order of appearance,
724 with no arguments. The buffer being killed is the current buffer
725 when they are called. The idea is that these functions ask for
726 confirmation from the user for various nonstandard reasons. If
727 any of them returns `nil', `kill-buffer' spares the buffer's life.
729 - Variable: kill-buffer-hook
730 This is a normal hook run by `kill-buffer' after asking all the
731 questions it is going to ask, just before actually killing the
732 buffer. The buffer to be killed is current when the hook
733 functions run. *Note Hooks::.
735 - Variable: buffer-offer-save
736 This variable, if non-`nil' in a particular buffer, tells
737 `save-buffers-kill-emacs' and `save-some-buffers' to offer to save
738 that buffer, just as they offer to save file-visiting buffers. The
739 variable `buffer-offer-save' automatically becomes buffer-local
740 when set for any reason. *Note Buffer-Local Variables::.
743 File: lispref.info, Node: Indirect Buffers, Prev: Killing Buffers, Up: Buffers
748 An "indirect buffer" shares the text of some other buffer, which is
749 called the "base buffer" of the indirect buffer. In some ways it is
750 the analogue, for buffers, of a symbolic link among files. The base
751 buffer may not itself be an indirect buffer. One base buffer may have
752 several "indirect children".
754 The text of the indirect buffer is always identical to the text of
755 its base buffer; changes made by editing either one are visible
756 immediately in the other.
758 But in all other respects, the indirect buffer and its base buffer
759 are completely separate. They have different names, different values of
760 point and mark, different narrowing, different markers and extents
761 (though inserting or deleting text in either buffer relocates the
762 markers and extents for both), different major modes, and different
763 local variables. Unlike in FSF Emacs, XEmacs indirect buffers do not
764 automatically share text properties among themselves and their base
767 An indirect buffer cannot visit a file, but its base buffer can. If
768 you try to save the indirect buffer, that actually works by saving the
771 Killing an indirect buffer has no effect on its base buffer. Killing
772 the base buffer kills all its indirect children.
774 - Command: make-indirect-buffer base-buffer name
775 This creates an indirect buffer named NAME whose base buffer is
776 BASE-BUFFER. The argument BASE-BUFFER may be a buffer or a string.
778 If BASE-BUFFER is an indirect buffer, its base buffer is used as
779 the base for the new buffer.
781 (make-indirect-buffer "*scratch*" "indirect")
782 => #<buffer "indirect">
784 - Function: buffer-base-buffer &optional buffer
785 This function returns the base buffer of BUFFER. If BUFFER is not
786 indirect, the value is `nil'. Otherwise, the value is another
787 buffer, which is never an indirect buffer. If BUFFER is not
788 supplied, it defaults to the current buffer.
790 (buffer-base-buffer (get-buffer "indirect"))
791 => #<buffer "*scratch*">
793 - Function: buffer-indirect-children &optional buffer
794 This function returns a list of all indirect buffers whose base
795 buffer is BUFFER. If BUFFER is indirect, the return value will
796 always be nil; see `make-indirect-buffer'. If BUFFER is not
797 supplied, it defaults to the current buffer.
799 (buffer-indirect-children (get-buffer "*scratch*"))
800 => (#<buffer "indirect">)
803 File: lispref.info, Node: Windows, Next: Frames, Prev: Buffers, Up: Top
808 This chapter describes most of the functions and variables related to
809 Emacs windows. See *Note Display::, for information on how text is
810 displayed in windows.
814 * Basic Windows:: Basic information on using windows.
815 * Splitting Windows:: Splitting one window into two windows.
816 * Deleting Windows:: Deleting a window gives its space to other windows.
817 * Selecting Windows:: The selected window is the one that you edit in.
818 * Cyclic Window Ordering:: Moving around the existing windows.
819 * Buffers and Windows:: Each window displays the contents of a buffer.
820 * Displaying Buffers:: Higher-lever functions for displaying a buffer
821 and choosing a window for it.
822 * Choosing Window:: How to choose a window for displaying a buffer.
823 * Window Point:: Each window has its own location of point.
824 * Window Start:: The display-start position controls which text
825 is on-screen in the window.
826 * Vertical Scrolling:: Moving text up and down in the window.
827 * Horizontal Scrolling:: Moving text sideways on the window.
828 * Size of Window:: Accessing the size of a window.
829 * Position of Window:: Accessing the position of a window.
830 * Resizing Windows:: Changing the size of a window.
831 * Window Configurations:: Saving and restoring the state of the screen.
834 File: lispref.info, Node: Basic Windows, Next: Splitting Windows, Up: Windows
836 Basic Concepts of Emacs Windows
837 ===============================
839 A "window" in XEmacs is the physical area of the screen in which a
840 buffer is displayed. The term is also used to refer to a Lisp object
841 that represents that screen area in XEmacs Lisp. It should be clear
842 from the context which is meant.
844 XEmacs groups windows into frames. A frame represents an area of
845 screen available for XEmacs to use. Each frame always contains at least
846 one window, but you can subdivide it vertically or horizontally into
847 multiple nonoverlapping Emacs windows.
849 In each frame, at any time, one and only one window is designated as
850 "selected within the frame". The frame's cursor appears in that
851 window. At ant time, one frame is the selected frame; and the window
852 selected within that frame is "the selected window". The selected
853 window's buffer is usually the current buffer (except when `set-buffer'
854 has been used). *Note Current Buffer::.
856 For practical purposes, a window exists only while it is displayed in
857 a frame. Once removed from the frame, the window is effectively deleted
858 and should not be used, _even though there may still be references to
859 it_ from other Lisp objects. Restoring a saved window configuration is
860 the only way for a window no longer on the screen to come back to life.
861 (*Note Deleting Windows::.)
863 Each window has the following attributes:
871 * window edges with respect to the frame or screen
873 * the buffer it displays
875 * position within the buffer at the upper left of the window
877 * amount of horizontal scrolling, in columns
883 * how recently the window was selected
885 Users create multiple windows so they can look at several buffers at
886 once. Lisp libraries use multiple windows for a variety of reasons, but
887 most often to display related information. In Rmail, for example, you
888 can move through a summary buffer in one window while the other window
889 shows messages one at a time as they are reached.
891 The meaning of "window" in XEmacs is similar to what it means in the
892 context of general-purpose window systems such as X, but not identical.
893 The X Window System places X windows on the screen; XEmacs uses one or
894 more X windows as frames, and subdivides them into Emacs windows. When
895 you use XEmacs on a character-only terminal, XEmacs treats the whole
896 terminal screen as one frame.
898 Most window systems support arbitrarily located overlapping windows.
899 In contrast, Emacs windows are "tiled"; they never overlap, and
900 together they fill the whole screen or frame. Because of the way in
901 which XEmacs creates new windows and resizes them, you can't create
902 every conceivable tiling of windows on an Emacs frame. *Note Splitting
903 Windows::, and *Note Size of Window::.
905 *Note Display::, for information on how the contents of the window's
906 buffer are displayed in the window.
908 - Function: windowp object
909 This function returns `t' if OBJECT is a window.
912 File: lispref.info, Node: Splitting Windows, Next: Deleting Windows, Prev: Basic Windows, Up: Windows
917 The functions described here are the primitives used to split a
918 window into two windows. Two higher level functions sometimes split a
919 window, but not always: `pop-to-buffer' and `display-buffer' (*note
920 Displaying Buffers::).
922 The functions described here do not accept a buffer as an argument.
923 The two "halves" of the split window initially display the same buffer
924 previously visible in the window that was split.
926 - Function: one-window-p &optional no-mini all-frames
927 This function returns non-`nil' if there is only one window. The
928 argument NO-MINI, if non-`nil', means don't count the minibuffer
929 even if it is active; otherwise, the minibuffer window is
930 included, if active, in the total number of windows which is
931 compared against one.
933 The argument ALL-FRAME controls which set of windows are counted.
934 * If it is `nil' or omitted, then count only the selected
935 frame, plus the minibuffer it uses (which may be on another
938 * If it is `t', then windows on all frames that currently exist
939 (including invisible and iconified frames) are counted.
941 * If it is the symbol `visible', then windows on all visible
944 * If it is the number 0, then windows on all visible and
945 iconified frames are counted.
947 * If it is any other value, then precisely the windows in
948 WINDOW's frame are counted, excluding the minibuffer in use
949 if it lies in some other frame.
951 - Command: split-window &optional window size horizontal
952 This function splits WINDOW into two windows. The original window
953 WINDOW remains the selected window, but occupies only part of its
954 former screen area. The rest is occupied by a newly created
955 window which is returned as the value of this function.
957 If HORIZONTAL is non-`nil', then WINDOW splits into two side by
958 side windows. The original window WINDOW keeps the leftmost SIZE
959 columns, and gives the rest of the columns to the new window.
960 Otherwise, it splits into windows one above the other, and WINDOW
961 keeps the upper SIZE lines and gives the rest of the lines to the
962 new window. The original window is therefore the left-hand or
963 upper of the two, and the new window is the right-hand or lower.
965 If WINDOW is omitted or `nil', then the selected window is split.
966 If SIZE is omitted or `nil', then WINDOW is divided evenly into
967 two parts. (If there is an odd line, it is allocated to the new
968 window.) When `split-window' is called interactively, all its
971 The following example starts with one window on a frame that is 50
972 lines high by 80 columns wide; then the window is split.
974 (setq w (selected-window))
975 => #<window 8 on windows.texi>
976 (window-edges) ; Edges in order:
977 => (0 0 80 50) ; left-top-right-bottom
979 ;; Returns window created
980 (setq w2 (split-window w 15))
981 => #<window 28 on windows.texi>
983 => (0 15 80 50) ; Bottom window;
986 => (0 0 80 15) ; Top window
988 The frame looks like this:
1000 Next, the top window is split horizontally:
1002 (setq w3 (split-window w 35 t))
1003 => #<window 32 on windows.texi>
1005 => (35 0 80 15) ; Left edge at column 35
1007 => (0 0 35 15) ; Right edge at column 35
1009 => (0 15 80 50) ; Bottom window unchanged
1011 Now, the screen looks like this:
1024 Normally, Emacs indicates the border between two side-by-side
1025 windows with a scroll bar (*note Scroll Bars: X Frame Properties.)
1026 or `|' characters. The display table can specify alternative
1027 border characters; see *Note Display Tables::.
1029 - Command: split-window-vertically &optional size
1030 This function splits the selected window into two windows, one
1031 above the other, leaving the selected window with SIZE lines.
1033 This function is simply an interface to `split-windows'. Here is
1034 the complete function definition for it:
1036 (defun split-window-vertically (&optional arg)
1037 "Split current window into two windows, one above the other."
1039 (split-window nil (and arg (prefix-numeric-value arg))))
1041 - Command: split-window-horizontally &optional size
1042 This function splits the selected window into two windows
1043 side-by-side, leaving the selected window with SIZE columns.
1045 This function is simply an interface to `split-windows'. Here is
1046 the complete definition for `split-window-horizontally' (except for
1047 part of the documentation string):
1049 (defun split-window-horizontally (&optional arg)
1050 "Split selected window into two windows, side by side..."
1052 (split-window nil (and arg (prefix-numeric-value arg)) t))
1054 - Function: one-window-p &optional no-mini all-frames
1055 This function returns non-`nil' if there is only one window. The
1056 argument NO-MINI, if non-`nil', means don't count the minibuffer
1057 even if it is active; otherwise, the minibuffer window is
1058 included, if active, in the total number of windows, which is
1059 compared against one.
1061 The argument ALL-FRAMES specifies which frames to consider. Here
1062 are the possible values and their meanings:
1065 Count the windows in the selected frame, plus the minibuffer
1066 used by that frame even if it lies in some other frame.
1069 Count all windows in all existing frames.
1072 Count all windows in all visible frames.
1075 Count all windows in all visible or iconified frames.
1078 Count precisely the windows in the selected frame, and no
1082 File: lispref.info, Node: Deleting Windows, Next: Selecting Windows, Prev: Splitting Windows, Up: Windows
1087 A window remains visible on its frame unless you "delete" it by
1088 calling certain functions that delete windows. A deleted window cannot
1089 appear on the screen, but continues to exist as a Lisp object until
1090 there are no references to it. There is no way to cancel the deletion
1091 of a window aside from restoring a saved window configuration (*note
1092 Window Configurations::). Restoring a window configuration also
1093 deletes any windows that aren't part of that configuration.
1095 When you delete a window, the space it took up is given to one
1096 adjacent sibling. (In Emacs version 18, the space was divided evenly
1097 among all the siblings.)
1099 - Function: window-live-p window
1100 This function returns `nil' if WINDOW is deleted, and `t'
1103 *Warning:* Erroneous information or fatal errors may result from
1104 using a deleted window as if it were live.
1106 - Command: delete-window &optional window
1107 This function removes WINDOW from the display. If WINDOW is
1108 omitted, then the selected window is deleted. An error is signaled
1109 if there is only one window when `delete-window' is called.
1111 This function returns `nil'.
1113 When `delete-window' is called interactively, WINDOW defaults to
1114 the selected window.
1116 - Command: delete-other-windows &optional window
1117 This function makes WINDOW the only window on its frame, by
1118 deleting the other windows in that frame. If WINDOW is omitted or
1119 `nil', then the selected window is used by default.
1121 The result is `nil'.
1123 - Command: delete-windows-on buffer &optional frame
1124 This function deletes all windows showing BUFFER. If there are no
1125 windows showing BUFFER, it does nothing.
1127 `delete-windows-on' operates frame by frame. If a frame has
1128 several windows showing different buffers, then those showing
1129 BUFFER are removed, and the others expand to fill the space. If
1130 all windows in some frame are showing BUFFER (including the case
1131 where there is only one window), then the frame reverts to having a
1132 single window showing another buffer chosen with `other-buffer'.
1133 *Note The Buffer List::.
1135 The argument FRAME controls which frames to operate on:
1137 * If it is `nil', operate on the selected frame.
1139 * If it is `t', operate on all frames.
1141 * If it is `visible', operate on all visible frames.
1143 * 0 If it is 0, operate on all visible or iconified frames.
1145 * If it is a frame, operate on that frame.
1147 This function always returns `nil'.