aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-03-29 00:10:31 +0000
committerRichard M. Stallman1994-03-29 00:10:31 +0000
commitb1b12a8ee9455a0512f10ec980f0d79bf6617cd4 (patch)
tree8e566ff9ba62823287a3595e86f7b245705a46d4
parent32eff0b035c0b8857f34ca2dcb0282e5e385765f (diff)
downloademacs-b1b12a8ee9455a0512f10ec980f0d79bf6617cd4.tar.gz
emacs-b1b12a8ee9455a0512f10ec980f0d79bf6617cd4.zip
Initial revision
-rw-r--r--lispref/backups.texi621
-rw-r--r--lispref/buffers.texi828
-rw-r--r--lispref/windows.texi1592
3 files changed, 3041 insertions, 0 deletions
diff --git a/lispref/backups.texi b/lispref/backups.texi
new file mode 100644
index 00000000000..57108105e0b
--- /dev/null
+++ b/lispref/backups.texi
@@ -0,0 +1,621 @@
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
3@c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4@c See the file elisp.texi for copying conditions.
5@setfilename ../info/backups
6@node Backups and Auto-Saving, Buffers, Files, Top
7@chapter Backups and Auto-Saving
8
9 Backup files and auto-save files are two methods by which Emacs tries
10to protect the user from the consequences of crashes or of the user's
11own errors. Auto-saving preserves the text from earlier in the current
12editing session; backup files preserve file contents prior to the
13current session.
14
15@menu
16* Backup Files:: How backup files are made; how their names are chosen.
17* Auto-Saving:: How auto-save files are made; how their names are chosen.
18* Reverting:: @code{revert-buffer}, and how to customize what it does.
19@end menu
20
21@node Backup Files, Auto-Saving, Backups and Auto-Saving, Backups and Auto-Saving
22@section Backup Files
23@cindex backup file
24
25 A @dfn{backup file} is a copy of the old contents of a file you are
26editing. Emacs makes a backup file the first time you save a buffer
27into its visited file. Normally, this means that the backup file
28contains the contents of the file as it was before the current editing
29session. The contents of the backup file normally remain unchanged once
30it exists.
31
32 Backups are usually made by renaming the visited file to a new name.
33Optionally, you can specify that backup files should be made by copying
34the visited file. This choice makes a difference for files with
35multiple names; it also can affect whether the edited file remains owned
36by the original owner or becomes owned by the user editing it.
37
38 By default, Emacs makes a single backup file for each file edited.
39You can alternatively request numbered backups; then each new backup
40file gets a new name. You can delete old numbered backups when you
41don't want them any more, or Emacs can delete them automatically.
42
43@menu
44* Making Backups:: How Emacs makes backup files, and when.
45* Rename or Copy:: Two alternatives: renaming the old file or copying it.
46* Numbered Backups:: Keeping multiple backups for each source file.
47* Backup Names:: How backup file names are computed; customization.
48@end menu
49
50@node Making Backups, Rename or Copy, Backup Files, Backup Files
51@subsection Making Backup Files
52
53@defun backup-buffer
54 This function makes a backup of the file visited by the current
55buffer, if appropriate. It is called by @code{save-buffer} before
56saving the buffer the first time.
57@end defun
58
59@defvar buffer-backed-up
60 This buffer-local variable indicates whether this buffer's file has
61been backed up on account of this buffer. If it is non-@code{nil}, then
62the backup file has been written. Otherwise, the file should be backed
63up when it is next saved (if backup files are enabled). This is a
64permanent local; @code{kill-local-variables} does not alter it.
65@end defvar
66
67@defopt make-backup-files
68 This variable determines whether or not to make backup files. If it
69is non-@code{nil}, then Emacs creates a backup of each file when it is
70saved for the first time.
71
72 The following example shows how to change the @code{make-backup-files}
73variable only in the @file{RMAIL} buffer and not elsewhere. Setting it
74@code{nil} stops Emacs from making backups of the @file{RMAIL} file,
75which may save disk space. (You would put this code in your
76@file{.emacs} file.)
77
78@smallexample
79@group
80(add-hook 'rmail-mode-hook
81 (function (lambda ()
82 (make-local-variable
83 'make-backup-files)
84 (setq make-backup-files nil))))
85@end group
86@end smallexample
87@end defopt
88
89@defvar backup-enable-predicate filename
90This variable's value is a function to be called on certain occasions to
91decide whether a there should be backup files for file name
92@var{filename}. If it returns @code{nil}, backups are disabled.
93Otherwise, the other variables in this section say whether and how to
94make backups.
95
96The default value is this:
97
98@example
99(lambda (name)
100 (or (< (length name) 5)
101 (not (string-equal "/tmp/"
102 (substring name 0 5)))))
103@end example
104@end defvar
105
106@defvar backup-inhibited
107If this variable is non-@code{nil}, backups are inhibited. It records
108the result of testing @code{backup-enable-predicate} on the visited file
109name. It can also coherently be used by other mechanisms that inhibit
110backups based on which file is visited. Major modes should not set this
111variable.
112@end defvar
113
114@node Rename or Copy, Numbered Backups, Making Backups, Backup Files
115@subsection Backup by Renaming or by Copying?
116@cindex backup files, how to make them
117
118 There are two ways that Emacs can make a backup file:
119
120@itemize @bullet
121@item
122Emacs can rename the original file so that it becomes a backup file, and
123then write the buffer being saved into a new file. After this
124procedure, any other names (i.e., hard links) of the original file now
125refer to the backup file. The new file is owned by the user doing the
126editing, and its group is the default for new files written by the user
127in that directory.
128
129@item
130Emacs can copy the original file into a backup file, and then overwrite
131the original file with new contents. After this procedure, any other
132names (i.e., hard links) of the original file still refer to the current
133version of the file. The file's owner and group will be unchanged.
134@end itemize
135
136 The first method, renaming, is the default.
137
138 The variable @code{backup-by-copying}, if non-@code{nil}, says to use
139the second method, which is to copy the original file and overwrite it
140with the new buffer contents. The variable @code{file-precious-flag},
141if non-@code{nil}, also has this effect (as a sideline of its main
142significance). @xref{Saving Buffers}.
143
144@defvar backup-by-copying
145If this variable is non-@code{nil}, Emacs always makes backup files by
146copying.
147@end defvar
148
149 The following two variables, when non-@code{nil}, cause the second
150method to be used in certain special cases. They have no effect on the
151treatment of files that don't fall into the special cases.
152
153@defvar backup-by-copying-when-linked
154If this variable is non-@code{nil}, Emacs makes backups by copying for
155files with multiple names (hard links).
156
157This variable is significant only if @code{backup-by-copying} is
158@code{nil}, since copying is always used when that variable is
159non-@code{nil}.
160@end defvar
161
162@defvar backup-by-copying-when-mismatch
163If this variable is non-@code{nil}, Emacs makes backups by copying in cases
164where renaming would change either the owner or the group of the file.
165
166The value has no effect when renaming would not alter the owner or
167group of the file; that is, for files which are owned by the user and
168whose group matches the default for a new file created there by the
169user.
170
171This variable is significant only if @code{backup-by-copying} is
172@code{nil}, since copying is always used when that variable is
173non-@code{nil}.
174@end defvar
175
176@node Numbered Backups, Backup Names, Rename or Copy, Backup Files
177@subsection Making and Deleting Numbered Backup Files
178
179 If a file's name is @file{foo}, the names of its numbered backup
180versions are @file{foo.~@var{v}~}, for various integers @var{v}, like
181this: @file{foo.~1~}, @file{foo.~2~}, @file{foo.~3~}, @dots{},
182@file{foo.~259~}, and so on.
183
184@defopt version-control
185This variable controls whether to make a single non-numbered backup
186file or multiple numbered backups.
187
188@table @asis
189@item @code{nil}
190Make numbered backups if the visited file already has numbered backups;
191otherwise, do not.
192
193@item @code{never}
194Do not make numbered backups.
195
196@item @var{anything else}
197Do make numbered backups.
198@end table
199@end defopt
200
201 The use of numbered backups ultimately leads to a large number of
202backup versions, which must then be deleted. Emacs can do this
203automatically.
204
205@defopt kept-new-versions
206The value of this variable is the number of oldest versions to keep
207when a new numbered backup is made. The newly made backup is included
208in the count. The default value is 2.
209@end defopt
210
211@defopt kept-old-versions
212The value of this variable is the number of oldest versions to keep
213when a new numbered backup is made. The default value is 2.
214@end defopt
215
216 If there are backups numbered 1, 2, 3, 5, and 7, and both of these
217variables have the value 2, then the backups numbered 1 and 2 are kept
218as old versions and those numbered 5 and 7 are kept as new versions;
219backup version 3 is deleted. The function @code{find-backup-file-name}
220(@pxref{Backup Names}) is responsible for determining which backup
221versions to delete, but does not delete them itself.
222
223@defopt trim-versions-without-asking
224If this variable is non-@code{nil}, then saving a file deletes excess
225backup versions silently. Otherwise, it asks the user whether to delete
226them.
227@end defopt
228
229@defopt dired-kept-versions
230This variable specifies how many of the newest backup versions to keep
231in the Dired command @kbd{.} (@code{dired-clean-directory}). That's the
232same thing @code{kept-new-versions} does when you make a new backup
233file. The default value is 2.
234@end defopt
235
236@node Backup Names, , Numbered Backups, Backup Files
237@subsection Naming Backup Files
238
239 The functions in this section are documented mainly because you can
240customize the naming conventions for backup files by redefining them.
241If you change one, you probably need to change the rest.
242
243@defun backup-file-name-p filename
244This function returns a non-@code{nil} value if @var{filename} is a
245possible name for a backup file. A file with the name @var{filename}
246need not exist; the function just checks the name.
247
248@smallexample
249@group
250(backup-file-name-p "foo")
251 @result{} nil
252@end group
253@group
254(backup-file-name-p "foo~")
255 @result{} 3
256@end group
257@end smallexample
258
259The standard definition of this function is as follows:
260
261@smallexample
262@group
263(defun backup-file-name-p (file)
264 "Return non-nil if FILE is a backup file \
265name (numeric or not)..."
266 (string-match "~$" file))
267@end group
268@end smallexample
269
270@noindent
271Thus, the function returns a non-@code{nil} value if the file name ends
272with a @samp{~}. (We use a backslash to split the documentation
273string's first line into two lines in the text, but produce just one
274line in the string itself.)
275
276This simple expression is placed in a separate function to make it easy
277to redefine for customization.
278@end defun
279
280@defun make-backup-file-name filename
281This function returns a string which is the name to use for a
282non-numbered backup file for file @var{filename}. On Unix, this is just
283@var{filename} with a tilde appended.
284
285The standard definition of this function is as follows:
286
287@smallexample
288@group
289(defun make-backup-file-name (file)
290 "Create the non-numeric backup file name for FILE.
291@dots{}"
292 (concat file "~"))
293@end group
294@end smallexample
295
296You can change the backup file naming convention by redefining this
297function. The following example redefines @code{make-backup-file-name}
298to prepend a @samp{.} as well as appending a tilde:
299
300@smallexample
301@group
302(defun make-backup-file-name (filename)
303 (concat "." filename "~"))
304@end group
305
306@group
307(make-backup-file-name "backups.texi")
308 @result{} ".backups.texi~"
309@end group
310@end smallexample
311@end defun
312
313@defun find-backup-file-name filename
314This function computes the file name for a new backup file for
315@var{filename}. It may also propose certain existing backup files for
316deletion. @code{find-backup-file-name} returns a list whose @sc{car} is
317the name for the new backup file and whose @sc{cdr} is a list of backup
318files whose deletion is proposed.
319
320Two variables, @code{kept-old-versions} and @code{kept-new-versions},
321determine which backup versions should be kept. This function keeps
322those versions by excluding them from the @sc{cdr} of the value.
323@xref{Numbered Backups}.
324
325In this example, the value says that @file{~rms/foo.~5~} is the name
326to use for the new backup file, and @file{~rms/foo.~3~} is an ``excess''
327version that the caller should consider deleting now.
328
329@smallexample
330@group
331(find-backup-file-name "~rms/foo")
332 @result{} ("~rms/foo.~5~" "~rms/foo.~3~")
333@end group
334@end smallexample
335@end defun
336
337@c Emacs 19 feature
338@defun file-newest-backup filename
339This function returns the name of the most recent backup file for
340@var{filename}, or @code{nil} that file has no backup files.
341
342Some file comparison commands use this function in order to compare
343a file by default with its most recent backup.
344@end defun
345
346@node Auto-Saving, Reverting, Backup Files, Backups and Auto-Saving
347@section Auto-Saving
348@cindex auto-saving
349
350 Emacs periodically saves all files that you are visiting; this is
351called @dfn{auto-saving}. Auto-saving prevents you from losing more
352than a limited amount of work if the system crashes. By default,
353auto-saves happen every 300 keystrokes, or after around 30 seconds of
354idle time. @xref{Auto-Save, Auto-Save, Auto-Saving: Protection Against
355Disasters, emacs, The GNU Emacs Manual}, for information on auto-save
356for users. Here we describe the functions used to implement auto-saving
357and the variables that control them.
358
359@defvar buffer-auto-save-file-name
360This buffer-local variable is the name of the file used for
361auto-saving the current buffer. It is @code{nil} if the buffer
362should not be auto-saved.
363
364@example
365@group
366buffer-auto-save-file-name
367=> "/xcssun/users/rms/lewis/#files.texi#"
368@end group
369@end example
370@end defvar
371
372@deffn Command auto-save-mode arg
373When used interactively without an argument, this command is a toggle
374switch: it turns on auto-saving of the current buffer if it is off, and
375vice-versa. With an argument @var{arg}, the command turns auto-saving
376on if the value of @var{arg} is @code{t}, a nonempty list, or a positive
377integer. Otherwise, it turns auto-saving off.
378@end deffn
379
380@defun auto-save-file-name-p filename
381This function returns a non-@code{nil} value if @var{filename} is a
382string that could be the name of an auto-save file. It works based on
383knowledge of the naming convention for auto-save files: a name that
384begins and ends with hash marks (@samp{#}) is a possible auto-save file
385name. The argument @var{filename} should not contain a directory part.
386
387@example
388@group
389(make-auto-save-file-name)
390 @result{} "/xcssun/users/rms/lewis/#files.texi#"
391@end group
392@group
393(auto-save-file-name-p "#files.texi#")
394 @result{} 0
395@end group
396@group
397(auto-save-file-name-p "files.texi")
398 @result{} nil
399@end group
400@end example
401
402The standard definition of this function is as follows:
403
404@example
405@group
406(defun auto-save-file-name-p (filename)
407 "Return non-nil if FILENAME can be yielded by..."
408 (string-match "^#.*#$" filename))
409@end group
410@end example
411
412This function exists so that you can customize it if you wish to
413change the naming convention for auto-save files. If you redefine it,
414be sure to redefine the function @code{make-auto-save-file-name}
415correspondingly.
416@end defun
417
418@defun make-auto-save-file-name
419This function returns the file name to use for auto-saving the current
420buffer. This is just the file name with hash marks (@samp{#}) appended
421and prepended to it. This function does not look at the variable
422@code{auto-save-visited-file-name}; you should check that before calling
423this function.
424
425@example
426@group
427(make-auto-save-file-name)
428 @result{} "/xcssun/users/rms/lewis/#backup.texi#"
429@end group
430@end example
431
432The standard definition of this function is as follows:
433
434@example
435@group
436(defun make-auto-save-file-name ()
437 "Return file name to use for auto-saves \
438of current buffer.
439@dots{}"
440 (if buffer-file-name
441@end group
442@group
443 (concat
444 (file-name-directory buffer-file-name)
445 "#"
446 (file-name-nondirectory buffer-file-name)
447 "#")
448 (expand-file-name
449 (concat "#%" (buffer-name) "#"))))
450@end group
451@end example
452
453This exists as a separate function so that you can redefine it to
454customize the naming convention for auto-save files. Be sure to
455change @code{auto-save-file-name-p} in a corresponding way.
456@end defun
457
458@defvar auto-save-visited-file-name
459If this variable is non-@code{nil}, Emacs auto-saves buffers in
460the files they are visiting. That is, the auto-save is done in the same
461file which you are editing. Normally, this variable is @code{nil}, so
462auto-save files have distinct names that are created by
463@code{make-auto-save-file-name}.
464
465When you change the value of this variable, the value does not take
466effect until the next time auto-save mode is reenabled in any given
467buffer. If auto-save mode is already enabled, auto-saves continue to go
468in the same file name until @code{auto-save-mode} is called again.
469@end defvar
470
471@defun recent-auto-save-p
472This function returns @code{t} if the current buffer has been
473auto-saved since the last time it was read in or saved.
474@end defun
475
476@defun set-buffer-auto-saved
477This function marks the current buffer as auto-saved. The buffer will
478not be auto-saved again until the buffer text is changed again. The
479function returns @code{nil}.
480@end defun
481
482@defopt auto-save-interval
483The value of this variable is the number of characters that Emacs
484reads from the keyboard between auto-saves. Each time this many more
485characters are read, auto-saving is done for all buffers in which it is
486enabled.
487@end defopt
488
489@defopt auto-save-timeout
490The value of this variable is the number of seconds of idle time that
491should cause auto-saving. Each time the user pauses for this long,
492Emacs auto-saves any buffers that need it. (Actually, the specified
493timeout is multiplied by a factor depending on the size of the current
494buffer.)
495@end defopt
496
497@defvar auto-save-hook
498This normal hook is run whenever an auto-save is about to happen.
499@end defvar
500
501@defopt auto-save-default
502If this variable is non-@code{nil}, buffers that are visiting files
503have auto-saving enabled by default. Otherwise, they do not.
504@end defopt
505
506@deffn Command do-auto-save &optional no-message
507This function auto-saves all buffers that need to be auto-saved. It
508saves all buffers for which auto-saving is enabled and that have been
509changed since the previous auto-save.
510
511Normally, if any buffers are auto-saved, a message that says
512@samp{Auto-saving...} is displayed in the echo area while auto-saving is
513going on. However, if @var{no-message} is non-@code{nil}, the message
514is inhibited.
515@end deffn
516
517@defun delete-auto-save-file-if-necessary
518This function deletes the current buffer's auto-save file if
519@code{delete-auto-save-files} is non-@code{nil}. It is called every
520time a buffer is saved.
521@end defun
522
523@defvar delete-auto-save-files
524This variable is used by the function
525@code{delete-auto-save-file-if-necessary}. If it is non-@code{nil},
526Emacs deletes auto-save files when a true save is done (in the visited
527file). This saves disk space and unclutters your directory.
528@end defvar
529
530@defun rename-auto-save-file
531This function adjusts the current buffer's auto-save file name if the
532visited file name has changed. It also renames an existing auto-save
533file. If the visited file name has not changed, this function does
534nothing.
535@end defun
536
537@node Reverting, , Auto-Saving, Backups and Auto-Saving
538@section Reverting
539
540 If you have made extensive changes to a file and then change your mind
541about them, you can get rid of them by reading in the previous version
542of the file with the @code{revert-buffer} command. @xref{Reverting, ,
543Reverting a Buffer, emacs, The GNU Emacs Manual}.
544
545@deffn Command revert-buffer &optional check-auto-save noconfirm
546This command replaces the buffer text with the text of the visited
547file on disk. This action undoes all changes since the file was visited
548or saved.
549
550If the argument @var{check-auto-save} is non-@code{nil}, and the
551latest auto-save file is more recent than the visited file,
552@code{revert-buffer} asks the user whether to use that instead.
553Otherwise, it always uses the text of the visited file itself.
554Interactively, @var{check-auto-save} is set if there is a numeric prefix
555argument.
556
557Normally, @code{revert-buffer} asks for confirmation before it changes
558the buffer; but if the argument @var{noconfirm} is non-@code{nil},
559@code{revert-buffer} does not ask for confirmation.
560
561Reverting tries to preserve marker positions in the buffer by using the
562replacement feature of @code{insert-file-contents}. If there is no
563actual difference between the buffer and the file, before reversion,
564this preserves all the markers. If reversion does change the buffer,
565this preserves the markers in the unchanged text (if any) at the
566beginning and end of the buffer. Preserving any additional markers
567would be problematical.
568
569If the value of the @code{revert-buffer-function} variable is
570non-@code{nil}, it is called as a function with no arguments to do the
571work.
572@end deffn
573
574@defvar revert-buffer-function
575The value of this variable is the function to use to revert this
576buffer; but if the value of this variable is @code{nil}, then the
577@code{revert-buffer} function carries out its default action. Modes
578such as Dired mode, in which the text being edited does not consist of a
579file's contents but can be regenerated in some other fashion, give this
580variable a buffer-local value that is a function to regenerate the
581contents.
582@end defvar
583
584@defvar revert-buffer-insert-file-contents-function
585The value of this variable, if non-@code{nil}, is the function to use
586to insert contents when reverting this buffer. The function receives
587two arguments, first the file name to use, and second, @code{t} if the
588user has asked to read the auto-save file.
589@end defvar
590
591@defvar before-revert-hook
592This normal hook is run by @code{revert-buffer} before actually
593inserting the modified contents---but only if
594@code{revert-buffer-function} is @code{nil}.
595
596Font Lock mode uses this hook to record that the buffer contents are no
597longer fontified.
598@end defvar
599
600@defvar after-revert-hook
601This normal hook is run by @code{revert-buffer} after actually inserting
602the modified contents---but only if @code{revert-buffer-function} is
603@code{nil}.
604
605Font Lock mode uses this hook to recompute the fonts for the updated
606buffer contents.
607@end defvar
608
609@deffn Command recover-file filename
610This function visits @var{filename}, but gets the contents from its
611last auto-save file. This is useful after the system has crashed, to
612resume editing the same file without losing all the work done in the
613previous session.
614
615An error is signaled if there is no auto-save file for @var{filename},
616or if @var{filename} is newer than its auto-save file. If
617@var{filename} does not exist, but its auto-save file does, then the
618auto-save file is read as usual. This last situation may occur if you
619visited a nonexistent file and never actually saved it.
620@end deffn
621
diff --git a/lispref/buffers.texi b/lispref/buffers.texi
new file mode 100644
index 00000000000..6f777d7480c
--- /dev/null
+++ b/lispref/buffers.texi
@@ -0,0 +1,828 @@
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
3@c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4@c See the file elisp.texi for copying conditions.
5@setfilename ../info/buffers
6@node Buffers, Windows, Backups and Auto-Saving, Top
7@chapter Buffers
8@cindex buffer
9
10 A @dfn{buffer} is a Lisp object containing text to be edited. Buffers
11are used to hold the contents of files that are being visited; there may
12also be buffers which are not visiting files. While several buffers may
13exist at one time, exactly one buffer is designated the @dfn{current
14buffer} at any time. Most editing commands act on the contents of the
15current buffer. Each buffer, including the current buffer, may or may
16not be displayed in any windows.
17
18@menu
19* Buffer Basics:: What is a buffer?
20* Buffer Names:: Accessing and changing buffer names.
21* Buffer File Name:: The buffer file name indicates which file is visited.
22* Buffer Modification:: A buffer is @dfn{modified} if it needs to be saved.
23* Modification Time:: Determining whether the visited file was changed
24 ``behind Emacs's back''.
25* Read Only Buffers:: Modifying text is not allowed in a read-only buffer.
26* The Buffer List:: How to look at all the existing buffers.
27* Creating Buffers:: Functions that create buffers.
28* Killing Buffers:: Buffers exist until explicitly killed.
29* Current Buffer:: Designating a buffer as current
30 so primitives will access its contents.
31@end menu
32
33@node Buffer Basics
34@comment node-name, next, previous, up
35@section Buffer Basics
36
37@ifinfo
38 A @dfn{buffer} is a Lisp object containing text to be edited. Buffers
39are used to hold the contents of files that are being visited; there may
40also be buffers which are not visiting files. While several buffers may
41exist at one time, exactly one buffer is designated the @dfn{current
42buffer} at any time. Most editing commands act on the contents of the
43current buffer. Each buffer, including the current buffer, may or may
44not be displayed in any windows.
45@end ifinfo
46
47 Buffers in Emacs editing are objects which have distinct names and
48hold text that can be edited. Buffers appear to Lisp programs as a
49special data type. The contents of a buffer may be viewed as an
50extendable string; insertions and deletions may occur in any part of the
51buffer. @xref{Text}.
52
53 A Lisp buffer object contains numerous pieces of information. Some of
54this information is directly accessible to the programmer through
55variables, while other information is only accessible through
56special-purpose functions. For example, the visited file name is
57directly accessible through a variable, while the value of point is
58accessible only through a primitive function.
59
60 Buffer-specific information that is directly accessible is stored in
61@dfn{buffer-local} variable bindings, which are variable values that are
62effective only in a particular buffer. This feature allows each buffer
63to override the values of certain variables. Most major modes override
64variables such as @code{fill-column} or @code{comment-column} in this
65way. For more information about buffer-local variables and functions
66related to them, see @ref{Buffer-Local Variables}.
67
68 For functions and variables related to visiting files in buffers, see
69@ref{Visiting Files} and @ref{Saving Buffers}. For functions and
70variables related to the display of buffers in windows, see
71@ref{Buffers and Windows}.
72
73@defun bufferp object
74This function returns @code{t} if @var{object} is a buffer,
75@code{nil} otherwise.
76@end defun
77
78@node Buffer Names
79@section Buffer Names
80@cindex buffer names
81
82 Each buffer has a unique name, which is a string. Many of the
83functions that work on buffers accept either a buffer or a buffer name
84as an argument. Any argument called @var{buffer-or-name} is of this
85sort, and an error is signaled if it is neither a string nor a buffer.
86Any argument called @var{buffer} must be an actual buffer
87object, not a name.
88
89 Buffers that are ephemeral and generally uninteresting to the user
90have names starting with a space, so that the @code{list-buffers} or
91@code{buffer-menu} commands don't mention them. A name starting with
92space also initially disables recording undo information; see
93@ref{Undo}.
94
95@defun buffer-name &optional buffer
96This function returns the name of @var{buffer} as a string. If
97@var{buffer} is not supplied, it defaults to the current buffer.
98
99If @code{buffer-name} returns @code{nil}, it means that @var{buffer}
100has been killed. @xref{Killing Buffers}.
101
102@example
103@group
104(buffer-name)
105 @result{} "buffers.texi"
106@end group
107
108@group
109(setq foo (get-buffer "temp"))
110 @result{} #<buffer temp>
111@end group
112@group
113(kill-buffer foo)
114 @result{} nil
115@end group
116@group
117(buffer-name foo)
118 @result{} nil
119@end group
120@group
121foo
122 @result{} #<killed buffer>
123@end group
124@end example
125@end defun
126
127@deffn Command rename-buffer newname &optional unique
128This function renames the current buffer to @var{newname}. An error
129is signaled if @var{newname} is not a string, or if there is already a
130buffer with that name. The function returns @code{nil}.
131
132@c Emacs 19 feature
133Ordinarily, @code{rename-buffer} signals an error if @var{newname} is
134already in use. However, if @var{unique} is non-@code{nil}, it modifies
135@var{newname} to make a name that is not in use. Interactively, you can
136make @var{unique} non-@code{nil} with a numeric prefix argument.
137
138One application of this command is to rename the @samp{*shell*} buffer
139to some other name, thus making it possible to create a second shell
140buffer under the name @samp{*shell*}.
141@end deffn
142
143@defun get-buffer buffer-or-name
144This function returns the buffer specified by @var{buffer-or-name}.
145If @var{buffer-or-name} is a string and there is no buffer with that
146name, the value is @code{nil}. If @var{buffer-or-name} is a buffer, it
147is returned as given. (That is not very useful, so the argument is usually
148a name.) For example:
149
150@example
151@group
152(setq b (get-buffer "lewis"))
153 @result{} #<buffer lewis>
154@end group
155@group
156(get-buffer b)
157 @result{} #<buffer lewis>
158@end group
159@group
160(get-buffer "Frazzle-nots")
161 @result{} nil
162@end group
163@end example
164
165See also the function @code{get-buffer-create} in @ref{Creating Buffers}.
166@end defun
167
168@c Emacs 19 feature
169@defun generate-new-buffer-name starting-name
170This function returns a name that would be unique for a new buffer---but
171does not create the buffer. It starts with @var{starting-name}, and
172produces a name not currently in use for any buffer by appending a
173number inside of @samp{<@dots{}>}.
174
175See the related function @code{generate-new-buffer} in @ref{Creating
176Buffers}.
177@end defun
178
179@node Buffer File Name
180@section Buffer File Name
181@cindex visited file
182@cindex buffer file name
183@cindex file name of buffer
184
185 The @dfn{buffer file name} is the name of the file that is visited in
186that buffer. When a buffer is not visiting a file, its buffer file name
187is @code{nil}. Most of the time, the buffer name is the same as the
188nondirectory part of the buffer file name, but the buffer file name and
189the buffer name are distinct and can be set independently.
190@xref{Visiting Files}.
191
192@defun buffer-file-name &optional buffer
193This function returns the absolute file name of the file that
194@var{buffer} is visiting. If @var{buffer} is not visiting any file,
195@code{buffer-file-name} returns @code{nil}. If @var{buffer} is not
196supplied, it defaults to the current buffer.
197
198@example
199@group
200(buffer-file-name (other-buffer))
201 @result{} "/usr/user/lewis/manual/files.texi"
202@end group
203@end example
204@end defun
205
206@defvar buffer-file-name
207This buffer-local variable contains the name of the file being visited
208in the current buffer, or @code{nil} if it is not visiting a file. It
209is a permanent local, unaffected by @code{kill-local-variables}.
210
211@example
212@group
213buffer-file-name
214 @result{} "/usr/user/lewis/manual/buffers.texi"
215@end group
216@end example
217
218It is risky to change this variable's value without doing various other
219things. See the definition of @code{set-visited-file-name} in
220@file{files.el}; some of the things done there, such as changing the
221buffer name, are not strictly necessary, but others are essential to
222avoid confusing Emacs.
223@end defvar
224
225@defvar buffer-file-truename
226This buffer-local variable holds the truename of the file visited in the
227current buffer, or @code{nil} if no file is visited. It is a permanent
228local, unaffected by @code{kill-local-variables}. @xref{Truenames}.
229@end defvar
230
231@defvar buffer-file-number
232This buffer-local variable holds the file number and directory device
233number of the file visited in the current buffer, or @code{nil} if no
234file or a nonexistent file is visited. It is a permanent local,
235unaffected by @code{kill-local-variables}. @xref{Truenames}.
236
237The value is normally a list of the form @code{(@var{filenum}
238@var{devnum})}. This pair of numbers uniquely identifies the file among
239all files accessible on the system. See the function
240@code{file-attributes}, in @ref{File Attributes}, for more information
241about them.
242@end defvar
243
244@defun get-file-buffer filename
245This function returns the buffer visiting file @var{filename}. If
246there is no such buffer, it returns @code{nil}. The argument
247@var{filename}, which must be a string, is expanded (@pxref{File Name
248Expansion}), then compared against the visited file names of all live
249buffers.
250
251@example
252@group
253(get-file-buffer "buffers.texi")
254 @result{} #<buffer buffers.texi>
255@end group
256@end example
257
258In unusual circumstances, there can be more than one buffer visiting
259the same file name. In such cases, this function returns the first
260such buffer in the buffer list.
261@end defun
262
263@deffn Command set-visited-file-name filename
264If @var{filename} is a non-empty string, this function changes the
265name of the file visited in current buffer to @var{filename}. (If the
266buffer had no visited file, this gives it one.) The @emph{next time}
267the buffer is saved it will go in the newly-specified file. This
268command marks the buffer as modified, since it does not (as far as Emacs
269knows) match the contents of @var{filename}, even if it matched the
270former visited file.
271
272If @var{filename} is @code{nil} or the empty string, that stands for
273``no visited file''. In this case, @code{set-visited-file-name} marks
274the buffer as having no visited file.
275
276@c Wordy to avoid overfull hbox. --rjc 16mar92
277When the function @code{set-visited-file-name} is called interactively, it
278prompts for @var{filename} in the minibuffer.
279
280See also @code{clear-visited-file-modtime} and
281@code{verify-visited-file-modtime} in @ref{Buffer Modification}.
282@end deffn
283
284@defvar list-buffers-directory
285This buffer-local variable records a string to display in a buffer
286listing in place of the visited file name, for buffers that don't have a
287visited file name. Dired buffers use this variable.
288@end defvar
289
290@node Buffer Modification
291@section Buffer Modification
292@cindex buffer modification
293@cindex modification flag (of buffer)
294
295 Emacs keeps a flag called the @dfn{modified flag} for each buffer, to
296record whether you have changed the text of the buffer. This flag is
297set to @code{t} whenever you alter the contents of the buffer, and
298cleared to @code{nil} when you save it. Thus, the flag shows whether
299there are unsaved changes. The flag value is normally shown in the mode
300line (@pxref{Mode Line Variables}), and controls saving (@pxref{Saving
301Buffers}) and auto-saving (@pxref{Auto-Saving}).
302
303 Some Lisp programs set the flag explicitly. For example, the function
304@code{set-visited-file-name} sets the flag to @code{t}, because the text
305does not match the newly-visited file, even if it is unchanged from the
306file formerly visited.
307
308 The functions that modify the contents of buffers are described in
309@ref{Text}.
310
311@defun buffer-modified-p &optional buffer
312This function returns @code{t} if the buffer @var{buffer} has been modified
313since it was last read in from a file or saved, or @code{nil}
314otherwise. If @var{buffer} is not supplied, the current buffer
315is tested.
316@end defun
317
318@defun set-buffer-modified-p flag
319This function marks the current buffer as modified if @var{flag} is
320non-@code{nil}, or as unmodified if the flag is @code{nil}.
321
322Another effect of calling this function is to cause unconditional
323redisplay of the mode line for the current buffer. In fact, the
324function @code{force-mode-line-update} works by doing this:
325
326@example
327@group
328(set-buffer-modified-p (buffer-modified-p))
329@end group
330@end example
331@end defun
332
333@deffn Command not-modified
334This command marks the current buffer as unmodified, and not needing
335to be saved. Don't use this function in programs, since it prints a
336message in the echo area; use @code{set-buffer-modified-p} (above) instead.
337@end deffn
338
339@c Emacs 19 feature
340@defun buffer-modified-tick &optional buffer
341This function returns @var{buffer}`s modification-count. This is a
342counter that increments every time the buffer is modified. If
343@var{buffer} is @code{nil} (or omitted), the current buffer is used.
344@end defun
345
346@node Modification Time
347@comment node-name, next, previous, up
348@section Comparison of Modification Time
349@cindex comparison of modification time
350@cindex modification time, comparison of
351
352 Suppose that you visit a file and make changes in its buffer, and
353meanwhile the file itself is changed on disk. At this point, saving the
354buffer would overwrite the changes in the file. Occasionally this may
355be what you want, but usually it would lose valuable information. Emacs
356therefore checks the file's modification time using the functions
357described below before saving the file.
358
359@defun verify-visited-file-modtime buffer
360This function compares what @var{buffer} has recorded for the
361modification time of its visited file against the actual modification
362time of the file as recorded by the operating system. The two should be
363the same unless some other process has written the file since Emacs
364visited or saved it.
365
366The function returns @code{t} if the last actual modification time and
367Emacs's recorded modification time are the same, @code{nil} otherwise.
368@end defun
369
370@defun clear-visited-file-modtime
371This function clears out the record of the last modification time of
372the file being visited by the current buffer. As a result, the next
373attempt to save this buffer will not complain of a discrepancy in
374file modification times.
375
376This function is called in @code{set-visited-file-name} and other
377exceptional places where the usual test to avoid overwriting a changed
378file should not be done.
379@end defun
380
381@c Emacs 19 feature
382@defun visited-file-modtime
383This function returns the buffer's recorded last file modification time,
384as a list of the form @code{(@var{high} . @var{low})}. (This is the
385same format that @code{file-attributes} uses to return time values; see
386@ref{File Attributes}.)
387@end defun
388
389@c Emacs 19 feature
390@defun set-visited-file-modtime &optional time
391This function updates the buffer's record of the last modification time
392of the visited file, to the value specified by @var{time} if @var{time}
393is not @code{nil}, and otherwise to the last modification time of the
394visited file.
395
396If @var{time} is not @code{nil}, it should have the form
397@code{(@var{high} . @var{low})} or @code{(@var{high} @var{low})}, in
398either case containing two integers, each of which holds 16 bits of the
399time.
400
401This function is useful if the buffer was not read from the file
402normally, or if the file itself has been changed for some known benign
403reason.
404@end defun
405
406@defun ask-user-about-supersession-threat fn
407@cindex obsolete buffer
408This function is used to ask a user how to proceed after an attempt to
409modify an obsolete buffer. An @dfn{obsolete buffer} is an unmodified
410buffer for which the associated file on disk is newer than the last
411save-time of the buffer. This means some other program has probably
412altered the file.
413
414This function is called automatically by Emacs on the proper
415occasions. It exists so you can customize Emacs by redefining it.
416See the file @file{userlock.el} for the standard definition.
417
418@kindex file-supersession
419Depending on the user's answer, the function may return normally, in
420which case the modification of the buffer proceeds, or it may signal a
421@code{file-supersession} error with data @code{(@var{fn})}, in which
422case the proposed buffer modification is not allowed.
423
424See also the file locking mechanism in @ref{File Locks}.
425@end defun
426
427@node Read Only Buffers
428@section Read-Only Buffers
429@cindex read-only buffer
430@cindex buffer, read-only
431
432 If a buffer is @dfn{read-only}, then you cannot change its contents,
433although you may change your view of the contents by scrolling and
434narrowing.
435
436 Read-only buffers are used in two kinds of situations:
437
438@itemize @bullet
439@item
440A buffer visiting a write-protected file is normally read-only.
441
442Here, the purpose is to show the user that editing the buffer with the
443aim of saving it in the file may be futile or undesirable. The user who
444wants to change the buffer text despite this can do so after clearing
445the read-only flag with @kbd{C-M-q}.
446
447@item
448Modes such as Dired and Rmail make buffers read-only when altering the
449contents with the usual editing commands is probably a mistake.
450
451The special commands of these modes bind @code{buffer-read-only} to
452@code{nil} (with @code{let}) or bind @code{inhibit-read-only} to
453@code{t} around the places where they change the text.
454@end itemize
455
456@defvar buffer-read-only
457This buffer-local variable specifies whether the buffer is read-only.
458The buffer is read-only if this variable is non-@code{nil}.
459@end defvar
460
461@defvar inhibit-read-only
462If this variable is non-@code{nil}, then read-only buffers and read-only
463characters may be modified. The value of @code{buffer-read-only} does
464not matter when @code{inhibit-read-only} is non-@code{nil}.
465
466If @code{inhibit-read-only} is @code{t}, all @code{read-only} text
467properties have no effect (@pxref{Special Properties}). If
468@code{inhibit-read-only} is a list, then @code{read-only} text
469properties are ignored if they are members of the list (comparison is
470done with @code{eq}).
471@end defvar
472
473@deffn Command toggle-read-only
474This command changes whether the current buffer is read-only. It is
475intended for interactive use; don't use it in programs. At any given
476point in a program, you should know whether you want the read-only flag
477on or off; so you can set @code{buffer-read-only} explicitly to the
478proper value, @code{t} or @code{nil}.
479@end deffn
480
481@defun barf-if-buffer-read-only
482This function signals a @code{buffer-read-only} error if the current
483buffer is read-only. @xref{Interactive Call}, for another way to
484signal an error if the current buffer is read-only.
485@end defun
486
487@node The Buffer List
488@section The Buffer List
489@cindex buffer list
490
491 The @dfn{buffer list} is a list of all live buffers. Creating a
492buffer adds it to this list, and killing a buffer deletes it. The order
493of the buffers in the list is based primarily on how recently each
494buffer has been displayed in the selected window. Buffers move to the
495front of the list when they are selected and to the end when they are
496buried. Several functions, notably @code{other-buffer}, use this
497ordering. A buffer list displayed for the user also follows this order.
498
499@defun buffer-list
500This function returns a list of all buffers, including those whose names
501begin with a space. The elements are actual buffers, not their names.
502
503@example
504@group
505(buffer-list)
506 @result{} (#<buffer buffers.texi>
507 #<buffer *Minibuf-1*> #<buffer buffer.c>
508 #<buffer *Help*> #<buffer TAGS>)
509@end group
510
511@group
512;; @r{Note that the name of the minibuffer}
513;; @r{begins with a space!}
514(mapcar (function buffer-name) (buffer-list))
515 @result{} ("buffers.texi" " *Minibuf-1*"
516 "buffer.c" "*Help*" "TAGS")
517@end group
518@end example
519
520This list is a copy of a list used inside Emacs; modifying it has no
521effect on the ordering of buffers.
522@end defun
523
524@defun other-buffer &optional buffer-or-name visible-ok
525This function returns the first buffer in the buffer list other than
526@var{buffer-or-name}. Usually this is the buffer most recently shown in
527the selected window, aside from @var{buffer-or-name}. Buffers whose
528names start with a space are not considered.
529
530If @var{buffer-or-name} is not supplied (or if it is not a buffer),
531then @code{other-buffer} returns the first buffer on the buffer list
532that is not visible in any window in a visible frame.
533
534@c Emacs 19 feature
535If @var{visible-ok} is @code{nil}, @code{other-buffer} avoids returning
536a buffer visible in any window on any visible frame, except as a last
537resort. If @var{visible-ok} is non-@code{nil}, then it does not matter
538whether a buffer is displayed somewhere or not.
539
540If no suitable buffer exists, the buffer @samp{*scratch*} is returned
541(and created, if necessary).
542@end defun
543
544@deffn Command bury-buffer &optional buffer-or-name
545This function puts @var{buffer-or-name} at the end of the buffer list
546without changing the order of any of the other buffers on the list.
547This buffer therefore becomes the least desirable candidate for
548@code{other-buffer} to return.
549
550If @var{buffer-or-name} is @code{nil} or omitted, this means to bury
551the current buffer. In addition, this switches to some other buffer
552(obtained using @code{other-buffer}) in the selected window. If the
553buffer is displayed in a window other than the selected one, it remains
554there.
555
556If you wish to replace a buffer in all the windows that display it, use
557@code{replace-buffer-in-windows}. @xref{Buffers and Windows}.
558@end deffn
559
560@node Creating Buffers
561@section Creating Buffers
562@cindex creating buffers
563@cindex buffers, creating
564
565 This section describes the two primitives for creating buffers.
566@code{get-buffer-create} creates a buffer if it finds no existing
567buffer; @code{generate-new-buffer} always creates a new buffer, and
568gives it a unique name.
569
570 Other functions you can use to create buffers include
571@code{with-output-to-temp-buffer} (@pxref{Temporary Displays}) and
572@code{create-file-buffer} (@pxref{Visiting Files}). Starting a
573subprocess can also create a buffer (@pxref{Processes}).
574
575@defun get-buffer-create name
576This function returns a buffer named @var{name}. It returns an existing
577buffer with that name, if one exists; otherwise, it creates a new
578buffer. The buffer does not become the current buffer---this function
579does not change which buffer is current.
580
581An error is signaled if @var{name} is not a string.
582
583@example
584@group
585(get-buffer-create "foo")
586 @result{} #<buffer foo>
587@end group
588@end example
589
590The major mode for the new buffer is set according to the variable
591@code{default-major-mode}. @xref{Auto Major Mode}.
592@end defun
593
594@defun generate-new-buffer name
595This function returns a newly created, empty buffer, but does not make
596it current. If there is no buffer named @var{name}, then that is the
597name of the new buffer. If that name is in use, this function adds
598suffixes of the form @samp{<@var{n}>} are added to @var{name}, where
599@var{n} is an integer. It tries successive integers starting with 2
600until it finds an available name.
601
602An error is signaled if @var{name} is not a string.
603
604@example
605@group
606(generate-new-buffer "bar")
607 @result{} #<buffer bar>
608@end group
609@group
610(generate-new-buffer "bar")
611 @result{} #<buffer bar<2>>
612@end group
613@group
614(generate-new-buffer "bar")
615 @result{} #<buffer bar<3>>
616@end group
617@end example
618
619The major mode for the new buffer is set by the value of
620@code{default-major-mode}. @xref{Auto Major Mode}.
621
622See the related function @code{generate-new-buffer-name} in @ref{Buffer
623Names}.
624@end defun
625
626@node Killing Buffers
627@section Killing Buffers
628@cindex killing buffers
629@cindex buffers, killing
630
631 @dfn{Killing a buffer} makes its name unknown to Emacs and makes its
632space available for other use.
633
634 The buffer object for the buffer which has been killed remains in
635existence as long as anything refers to it, but it is specially marked
636so that you cannot make it current or display it. Killed buffers retain
637their identity, however; two distinct buffers, when killed, remain
638distinct according to @code{eq}.
639
640 If you kill a buffer that is current or displayed in a window, Emacs
641automatically selects or displays some other buffer instead. This means
642that killing a buffer can in general change the current buffer.
643Therefore, when you kill a buffer, you should also take the precautions
644associated with changing the current buffer (unless you happen to know
645that the buffer being killed isn't current). @xref{Current Buffer}.
646
647 The @code{buffer-name} of a killed buffer is @code{nil}. You can use
648this feature to test whether a buffer has been killed:
649
650@example
651@group
652(defun buffer-killed-p (buffer)
653 "Return t if BUFFER is killed."
654 (not (buffer-name buffer)))
655@end group
656@end example
657
658@deffn Command kill-buffer buffer-or-name
659This function kills the buffer @var{buffer-or-name}, freeing all its
660memory for use as space for other buffers. (Emacs version 18 and older
661was unable to return the memory to the operating system.) It returns
662@code{nil}.
663
664Any processes that have this buffer as the @code{process-buffer} are
665sent the @code{SIGHUP} signal, which normally causes them to terminate.
666(The basic meaning of @code{SIGHUP} is that a dialup line has been
667disconnected.) @xref{Deleting Processes}.
668
669If the buffer is visiting a file and contains unsaved changes,
670@code{kill-buffer} asks the user to confirm before the buffer is killed.
671It does this even if not called interactively. To prevent the request
672for confirmation, clear the modified flag before calling
673@code{kill-buffer}. @xref{Buffer Modification}.
674
675@vindex kill-buffer-query-functions
676You can program additional requests for confirmation. After confirming
677unsaved changes, @code{kill-buffer} calls the functions in the list
678@code{kill-buffer-query-functions}, in order of appearance, with no
679arguments. The buffer being killed is the current buffer when they are
680called. The idea is that these functions ask for confirmation from the
681user for various nonstandard reasons. If any of them returns
682non-@code{nil}, the buffer is not killed.
683
684@c Emacs 19 feature
685@vindex kill-buffer-hook
686Just before actually killing the buffer, after asking all questions,
687@code{kill-buffer} runs the normal hook @code{kill-buffer-hook}. The
688buffer to be killed is current when the hook functions run.
689@xref{Hooks}.
690
691Killing a buffer that is already dead has no effect.
692
693@smallexample
694(kill-buffer "foo.unchanged")
695 @result{} nil
696(kill-buffer "foo.changed")
697
698---------- Buffer: Minibuffer ----------
699Buffer foo.changed modified; kill anyway? (yes or no) @kbd{yes}
700---------- Buffer: Minibuffer ----------
701
702 @result{} nil
703@end smallexample
704@end deffn
705
706@node Current Buffer
707@section The Current Buffer
708@cindex selecting a buffer
709@cindex changing to another buffer
710@cindex current buffer
711
712 There are, in general, many buffers in an Emacs session. At any time,
713one of them is designated as the @dfn{current buffer}. This is the
714buffer in which most editing takes place, because most of the primitives
715for examining or changing text in a buffer operate implicitly on the
716current buffer (@pxref{Text}). Normally the buffer that is displayed on
717the screen in the selected window is the current buffer, but this is not
718always so: a Lisp program can designate any buffer as current
719temporarily in order to operate on its contents, without changing what
720is displayed on the screen.
721
722 The way to designate a current buffer in a Lisp program is by calling
723@code{set-buffer}. The specified buffer remains current until a new one
724is designated.
725
726 When an editing command returns to the editor command loop, the
727command loop designates the buffer displayed in the selected window as
728current, to prevent confusion: the buffer that the cursor is in, when
729Emacs reads a command, is the one to which the command will apply.
730(@xref{Command Loop}.) Therefore, @code{set-buffer} is not the way to
731switch visibly to a different buffer so that the user can edit it. For
732this, you must use the functions described in @ref{Displaying Buffers}.
733
734 However, Lisp functions that change to a different current buffer
735should not depend on the command loop to set it back afterwards.
736Editing commands written in Emacs Lisp can be called from other programs
737as well as from the command loop. It is convenient for the caller if
738the subroutine does not change which buffer is current (unless, of
739course, that is the subroutine's purpose). Therefore, you should
740normally use @code{set-buffer} within a @code{save-excursion} that will
741restore the current buffer when your function is done
742(@pxref{Excursions}). Here is an example, the code for the command
743@code{append-to-buffer} (with the documentation string abridged):
744
745@example
746@group
747(defun append-to-buffer (buffer start end)
748 "Append to specified buffer the text of the region.
749@dots{}"
750 (interactive "BAppend to buffer: \nr")
751 (let ((oldbuf (current-buffer)))
752 (save-excursion
753 (set-buffer (get-buffer-create buffer))
754 (insert-buffer-substring oldbuf start end))))
755@end group
756@end example
757
758@noindent
759This function binds a local variable to the current buffer, and then
760@code{save-excursion} records the values of point, the mark, and the
761original buffer. Next, @code{set-buffer} makes another buffer current.
762Finally, @code{insert-buffer-substring} copies the string from the
763original current buffer to the new current buffer.
764
765 If the buffer appended to happens to be displayed in some window,
766the next redisplay will show how its text has changed. Otherwise, you
767will not see the change immediately on the screen. The buffer becomes
768current temporarily during the execution of the command, but this does
769not cause it to be displayed.
770
771 If you make local bindings (with @code{let} or function arguments) for
772a variable that may also have buffer-local bindings, make sure that the
773same buffer is current at the beginning and at the end of the local
774binding's scope. Otherwise you might bind it in one buffer and unbind
775it in another! There are two ways to do this. In simple cases, you may
776see that nothing ever changes the current buffer within the scope of the
777binding. Otherwise, use @code{save-excursion} to make sure that the
778buffer current at the beginning is current again whenever the variable
779is unbound.
780
781 It is not reliable to change the current buffer back with
782@code{set-buffer}, because that won't do the job if a quit happens while
783the wrong buffer is current. Here is what not to do:
784
785@example
786@group
787(let (buffer-read-only
788 (obuf (current-buffer)))
789 (set-buffer @dots{})
790 @dots{}
791 (set-buffer obuf))
792@end group
793@end example
794
795@noindent
796Using @code{save-excursion}, as shown below, handles quitting, errors
797and @code{throw} as well as ordinary evaluation.
798
799@example
800@group
801(let (buffer-read-only)
802 (save-excursion
803 (set-buffer @dots{})
804 @dots{}))
805@end group
806@end example
807
808@defun current-buffer
809This function returns the current buffer.
810
811@example
812@group
813(current-buffer)
814 @result{} #<buffer buffers.texi>
815@end group
816@end example
817@end defun
818
819@defun set-buffer buffer-or-name
820This function makes @var{buffer-or-name} the current buffer. It does
821not display the buffer in the currently selected window or in any other
822window, so the user cannot necessarily see the buffer. But Lisp
823programs can in any case work on it.
824
825This function returns the buffer identified by @var{buffer-or-name}.
826An error is signaled if @var{buffer-or-name} does not identify an
827existing buffer.
828@end defun
diff --git a/lispref/windows.texi b/lispref/windows.texi
new file mode 100644
index 00000000000..a859fd9cf20
--- /dev/null
+++ b/lispref/windows.texi
@@ -0,0 +1,1592 @@
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
3@c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4@c See the file elisp.texi for copying conditions.
5@setfilename ../info/windows
6@node Windows, Frames, Buffers, Top
7@chapter Windows
8
9 This chapter describes most of the functions and variables related to
10Emacs windows. See @ref{Display}, for information on how text is
11displayed in windows.
12
13@menu
14* Basic Windows:: Basic information on using windows.
15* Splitting Windows:: Splitting one window into two windows.
16* Deleting Windows:: Deleting a window gives its space to other windows.
17* Selecting Windows:: The selected window is the one that you edit in.
18* Cyclic Window Ordering:: Moving around the existing windows.
19* Buffers and Windows:: Each window displays the contents of a buffer.
20* Displaying Buffers:: Higher-lever functions for displaying a buffer
21 and choosing a window for it.
22* Choosing Window:: How to choose a window for displaying a buffer.
23* Window Point:: Each window has its own location of point.
24* Window Start:: The display-start position controls which text
25 is on-screen in the window.
26* Vertical Scrolling:: Moving text up and down in the window.
27* Horizontal Scrolling:: Moving text sideways on the window.
28* Size of Window:: Accessing the size of a window.
29* Resizing Windows:: Changing the size of a window.
30* Coordinates and Windows::Converting coordinates to windows.
31* Window Configurations:: Saving and restoring the state of the screen.
32@end menu
33
34@node Basic Windows
35@section Basic Concepts of Emacs Windows
36@cindex window
37@cindex selected window
38
39 A @dfn{window} is the physical area of the screen in which a buffer is
40displayed. The term is also used to refer to a Lisp object which
41represents that screen area in Emacs Lisp. It should be
42clear from the context which is meant.
43
44 There is always at least one window in any frame. In each frame, at
45any time, one and only one window is designated as @dfn{selected within
46the frame}. The frame's cursor appears in that window. There is also
47one selected frame; and the window selected within that frame is
48@dfn{the selected window}. The selected window's buffer is usually the
49current buffer (except when @code{set-buffer} has been used).
50@xref{Current Buffer}.
51
52 For all intents, a window only exists while it is displayed on the
53terminal. Once removed from the display, the window is effectively
54deleted and should not be used, @emph{even though there may still be
55references to it} from other Lisp objects. Restoring a saved window
56configuration is the only way for a window no longer on the screen to
57come back to life. (@xref{Deleting Windows}.)
58
59 Each window has the following attributes:
60
61@itemize @bullet
62@item
63containing frame
64
65@item
66window height
67
68@item
69window width
70
71@item
72window edges with respect to the screen or frame
73
74@item
75the buffer it displays
76
77@item
78position within the buffer at the upper left of the window
79
80@item
81the amount of horizontal scrolling, in columns
82
83@item
84point
85
86@item
87the mark
88
89@item
90how recently the window was selected
91@end itemize
92
93@cindex multiple windows
94 Users create multiple windows so they can look at several buffers at
95once. Lisp libraries use multiple windows for a variety of reasons, but
96most often to give different views of the same information. In Rmail,
97for example, you can move through a summary buffer in one window while
98the other window shows messages one at a time as they are reached.
99
100 The meaning of ``window'' in Emacs is similar to what it means in the
101context of general purpose window systems such as X, but not identical.
102The X Window System subdivides the screen into X windows; Emacs uses one
103or more X windows, called @dfn{frames} in Emacs terminology, and
104subdivides each of them into (nonoverlapping) Emacs windows. When you
105use Emacs on an ordinary display terminal, Emacs subdivides the terminal
106screen into Emacs windows.
107
108@cindex terminal screen
109@cindex screen of terminal
110@cindex tiled windows
111 Most window systems support arbitrarily located overlapping windows.
112In contrast, Emacs windows are @dfn{tiled}; they never overlap, and
113together they fill the whole of the screen or frame. Because of the way
114in which Emacs creates new windows and resizes them, you can't create
115every conceivable tiling of windows on an Emacs frame. @xref{Splitting
116Windows}, and @ref{Size of Window}.
117
118 @xref{Display}, for information on how the contents of the
119window's buffer are displayed in the window.
120
121@defun windowp object
122 This function returns @code{t} if @var{object} is a window.
123@end defun
124
125@node Splitting Windows
126@section Splitting Windows
127@cindex splitting windows
128@cindex window splitting
129
130 The functions described here are the primitives used to split a window
131into two windows. Two higher level functions sometimes split a window,
132but not always: @code{pop-to-buffer} and @code{display-buffer}
133(@pxref{Displaying Buffers}).
134
135 The functions described here do not accept a buffer as an argument.
136The two ``halves'' of the split window initially display the same buffer
137previously visible in the window that was split.
138
139@deffn Command split-window &optional window size horizontal
140This function splits @var{window} into two windows. The original
141window @var{window} remains the selected window, but occupies only
142part of its former screen area. The rest is occupied by a newly created
143window which is returned as the value of this function.
144
145 If @var{horizontal} is non-@code{nil}, then @var{window} splits into
146two side by side windows. The original window @var{window} keeps the
147leftmost @var{size} columns, and gives the rest of the columns to the
148new window. Otherwise, it splits into windows one above the other, and
149@var{window} keeps the upper @var{size} lines and gives the rest of the
150lines to the new window. The original window is therefore the
151right-hand or upper of the two, and the new window is the left-hand or
152lower.
153
154 If @var{window} is omitted or @code{nil}, then the selected window is
155split. If @var{size} is omitted or @code{nil}, then @var{window} is
156divided evenly into two parts. (If there is an odd line, it is
157allocated to the new window.) When @code{split-window} is called
158interactively, all its arguments are @code{nil}.
159
160 The following example starts with one window on a screen that is 50
161lines high by 80 columns wide; then the window is split.
162
163@smallexample
164@group
165(setq w (selected-window))
166 @result{} #<window 8 on windows.texi>
167(window-edges) ; @r{Edges in order:}
168 @result{} (0 0 80 50) ; @r{left--top--right--bottom}
169@end group
170
171@group
172;; @r{Returns window created}
173(setq w2 (split-window w 15))
174 @result{} #<window 28 on windows.texi>
175@end group
176@group
177(window-edges w2)
178 @result{} (0 15 80 50) ; @r{Bottom window;}
179 ; @r{top is line 15}
180@end group
181@group
182(window-edges w)
183 @result{} (0 0 80 15) ; @r{Top window}
184@end group
185@end smallexample
186
187The screen looks like this:
188
189@smallexample
190@group
191 __________
192 | | line 0
193 | w |
194 |__________|
195 | | line 15
196 | w2 |
197 |__________|
198 line 50
199 column 0 column 80
200@end group
201@end smallexample
202
203Next, the top window is split horizontally:
204
205@smallexample
206@group
207(setq w3 (split-window w 35 t))
208 @result{} #<window 32 on windows.texi>
209@end group
210@group
211(window-edges w3)
212 @result{} (35 0 80 15) ; @r{Left edge at column 35}
213@end group
214@group
215(window-edges w)
216 @result{} (0 0 35 15) ; @r{Right edge at column 35}
217@end group
218@group
219(window-edges w2)
220 @result{} (0 15 80 50) ; @r{Bottom window unchanged}
221@end group
222@end smallexample
223
224Now, the screen looks like this:
225
226@smallexample
227@group
228 column 35
229 __________
230 | | | line 0
231 | w | w3 |
232 |___|______|
233 | | line 15
234 | w2 |
235 |__________|
236 line 50
237 column 0 column 80
238@end group
239@end smallexample
240@end deffn
241
242@deffn Command split-window-vertically size
243This function splits the selected window into two windows, one above
244the other, leaving the selected window with @var{size} lines.
245
246This function is simply an interface to @code{split-windows}.
247Here is the complete function definition for it:
248
249@smallexample
250@group
251(defun split-window-vertically (&optional arg)
252 "Split current window into two windows, one above the other."
253 (interactive "P")
254 (split-window nil (and arg (prefix-numeric-value arg))))
255@end group
256@end smallexample
257@end deffn
258
259@deffn Command split-window-horizontally size
260This function splits the selected window into two windows
261side-by-side, leaving the selected window with @var{size} columns.
262
263This function is simply an interface to @code{split-windows}. Here is
264the complete definition for @code{split-window-horizontally} (except for
265part of the documentation string):
266
267@smallexample
268@group
269(defun split-window-horizontally (&optional arg)
270 "Split selected window into two windows, side by side..."
271 (interactive "P")
272 (split-window nil (and arg (prefix-numeric-value arg)) t))
273@end group
274@end smallexample
275@end deffn
276
277@defun one-window-p &optional no-mini all-frames
278This function returns non-@code{nil} if there is only one window. The
279argument @var{no-mini}, if non-@code{nil}, means don't count the
280minibuffer even if it is active; otherwise, the minibuffer window is
281included, if active, in the total number of windows which is compared
282against one.
283
284The argument @var{all-frames} specifies which frames to consider. Here
285are the possible values and their meanings:
286
287@table @asis
288@item @code{nil}
289Count the windows in the selected frame, plus the minibuffer used
290by that frame even if it lies in some other frame.
291
292@item @code{t}
293Count all windows in all existing frames.
294
295@item @code{visible}
296Count all windows in all visible frames.
297
298@item anything else
299Count precisely the windows in the selected frame, and no others.
300@end table
301@end defun
302
303@node Deleting Windows
304@section Deleting Windows
305@cindex deleting windows
306
307A window remains visible on its frame unless you @dfn{delete} it by
308calling certain functions that delete windows. A deleted window cannot
309appear on the screen, but continues to exist as a Lisp object until
310there are no references to it. There is no way to cancel the deletion
311of a window aside from restoring a saved window configuration
312(@pxref{Window Configurations}). Restoring a window configuration also
313deletes any windows that aren't part of that configuration.
314
315 When you delete a window, the space it took up is given to one
316adjacent sibling. (In Emacs version 18, the space was divided evenly
317among all the siblings.)
318
319@c Emacs 19 feature
320@defun window-live-p window
321This function returns @code{nil} if @var{window} is deleted, and
322@code{t} otherwise.
323
324@strong{Warning:} erroneous information or fatal errors may result from
325using a deleted window as if it were live.
326@end defun
327
328@deffn Command delete-window &optional window
329This function removes @var{window} from the display. If @var{window}
330is omitted, then the selected window is deleted. An error is signaled
331if there is only one window when @code{delete-window} is called.
332
333This function returns @code{nil}.
334
335When @code{delete-window} is called interactively, @var{window}
336defaults to the selected window.
337@end deffn
338
339@deffn Command delete-other-windows &optional window
340This function makes @var{window} the only window on its frame, by
341deleting the other windows in that frame. If @var{window} is omitted or
342@code{nil}, then the selected window is used by default.
343
344The result is @code{nil}.
345@end deffn
346
347@deffn Command delete-windows-on buffer &optional frame
348This function deletes all windows showing @var{buffer}. If there are
349no windows showing @var{buffer}, it does nothing.
350
351@code{delete-windows-on} operates frame by frame. If a frame has
352several windows showing different buffers, then those showing
353@var{buffer} are removed, and the others expand to fill the space. If
354all windows in some frame are showing @var{buffer} (including the case
355where there is only one window), then the frame reverts to having a
356single window showing another buffer chosen with @code{other-buffer}.
357@xref{The Buffer List}.
358
359The argument @var{frame} controls which frames to operate on:
360
361@itemize @bullet
362@item
363If it is @code{nil}, operate on the selected frame.
364@item
365If it is @code{t}, operate on all frames.
366@item
367If it is @code{visible}, operate on all visible frames.
368@item
369If it is a frame, operate on that frame.
370@end itemize
371
372This function always returns @code{nil}.
373@end deffn
374
375@node Selecting Windows
376@section Selecting Windows
377@cindex selecting windows
378
379 When a window is selected, the buffer in the window becomes the current
380buffer, and the cursor will appear in it.
381
382@defun selected-window
383This function returns the selected window. This is the window in
384which the cursor appears and to which many commands apply.
385@end defun
386
387@defun select-window window
388This function makes @var{window} the selected window. The cursor then
389appears in @var{window} (on redisplay). The buffer being displayed in
390@var{window} is immediately designated the current buffer.
391
392The return value is @var{window}.
393
394@example
395@group
396(setq w (next-window))
397(select-window w)
398 @result{} #<window 65 on windows.texi>
399@end group
400@end example
401@end defun
402
403@cindex finding windows
404 The following functions choose one of the windows on the screen,
405offering various criteria for the choice.
406
407@defun get-lru-window &optional frame
408This function returns the window least recently ``used'' (that is,
409selected). The selected window is always the most recently used window.
410
411The selected window can be the least recently used window if it is the
412only window. A newly created window becomes the least recently used
413window until it is selected. A minibuffer window is never a candidate.
414
415The argument @var{frame} controls which set of windows are
416considered.
417
418@itemize @bullet
419@item
420If it is @code{nil}, consider windows on the selected frame.
421@item
422If it is @code{t}, consider windows on all frames.
423@item
424If it is @code{visible}, consider windows on all visible frames.
425@item
426If it is a frame, consider windows on that frame.
427@end itemize
428@end defun
429
430@defun get-largest-window &optional frame
431This function returns the window with the largest area (height times
432width). If there are no side-by-side windows, then this is the window
433with the most lines. A minibuffer window is never a candidate.
434
435If there are two windows of the same size, then the function returns
436the window which is first in the cyclic ordering of windows (see
437following section), starting from the selected window.
438
439The argument @var{frame} controls which set of windows are
440considered. See @code{get-lru-window}, above.
441@end defun
442
443@node Cyclic Window Ordering
444@comment node-name, next, previous, up
445@section Cyclic Ordering of Windows
446@cindex cyclic ordering of windows
447@cindex ordering of windows, cyclic
448@cindex window ordering, cyclic
449
450 When you use the command @kbd{C-x o} (@code{other-window}) to select
451the next window, it moves through all the windows on the screen in a
452specific cyclic order. For any given configuration of windows, this
453order never varies. It is called the @dfn{cyclic ordering of windows}.
454
455 This ordering generally goes from top to bottom, and from left to
456right. But it may go down first or go right first, depending on the
457order in which the windows were split.
458
459 If the first split was vertical (into windows one above each other),
460and then the subwindows were split horizontally, then the ordering is
461left to right in the top of the frame, and then left to right in the
462next lower part of the frame, and so on. If the first split was
463horizontal, the ordering is top to bottom in the left part, and so on.
464In general, within each set of siblings at any level in the window tree,
465the order is left to right, or top to bottom.
466
467@defun next-window &optional window minibuf all-frames
468@cindex minibuffer window
469This function returns the window following @var{window} in the cyclic
470ordering of windows. This is the window which @kbd{C-x o} would select
471if done when @var{window} is selected. If @var{window} is the only
472window visible, then this function returns @var{window}. If omitted,
473@var{window} defaults to the selected window.
474
475The value of the argument @var{minibuf} determines whether the
476minibuffer is included in the window order. Normally, when
477@var{minibuf} is @code{nil}, the minibuffer is included if it is
478currently active; this is the behavior of @kbd{C-x o}. (The minibuffer
479window is active while the minibuffer is in use. @xref{Minibuffers}.)
480
481If @var{minibuf} is @code{t}, then the cyclic ordering includes the
482minibuffer window even if it is not active.
483
484If @var{minibuf} is neither @code{t} nor @code{nil}, then the minibuffer
485window is not included even if it is active.
486
487The argument @var{all-frames} specifies which frames to consider. Here
488are the possible values and their meanings:
489
490@table @asis
491@item @code{nil}
492Consider all the windows in @var{window}'s frame, plus the minibuffer
493used by that frame even if it lies in some other frame.
494
495@item @code{t}
496Consider all windows in all existing frames.
497
498@item @code{visible}
499Consider all windows in all visible frames. (To get useful results, you
500must ensure @var{window} is in a visible frame.)
501
502@item anything else
503Consider precisely the windows in @var{window}'s frame, and no others.
504@end table
505
506This example assumes there are two windows, both displaying the
507buffer @samp{windows.texi}:
508
509@example
510@group
511(selected-window)
512 @result{} #<window 56 on windows.texi>
513@end group
514@group
515(next-window (selected-window))
516 @result{} #<window 52 on windows.texi>
517@end group
518@group
519(next-window (next-window (selected-window)))
520 @result{} #<window 56 on windows.texi>
521@end group
522@end example
523@end defun
524
525@defun previous-window &optional window minibuf all-frames
526This function returns the window preceding @var{window} in the cyclic
527ordering of windows. The other arguments specify which windows to
528include in the cycle, as in @code{next-window}.
529@end defun
530
531@deffn Command other-window count
532This function selects the @var{count}th following window in the cyclic
533order. If count is negative, then it selects the @minus{}@var{count}th
534preceding window. It returns @code{nil}.
535
536In an interactive call, @var{count} is the numeric prefix argument.
537@end deffn
538
539@c Emacs 19 feature
540@defun walk-windows proc &optional minibuf all-frames
541This function cycles through all windows, calling @code{proc}
542once for each window with the window as its sole argument.
543
544The optional arguments @var{minibuf} and @var{all-frames} specify the
545set of windows to include in the scan. See @code{next-window}, above,
546for details.
547@end defun
548
549@node Buffers and Windows
550@section Buffers and Windows
551@cindex examining windows
552@cindex windows, controlling precisely
553@cindex buffers, controlled in windows
554
555 This section describes low-level functions to examine windows or to
556display buffers in windows in a precisely controlled fashion.
557@iftex
558See the following section for
559@end iftex
560@ifinfo
561@xref{Displaying Buffers}, for
562@end ifinfo
563related functions that find a window to use and specify a buffer for it.
564The functions described there are easier to use than these, but they
565employ heuristics in choosing or creating a window; use these functions
566when you need complete control.
567
568@defun set-window-buffer window buffer-or-name
569This function makes @var{window} display @var{buffer-or-name} as its
570contents. It returns @code{nil}.
571
572@example
573@group
574(set-window-buffer (selected-window) "foo")
575 @result{} nil
576@end group
577@end example
578@end defun
579
580@defun window-buffer &optional window
581This function returns the buffer that @var{window} is displaying. If
582@var{window} is omitted, this function returns the buffer for the
583selected window.
584
585@example
586@group
587(window-buffer)
588 @result{} #<buffer windows.texi>
589@end group
590@end example
591@end defun
592
593@defun get-buffer-window buffer-or-name &optional all-frames
594This function returns a window currently displaying
595@var{buffer-or-name}, or @code{nil} if there is none. If there are
596several such windows, then the function returns the first one in the
597cyclic ordering of windows, starting from the selected window.
598@xref{Cyclic Window Ordering}.
599
600The argument @var{all-frames} controls which windows to consider.
601
602@itemize @bullet
603@item
604If it is @code{nil}, consider windows on the selected frame.
605@item
606If it is @code{t}, consider windows on all frames.
607@item
608If it is @code{visible}, consider windows on all visible frames.
609@item
610If it is a frame, consider windows on that frame.
611@end itemize
612@end defun
613
614@deffn Command replace-buffer-in-windows buffer
615This function replaces @var{buffer} with some other buffer in all
616windows displaying it. The other buffer used is chosen with
617@code{other-buffer}. In the usual applications of this function, you
618don't care which other buffer is used; you just want to make sure that
619@var{buffer} is no longer displayed.
620
621This function returns @code{nil}.
622@end deffn
623
624@node Displaying Buffers
625@section Displaying Buffers in Windows
626@cindex switching to a buffer
627@cindex displaying a buffer
628
629 In this section we describe convenient functions that choose a window
630automatically and use it to display a specified buffer. These functions
631can also split an existing window in certain circumstances. We also
632describe variables that parameterize the heuristics used for choosing a
633window.
634@iftex
635See the preceding section for
636@end iftex
637@ifinfo
638@xref{Buffers and Windows}, for
639@end ifinfo
640low-level functions that give you more precise control.
641
642 Do not use the functions in this section in order to make a buffer
643current so that a Lisp program can access or modify it; they are too
644drastic for that purpose, since they change the display of buffers in
645windows, which is gratuitous and will surprise the user. Instead, use
646@code{set-buffer} (@pxref{Current Buffer}) and @code{save-excursion}
647(@pxref{Excursions}), which designate buffers as current for programmed
648access without affecting the display of buffers in windows.
649
650@deffn Command switch-to-buffer buffer-or-name &optional norecord
651This function makes @var{buffer-or-name} the current buffer, and also
652displays the buffer in the selected window. This means that a human can
653see the buffer and subsequent keyboard commands will apply to it.
654Contrast this with @code{set-buffer}, which makes @var{buffer-or-name}
655the current buffer but does not display it in the selected window.
656@xref{Current Buffer}.
657
658If @var{buffer-or-name} does not identify an existing buffer, then
659a new buffer by that name is created.
660
661Normally the specified buffer is put at the front of the buffer list.
662This affects the operation of @code{other-buffer}. However, if
663@var{norecord} is non-@code{nil}, this is not done. @xref{The Buffer
664List}.
665
666The @code{switch-to-buffer} function is often used interactively, as
667the binding of @kbd{C-x b}. It is also used frequently in programs. It
668always returns @code{nil}.
669@end deffn
670
671@deffn Command switch-to-buffer-other-window buffer-or-name
672This function makes @var{buffer-or-name} the current buffer and
673displays it in a window not currently selected. It then selects that
674window. The handling of the buffer is the same as in
675@code{switch-to-buffer}.
676
677The previously selected window is absolutely never used to display the
678buffer. If it is the only window, then it is split to make a distinct
679window for this purpose. If the selected window is already displaying
680the buffer, then it continues to do so, but another window is
681nonetheless found to display it in as well.
682@end deffn
683
684@defun pop-to-buffer buffer-or-name &optional other-window
685This function makes @var{buffer-or-name} the current buffer and
686switches to it in some window, preferably not the window previously
687selected. The ``popped-to'' window becomes the selected window within
688its frame.
689
690If the variable @code{pop-up-frames} is non-@code{nil},
691@code{pop-to-buffer} looks for a window in any visible frame already
692displaying the buffer; if there is one, it returns that window and makes
693it be selected within its frame. If there is none, it creates a new
694frame and displays the buffer in it.
695
696If @code{pop-up-frames} is @code{nil}, then @code{pop-to-buffer}
697operates entirely within the selected frame. (If the selected frame has
698just a minibuffer, @code{pop-to-buffer} operates within the most
699recently selected frame that was not just a minibuffer.)
700
701If the variable @code{pop-up-windows} is non-@code{nil}, windows may
702be split to create a new window that is different from the original
703window. For details, see @ref{Choosing Window}.
704
705If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or
706creates another window even if @var{buffer-or-name} is already visible
707in the selected window. Thus @var{buffer-or-name} could end up
708displayed in two windows. On the other hand, if @var{buffer-or-name} is
709already displayed in the selected window and @var{other-window} is
710@code{nil}, then the selected window is considered sufficient display
711for @var{buffer-or-name}, so that nothing needs to be done.
712
713If @var{buffer-or-name} is a string that does not name an existing
714buffer, a buffer by that name is created.
715
716An example use of this function is found at the end of @ref{Filter
717Functions}.
718@end defun
719
720@node Choosing Window
721@section Choosing a Window for Display
722
723 This section describes the basic facility which chooses a window to
724display a buffer in---@code{display-buffer}. All the higher-level
725functions and commands use this subroutine. Here we describe how to use
726@code{display-buffer} and how to customize it.
727
728@deffn Command display-buffer buffer-or-name &optional not-this-window
729This command makes @var{buffer-or-name} appear in some window, like
730@code{pop-to-buffer}, but it does not select that window and does not
731make the buffer current. The identity of the selected window is
732unaltered by this function.
733
734If @var{not-this-window} is non-@code{nil}, it means to display the
735specified buffer in a window other than the selected one, even if it is
736already on display in the selected window. This can cause the buffer to
737appear in two windows at once. Otherwise, if @var{buffer-or-name} is
738already being displayed in any window, that is good enough, so this
739function does nothing.
740
741@code{display-buffer} returns the window chosen to display
742@var{buffer-or-name}.
743
744Precisely how @code{display-buffer} finds or creates a window depends on
745the variables described below.
746@end deffn
747
748@defopt pop-up-windows
749This variable controls whether @code{display-buffer} makes new windows.
750If it is non-@code{nil} and there is only one window, then that window
751is split. If it is @code{nil}, then @code{display-buffer} does not
752split the single window, but uses it whole.
753@end defopt
754
755@defopt split-height-threshold
756This variable determines when @code{display-buffer} may split a window,
757if there are multiple windows. @code{display-buffer} always splits the
758largest window if it has at least this many lines. If the largest
759window is not this tall, it is split only if it is the sole window and
760@code{pop-up-windows} is non-@code{nil}.
761@end defopt
762
763@c Emacs 19 feature
764@defopt pop-up-frames
765This variable controls whether @code{display-buffer} makes new frames.
766If it is non-@code{nil}, @code{display-buffer} looks for an existing
767window already displaying the desired buffer, on any visible frame. If
768it finds one, it returns that window. Otherwise it makes a new frame.
769The variables @code{pop-up-windows} and @code{split-height-threshold} do
770not matter if @code{pop-up-frames} is non-@code{nil}.
771
772If @code{pop-up-frames} is @code{nil}, then @code{display-buffer} either
773splits a window or reuses one.
774
775@xref{Frames}, for more information.
776@end defopt
777
778@c Emacs 19 feature
779@defvar pop-up-frame-function
780This variable specifies how to make a new frame if @code{pop-up-frames}
781is non-@code{nil}.
782
783Its value should be a function of no arguments. When
784@code{display-buffer} makes a new frame, it does so by calling that
785function, which should return a frame. The default value of the
786variable is a function which creates a frame using parameters from
787@code{pop-up-frame-alist}.
788@end defvar
789
790@defvar pop-up-frame-alist
791This variable holds an alist specifying frame parameters used when
792@code{display-buffer} makes a new frame. @xref{Frame Parameters}, for
793more information about frame parameters.
794@end defvar
795
796@c Emacs 19 feature
797@defvar display-buffer-function
798This variable is the most flexible way to customize the behavior of
799@code{display-buffer}. If it is non-@code{nil}, it should be a function
800that @code{display-buffer} calls to do the work. The function should
801accept two arguments, the same two arguments that @code{display-buffer}
802received. It should choose or create a window, display the specified
803buffer, and then return the window.
804
805This hook takes precedence over all the other options and hooks
806described above.
807@end defvar
808
809@c Emacs 19 feature
810@cindex dedicated window
811A window can be marked as ``dedicated'' to its buffer. Then
812@code{display-buffer} does not try to use that window.
813
814@defun window-dedicated-p window
815This function returns @code{t} if @var{window} is marked as dedicated;
816otherwise @code{nil}.
817@end defun
818
819@defun set-window-dedicated-p window flag
820This function marks @var{window} as dedicated if @var{flag} is
821non-@code{nil}, and nondedicated otherwise.
822@end defun
823
824@node Window Point
825@section Windows and Point
826@cindex window position
827@cindex window point
828@cindex position in window
829@cindex point in window
830
831 Each window has its own value of point, independent of the value of
832point in other windows displaying the same buffer. This makes it useful
833to have multiple windows showing one buffer.
834
835@itemize @bullet
836@item
837The window point is established when a window is first created; it is
838initialized from the buffer's point, or from the window point of another
839window opened on the buffer if such a window exists.
840
841@item
842Selecting a window sets the value of point in its buffer to the window's
843value of point. Conversely, deselecting a window sets the window's
844value of point from that of the buffer. Thus, when you switch between
845windows that display a given buffer, the point value for the selected
846window is in effect in the buffer, while the point values for the other
847windows are stored in those windows.
848
849@item
850As long as the selected window displays the current buffer, the window's
851point and the buffer's point always move together; they remain equal.
852
853@item
854@xref{Positions}, for more details on buffer positions.
855@end itemize
856
857 As far as the user is concerned, point is where the cursor is, and
858when the user switches to another buffer, the cursor jumps to the
859position of point in that buffer.
860
861@defun window-point window
862This function returns the current position of point in @var{window}.
863For a nonselected window, this is the value point would have (in that
864window's buffer) if that window were selected.
865
866When @var{window} is the selected window and its buffer is also the
867current buffer, the value returned is the same as point in that buffer.
868
869Strictly speaking, it would be more correct to return the
870``top-level'' value of point, outside of any @code{save-excursion}
871forms. But that value is hard to find.
872@end defun
873
874@defun set-window-point window position
875This function positions point in @var{window} at position
876@var{position} in @var{window}'s buffer.
877@end defun
878
879@node Window Start
880@section The Window Start Position
881
882 Each window contains a marker used to keep track of a buffer position
883which specifies where in the buffer display should start. This position
884is called the @dfn{display-start} position of the window (or just the
885@dfn{start}). The character after this position is the one that appears
886at the upper left corner of the window. It is usually, but not
887inevitably, at the beginning of a text line.
888
889@defun window-start &optional window
890@cindex window top line
891This function returns the display-start position of window
892@var{window}. If @var{window} is @code{nil}, the selected window is
893used. For example,
894
895@example
896@group
897(window-start)
898 @result{} 7058
899@end group
900@end example
901
902When you create a window, or display a different buffer in it, the the
903display-start position is set to a display-start position recently used
904for the same buffer, or 1 if the buffer doesn't have any.
905
906For a realistic example, see the description of @code{count-lines} in
907@ref{Text Lines}.
908@end defun
909
910@defun window-end &optional window
911This function returns the position of the end of the display in window
912@var{window}. If @var{window} is @code{nil}, the selected window is
913used.
914@end defun
915
916@defun set-window-start window position &optional noforce
917This function sets the display-start position of @var{window} to
918@var{position} in @var{window}'s buffer.
919
920The display routines insist that the position of point be visible when a
921buffer is displayed. Normally, they change the display-start position
922(that is, scroll the window) whenever necessary to make point visible.
923However, if you specify the start position with this function using
924@code{nil} for @var{noforce}, it means you want display to start at
925@var{position} even if that would put the location of point off the
926screen. If this does place point off screen, the display routines move
927point to the left margin on the middle line in the window.
928
929For example, if point @w{is 1} and you set the start of the window @w{to
9302}, then point would be ``above'' the top of the window. The display
931routines will automatically move point if it is still 1 when redisplay
932occurs. Here is an example:
933
934@example
935@group
936;; @r{Here is what @samp{foo} looks like before executing}
937;; @r{the @code{set-window-start} expression.}
938@end group
939
940@group
941---------- Buffer: foo ----------
942@point{}This is the contents of buffer foo.
9432
9443
9454
9465
9476
948---------- Buffer: foo ----------
949@end group
950
951@group
952(set-window-start
953 (selected-window)
954 (1+ (window-start)))
955@result{} 2
956@end group
957
958@group
959;; @r{Here is what @samp{foo} looks like after executing}
960;; @r{the @code{set-window-start} expression.}
961---------- Buffer: foo ----------
962his is the contents of buffer foo.
9632
9643
965@point{}4
9665
9676
968---------- Buffer: foo ----------
969@end group
970@end example
971
972If @var{noforce} is non-@code{nil}, and @var{position} would place point
973off screen at the next redisplay, then redisplay computes a new window-start
974position that works well with point, and thus @var{position} is not used.
975
976This function returns @var{position}.
977@end defun
978
979@defun pos-visible-in-window-p &optional position window
980This function returns @code{t} if @var{position} is within the range
981of text currently visible on the screen in @var{window}. It returns
982@code{nil} if @var{position} is scrolled vertically out of view. The
983argument @var{position} defaults to the current position of point;
984@var{window}, to the selected window. Here is an example:
985
986@example
987@group
988(or (pos-visible-in-window-p
989 (point) (selected-window))
990 (recenter 0))
991@end group
992@end example
993
994The @code{pos-visible-in-window-p} function considers only vertical
995scrolling. If @var{position} is out of view only because @var{window}
996has been scrolled horizontally, @code{pos-visible-in-window-p} returns
997@code{t}. @xref{Horizontal Scrolling}.
998@end defun
999
1000@node Vertical Scrolling
1001@section Vertical Scrolling
1002@cindex vertical scrolling
1003@cindex scrolling vertically
1004
1005 Vertical scrolling means moving the text up or down in a window. It
1006works by changing the value of the window's display-start location. It
1007may also change the value of @code{window-point} to keep it on the
1008screen.
1009
1010 In the commands @code{scroll-up} and @code{scroll-down}, the directions
1011``up'' and ``down'' refer to the motion of the text in the buffer at which
1012you are looking through the window. Imagine that the text is
1013written on a long roll of paper and that the scrolling commands move the
1014paper up and down. Thus, if you are looking at text in the middle of a
1015buffer and repeatedly call @code{scroll-down}, you will eventually see
1016the beginning of the buffer.
1017
1018 Some people have urged that the opposite convention be used: they
1019imagine that the window moves over text that remains in place. Then
1020``down'' commands would take you to the end of the buffer. This view is
1021more consistent with the actual relationship between windows and the
1022text in the buffer, but it is less like what the user sees. The
1023position of a window on the terminal does not move, and short scrolling
1024commands clearly move the text up or down on the screen. We have chosen
1025names that fit the user's point of view.
1026
1027 The scrolling functions (aside from @code{scroll-other-window}) have
1028unpredictable results if the current buffer is different from the buffer
1029that is displayed in the selected window. @xref{Current Buffer}.
1030
1031@deffn Command scroll-up &optional count
1032This function scrolls the text in the selected window upward
1033@var{count} lines. If @var{count} is negative, scrolling is actually
1034downward.
1035
1036If @var{count} is @code{nil} (or omitted), then the length of scroll
1037is @code{next-screen-context-lines} lines less than the usable height of
1038the window (not counting its mode line).
1039
1040@code{scroll-up} returns @code{nil}.
1041@end deffn
1042
1043@deffn Command scroll-down &optional count
1044This function scrolls the text in the selected window downward
1045@var{count} lines. If @var{count} is negative, scrolling is actually
1046upward.
1047
1048If @var{count} is omitted or @code{nil}, then the length of the scroll
1049is @code{next-screen-context-lines} lines less than the usable height of
1050the window.
1051
1052@code{scroll-down} returns @code{nil}.
1053@end deffn
1054
1055@deffn Command scroll-other-window &optional count
1056This function scrolls the text in another window upward @var{count}
1057lines. Negative values of @var{count}, or @code{nil}, are handled
1058as in @code{scroll-up}.
1059
1060The window that is scrolled is normally the one following the selected
1061window in the cyclic ordering of windows---the window that
1062@code{next-window} would return. @xref{Cyclic Window Ordering}.
1063
1064You can specify a buffer to scroll with the variable
1065@code{other-window-scroll-buffer}. When the selected window is the
1066minibuffer, the next window is normally the one at the top left corner.
1067You can specify a different window to scroll with the variable
1068@code{minibuffer-scroll-window}. This variable has no effect when any
1069other window is selected. @xref{Minibuffer Misc}.
1070
1071When the minibuffer is active, it is the next window if the selected
1072window is the one at the bottom right corner. In this case,
1073@code{scroll-other-window} attempts to scroll the minibuffer. If the
1074minibuffer contains just one line, it has nowhere to scroll to, so the
1075line reappears after the echo area momentarily displays the message
1076``Beginning of buffer''.
1077@end deffn
1078
1079@c Emacs 19 feature
1080@defvar other-window-scroll-buffer
1081If this variable is non-@code{nil}, it tells @code{scroll-other-window}
1082which buffer to scroll.
1083@end defvar
1084
1085@defopt scroll-step
1086This variable controls how scrolling is done automatically when point
1087moves off the screen. If the value is zero, then redisplay scrolls the
1088text to center point vertically in the window. If the value is a
1089positive integer @var{n}, then redisplay brings point back on screen by
1090scrolling @var{n} lines in either direction, if possible; otherwise, it
1091centers point if possible. The default value is zero.
1092@end defopt
1093
1094@defopt next-screen-context-lines
1095The value of this variable is the number of lines of continuity to
1096retain when scrolling by full screens. For example, @code{scroll-up}
1097with an argument of @code{nil} scrolls so that this many lines at the
1098bottom of the window appear instead at the top. The default value is
1099@code{2}.
1100@end defopt
1101
1102@deffn Command recenter &optional count
1103@cindex centering point
1104This function scrolls the selected window to put the text where point
1105is located at a specified vertical position within the window.
1106
1107If @var{count} is a nonnegative number, it puts the line containing
1108point @var{count} lines down from the top of the window. If @var{count}
1109is a negative number, then it counts upward from the bottom of the
1110window, so that @minus{}1 stands for the last usable line in the window.
1111If @var{count} is a non-@code{nil} list, then it stands for the line in
1112the middle of the window.
1113
1114If @var{count} is @code{nil}, @code{recenter} puts the line containing
1115point in the middle of the window, then clears and redisplays the entire
1116selected frame.
1117
1118When @code{recenter} is called interactively, @var{count} is the raw
1119prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
1120@var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
1121@var{count} to 4, which positions the current line four lines from the
1122top.
1123
1124Typing @kbd{C-u 0 C-l} positions the current line at the top of the
1125window. This action is so handy that some people bind the command to a
1126function key. For example,
1127
1128@example
1129@group
1130(defun line-to-top-of-window ()
1131 "Scroll current line to top of window.
1132Replaces three keystroke sequence C-u 0 C-l."
1133 (interactive)
1134 (recenter 0))
1135
1136(global-set-key "\C-cl" 'line-to-top-of-window)
1137@end group
1138@end example
1139@end deffn
1140
1141@node Horizontal Scrolling
1142@section Horizontal Scrolling
1143@cindex horizontal scrolling
1144
1145 Because we read English first from top to bottom and second from left
1146to right, horizontal scrolling is not like vertical scrolling. Vertical
1147scrolling involves selection of a contiguous portion of text to display.
1148Horizontal scrolling causes part of each line to go off screen. The
1149amount of horizontal scrolling is therefore specified as a number of
1150columns rather than as a position in the buffer. It has nothing to do
1151with the display-start position returned by @code{window-start}.
1152
1153 Usually, no horizontal scrolling is in effect; then the leftmost
1154column is at the left edge of the window. In this state, scrolling to
1155the right is meaningless, since there is no data to the left of the
1156screen to be revealed by it; so this is not allowed. Scrolling to the
1157left is allowed; it scrolls the first columns of text off the edge of
1158the window and can reveal additional columns on the right that were
1159truncated before. Once a window has a nonzero amount of leftward
1160horizontal scrolling, you can scroll it back to the right, but only so
1161far as to reduce the net horizontal scroll to zero. There is no limit
1162to how far left you can scroll, but eventually all the text will
1163disappear off the left edge.
1164
1165@deffn Command scroll-left count
1166This function scrolls the selected window @var{count} columns to the
1167left (or to the right if @var{count} is negative). The return value is
1168the total amount of leftward horizontal scrolling in effect after the
1169change---just like the value returned by @code{window-hscroll}.
1170@end deffn
1171
1172@deffn Command scroll-right count
1173This function scrolls the selected window @var{count} columns to the
1174right (or to the left if @var{count} is negative). The return value is
1175the total amount of leftward horizontal scrolling in effect after the
1176change---just like the value returned by @code{window-hscroll}.
1177
1178Once you scroll a window as far right as it can go, back to its normal
1179position where the total leftward scrolling is zero, attempts to scroll
1180any farther right have no effect.
1181@end deffn
1182
1183@defun window-hscroll &optional window
1184This function returns the total leftward horizontal scrolling of
1185@var{window}---the number of columns by which the text in @var{window}
1186is scrolled left past the left margin.
1187
1188The value is never negative. It is zero when no horizontal scrolling
1189has been done in @var{window} (which is usually the case).
1190
1191If @var{window} is @code{nil}, the selected window is used.
1192
1193@example
1194@group
1195(window-hscroll)
1196 @result{} 0
1197@end group
1198@group
1199(scroll-left 5)
1200 @result{} 5
1201@end group
1202@group
1203(window-hscroll)
1204 @result{} 5
1205@end group
1206@end example
1207@end defun
1208
1209@defun set-window-hscroll window columns
1210This function sets the number of columns from the left margin that
1211@var{window} is scrolled to the value of @var{columns}. The argument
1212@var{columns} should be zero or positive; if not, it is taken as zero.
1213
1214The value returned is @var{columns}.
1215
1216@example
1217@group
1218(set-window-hscroll (selected-window) 10)
1219 @result{} 10
1220@end group
1221@end example
1222@end defun
1223
1224 Here is how you can determine whether a given position @var{position}
1225is off the screen due to horizontal scrolling:
1226
1227@example
1228@group
1229(save-excursion
1230 (goto-char @var{position})
1231 (and
1232 (>= (- (current-column) (window-hscroll @var{window})) 0)
1233 (< (- (current-column) (window-hscroll @var{window}))
1234 (window-width @var{window}))))
1235@end group
1236@end example
1237
1238@node Size of Window
1239@section The Size of a Window
1240@cindex window size
1241@cindex size of window
1242
1243 An Emacs window is rectangular, and its size information consists of
1244the height (the number of lines) and the width (the number of character
1245positions in each line). The mode line is included in the height. But
1246the width does not count the scroll bar or the column of @samp{|}
1247characters separates side-by-side windows.
1248
1249 The following three functions return size information about a window:
1250
1251@defun window-height &optional window
1252This function returns the number of lines in @var{window}, including
1253its mode line. If @var{window} fills its entire frame, this is one less
1254than the value of @code{frame-height} on that frame (since the last line
1255is always reserved for the minibuffer).
1256
1257If @var{window} is @code{nil}, the function uses the selected window.
1258
1259@example
1260@group
1261(window-height)
1262 @result{} 23
1263@end group
1264@group
1265(split-window-vertically)
1266 @result{} #<window 4 on windows.texi>
1267@end group
1268@group
1269(window-height)
1270 @result{} 11
1271@end group
1272@end example
1273@end defun
1274
1275@defun window-width &optional window
1276This function returns the number of columns in @var{window}. If
1277@var{window} fills its entire frame, this is the same as the value of
1278@code{frame-width} on that frame. The width does not include the
1279window's scroll bar or the column of @samp{|} characters that separates
1280side-by-side windows.
1281
1282If @var{window} is @code{nil}, the function uses the selected window.
1283
1284@example
1285@group
1286(window-width)
1287 @result{} 80
1288@end group
1289@end example
1290@end defun
1291
1292@defun window-edges &optional window
1293This function returns a list of the edge coordinates of @var{window}.
1294If @var{window} is @code{nil}, the selected window is used.
1295
1296The order of the list is @code{(@var{left} @var{top} @var{right}
1297@var{bottom})}, all elements relative to 0, 0 at the top left corner of
1298the frame. The element @var{right} of the value is one more than the
1299rightmost column used by @var{window}, and @var{bottom} is one more than
1300the bottommost row used by @var{window} and its mode-line.
1301
1302When you have side-by-side windows, the right edge value for a window
1303with a neighbor on the right includes the width of the separator between
1304the window and that neighbor. This separator may be a column of
1305@samp{|} characters or it may be a scroll bar. Since the width of the
1306window does not include this separator, the width does not equal the
1307difference between the right and left edges in this case.
1308
1309Here is the result obtained on a typical 24-line terminal with just one
1310window:
1311
1312@example
1313@group
1314(window-edges (selected-window))
1315 @result{} (0 0 80 23)
1316@end group
1317@end example
1318
1319If @var{window} is at the upper left corner of its frame, @var{right}
1320and @var{bottom} are the same as the values returned by
1321@code{(window-width)} and @code{(window-height)} respectively, and
1322@var{top} and @var{bottom} are zero. For example, the edges of the
1323following window are @w{@samp{0 0 5 8}}. Assuming that the frame has
1324more than 8 columns, the last column of the window (column 7) holds a
1325border rather than text. The last row (row 4) holds the mode line,
1326shown here with @samp{xxxxxxxxx}.
1327
1328@example
1329@group
1330 0
1331 _______
1332 0 | |
1333 | |
1334 | |
1335 | |
1336 xxxxxxxxx 4
1337
1338 7
1339@end group
1340@end example
1341
1342When there are side-by-side windows, any window not at the right edge of
1343its frame has a separator in its last column or columns. The separator
1344counts as one or two columns in the width of the window. A window never
1345includes a separator on its left, since that belongs to the window to
1346the left.
1347
1348In the following example, let's suppose that the frame is 7
1349columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}}
1350and the edges of the right window are @w{@samp{4 0 7 3}}.
1351
1352@example
1353@group
1354 ___ ___
1355 | | |
1356 | | |
1357 xxxxxxxxx
1358
1359 0 34 7
1360@end group
1361@end example
1362@end defun
1363
1364@node Resizing Windows
1365@section Changing the Size of a Window
1366@cindex window resizing
1367@cindex changing window size
1368@cindex window size, changing
1369
1370 The window size functions fall into two classes: high-level commands
1371that change the size of windows and low-level functions that access
1372window size. Emacs does not permit overlapping windows or gaps between
1373windows, so resizing one window affects other windows.
1374
1375@deffn Command enlarge-window size &optional horizontal
1376This function makes the selected window @var{size} lines bigger,
1377stealing lines from neighboring windows. It takes the lines from one
1378window at a time until that window is used up, then takes from another.
1379If a window from which lines are stolen shrinks below
1380@code{window-min-height} lines, that window disappears.
1381
1382If @var{horizontal} is non-@code{nil}, this function makes
1383@var{window} wider by @var{size} columns, stealing columns instead of
1384lines. If a window from which columns are stolen shrinks below
1385@code{window-min-width} columns, that window disappears.
1386
1387If the window's frame is smaller than @var{size} lines (or columns),
1388then the function makes the window occupy the entire height (or width)
1389of the frame.
1390
1391If @var{size} is negative, this function shrinks the window by
1392@minus{}@var{size} lines or columns. If that makes the window smaller
1393than the minimum size (@code{window-min-height} and
1394@code{window-min-width}), @code{enlarge-window} deletes the window.
1395
1396@code{enlarge-window} returns @code{nil}.
1397@end deffn
1398
1399@deffn Command enlarge-window-horizontally columns
1400This function makes the selected window @var{columns} wider.
1401It could be defined as follows:
1402
1403@example
1404@group
1405(defun enlarge-window-horizontally (columns)
1406 (enlarge-window columns t))
1407@end group
1408@end example
1409@end deffn
1410
1411@deffn Command shrink-window size &optional horizontal
1412This function is like @code{enlarge-window} but negates the argument
1413@var{size}, making the selected window smaller by giving lines (or
1414columns) to the other windows. If the window shrinks below
1415@code{window-min-height} or @code{window-min-width}, then it disappears.
1416
1417If @var{size} is negative, the window is enlarged by @minus{}@var{size}
1418lines or columns.
1419@end deffn
1420
1421@deffn Command shrink-window-horizontally columns
1422This function makes the selected window @var{columns} narrower.
1423It could be defined as follows:
1424
1425@example
1426@group
1427(defun shrink-window-horizontally (columns)
1428 (shrink-window columns t))
1429@end group
1430@end example
1431@end deffn
1432
1433@cindex minimum window size
1434 The following two variables constrain the window size changing
1435functions to a minimum height and width.
1436
1437@defopt window-min-height
1438The value of this variable determines how short a window may become
1439before it is automatically deleted. Making a window smaller than
1440@code{window-min-height} automatically deletes it, and no window may be
1441created shorter than this. The absolute minimum height is two (allowing
1442one line for the mode line, and one line for the buffer display).
1443Actions which change window sizes reset this variable to two if it is
1444less than two. The default value is 4.
1445@end defopt
1446
1447@defopt window-min-width
1448The value of this variable determines how narrow a window may become
1449before it automatically deleted. Making a window smaller than
1450@code{window-min-width} automatically deletes it, and no window may be
1451created narrower than this. The absolute minimum width is one; any
1452value below that is ignored. The default value is 10.
1453@end defopt
1454
1455@node Coordinates and Windows
1456@section Coordinates and Windows
1457
1458This section describes how to compare screen coordinates with windows.
1459
1460@defun window-at x y &optional frame
1461This function returns the window containing the specified cursor
1462position in the frame @var{frame}. The coordinates @var{x} and @var{y}
1463are measured in characters and count from the top left corner of the
1464frame. If they are out of range, @code{window-at} returns @code{nil}.
1465
1466If you omit @var{frame}, the selected frame is used.
1467@end defun
1468
1469@defun coordinates-in-window-p coordinates window
1470This function checks whether a particular frame position falls within
1471the window @var{window}.
1472
1473The argument @var{coordinates} is a cons cell of this form:
1474
1475@example
1476(@var{x} . @var{y})
1477@end example
1478
1479@noindent
1480The coordinates @var{x} and @var{y} are measured in characters, and
1481count from the top left corner of the screen or frame.
1482
1483The value of @code{coordinates-in-window-p} is non-@code{nil} if the
1484coordinates are inside @var{window}. The value also indicates what part
1485of the window the position is in, as follows:
1486
1487@table @code
1488@item (@var{relx} . @var{rely})
1489The coordinates are inside @var{window}. The numbers @var{relx} and
1490@var{rely} are the equivalent window-relative coordinates for the
1491specified position, counting from 0 at the top left corner of the
1492window.
1493
1494@item mode-line
1495The coordinates are in the mode line of @var{window}.
1496
1497@item vertical-split
1498The coordinates are in the vertical line between @var{window} and its
1499neighbor to the right. This value occurs only if the window doesn't
1500have a scroll bar; positions in a scroll bar are considered outside the
1501window.
1502
1503@item nil
1504The coordinates are not in any part of @var{window}.
1505@end table
1506
1507The function @code{coordinates-in-window-p} does not require a frame as
1508argument because it always uses the frame that @var{window} is on.
1509@end defun
1510
1511@node Window Configurations
1512@section Window Configurations
1513@cindex window configurations
1514@cindex saving window information
1515
1516 A @dfn{window configuration} records the entire layout of a
1517frame---all windows, their sizes, which buffers they contain, what part
1518of each buffer is displayed, and the values of point and the mark. You
1519can bring back an entire previous layout by restoring a window
1520configuration previously saved.
1521
1522 If you want to record all frames instead of just one, use a frame
1523configuration instead of a window configuration. @xref{Frame
1524Configurations}.
1525
1526@defun current-window-configuration
1527This function returns a new object representing Emacs's current window
1528configuration, namely the number of windows, their sizes and current
1529buffers, which window is the selected window, and for each window the
1530displayed buffer, the display-start position, and the positions of point
1531and the mark. An exception is made for point in the current buffer,
1532whose value is not saved.
1533@end defun
1534
1535@defun set-window-configuration configuration
1536This function restores the configuration of Emacs's windows and
1537buffers to the state specified by @var{configuration}. The argument
1538@var{configuration} must be a value that was previously returned by
1539@code{current-window-configuration}.
1540
1541Here is a way of using this function to get the same effect
1542as @code{save-window-excursion}:
1543
1544@example
1545@group
1546(let ((config (current-window-configuration)))
1547 (unwind-protect
1548 (progn (split-window-vertically nil)
1549 @dots{})
1550 (set-window-configuration config)))
1551@end group
1552@end example
1553@end defun
1554
1555@defspec save-window-excursion forms@dots{}
1556This special form records the window configuration, executes @var{forms}
1557in sequence, then restores the earlier window configuration. The window
1558configuration includes the value of point and the portion of the buffer
1559which is visible. It also includes the choice of selected window.
1560However, it does not include the value of point in the current buffer;
1561use @code{save-excursion} if you wish to preserve that.
1562
1563The return value is the value of the final form in @var{forms}.
1564For example:
1565
1566@example
1567@group
1568(split-window)
1569 @result{} #<window 25 on control.texi>
1570@end group
1571@group
1572(setq w (selected-window))
1573 @result{} #<window 19 on control.texi>
1574@end group
1575@group
1576(save-window-excursion
1577 (delete-other-windows w)
1578 (switch-to-buffer "foo")
1579 'do-something)
1580 @result{} do-something
1581 ;; @r{The screen is now split again.}
1582@end group
1583@end example
1584@end defspec
1585
1586@defun window-configuration-p object
1587This function returns @code{t} if @var{object} is a window configuration.
1588@end defun
1589
1590 Primitives to look inside of window configurations would make sense,
1591but none are implemented. It is not clear they are useful enough to be
1592worth implementing.