feffc1f1badd9837100bc0f9885f4eea2456d4cf
[chise/xemacs-chise.git] / info / lispref.info-25
1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
2 lispref/lispref.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Lispref: (lispref).           XEmacs Lisp Reference Manual.
7 END-INFO-DIR-ENTRY
8
9    Edition History:
10
11    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
20
21    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
24
25    Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
28
29    Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
33
34    Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
38
39    Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
45
46    Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
51
52 \1f
53 File: lispref.info,  Node: Current Buffer,  Next: Buffer Names,  Prev: Buffer Basics,  Up: Buffers
54
55 The Current Buffer
56 ==================
57
58    There are, in general, many buffers in an Emacs session.  At any
59 time, one of them is designated as the "current buffer".  This is the
60 buffer in which most editing takes place, because most of the primitives
61 for examining or changing text in a buffer operate implicitly on the
62 current buffer (*note Text::).  Normally the buffer that is displayed on
63 the screen in the selected window is the current buffer, but this is not
64 always so: a Lisp program can designate any buffer as current
65 temporarily in order to operate on its contents, without changing what
66 is displayed on the screen.
67
68    The way to designate a current buffer in a Lisp program is by calling
69 `set-buffer'.  The specified buffer remains current until a new one is
70 designated.
71
72    When an editing command returns to the editor command loop, the
73 command loop designates the buffer displayed in the selected window as
74 current, to prevent confusion: the buffer that the cursor is in when
75 Emacs reads a command is the buffer that the command will apply to.
76 (*Note Command Loop::.)  Therefore, `set-buffer' is not the way to
77 switch visibly to a different buffer so that the user can edit it.  For
78 this, you must use the functions described in *Note Displaying
79 Buffers::.
80
81    However, Lisp functions that change to a different current buffer
82 should not depend on the command loop to set it back afterwards.
83 Editing commands written in XEmacs Lisp can be called from other
84 programs as well as from the command loop.  It is convenient for the
85 caller if the subroutine does not change which buffer is current
86 (unless, of course, that is the subroutine's purpose).  Therefore, you
87 should normally use `set-buffer' within a `save-excursion' that will
88 restore the current buffer when your function is done (*note
89 Excursions::).  Here is an example, the code for the command
90 `append-to-buffer' (with the documentation string abridged):
91
92      (defun append-to-buffer (buffer start end)
93        "Append to specified buffer the text of the region.
94      ..."
95        (interactive "BAppend to buffer: \nr")
96        (let ((oldbuf (current-buffer)))
97          (save-excursion
98            (set-buffer (get-buffer-create buffer))
99            (insert-buffer-substring oldbuf start end))))
100
101 This function binds a local variable to the current buffer, and then
102 `save-excursion' records the values of point, the mark, and the
103 original buffer.  Next, `set-buffer' makes another buffer current.
104 Finally, `insert-buffer-substring' copies the string from the original
105 current buffer to the new current buffer.
106
107    If the buffer appended to happens to be displayed in some window,
108 the next redisplay will show how its text has changed.  Otherwise, you
109 will not see the change immediately on the screen.  The buffer becomes
110 current temporarily during the execution of the command, but this does
111 not cause it to be displayed.
112
113    If you make local bindings (with `let' or function arguments) for a
114 variable that may also have buffer-local bindings, make sure that the
115 same buffer is current at the beginning and at the end of the local
116 binding's scope.  Otherwise you might bind it in one buffer and unbind
117 it in another!  There are two ways to do this.  In simple cases, you may
118 see that nothing ever changes the current buffer within the scope of the
119 binding.  Otherwise, use `save-excursion' to make sure that the buffer
120 current at the beginning is current again whenever the variable is
121 unbound.
122
123    It is not reliable to change the current buffer back with
124 `set-buffer', because that won't do the job if a quit happens while the
125 wrong buffer is current.  Here is what _not_ to do:
126
127      (let (buffer-read-only
128            (obuf (current-buffer)))
129        (set-buffer ...)
130        ...
131        (set-buffer obuf))
132
133 Using `save-excursion', as shown below, handles quitting, errors, and
134 `throw', as well as ordinary evaluation.
135
136      (let (buffer-read-only)
137        (save-excursion
138          (set-buffer ...)
139          ...))
140
141  - Function: current-buffer
142      This function returns the current buffer.
143
144           (current-buffer)
145                => #<buffer buffers.texi>
146
147  - Function: set-buffer buffer-or-name
148      This function makes BUFFER-OR-NAME the current buffer.  It does
149      not display the buffer in the currently selected window or in any
150      other window, so the user cannot necessarily see the buffer.  But
151      Lisp programs can in any case work on it.
152
153      This function returns the buffer identified by BUFFER-OR-NAME.  An
154      error is signaled if BUFFER-OR-NAME does not identify an existing
155      buffer.
156
157 \1f
158 File: lispref.info,  Node: Buffer Names,  Next: Buffer File Name,  Prev: Current Buffer,  Up: Buffers
159
160 Buffer Names
161 ============
162
163    Each buffer has a unique name, which is a string.  Many of the
164 functions that work on buffers accept either a buffer or a buffer name
165 as an argument.  Any argument called BUFFER-OR-NAME is of this sort,
166 and an error is signaled if it is neither a string nor a buffer.  Any
167 argument called BUFFER must be an actual buffer object, not a name.
168
169    Buffers that are ephemeral and generally uninteresting to the user
170 have names starting with a space, so that the `list-buffers' and
171 `buffer-menu' commands don't mention them.  A name starting with space
172 also initially disables recording undo information; see *Note Undo::.
173
174  - Function: buffer-name &optional buffer
175      This function returns the name of BUFFER as a string.  If BUFFER
176      is not supplied, it defaults to the current buffer.
177
178      If `buffer-name' returns `nil', it means that BUFFER has been
179      killed.  *Note Killing Buffers::.
180
181           (buffer-name)
182                => "buffers.texi"
183           
184           (setq foo (get-buffer "temp"))
185                => #<buffer temp>
186           (kill-buffer foo)
187                => nil
188           (buffer-name foo)
189                => nil
190           foo
191                => #<killed buffer>
192
193  - Command: rename-buffer newname &optional unique
194      This function renames the current buffer to NEWNAME.  An error is
195      signaled if NEWNAME is not a string, or if there is already a
196      buffer with that name.  The function returns `nil'.
197
198      Ordinarily, `rename-buffer' signals an error if NEWNAME is already
199      in use.  However, if UNIQUE is non-`nil', it modifies NEWNAME to
200      make a name that is not in use.  Interactively, you can make
201      UNIQUE non-`nil' with a numeric prefix argument.
202
203      One application of this command is to rename the `*shell*' buffer
204      to some other name, thus making it possible to create a second
205      shell buffer under the name `*shell*'.
206
207  - Function: get-buffer buffer-or-name
208      This function returns the buffer specified by BUFFER-OR-NAME.  If
209      BUFFER-OR-NAME is a string and there is no buffer with that name,
210      the value is `nil'.  If BUFFER-OR-NAME is a buffer, it is returned
211      as given.  (That is not very useful, so the argument is usually a
212      name.)  For example:
213
214           (setq b (get-buffer "lewis"))
215                => #<buffer lewis>
216           (get-buffer b)
217                => #<buffer lewis>
218           (get-buffer "Frazzle-nots")
219                => nil
220
221      See also the function `get-buffer-create' in *Note Creating
222      Buffers::.
223
224  - Function: generate-new-buffer-name starting-name &optional ignore
225      This function returns a name that would be unique for a new
226      buffer--but does not create the buffer.  It starts with
227      STARTING-NAME, and produces a name not currently in use for any
228      buffer by appending a number inside of `<...>'.
229
230      If IGNORE is given, it specifies a name that is okay to use (if it
231      is in the sequence to be tried), even if a buffer with that name
232      exists.
233
234      See the related function `generate-new-buffer' in *Note Creating
235      Buffers::.
236
237 \1f
238 File: lispref.info,  Node: Buffer File Name,  Next: Buffer Modification,  Prev: Buffer Names,  Up: Buffers
239
240 Buffer File Name
241 ================
242
243    The "buffer file name" is the name of the file that is visited in
244 that buffer.  When a buffer is not visiting a file, its buffer file name
245 is `nil'.  Most of the time, the buffer name is the same as the
246 nondirectory part of the buffer file name, but the buffer file name and
247 the buffer name are distinct and can be set independently.  *Note
248 Visiting Files::.
249
250  - Function: buffer-file-name &optional buffer
251      This function returns the absolute file name of the file that
252      BUFFER is visiting.  If BUFFER is not visiting any file,
253      `buffer-file-name' returns `nil'.  If BUFFER is not supplied, it
254      defaults to the current buffer.
255
256           (buffer-file-name (other-buffer))
257                => "/usr/user/lewis/manual/files.texi"
258
259  - Variable: buffer-file-name
260      This buffer-local variable contains the name of the file being
261      visited in the current buffer, or `nil' if it is not visiting a
262      file.  It is a permanent local, unaffected by
263      `kill-local-variables'.
264
265           buffer-file-name
266                => "/usr/user/lewis/manual/buffers.texi"
267
268      It is risky to change this variable's value without doing various
269      other things.  See the definition of `set-visited-file-name' in
270      `files.el'; some of the things done there, such as changing the
271      buffer name, are not strictly necessary, but others are essential
272      to avoid confusing XEmacs.
273
274  - Variable: buffer-file-truename
275      This buffer-local variable holds the truename of the file visited
276      in the current buffer, or `nil' if no file is visited.  It is a
277      permanent local, unaffected by `kill-local-variables'.  *Note
278      Truenames::.
279
280  - Variable: buffer-file-number
281      This buffer-local variable holds the file number and directory
282      device number of the file visited in the current buffer, or `nil'
283      if no file or a nonexistent file is visited.  It is a permanent
284      local, unaffected by `kill-local-variables'.  *Note Truenames::.
285
286      The value is normally a list of the form `(FILENUM DEVNUM)'.  This
287      pair of numbers uniquely identifies the file among all files
288      accessible on the system.  See the function `file-attributes', in
289      *Note File Attributes::, for more information about them.
290
291  - Function: get-file-buffer filename
292      This function returns the buffer visiting file FILENAME.  If there
293      is no such buffer, it returns `nil'.  The argument FILENAME, which
294      must be a string, is expanded (*note File Name Expansion::), then
295      compared against the visited file names of all live buffers.
296
297           (get-file-buffer "buffers.texi")
298               => #<buffer buffers.texi>
299
300      In unusual circumstances, there can be more than one buffer
301      visiting the same file name.  In such cases, this function returns
302      the first such buffer in the buffer list.
303
304  - Command: set-visited-file-name filename
305      If FILENAME is a non-empty string, this function changes the name
306      of the file visited in current buffer to FILENAME.  (If the buffer
307      had no visited file, this gives it one.)  The _next time_ the
308      buffer is saved it will go in the newly-specified file.  This
309      command marks the buffer as modified, since it does not (as far as
310      XEmacs knows) match the contents of FILENAME, even if it matched
311      the former visited file.
312
313      If FILENAME is `nil' or the empty string, that stands for "no
314      visited file".  In this case, `set-visited-file-name' marks the
315      buffer as having no visited file.
316
317      When the function `set-visited-file-name' is called interactively,
318      it prompts for FILENAME in the minibuffer.
319
320      See also `clear-visited-file-modtime' and
321      `verify-visited-file-modtime' in *Note Buffer Modification::.
322
323  - Variable: list-buffers-directory
324      This buffer-local variable records a string to display in a buffer
325      listing in place of the visited file name, for buffers that don't
326      have a visited file name.  Dired buffers use this variable.
327
328 \1f
329 File: lispref.info,  Node: Buffer Modification,  Next: Modification Time,  Prev: Buffer File Name,  Up: Buffers
330
331 Buffer Modification
332 ===================
333
334    XEmacs keeps a flag called the "modified flag" for each buffer, to
335 record whether you have changed the text of the buffer.  This flag is
336 set to `t' whenever you alter the contents of the buffer, and cleared
337 to `nil' when you save it.  Thus, the flag shows whether there are
338 unsaved changes.  The flag value is normally shown in the modeline
339 (*note Modeline Variables::), and controls saving (*note Saving
340 Buffers::) and auto-saving (*note Auto-Saving::).
341
342    Some Lisp programs set the flag explicitly.  For example, the
343 function `set-visited-file-name' sets the flag to `t', because the text
344 does not match the newly-visited file, even if it is unchanged from the
345 file formerly visited.
346
347    The functions that modify the contents of buffers are described in
348 *Note Text::.
349
350  - Function: buffer-modified-p &optional buffer
351      This function returns `t' if the buffer BUFFER has been modified
352      since it was last read in from a file or saved, or `nil'
353      otherwise.  If BUFFER is not supplied, the current buffer is
354      tested.
355
356  - Function: set-buffer-modified-p flag
357      This function marks the current buffer as modified if FLAG is
358      non-`nil', or as unmodified if the flag is `nil'.
359
360      Another effect of calling this function is to cause unconditional
361      redisplay of the modeline for the current buffer.  In fact, the
362      function `redraw-modeline' works by doing this:
363
364           (set-buffer-modified-p (buffer-modified-p))
365
366  - Command: not-modified &optional arg
367      This command marks the current buffer as unmodified, and not
368      needing to be saved. (If ARG is non-`nil', the buffer is instead
369      marked as modified.) Don't use this function in programs, since it
370      prints a message in the echo area; use `set-buffer-modified-p'
371      (above) instead.
372
373  - Function: buffer-modified-tick &optional buffer
374      This function returns BUFFER`s modification-count.  This is a
375      counter that increments every time the buffer is modified.  If
376      BUFFER is `nil' (or omitted), the current buffer is used.
377
378 \1f
379 File: lispref.info,  Node: Modification Time,  Next: Read Only Buffers,  Prev: Buffer Modification,  Up: Buffers
380
381 Comparison of Modification Time
382 ===============================
383
384    Suppose that you visit a file and make changes in its buffer, and
385 meanwhile the file itself is changed on disk.  At this point, saving the
386 buffer would overwrite the changes in the file.  Occasionally this may
387 be what you want, but usually it would lose valuable information.
388 XEmacs therefore checks the file's modification time using the functions
389 described below before saving the file.
390
391  - Function: verify-visited-file-modtime buffer
392      This function compares what BUFFER has recorded for the
393      modification time of its visited file against the actual
394      modification time of the file as recorded by the operating system.
395      The two should be the same unless some other process has written
396      the file since XEmacs visited or saved it.
397
398      The function returns `t' if the last actual modification time and
399      XEmacs's recorded modification time are the same, `nil' otherwise.
400
401  - Function: clear-visited-file-modtime
402      This function clears out the record of the last modification time
403      of the file being visited by the current buffer.  As a result, the
404      next attempt to save this buffer will not complain of a
405      discrepancy in file modification times.
406
407      This function is called in `set-visited-file-name' and other
408      exceptional places where the usual test to avoid overwriting a
409      changed file should not be done.
410
411  - Function: visited-file-modtime
412      This function returns the buffer's recorded last file modification
413      time, as a list of the form `(HIGH . LOW)'.  (This is the same
414      format that `file-attributes' uses to return time values; see
415      *Note File Attributes::.)
416
417  - Function: set-visited-file-modtime &optional time
418      This function updates the buffer's record of the last modification
419      time of the visited file, to the value specified by TIME if TIME
420      is not `nil', and otherwise to the last modification time of the
421      visited file.
422
423      If TIME is not `nil', it should have the form `(HIGH . LOW)' or
424      `(HIGH LOW)', in either case containing two integers, each of
425      which holds 16 bits of the time.
426
427      This function is useful if the buffer was not read from the file
428      normally, or if the file itself has been changed for some known
429      benign reason.
430
431  - Function: ask-user-about-supersession-threat filename
432      This function is used to ask a user how to proceed after an
433      attempt to modify an obsolete buffer visiting file FILENAME.  An
434      "obsolete buffer" is an unmodified buffer for which the associated
435      file on disk is newer than the last save-time of the buffer.  This
436      means some other program has probably altered the file.
437
438      Depending on the user's answer, the function may return normally,
439      in which case the modification of the buffer proceeds, or it may
440      signal a `file-supersession' error with data `(FILENAME)', in which
441      case the proposed buffer modification is not allowed.
442
443      This function is called automatically by XEmacs on the proper
444      occasions.  It exists so you can customize XEmacs by redefining it.
445      See the file `userlock.el' for the standard definition.
446
447      See also the file locking mechanism in *Note File Locks::.
448
449 \1f
450 File: lispref.info,  Node: Read Only Buffers,  Next: The Buffer List,  Prev: Modification Time,  Up: Buffers
451
452 Read-Only Buffers
453 =================
454
455    If a buffer is "read-only", then you cannot change its contents,
456 although you may change your view of the contents by scrolling and
457 narrowing.
458
459    Read-only buffers are used in two kinds of situations:
460
461    * A buffer visiting a write-protected file is normally read-only.
462
463      Here, the purpose is to show the user that editing the buffer with
464      the aim of saving it in the file may be futile or undesirable.
465      The user who wants to change the buffer text despite this can do
466      so after clearing the read-only flag with `C-x C-q'.
467
468    * Modes such as Dired and Rmail make buffers read-only when altering
469      the contents with the usual editing commands is probably a mistake.
470
471      The special commands of these modes bind `buffer-read-only' to
472      `nil' (with `let') or bind `inhibit-read-only' to `t' around the
473      places where they change the text.
474
475  - Variable: buffer-read-only
476      This buffer-local variable specifies whether the buffer is
477      read-only.  The buffer is read-only if this variable is non-`nil'.
478
479  - Variable: inhibit-read-only
480      If this variable is non-`nil', then read-only buffers and read-only
481      characters may be modified.  Read-only characters in a buffer are
482      those that have non-`nil' `read-only' properties (either text
483      properties or extent properties).  *Note Extent Properties::, for
484      more information about text properties and extent properties.
485
486      If `inhibit-read-only' is `t', all `read-only' character
487      properties have no effect.  If `inhibit-read-only' is a list, then
488      `read-only' character properties have no effect if they are members
489      of the list (comparison is done with `eq').
490
491  - Command: toggle-read-only
492      This command changes whether the current buffer is read-only.  It
493      is intended for interactive use; don't use it in programs.  At any
494      given point in a program, you should know whether you want the
495      read-only flag on or off; so you can set `buffer-read-only'
496      explicitly to the proper value, `t' or `nil'.
497
498  - Function: barf-if-buffer-read-only
499      This function signals a `buffer-read-only' error if the current
500      buffer is read-only.  *Note Interactive Call::, for another way to
501      signal an error if the current buffer is read-only.
502
503 \1f
504 File: lispref.info,  Node: The Buffer List,  Next: Creating Buffers,  Prev: Read Only Buffers,  Up: Buffers
505
506 The Buffer List
507 ===============
508
509    The "buffer list" is a list of all live buffers.  Creating a buffer
510 adds it to this list, and killing a buffer deletes it.  The order of
511 the buffers in the list is based primarily on how recently each buffer
512 has been displayed in the selected window.  Buffers move to the front
513 of the list when they are selected and to the end when they are buried.
514 Several functions, notably `other-buffer', use this ordering.  A
515 buffer list displayed for the user also follows this order.
516
517    Every frame has its own order for the buffer list.  Switching to a
518 new buffer inside of a particular frame changes the buffer list order
519 for that frame, but does not affect the buffer list order of any other
520 frames.  In addition, there is a global, non-frame buffer list order
521 that is independent of the buffer list orders for any particular frame.
522
523    Note that the different buffer lists all contain the same elements.
524 It is only the order of those elements that is different.
525
526  - Function: buffer-list &optional frame
527      This function returns a list of all buffers, including those whose
528      names begin with a space.  The elements are actual buffers, not
529      their names.  The order of the list is specific to FRAME, which
530      defaults to the current frame.  If FRAME is `t', the global,
531      non-frame ordering is returned instead.
532
533           (buffer-list)
534                => (#<buffer buffers.texi>
535                    #<buffer  *Minibuf-1*> #<buffer buffer.c>
536                    #<buffer *Help*> #<buffer TAGS>)
537           
538           ;; Note that the name of the minibuffer
539           ;;   begins with a space!
540           (mapcar (function buffer-name) (buffer-list))
541               => ("buffers.texi" " *Minibuf-1*"
542                   "buffer.c" "*Help*" "TAGS")
543
544      Buffers appear earlier in the list if they were current more
545      recently.
546
547      This list is a copy of a list used inside XEmacs; modifying it has
548      no effect on the buffers.
549
550  - Function: other-buffer &optional buffer-or-name frame visible-ok
551      This function returns the first buffer in the buffer list other
552      than BUFFER-OR-NAME, in FRAME's ordering for the buffer list.
553      (FRAME defaults to the current frame.  If FRAME is `t', then the
554      global, non-frame ordering is used.) Usually this is the buffer
555      most recently shown in the selected window, aside from
556      BUFFER-OR-NAME.  Buffers are moved to the front of the list when
557      they are selected and to the end when they are buried.  Buffers
558      whose names start with a space are not considered.
559
560      If BUFFER-OR-NAME is not supplied (or if it is not a buffer), then
561      `other-buffer' returns the first buffer on the buffer list that is
562      not visible in any window in a visible frame.
563
564      If the selected frame has a non-`nil' `buffer-predicate' property,
565      then `other-buffer' uses that predicate to decide which buffers to
566      consider.  It calls the predicate once for each buffer, and if the
567      value is `nil', that buffer is ignored.  *Note X Frame
568      Properties::.
569
570      If VISIBLE-OK is `nil', `other-buffer' avoids returning a buffer
571      visible in any window on any visible frame, except as a last
572      resort.   If VISIBLE-OK is non-`nil', then it does not matter
573      whether a buffer is displayed somewhere or not.
574
575      If no suitable buffer exists, the buffer `*scratch*' is returned
576      (and created, if necessary).
577
578      Note that in FSF Emacs 19, there is no FRAME argument, and
579      VISIBLE-OK is the second argument instead of the third.  FSF Emacs
580      19.
581
582  - Command: list-buffers &optional files-only
583      This function displays a listing of the names of existing buffers.
584      It clears the buffer `*Buffer List*', then inserts the listing
585      into that buffer and displays it in a window.  `list-buffers' is
586      intended for interactive use, and is described fully in `The XEmacs
587      Reference Manual'.  It returns `nil'.
588
589  - Command: bury-buffer &optional buffer-or-name
590      This function puts BUFFER-OR-NAME at the end of the buffer list
591      without changing the order of any of the other buffers on the list.
592      This buffer therefore becomes the least desirable candidate for
593      `other-buffer' to return.
594
595      If BUFFER-OR-NAME is `nil' or omitted, this means to bury the
596      current buffer.  In addition, if the buffer is displayed in the
597      selected window, this switches to some other buffer (obtained using
598      `other-buffer') in the selected window.  But if the buffer is
599      displayed in some other window, it remains displayed there.
600
601      If you wish to replace a buffer in all the windows that display
602      it, use `replace-buffer-in-windows'.  *Note Buffers and Windows::.
603
604 \1f
605 File: lispref.info,  Node: Creating Buffers,  Next: Killing Buffers,  Prev: The Buffer List,  Up: Buffers
606
607 Creating Buffers
608 ================
609
610    This section describes the two primitives for creating buffers.
611 `get-buffer-create' creates a buffer if it finds no existing buffer
612 with the specified name; `generate-new-buffer' always creates a new
613 buffer and gives it a unique name.
614
615    Other functions you can use to create buffers include
616 `with-output-to-temp-buffer' (*note Temporary Displays::) and
617 `create-file-buffer' (*note Visiting Files::).  Starting a subprocess
618 can also create a buffer (*note Processes::).
619
620  - Function: get-buffer-create name
621      This function returns a buffer named NAME.  It returns an existing
622      buffer with that name, if one exists; otherwise, it creates a new
623      buffer.  The buffer does not become the current buffer--this
624      function does not change which buffer is current.
625
626      An error is signaled if NAME is not a string.
627
628           (get-buffer-create "foo")
629                => #<buffer foo>
630
631      The major mode for the new buffer is set to Fundamental mode.  The
632      variable `default-major-mode' is handled at a higher level.  *Note
633      Auto Major Mode::.
634
635  - Function: generate-new-buffer name
636      This function returns a newly created, empty buffer, but does not
637      make it current.  If there is no buffer named NAME, then that is
638      the name of the new buffer.  If that name is in use, this function
639      adds suffixes of the form `<N>' to NAME, where N is an integer.
640      It tries successive integers starting with 2 until it finds an
641      available name.
642
643      An error is signaled if NAME is not a string.
644
645           (generate-new-buffer "bar")
646                => #<buffer bar>
647           (generate-new-buffer "bar")
648                => #<buffer bar<2>>
649           (generate-new-buffer "bar")
650                => #<buffer bar<3>>
651
652      The major mode for the new buffer is set to Fundamental mode.  The
653      variable `default-major-mode' is handled at a higher level.  *Note
654      Auto Major Mode::.
655
656      See the related function `generate-new-buffer-name' in *Note
657      Buffer Names::.
658
659 \1f
660 File: lispref.info,  Node: Killing Buffers,  Next: Indirect Buffers,  Prev: Creating Buffers,  Up: Buffers
661
662 Killing Buffers
663 ===============
664
665    "Killing a buffer" makes its name unknown to XEmacs and makes its
666 text space available for other use.
667
668    The buffer object for the buffer that has been killed remains in
669 existence as long as anything refers to it, but it is specially marked
670 so that you cannot make it current or display it.  Killed buffers retain
671 their identity, however; two distinct buffers, when killed, remain
672 distinct according to `eq'.
673
674    If you kill a buffer that is current or displayed in a window, XEmacs
675 automatically selects or displays some other buffer instead.  This means
676 that killing a buffer can in general change the current buffer.
677 Therefore, when you kill a buffer, you should also take the precautions
678 associated with changing the current buffer (unless you happen to know
679 that the buffer being killed isn't current).  *Note Current Buffer::.
680
681    If you kill a buffer that is the base buffer of one or more indirect
682 buffers, the indirect buffers are automatically killed as well.
683
684    The `buffer-name' of a killed buffer is `nil'.  To test whether a
685 buffer has been killed, you can either use this feature or the function
686 `buffer-live-p'.
687
688  - Function: buffer-live-p buffer
689      This function returns `nil' if BUFFER is deleted, and `t'
690      otherwise.
691
692  - Command: kill-buffer buffer-or-name
693      This function kills the buffer BUFFER-OR-NAME, freeing all its
694      memory for use as space for other buffers.  (Emacs version 18 and
695      older was unable to return the memory to the operating system.)
696      It returns `nil'.
697
698      Any processes that have this buffer as the `process-buffer' are
699      sent the `SIGHUP' signal, which normally causes them to terminate.
700      (The basic meaning of `SIGHUP' is that a dialup line has been
701      disconnected.)  *Note Deleting Processes::.
702
703      If the buffer is visiting a file and contains unsaved changes,
704      `kill-buffer' asks the user to confirm before the buffer is killed.
705      It does this even if not called interactively.  To prevent the
706      request for confirmation, clear the modified flag before calling
707      `kill-buffer'.  *Note Buffer Modification::.
708
709      Killing a buffer that is already dead has no effect.
710
711           (kill-buffer "foo.unchanged")
712                => nil
713           (kill-buffer "foo.changed")
714           
715           ---------- Buffer: Minibuffer ----------
716           Buffer foo.changed modified; kill anyway? (yes or no) yes
717           ---------- Buffer: Minibuffer ----------
718           
719                => nil
720
721  - Variable: kill-buffer-query-functions
722      After confirming unsaved changes, `kill-buffer' calls the functions
723      in the list `kill-buffer-query-functions', in order of appearance,
724      with no arguments.  The buffer being killed is the current buffer
725      when they are called.  The idea is that these functions ask for
726      confirmation from the user for various nonstandard reasons.  If
727      any of them returns `nil', `kill-buffer' spares the buffer's life.
728
729  - Variable: kill-buffer-hook
730      This is a normal hook run by `kill-buffer' after asking all the
731      questions it is going to ask, just before actually killing the
732      buffer.  The buffer to be killed is current when the hook
733      functions run.  *Note Hooks::.
734
735  - Variable: buffer-offer-save
736      This variable, if non-`nil' in a particular buffer, tells
737      `save-buffers-kill-emacs' and `save-some-buffers' to offer to save
738      that buffer, just as they offer to save file-visiting buffers.  The
739      variable `buffer-offer-save' automatically becomes buffer-local
740      when set for any reason.  *Note Buffer-Local Variables::.
741
742 \1f
743 File: lispref.info,  Node: Indirect Buffers,  Prev: Killing Buffers,  Up: Buffers
744
745 Indirect Buffers
746 ================
747
748    An "indirect buffer" shares the text of some other buffer, which is
749 called the "base buffer" of the indirect buffer.  In some ways it is
750 the analogue, for buffers, of a symbolic link among files.  The base
751 buffer may not itself be an indirect buffer.  One base buffer may have
752 several "indirect children".
753
754    The text of the indirect buffer is always identical to the text of
755 its base buffer; changes made by editing either one are visible
756 immediately in the other.
757
758    But in all other respects, the indirect buffer and its base buffer
759 are completely separate.  They have different names, different values of
760 point and mark, different narrowing, different markers and extents
761 (though inserting or deleting text in either buffer relocates the
762 markers and extents for both), different major modes, and different
763 local variables.  Unlike in FSF Emacs, XEmacs indirect buffers do not
764 automatically share text properties among themselves and their base
765 buffer.
766
767    An indirect buffer cannot visit a file, but its base buffer can.  If
768 you try to save the indirect buffer, that actually works by saving the
769 base buffer.
770
771    Killing an indirect buffer has no effect on its base buffer.  Killing
772 the base buffer kills all its indirect children.
773
774  - Command: make-indirect-buffer base-buffer name
775      This creates an indirect buffer named NAME whose base buffer is
776      BASE-BUFFER.  The argument BASE-BUFFER may be a buffer or a string.
777
778      If BASE-BUFFER is an indirect buffer, its base buffer is used as
779      the base for the new buffer.
780
781           (make-indirect-buffer "*scratch*" "indirect")
782                => #<buffer "indirect">
783
784  - Function: buffer-base-buffer &optional buffer
785      This function returns the base buffer of BUFFER.  If BUFFER is not
786      indirect, the value is `nil'.  Otherwise, the value is another
787      buffer, which is never an indirect buffer.  If BUFFER is not
788      supplied, it defaults to the current buffer.
789
790           (buffer-base-buffer (get-buffer "indirect"))
791                => #<buffer "*scratch*">
792
793  - Function: buffer-indirect-children &optional buffer
794      This function returns a list of all indirect buffers whose base
795      buffer is BUFFER.  If BUFFER is indirect, the return value will
796      always be nil; see `make-indirect-buffer'.  If BUFFER is not
797      supplied, it defaults to the current buffer.
798
799           (buffer-indirect-children (get-buffer "*scratch*"))
800                => (#<buffer "indirect">)
801
802 \1f
803 File: lispref.info,  Node: Windows,  Next: Frames,  Prev: Buffers,  Up: Top
804
805 Windows
806 *******
807
808    This chapter describes most of the functions and variables related to
809 Emacs windows.  See *Note Display::, for information on how text is
810 displayed in windows.
811
812 * Menu:
813
814 * Basic Windows::          Basic information on using windows.
815 * Splitting Windows::      Splitting one window into two windows.
816 * Deleting Windows::       Deleting a window gives its space to other windows.
817 * Selecting Windows::      The selected window is the one that you edit in.
818 * Cyclic Window Ordering:: Moving around the existing windows.
819 * Buffers and Windows::    Each window displays the contents of a buffer.
820 * Displaying Buffers::     Higher-lever functions for displaying a buffer
821                              and choosing a window for it.
822 * Choosing Window::        How to choose a window for displaying a buffer.
823 * Window Point::           Each window has its own location of point.
824 * Window Start::           The display-start position controls which text
825                              is on-screen in the window.
826 * Vertical Scrolling::     Moving text up and down in the window.
827 * Horizontal Scrolling::   Moving text sideways on the window.
828 * Size of Window::         Accessing the size of a window.
829 * Position of Window::     Accessing the position of a window.
830 * Resizing Windows::       Changing the size of a window.
831 * Window Configurations::  Saving and restoring the state of the screen.
832
833 \1f
834 File: lispref.info,  Node: Basic Windows,  Next: Splitting Windows,  Up: Windows
835
836 Basic Concepts of Emacs Windows
837 ===============================
838
839    A "window" in XEmacs is the physical area of the screen in which a
840 buffer is displayed.  The term is also used to refer to a Lisp object
841 that represents that screen area in XEmacs Lisp.  It should be clear
842 from the context which is meant.
843
844    XEmacs groups windows into frames.  A frame represents an area of
845 screen available for XEmacs to use.  Each frame always contains at least
846 one window, but you can subdivide it vertically or horizontally into
847 multiple nonoverlapping Emacs windows.
848
849    In each frame, at any time, one and only one window is designated as
850 "selected within the frame".  The frame's cursor appears in that
851 window.  At ant time, one frame is the selected frame; and the window
852 selected within that frame is "the selected window".  The selected
853 window's buffer is usually the current buffer (except when `set-buffer'
854 has been used).  *Note Current Buffer::.
855
856    For practical purposes, a window exists only while it is displayed in
857 a frame.  Once removed from the frame, the window is effectively deleted
858 and should not be used, _even though there may still be references to
859 it_ from other Lisp objects.  Restoring a saved window configuration is
860 the only way for a window no longer on the screen to come back to life.
861 (*Note Deleting Windows::.)
862
863    Each window has the following attributes:
864
865    * containing frame
866
867    * window height
868
869    * window width
870
871    * window edges with respect to the frame or screen
872
873    * the buffer it displays
874
875    * position within the buffer at the upper left of the window
876
877    * amount of horizontal scrolling, in columns
878
879    * point
880
881    * the mark
882
883    * how recently the window was selected
884
885    Users create multiple windows so they can look at several buffers at
886 once.  Lisp libraries use multiple windows for a variety of reasons, but
887 most often to display related information.  In Rmail, for example, you
888 can move through a summary buffer in one window while the other window
889 shows messages one at a time as they are reached.
890
891    The meaning of "window" in XEmacs is similar to what it means in the
892 context of general-purpose window systems such as X, but not identical.
893 The X Window System places X windows on the screen; XEmacs uses one or
894 more X windows as frames, and subdivides them into Emacs windows.  When
895 you use XEmacs on a character-only terminal, XEmacs treats the whole
896 terminal screen as one frame.
897
898    Most window systems support arbitrarily located overlapping windows.
899 In contrast, Emacs windows are "tiled"; they never overlap, and
900 together they fill the whole screen or frame.  Because of the way in
901 which XEmacs creates new windows and resizes them, you can't create
902 every conceivable tiling of windows on an Emacs frame.  *Note Splitting
903 Windows::, and *Note Size of Window::.
904
905    *Note Display::, for information on how the contents of the window's
906 buffer are displayed in the window.
907
908  - Function: windowp object
909      This function returns `t' if OBJECT is a window.
910
911 \1f
912 File: lispref.info,  Node: Splitting Windows,  Next: Deleting Windows,  Prev: Basic Windows,  Up: Windows
913
914 Splitting Windows
915 =================
916
917    The functions described here are the primitives used to split a
918 window into two windows.  Two higher level functions sometimes split a
919 window, but not always: `pop-to-buffer' and `display-buffer' (*note
920 Displaying Buffers::).
921
922    The functions described here do not accept a buffer as an argument.
923 The two "halves" of the split window initially display the same buffer
924 previously visible in the window that was split.
925
926  - Function: one-window-p &optional no-mini all-frames
927      This function returns non-`nil' if there is only one window.  The
928      argument NO-MINI, if non-`nil', means don't count the minibuffer
929      even if it is active; otherwise, the minibuffer window is
930      included, if active, in the total number of windows which is
931      compared against one.
932
933      The argument ALL-FRAME controls which set of windows are counted.
934         * If it is `nil' or omitted, then count only the selected
935           frame, plus the minibuffer it uses (which may be on another
936           frame).
937
938         * If it is `t', then windows on all frames that currently exist
939           (including invisible and iconified frames) are counted.
940
941         * If it is the symbol `visible', then windows on all visible
942           frames are counted.
943
944         * If it is the number 0, then windows on all visible and
945           iconified frames are counted.
946
947         * If it is any other value, then precisely the windows in
948           WINDOW's frame are counted, excluding the minibuffer in use
949           if it lies in some other frame.
950
951  - Command: split-window &optional window size horizontal
952      This function splits WINDOW into two windows.  The original window
953      WINDOW remains the selected window, but occupies only part of its
954      former screen area.  The rest is occupied by a newly created
955      window which is returned as the value of this function.
956
957      If HORIZONTAL is non-`nil', then WINDOW splits into two side by
958      side windows.  The original window WINDOW keeps the leftmost SIZE
959      columns, and gives the rest of the columns to the new window.
960      Otherwise, it splits into windows one above the other, and WINDOW
961      keeps the upper SIZE lines and gives the rest of the lines to the
962      new window.  The original window is therefore the left-hand or
963      upper of the two, and the new window is the right-hand or lower.
964
965      If WINDOW is omitted or `nil', then the selected window is split.
966      If SIZE is omitted or `nil', then WINDOW is divided evenly into
967      two parts.  (If there is an odd line, it is allocated to the new
968      window.)  When `split-window' is called interactively, all its
969      arguments are `nil'.
970
971      The following example starts with one window on a frame that is 50
972      lines high by 80 columns wide; then the window is split.
973
974           (setq w (selected-window))
975                => #<window 8 on windows.texi>
976           (window-edges)          ; Edges in order:
977                => (0 0 80 50)     ;   left-top-right-bottom
978           
979           ;; Returns window created
980           (setq w2 (split-window w 15))
981                => #<window 28 on windows.texi>
982           (window-edges w2)
983                => (0 15 80 50)    ; Bottom window;
984                                   ;   top is line 15
985           (window-edges w)
986                => (0 0 80 15)     ; Top window
987
988      The frame looks like this:
989
990                    __________
991                   |          |  line 0
992                   |    w     |
993                   |__________|
994                   |          |  line 15
995                   |    w2    |
996                   |__________|
997                                 line 50
998            column 0   column 80
999
1000      Next, the top window is split horizontally:
1001
1002           (setq w3 (split-window w 35 t))
1003                => #<window 32 on windows.texi>
1004           (window-edges w3)
1005                => (35 0 80 15)  ; Left edge at column 35
1006           (window-edges w)
1007                => (0 0 35 15)   ; Right edge at column 35
1008           (window-edges w2)
1009                => (0 15 80 50)  ; Bottom window unchanged
1010
1011      Now, the screen looks like this:
1012
1013                column 35
1014                    __________
1015                   |   |      |  line 0
1016                   | w |  w3  |
1017                   |___|______|
1018                   |          |  line 15
1019                   |    w2    |
1020                   |__________|
1021                                 line 50
1022            column 0   column 80
1023
1024      Normally, Emacs indicates the border between two side-by-side
1025      windows with a scroll bar (*note Scroll Bars: X Frame Properties.)
1026      or `|' characters.  The display table can specify alternative
1027      border characters; see *Note Display Tables::.
1028
1029  - Command: split-window-vertically &optional size
1030      This function splits the selected window into two windows, one
1031      above the other, leaving the selected window with SIZE lines.
1032
1033      This function is simply an interface to `split-windows'.  Here is
1034      the complete function definition for it:
1035
1036           (defun split-window-vertically (&optional arg)
1037             "Split current window into two windows, one above the other."
1038             (interactive "P")
1039             (split-window nil (and arg (prefix-numeric-value arg))))
1040
1041  - Command: split-window-horizontally &optional size
1042      This function splits the selected window into two windows
1043      side-by-side, leaving the selected window with SIZE columns.
1044
1045      This function is simply an interface to `split-windows'.  Here is
1046      the complete definition for `split-window-horizontally' (except for
1047      part of the documentation string):
1048
1049           (defun split-window-horizontally (&optional arg)
1050             "Split selected window into two windows, side by side..."
1051             (interactive "P")
1052             (split-window nil (and arg (prefix-numeric-value arg)) t))
1053
1054  - Function: one-window-p &optional no-mini all-frames
1055      This function returns non-`nil' if there is only one window.  The
1056      argument NO-MINI, if non-`nil', means don't count the minibuffer
1057      even if it is active; otherwise, the minibuffer window is
1058      included, if active, in the total number of windows, which is
1059      compared against one.
1060
1061      The argument ALL-FRAMES specifies which frames to consider.  Here
1062      are the possible values and their meanings:
1063
1064     `nil'
1065           Count the windows in the selected frame, plus the minibuffer
1066           used by that frame even if it lies in some other frame.
1067
1068     `t'
1069           Count all windows in all existing frames.
1070
1071     `visible'
1072           Count all windows in all visible frames.
1073
1074     0
1075           Count all windows in all visible or iconified frames.
1076
1077     anything else
1078           Count precisely the windows in the selected frame, and no
1079           others.
1080
1081 \1f
1082 File: lispref.info,  Node: Deleting Windows,  Next: Selecting Windows,  Prev: Splitting Windows,  Up: Windows
1083
1084 Deleting Windows
1085 ================
1086
1087    A window remains visible on its frame unless you "delete" it by
1088 calling certain functions that delete windows.  A deleted window cannot
1089 appear on the screen, but continues to exist as a Lisp object until
1090 there are no references to it.  There is no way to cancel the deletion
1091 of a window aside from restoring a saved window configuration (*note
1092 Window Configurations::).  Restoring a window configuration also
1093 deletes any windows that aren't part of that configuration.
1094
1095    When you delete a window, the space it took up is given to one
1096 adjacent sibling.  (In Emacs version 18, the space was divided evenly
1097 among all the siblings.)
1098
1099  - Function: window-live-p window
1100      This function returns `nil' if WINDOW is deleted, and `t'
1101      otherwise.
1102
1103      *Warning:* Erroneous information or fatal errors may result from
1104      using a deleted window as if it were live.
1105
1106  - Command: delete-window &optional window
1107      This function removes WINDOW from the display.  If WINDOW is
1108      omitted, then the selected window is deleted.  An error is signaled
1109      if there is only one window when `delete-window' is called.
1110
1111      This function returns `nil'.
1112
1113      When `delete-window' is called interactively, WINDOW defaults to
1114      the selected window.
1115
1116  - Command: delete-other-windows &optional window
1117      This function makes WINDOW the only window on its frame, by
1118      deleting the other windows in that frame.  If WINDOW is omitted or
1119      `nil', then the selected window is used by default.
1120
1121      The result is `nil'.
1122
1123  - Command: delete-windows-on buffer &optional frame
1124      This function deletes all windows showing BUFFER.  If there are no
1125      windows showing BUFFER, it does nothing.
1126
1127      `delete-windows-on' operates frame by frame.  If a frame has
1128      several windows showing different buffers, then those showing
1129      BUFFER are removed, and the others expand to fill the space.  If
1130      all windows in some frame are showing BUFFER (including the case
1131      where there is only one window), then the frame reverts to having a
1132      single window showing another buffer chosen with `other-buffer'.
1133      *Note The Buffer List::.
1134
1135      The argument FRAME controls which frames to operate on:
1136
1137         * If it is `nil', operate on the selected frame.
1138
1139         * If it is `t', operate on all frames.
1140
1141         * If it is `visible', operate on all visible frames.
1142
1143         * 0 If it is 0, operate on all visible or iconified frames.
1144
1145         * If it is a frame, operate on that frame.
1146
1147      This function always returns `nil'.
1148