Merge r21-2-24-utf-2000-0_13-0.
[chise/xemacs-chise.git] / info / lispref.info-24
1 This is ../info/lispref.info, produced by makeinfo version 3.12s 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: Files and MS-DOS,  Prev: Format Conversion,  Up: Files
54
55 Files and MS-DOS
56 ================
57
58    Emacs on MS-DOS makes a distinction between text files and binary
59 files.  This is necessary because ordinary text files on MS-DOS use a
60 two character sequence between lines: carriage-return and linefeed
61 (CRLF).  Emacs expects just a newline character (a linefeed) between
62 lines.  When Emacs reads or writes a text file on MS-DOS, it needs to
63 convert the line separators.  This means it needs to know which files
64 are text files and which are binary.  It makes this decision when
65 visiting a file, and records the decision in the variable
66 `buffer-file-type' for use when the file is saved.
67
68    *Note MS-DOS Subprocesses::, for a related feature for subprocesses.
69
70  - Variable: buffer-file-type
71      This variable, automatically local in each buffer, records the
72      file type of the buffer's visited file.  The value is `nil' for
73      text, `t' for binary.
74
75  - Function: find-buffer-file-type filename
76      This function determines whether file FILENAME is a text file or a
77      binary file.  It returns `nil' for text, `t' for binary.
78
79  - User Option: file-name-buffer-file-type-alist
80      This variable holds an alist for distinguishing text files from
81      binary files.  Each element has the form (REGEXP . TYPE), where
82      REGEXP is matched against the file name, and TYPE may be is `nil'
83      for text, `t' for binary, or a function to call to compute which.
84      If it is a function, then it is called with a single argument (the
85      file name) and should return `t' or `nil'.
86
87  - User Option: default-buffer-file-type
88      This variable specifies the default file type for files whose names
89      don't indicate anything in particular.  Its value should be `nil'
90      for text, or `t' for binary.
91
92  - Command: find-file-text filename
93      Like `find-file', but treat the file as text regardless of its
94      name.
95
96  - Command: find-file-binary filename
97      Like `find-file', but treat the file as binary regardless of its
98      name.
99
100 \1f
101 File: lispref.info,  Node: Backups and Auto-Saving,  Next: Buffers,  Prev: Files,  Up: Top
102
103 Backups and Auto-Saving
104 ***********************
105
106    Backup files and auto-save files are two methods by which XEmacs
107 tries to protect the user from the consequences of crashes or of the
108 user's own errors.  Auto-saving preserves the text from earlier in the
109 current editing session; backup files preserve file contents prior to
110 the current session.
111
112 * Menu:
113
114 * Backup Files::   How backup files are made; how their names are chosen.
115 * Auto-Saving::    How auto-save files are made; how their names are chosen.
116 * Reverting::      `revert-buffer', and how to customize what it does.
117
118 \1f
119 File: lispref.info,  Node: Backup Files,  Next: Auto-Saving,  Up: Backups and Auto-Saving
120
121 Backup Files
122 ============
123
124    A "backup file" is a copy of the old contents of a file you are
125 editing.  XEmacs makes a backup file the first time you save a buffer
126 into its visited file.  Normally, this means that the backup file
127 contains the contents of the file as it was before the current editing
128 session.  The contents of the backup file normally remain unchanged once
129 it exists.
130
131    Backups are usually made by renaming the visited file to a new name.
132 Optionally, you can specify that backup files should be made by copying
133 the visited file.  This choice makes a difference for files with
134 multiple names; it also can affect whether the edited file remains owned
135 by the original owner or becomes owned by the user editing it.
136
137    By default, XEmacs makes a single backup file for each file edited.
138 You can alternatively request numbered backups; then each new backup
139 file gets a new name.  You can delete old numbered backups when you
140 don't want them any more, or XEmacs can delete them automatically.
141
142 * Menu:
143
144 * Making Backups::     How XEmacs makes backup files, and when.
145 * Rename or Copy::     Two alternatives: renaming the old file or copying it.
146 * Numbered Backups::   Keeping multiple backups for each source file.
147 * Backup Names::       How backup file names are computed; customization.
148
149 \1f
150 File: lispref.info,  Node: Making Backups,  Next: Rename or Copy,  Up: Backup Files
151
152 Making Backup Files
153 -------------------
154
155  - Function: backup-buffer
156      This function makes a backup of the file visited by the current
157      buffer, if appropriate.  It is called by `save-buffer' before
158      saving the buffer the first time.
159
160  - Variable: buffer-backed-up
161      This buffer-local variable indicates whether this buffer's file has
162      been backed up on account of this buffer.  If it is non-`nil', then
163      the backup file has been written.  Otherwise, the file should be
164      backed up when it is next saved (if backups are enabled).  This is
165      a permanent local; `kill-local-variables' does not alter it.
166
167  - User Option: make-backup-files
168      This variable determines whether or not to make backup files.  If
169      it is non-`nil', then XEmacs creates a backup of each file when it
170      is saved for the first time--provided that `backup-inhibited' is
171      `nil' (see below).
172
173      The following example shows how to change the `make-backup-files'
174      variable only in the `RMAIL' buffer and not elsewhere.  Setting it
175      `nil' stops XEmacs from making backups of the `RMAIL' file, which
176      may save disk space.  (You would put this code in your `.emacs'
177      file.)
178
179           (add-hook 'rmail-mode-hook
180                     (function (lambda ()
181                                 (make-local-variable
182                                  'make-backup-files)
183                                 (setq make-backup-files nil))))
184
185  - Variable: backup-enable-predicate
186      This variable's value is a function to be called on certain
187      occasions to decide whether a file should have backup files.  The
188      function receives one argument, a file name to consider.  If the
189      function returns `nil', backups are disabled for that file.
190      Otherwise, the other variables in this section say whether and how
191      to make backups.
192
193      The default value is this:
194
195           (lambda (name)
196             (or (< (length name) 5)
197                 (not (string-equal "/tmp/"
198                                    (substring name 0 5)))))
199
200  - Variable: backup-inhibited
201      If this variable is non-`nil', backups are inhibited.  It records
202      the result of testing `backup-enable-predicate' on the visited file
203      name.  It can also coherently be used by other mechanisms that
204      inhibit backups based on which file is visited.  For example, VC
205      sets this variable non-`nil' to prevent making backups for files
206      managed with a version control system.
207
208      This is a permanent local, so that changing the major mode does
209      not lose its value.  Major modes should not set this
210      variable--they should set `make-backup-files' instead.
211
212 \1f
213 File: lispref.info,  Node: Rename or Copy,  Next: Numbered Backups,  Prev: Making Backups,  Up: Backup Files
214
215 Backup by Renaming or by Copying?
216 ---------------------------------
217
218    There are two ways that XEmacs can make a backup file:
219
220    * XEmacs can rename the original file so that it becomes a backup
221      file, and then write the buffer being saved into a new file.
222      After this procedure, any other names (i.e., hard links) of the
223      original file now refer to the backup file.  The new file is owned
224      by the user doing the editing, and its group is the default for
225      new files written by the user in that directory.
226
227    * XEmacs can copy the original file into a backup file, and then
228      overwrite the original file with new contents.  After this
229      procedure, any other names (i.e., hard links) of the original file
230      still refer to the current version of the file.  The file's owner
231      and group will be unchanged.
232
233    The first method, renaming, is the default.
234
235    The variable `backup-by-copying', if non-`nil', says to use the
236 second method, which is to copy the original file and overwrite it with
237 the new buffer contents.  The variable `file-precious-flag', if
238 non-`nil', also has this effect (as a sideline of its main
239 significance).  *Note Saving Buffers::.
240
241  - Variable: backup-by-copying
242      If this variable is non-`nil', XEmacs always makes backup files by
243      copying.
244
245    The following two variables, when non-`nil', cause the second method
246 to be used in certain special cases.  They have no effect on the
247 treatment of files that don't fall into the special cases.
248
249  - Variable: backup-by-copying-when-linked
250      If this variable is non-`nil', XEmacs makes backups by copying for
251      files with multiple names (hard links).
252
253      This variable is significant only if `backup-by-copying' is `nil',
254      since copying is always used when that variable is non-`nil'.
255
256  - Variable: backup-by-copying-when-mismatch
257      If this variable is non-`nil', XEmacs makes backups by copying in
258      cases where renaming would change either the owner or the group of
259      the file.
260
261      The value has no effect when renaming would not alter the owner or
262      group of the file; that is, for files which are owned by the user
263      and whose group matches the default for a new file created there
264      by the user.
265
266      This variable is significant only if `backup-by-copying' is `nil',
267      since copying is always used when that variable is non-`nil'.
268
269 \1f
270 File: lispref.info,  Node: Numbered Backups,  Next: Backup Names,  Prev: Rename or Copy,  Up: Backup Files
271
272 Making and Deleting Numbered Backup Files
273 -----------------------------------------
274
275    If a file's name is `foo', the names of its numbered backup versions
276 are `foo.~V~', for various integers V, like this: `foo.~1~', `foo.~2~',
277 `foo.~3~', ..., `foo.~259~', and so on.
278
279  - User Option: version-control
280      This variable controls whether to make a single non-numbered backup
281      file or multiple numbered backups.
282
283     `nil'
284           Make numbered backups if the visited file already has
285           numbered backups; otherwise, do not.
286
287     `never'
288           Do not make numbered backups.
289
290     ANYTHING ELSE
291           Make numbered backups.
292
293    The use of numbered backups ultimately leads to a large number of
294 backup versions, which must then be deleted.  XEmacs can do this
295 automatically or it can ask the user whether to delete them.
296
297  - User Option: kept-new-versions
298      The value of this variable is the number of newest versions to keep
299      when a new numbered backup is made.  The newly made backup is
300      included in the count.  The default value is 2.
301
302  - User Option: kept-old-versions
303      The value of this variable is the number of oldest versions to keep
304      when a new numbered backup is made.  The default value is 2.
305
306    If there are backups numbered 1, 2, 3, 5, and 7, and both of these
307 variables have the value 2, then the backups numbered 1 and 2 are kept
308 as old versions and those numbered 5 and 7 are kept as new versions;
309 backup version 3 is excess.  The function `find-backup-file-name'
310 (*note Backup Names::) is responsible for determining which backup
311 versions to delete, but does not delete them itself.
312
313  - User Option: trim-versions-without-asking
314      If this variable is non-`nil', then saving a file deletes excess
315      backup versions silently.  Otherwise, it asks the user whether to
316      delete them.
317
318  - User Option: dired-kept-versions
319      This variable specifies how many of the newest backup versions to
320      keep in the Dired command `.' (`dired-clean-directory').  That's
321      the same thing `kept-new-versions' specifies when you make a new
322      backup file.  The default value is 2.
323
324 \1f
325 File: lispref.info,  Node: Backup Names,  Prev: Numbered Backups,  Up: Backup Files
326
327 Naming Backup Files
328 -------------------
329
330    The functions in this section are documented mainly because you can
331 customize the naming conventions for backup files by redefining them.
332 If you change one, you probably need to change the rest.
333
334  - Function: backup-file-name-p filename
335      This function returns a non-`nil' value if FILENAME is a possible
336      name for a backup file.  A file with the name FILENAME need not
337      exist; the function just checks the name.
338
339           (backup-file-name-p "foo")
340                => nil
341           (backup-file-name-p "foo~")
342                => 3
343
344      The standard definition of this function is as follows:
345
346           (defun backup-file-name-p (file)
347             "Return non-nil if FILE is a backup file \
348           name (numeric or not)..."
349             (string-match "~$" file))
350
351      Thus, the function returns a non-`nil' value if the file name ends
352      with a `~'.  (We use a backslash to split the documentation
353      string's first line into two lines in the text, but produce just
354      one line in the string itself.)
355
356      This simple expression is placed in a separate function to make it
357      easy to redefine for customization.
358
359  - Function: make-backup-file-name filename
360      This function returns a string that is the name to use for a
361      non-numbered backup file for file FILENAME.  On Unix, this is just
362      FILENAME with a tilde appended.
363
364      The standard definition of this function is as follows:
365
366           (defun make-backup-file-name (file)
367             "Create the non-numeric backup file name for FILE.
368           ..."
369             (concat file "~"))
370
371      You can change the backup-file naming convention by redefining this
372      function.  The following example redefines `make-backup-file-name'
373      to prepend a `.' in addition to appending a tilde:
374
375           (defun make-backup-file-name (filename)
376             (concat "." filename "~"))
377           
378           (make-backup-file-name "backups.texi")
379                => ".backups.texi~"
380
381  - Function: find-backup-file-name filename
382      This function computes the file name for a new backup file for
383      FILENAME.  It may also propose certain existing backup files for
384      deletion.  `find-backup-file-name' returns a list whose CAR is the
385      name for the new backup file and whose CDR is a list of backup
386      files whose deletion is proposed.
387
388      Two variables, `kept-old-versions' and `kept-new-versions',
389      determine which backup versions should be kept.  This function
390      keeps those versions by excluding them from the CDR of the value.
391      *Note Numbered Backups::.
392
393      In this example, the value says that `~rms/foo.~5~' is the name to
394      use for the new backup file, and `~rms/foo.~3~' is an "excess"
395      version that the caller should consider deleting now.
396
397           (find-backup-file-name "~rms/foo")
398                => ("~rms/foo.~5~" "~rms/foo.~3~")
399
400  - Function: file-newest-backup filename
401      This function returns the name of the most recent backup file for
402      FILENAME, or `nil' if that file has no backup files.
403
404      Some file comparison commands use this function so that they can
405      automatically compare a file with its most recent backup.
406
407 \1f
408 File: lispref.info,  Node: Auto-Saving,  Next: Reverting,  Prev: Backup Files,  Up: Backups and Auto-Saving
409
410 Auto-Saving
411 ===========
412
413    XEmacs periodically saves all files that you are visiting; this is
414 called "auto-saving".  Auto-saving prevents you from losing more than a
415 limited amount of work if the system crashes.  By default, auto-saves
416 happen every 300 keystrokes, or after around 30 seconds of idle time.
417 *Note Auto-Save: (emacs)Auto-Save, for information on auto-save for
418 users.  Here we describe the functions used to implement auto-saving
419 and the variables that control them.
420
421  - Variable: buffer-auto-save-file-name
422      This buffer-local variable is the name of the file used for
423      auto-saving the current buffer.  It is `nil' if the buffer should
424      not be auto-saved.
425
426           buffer-auto-save-file-name
427           => "/xcssun/users/rms/lewis/#files.texi#"
428
429  - Command: auto-save-mode arg
430      When used interactively without an argument, this command is a
431      toggle switch: it turns on auto-saving of the current buffer if it
432      is off, and vice-versa.  With an argument ARG, the command turns
433      auto-saving on if the value of ARG is `t', a nonempty list, or a
434      positive integer.  Otherwise, it turns auto-saving off.
435
436  - Function: auto-save-file-name-p filename
437      This function returns a non-`nil' value if FILENAME is a string
438      that could be the name of an auto-save file.  It works based on
439      knowledge of the naming convention for auto-save files: a name that
440      begins and ends with hash marks (`#') is a possible auto-save file
441      name.  The argument FILENAME should not contain a directory part.
442
443           (make-auto-save-file-name)
444                => "/xcssun/users/rms/lewis/#files.texi#"
445           (auto-save-file-name-p "#files.texi#")
446                => 0
447           (auto-save-file-name-p "files.texi")
448                => nil
449
450      The standard definition of this function is as follows:
451
452           (defun auto-save-file-name-p (filename)
453             "Return non-nil if FILENAME can be yielded by..."
454             (string-match "^#.*#$" filename))
455
456      This function exists so that you can customize it if you wish to
457      change the naming convention for auto-save files.  If you redefine
458      it, be sure to redefine the function `make-auto-save-file-name'
459      correspondingly.
460
461  - Function: make-auto-save-file-name
462      This function returns the file name to use for auto-saving the
463      current buffer.  This is just the file name with hash marks (`#')
464      appended and prepended to it.  This function does not look at the
465      variable `auto-save-visited-file-name' (described below); you
466      should check that before calling this function.
467
468           (make-auto-save-file-name)
469                => "/xcssun/users/rms/lewis/#backup.texi#"
470
471      The standard definition of this function is as follows:
472
473           (defun make-auto-save-file-name ()
474             "Return file name to use for auto-saves \
475           of current buffer.
476           ..."
477             (if buffer-file-name
478                 (concat
479                  (file-name-directory buffer-file-name)
480                  "#"
481                  (file-name-nondirectory buffer-file-name)
482                  "#")
483               (expand-file-name
484                (concat "#%" (buffer-name) "#"))))
485
486      This exists as a separate function so that you can redefine it to
487      customize the naming convention for auto-save files.  Be sure to
488      change `auto-save-file-name-p' in a corresponding way.
489
490  - Variable: auto-save-visited-file-name
491      If this variable is non-`nil', XEmacs auto-saves buffers in the
492      files they are visiting.  That is, the auto-save is done in the
493      same file that you are editing.  Normally, this variable is `nil',
494      so auto-save files have distinct names that are created by
495      `make-auto-save-file-name'.
496
497      When you change the value of this variable, the value does not take
498      effect until the next time auto-save mode is reenabled in any given
499      buffer.  If auto-save mode is already enabled, auto-saves continue
500      to go in the same file name until `auto-save-mode' is called again.
501
502  - Function: recent-auto-save-p
503      This function returns `t' if the current buffer has been
504      auto-saved since the last time it was read in or saved.
505
506  - Function: set-buffer-auto-saved
507      This function marks the current buffer as auto-saved.  The buffer
508      will not be auto-saved again until the buffer text is changed
509      again.  The function returns `nil'.
510
511  - User Option: auto-save-interval
512      The value of this variable is the number of characters that XEmacs
513      reads from the keyboard between auto-saves.  Each time this many
514      more characters are read, auto-saving is done for all buffers in
515      which it is enabled.
516
517  - User Option: auto-save-timeout
518      The value of this variable is the number of seconds of idle time
519      that should cause auto-saving.  Each time the user pauses for this
520      long, XEmacs auto-saves any buffers that need it.  (Actually, the
521      specified timeout is multiplied by a factor depending on the size
522      of the current buffer.)
523
524  - Variable: auto-save-hook
525      This normal hook is run whenever an auto-save is about to happen.
526
527  - User Option: auto-save-default
528      If this variable is non-`nil', buffers that are visiting files
529      have auto-saving enabled by default.  Otherwise, they do not.
530
531  - Command: do-auto-save &optional no-message current-only
532      This function auto-saves all buffers that need to be auto-saved.
533      It saves all buffers for which auto-saving is enabled and that
534      have been changed since the previous auto-save.
535
536      Normally, if any buffers are auto-saved, a message that says
537      `Auto-saving...' is displayed in the echo area while auto-saving is
538      going on.  However, if NO-MESSAGE is non-`nil', the message is
539      inhibited.
540
541      If CURRENT-ONLY is non-`nil', only the current buffer is
542      auto-saved.
543
544  - Function: delete-auto-save-file-if-necessary
545      This function deletes the current buffer's auto-save file if
546      `delete-auto-save-files' is non-`nil'.  It is called every time a
547      buffer is saved.
548
549  - Variable: delete-auto-save-files
550      This variable is used by the function
551      `delete-auto-save-file-if-necessary'.  If it is non-`nil', Emacs
552      deletes auto-save files when a true save is done (in the visited
553      file).  This saves disk space and unclutters your directory.
554
555  - Function: rename-auto-save-file
556      This function adjusts the current buffer's auto-save file name if
557      the visited file name has changed.  It also renames an existing
558      auto-save file.  If the visited file name has not changed, this
559      function does nothing.
560
561  - Variable: buffer-saved-size
562      The value of this buffer-local variable is the length of the
563      current buffer as of the last time it was read in, saved, or
564      auto-saved.  This is used to detect a substantial decrease in
565      size, and turn off auto-saving in response.
566
567      If it is -1, that means auto-saving is temporarily shut off in this
568      buffer due to a substantial deletion.  Explicitly saving the buffer
569      stores a positive value in this variable, thus reenabling
570      auto-saving.  Turning auto-save mode off or on also alters this
571      variable.
572
573  - Variable: auto-save-list-file-name
574      This variable (if non-`nil') specifies a file for recording the
575      names of all the auto-save files.  Each time XEmacs does
576      auto-saving, it writes two lines into this file for each buffer
577      that has auto-saving enabled.  The first line gives the name of
578      the visited file (it's empty if the buffer has none), and the
579      second gives the name of the auto-save file.
580
581      If XEmacs exits normally, it deletes this file.  If XEmacs
582      crashes, you can look in the file to find all the auto-save files
583      that might contain work that was otherwise lost.  The
584      `recover-session' command uses these files.
585
586      The default name for this file is in your home directory and
587      starts with `.saves-'.  It also contains the XEmacs process ID and
588      the host name.
589
590 \1f
591 File: lispref.info,  Node: Reverting,  Prev: Auto-Saving,  Up: Backups and Auto-Saving
592
593 Reverting
594 =========
595
596    If you have made extensive changes to a file and then change your
597 mind about them, you can get rid of them by reading in the previous
598 version of the file with the `revert-buffer' command.  *Note Reverting
599 a Buffer: (emacs)Reverting.
600
601  - Command: revert-buffer &optional check-auto-save noconfirm
602      This command replaces the buffer text with the text of the visited
603      file on disk.  This action undoes all changes since the file was
604      visited or saved.
605
606      If the argument CHECK-AUTO-SAVE is non-`nil', and the latest
607      auto-save file is more recent than the visited file,
608      `revert-buffer' asks the user whether to use that instead.
609      Otherwise, it always uses the text of the visited file itself.
610      Interactively, CHECK-AUTO-SAVE is set if there is a numeric prefix
611      argument.
612
613      Normally, `revert-buffer' asks for confirmation before it changes
614      the buffer; but if the argument NOCONFIRM is non-`nil',
615      `revert-buffer' does not ask for confirmation.
616
617      Reverting tries to preserve marker positions in the buffer by
618      using the replacement feature of `insert-file-contents'.  If the
619      buffer contents and the file contents are identical before the
620      revert operation, reverting preserves all the markers.  If they
621      are not identical, reverting does change the buffer; then it
622      preserves the markers in the unchanged text (if any) at the
623      beginning and end of the buffer.  Preserving any additional
624      markers would be problematical.
625
626    You can customize how `revert-buffer' does its work by setting these
627 variables--typically, as buffer-local variables.
628
629  - Variable: revert-buffer-function
630      The value of this variable is the function to use to revert this
631      buffer.  If non-`nil', it is called as a function with no
632      arguments to do the work of reverting.  If the value is `nil',
633      reverting works the usual way.
634
635      Modes such as Dired mode, in which the text being edited does not
636      consist of a file's contents but can be regenerated in some other
637      fashion, give this variable a buffer-local value that is a
638      function to regenerate the contents.
639
640  - Variable: revert-buffer-insert-file-contents-function
641      The value of this variable, if non-`nil', is the function to use to
642      insert the updated contents when reverting this buffer.  The
643      function receives two arguments: first the file name to use;
644      second, `t' if the user has asked to read the auto-save file.
645
646  - Variable: before-revert-hook
647      This normal hook is run by `revert-buffer' before actually
648      inserting the modified contents--but only if
649      `revert-buffer-function' is `nil'.
650
651      Font Lock mode uses this hook to record that the buffer contents
652      are no longer fontified.
653
654  - Variable: after-revert-hook
655      This normal hook is run by `revert-buffer' after actually inserting
656      the modified contents--but only if `revert-buffer-function' is
657      `nil'.
658
659      Font Lock mode uses this hook to recompute the fonts for the
660      updated buffer contents.
661
662 \1f
663 File: lispref.info,  Node: Buffers,  Next: Windows,  Prev: Backups and Auto-Saving,  Up: Top
664
665 Buffers
666 *******
667
668    A "buffer" is a Lisp object containing text to be edited.  Buffers
669 are used to hold the contents of files that are being visited; there may
670 also be buffers that are not visiting files.  While several buffers may
671 exist at one time, exactly one buffer is designated the "current
672 buffer" at any time.  Most editing commands act on the contents of the
673 current buffer.  Each buffer, including the current buffer, may or may
674 not be displayed in any windows.
675
676 * Menu:
677
678 * Buffer Basics::       What is a buffer?
679 * Current Buffer::      Designating a buffer as current
680                           so primitives will access its contents.
681 * Buffer Names::        Accessing and changing buffer names.
682 * Buffer File Name::    The buffer file name indicates which file is visited.
683 * Buffer Modification:: A buffer is "modified" if it needs to be saved.
684 * Modification Time::   Determining whether the visited file was changed
685                          ``behind XEmacs's back''.
686 * Read Only Buffers::   Modifying text is not allowed in a read-only buffer.
687 * The Buffer List::     How to look at all the existing buffers.
688 * Creating Buffers::    Functions that create buffers.
689 * Killing Buffers::     Buffers exist until explicitly killed.
690 * Indirect Buffers::    An indirect buffer shares text with some other buffer.
691
692 \1f
693 File: lispref.info,  Node: Buffer Basics,  Next: Current Buffer,  Up: Buffers
694
695 Buffer Basics
696 =============
697
698    A "buffer" is a Lisp object containing text to be edited.  Buffers
699 are used to hold the contents of files that are being visited; there may
700 also be buffers that are not visiting files.  While several buffers may
701 exist at one time, exactly one buffer is designated the "current
702 buffer" at any time.  Most editing commands act on the contents of the
703 current buffer.  Each buffer, including the current buffer, may or may
704 not be displayed in any windows.
705
706    Buffers in Emacs editing are objects that have distinct names and
707 hold text that can be edited.  Buffers appear to Lisp programs as a
708 special data type.  You can think of the contents of a buffer as an
709 extendable string; insertions and deletions may occur in any part of
710 the buffer.  *Note Text::.
711
712    A Lisp buffer object contains numerous pieces of information.  Some
713 of this information is directly accessible to the programmer through
714 variables, while other information is accessible only through
715 special-purpose functions.  For example, the visited file name is
716 directly accessible through a variable, while the value of point is
717 accessible only through a primitive function.
718
719    Buffer-specific information that is directly accessible is stored in
720 "buffer-local" variable bindings, which are variable values that are
721 effective only in a particular buffer.  This feature allows each buffer
722 to override the values of certain variables.  Most major modes override
723 variables such as `fill-column' or `comment-column' in this way.  For
724 more information about buffer-local variables and functions related to
725 them, see *Note Buffer-Local Variables::.
726
727    For functions and variables related to visiting files in buffers, see
728 *Note Visiting Files:: and *Note Saving Buffers::.  For functions and
729 variables related to the display of buffers in windows, see *Note
730 Buffers and Windows::.
731
732  - Function: bufferp object
733      This function returns `t' if OBJECT is a buffer, `nil' otherwise.
734
735 \1f
736 File: lispref.info,  Node: Current Buffer,  Next: Buffer Names,  Prev: Buffer Basics,  Up: Buffers
737
738 The Current Buffer
739 ==================
740
741    There are, in general, many buffers in an Emacs session.  At any
742 time, one of them is designated as the "current buffer".  This is the
743 buffer in which most editing takes place, because most of the primitives
744 for examining or changing text in a buffer operate implicitly on the
745 current buffer (*note Text::).  Normally the buffer that is displayed on
746 the screen in the selected window is the current buffer, but this is not
747 always so: a Lisp program can designate any buffer as current
748 temporarily in order to operate on its contents, without changing what
749 is displayed on the screen.
750
751    The way to designate a current buffer in a Lisp program is by calling
752 `set-buffer'.  The specified buffer remains current until a new one is
753 designated.
754
755    When an editing command returns to the editor command loop, the
756 command loop designates the buffer displayed in the selected window as
757 current, to prevent confusion: the buffer that the cursor is in when
758 Emacs reads a command is the buffer that the command will apply to.
759 (*Note Command Loop::.)  Therefore, `set-buffer' is not the way to
760 switch visibly to a different buffer so that the user can edit it.  For
761 this, you must use the functions described in *Note Displaying
762 Buffers::.
763
764    However, Lisp functions that change to a different current buffer
765 should not depend on the command loop to set it back afterwards.
766 Editing commands written in XEmacs Lisp can be called from other
767 programs as well as from the command loop.  It is convenient for the
768 caller if the subroutine does not change which buffer is current
769 (unless, of course, that is the subroutine's purpose).  Therefore, you
770 should normally use `set-buffer' within a `save-excursion' that will
771 restore the current buffer when your function is done (*note
772 Excursions::).  Here is an example, the code for the command
773 `append-to-buffer' (with the documentation string abridged):
774
775      (defun append-to-buffer (buffer start end)
776        "Append to specified buffer the text of the region.
777      ..."
778        (interactive "BAppend to buffer: \nr")
779        (let ((oldbuf (current-buffer)))
780          (save-excursion
781            (set-buffer (get-buffer-create buffer))
782            (insert-buffer-substring oldbuf start end))))
783
784 This function binds a local variable to the current buffer, and then
785 `save-excursion' records the values of point, the mark, and the
786 original buffer.  Next, `set-buffer' makes another buffer current.
787 Finally, `insert-buffer-substring' copies the string from the original
788 current buffer to the new current buffer.
789
790    If the buffer appended to happens to be displayed in some window,
791 the next redisplay will show how its text has changed.  Otherwise, you
792 will not see the change immediately on the screen.  The buffer becomes
793 current temporarily during the execution of the command, but this does
794 not cause it to be displayed.
795
796    If you make local bindings (with `let' or function arguments) for a
797 variable that may also have buffer-local bindings, make sure that the
798 same buffer is current at the beginning and at the end of the local
799 binding's scope.  Otherwise you might bind it in one buffer and unbind
800 it in another!  There are two ways to do this.  In simple cases, you may
801 see that nothing ever changes the current buffer within the scope of the
802 binding.  Otherwise, use `save-excursion' to make sure that the buffer
803 current at the beginning is current again whenever the variable is
804 unbound.
805
806    It is not reliable to change the current buffer back with
807 `set-buffer', because that won't do the job if a quit happens while the
808 wrong buffer is current.  Here is what _not_ to do:
809
810      (let (buffer-read-only
811            (obuf (current-buffer)))
812        (set-buffer ...)
813        ...
814        (set-buffer obuf))
815
816 Using `save-excursion', as shown below, handles quitting, errors, and
817 `throw', as well as ordinary evaluation.
818
819      (let (buffer-read-only)
820        (save-excursion
821          (set-buffer ...)
822          ...))
823
824  - Function: current-buffer
825      This function returns the current buffer.
826
827           (current-buffer)
828                => #<buffer buffers.texi>
829
830  - Function: set-buffer buffer-or-name
831      This function makes BUFFER-OR-NAME the current buffer.  It does
832      not display the buffer in the currently selected window or in any
833      other window, so the user cannot necessarily see the buffer.  But
834      Lisp programs can in any case work on it.
835
836      This function returns the buffer identified by BUFFER-OR-NAME.  An
837      error is signaled if BUFFER-OR-NAME does not identify an existing
838      buffer.
839
840 \1f
841 File: lispref.info,  Node: Buffer Names,  Next: Buffer File Name,  Prev: Current Buffer,  Up: Buffers
842
843 Buffer Names
844 ============
845
846    Each buffer has a unique name, which is a string.  Many of the
847 functions that work on buffers accept either a buffer or a buffer name
848 as an argument.  Any argument called BUFFER-OR-NAME is of this sort,
849 and an error is signaled if it is neither a string nor a buffer.  Any
850 argument called BUFFER must be an actual buffer object, not a name.
851
852    Buffers that are ephemeral and generally uninteresting to the user
853 have names starting with a space, so that the `list-buffers' and
854 `buffer-menu' commands don't mention them.  A name starting with space
855 also initially disables recording undo information; see *Note Undo::.
856
857  - Function: buffer-name &optional buffer
858      This function returns the name of BUFFER as a string.  If BUFFER
859      is not supplied, it defaults to the current buffer.
860
861      If `buffer-name' returns `nil', it means that BUFFER has been
862      killed.  *Note Killing Buffers::.
863
864           (buffer-name)
865                => "buffers.texi"
866           
867           (setq foo (get-buffer "temp"))
868                => #<buffer temp>
869           (kill-buffer foo)
870                => nil
871           (buffer-name foo)
872                => nil
873           foo
874                => #<killed buffer>
875
876  - Command: rename-buffer newname &optional unique
877      This function renames the current buffer to NEWNAME.  An error is
878      signaled if NEWNAME is not a string, or if there is already a
879      buffer with that name.  The function returns `nil'.
880
881      Ordinarily, `rename-buffer' signals an error if NEWNAME is already
882      in use.  However, if UNIQUE is non-`nil', it modifies NEWNAME to
883      make a name that is not in use.  Interactively, you can make
884      UNIQUE non-`nil' with a numeric prefix argument.
885
886      One application of this command is to rename the `*shell*' buffer
887      to some other name, thus making it possible to create a second
888      shell buffer under the name `*shell*'.
889
890  - Function: get-buffer buffer-or-name
891      This function returns the buffer specified by BUFFER-OR-NAME.  If
892      BUFFER-OR-NAME is a string and there is no buffer with that name,
893      the value is `nil'.  If BUFFER-OR-NAME is a buffer, it is returned
894      as given.  (That is not very useful, so the argument is usually a
895      name.)  For example:
896
897           (setq b (get-buffer "lewis"))
898                => #<buffer lewis>
899           (get-buffer b)
900                => #<buffer lewis>
901           (get-buffer "Frazzle-nots")
902                => nil
903
904      See also the function `get-buffer-create' in *Note Creating
905      Buffers::.
906
907  - Function: generate-new-buffer-name starting-name &optional ignore
908      This function returns a name that would be unique for a new
909      buffer--but does not create the buffer.  It starts with
910      STARTING-NAME, and produces a name not currently in use for any
911      buffer by appending a number inside of `<...>'.
912
913      If IGNORE is given, it specifies a name that is okay to use (if it
914      is in the sequence to be tried), even if a buffer with that name
915      exists.
916
917      See the related function `generate-new-buffer' in *Note Creating
918      Buffers::.
919
920 \1f
921 File: lispref.info,  Node: Buffer File Name,  Next: Buffer Modification,  Prev: Buffer Names,  Up: Buffers
922
923 Buffer File Name
924 ================
925
926    The "buffer file name" is the name of the file that is visited in
927 that buffer.  When a buffer is not visiting a file, its buffer file name
928 is `nil'.  Most of the time, the buffer name is the same as the
929 nondirectory part of the buffer file name, but the buffer file name and
930 the buffer name are distinct and can be set independently.  *Note
931 Visiting Files::.
932
933  - Function: buffer-file-name &optional buffer
934      This function returns the absolute file name of the file that
935      BUFFER is visiting.  If BUFFER is not visiting any file,
936      `buffer-file-name' returns `nil'.  If BUFFER is not supplied, it
937      defaults to the current buffer.
938
939           (buffer-file-name (other-buffer))
940                => "/usr/user/lewis/manual/files.texi"
941
942  - Variable: buffer-file-name
943      This buffer-local variable contains the name of the file being
944      visited in the current buffer, or `nil' if it is not visiting a
945      file.  It is a permanent local, unaffected by
946      `kill-local-variables'.
947
948           buffer-file-name
949                => "/usr/user/lewis/manual/buffers.texi"
950
951      It is risky to change this variable's value without doing various
952      other things.  See the definition of `set-visited-file-name' in
953      `files.el'; some of the things done there, such as changing the
954      buffer name, are not strictly necessary, but others are essential
955      to avoid confusing XEmacs.
956
957  - Variable: buffer-file-truename
958      This buffer-local variable holds the truename of the file visited
959      in the current buffer, or `nil' if no file is visited.  It is a
960      permanent local, unaffected by `kill-local-variables'.  *Note
961      Truenames::.
962
963  - Variable: buffer-file-number
964      This buffer-local variable holds the file number and directory
965      device number of the file visited in the current buffer, or `nil'
966      if no file or a nonexistent file is visited.  It is a permanent
967      local, unaffected by `kill-local-variables'.  *Note Truenames::.
968
969      The value is normally a list of the form `(FILENUM DEVNUM)'.  This
970      pair of numbers uniquely identifies the file among all files
971      accessible on the system.  See the function `file-attributes', in
972      *Note File Attributes::, for more information about them.
973
974  - Function: get-file-buffer filename
975      This function returns the buffer visiting file FILENAME.  If there
976      is no such buffer, it returns `nil'.  The argument FILENAME, which
977      must be a string, is expanded (*note File Name Expansion::), then
978      compared against the visited file names of all live buffers.
979
980           (get-file-buffer "buffers.texi")
981               => #<buffer buffers.texi>
982
983      In unusual circumstances, there can be more than one buffer
984      visiting the same file name.  In such cases, this function returns
985      the first such buffer in the buffer list.
986
987  - Command: set-visited-file-name filename
988      If FILENAME is a non-empty string, this function changes the name
989      of the file visited in current buffer to FILENAME.  (If the buffer
990      had no visited file, this gives it one.)  The _next time_ the
991      buffer is saved it will go in the newly-specified file.  This
992      command marks the buffer as modified, since it does not (as far as
993      XEmacs knows) match the contents of FILENAME, even if it matched
994      the former visited file.
995
996      If FILENAME is `nil' or the empty string, that stands for "no
997      visited file".  In this case, `set-visited-file-name' marks the
998      buffer as having no visited file.
999
1000      When the function `set-visited-file-name' is called interactively,
1001      it prompts for FILENAME in the minibuffer.
1002
1003      See also `clear-visited-file-modtime' and
1004      `verify-visited-file-modtime' in *Note Buffer Modification::.
1005
1006  - Variable: list-buffers-directory
1007      This buffer-local variable records a string to display in a buffer
1008      listing in place of the visited file name, for buffers that don't
1009      have a visited file name.  Dired buffers use this variable.
1010
1011 \1f
1012 File: lispref.info,  Node: Buffer Modification,  Next: Modification Time,  Prev: Buffer File Name,  Up: Buffers
1013
1014 Buffer Modification
1015 ===================
1016
1017    XEmacs keeps a flag called the "modified flag" for each buffer, to
1018 record whether you have changed the text of the buffer.  This flag is
1019 set to `t' whenever you alter the contents of the buffer, and cleared
1020 to `nil' when you save it.  Thus, the flag shows whether there are
1021 unsaved changes.  The flag value is normally shown in the modeline
1022 (*note Modeline Variables::), and controls saving (*note Saving
1023 Buffers::) and auto-saving (*note Auto-Saving::).
1024
1025    Some Lisp programs set the flag explicitly.  For example, the
1026 function `set-visited-file-name' sets the flag to `t', because the text
1027 does not match the newly-visited file, even if it is unchanged from the
1028 file formerly visited.
1029
1030    The functions that modify the contents of buffers are described in
1031 *Note Text::.
1032
1033  - Function: buffer-modified-p &optional buffer
1034      This function returns `t' if the buffer BUFFER has been modified
1035      since it was last read in from a file or saved, or `nil'
1036      otherwise.  If BUFFER is not supplied, the current buffer is
1037      tested.
1038
1039  - Function: set-buffer-modified-p flag
1040      This function marks the current buffer as modified if FLAG is
1041      non-`nil', or as unmodified if the flag is `nil'.
1042
1043      Another effect of calling this function is to cause unconditional
1044      redisplay of the modeline for the current buffer.  In fact, the
1045      function `redraw-modeline' works by doing this:
1046
1047           (set-buffer-modified-p (buffer-modified-p))
1048
1049  - Command: not-modified &optional arg
1050      This command marks the current buffer as unmodified, and not
1051      needing to be saved. (If ARG is non-`nil', the buffer is instead
1052      marked as modified.) Don't use this function in programs, since it
1053      prints a message in the echo area; use `set-buffer-modified-p'
1054      (above) instead.
1055
1056  - Function: buffer-modified-tick &optional buffer
1057      This function returns BUFFER`s modification-count.  This is a
1058      counter that increments every time the buffer is modified.  If
1059      BUFFER is `nil' (or omitted), the current buffer is used.
1060
1061 \1f
1062 File: lispref.info,  Node: Modification Time,  Next: Read Only Buffers,  Prev: Buffer Modification,  Up: Buffers
1063
1064 Comparison of Modification Time
1065 ===============================
1066
1067    Suppose that you visit a file and make changes in its buffer, and
1068 meanwhile the file itself is changed on disk.  At this point, saving the
1069 buffer would overwrite the changes in the file.  Occasionally this may
1070 be what you want, but usually it would lose valuable information.
1071 XEmacs therefore checks the file's modification time using the functions
1072 described below before saving the file.
1073
1074  - Function: verify-visited-file-modtime buffer
1075      This function compares what BUFFER has recorded for the
1076      modification time of its visited file against the actual
1077      modification time of the file as recorded by the operating system.
1078      The two should be the same unless some other process has written
1079      the file since XEmacs visited or saved it.
1080
1081      The function returns `t' if the last actual modification time and
1082      XEmacs's recorded modification time are the same, `nil' otherwise.
1083
1084  - Function: clear-visited-file-modtime
1085      This function clears out the record of the last modification time
1086      of the file being visited by the current buffer.  As a result, the
1087      next attempt to save this buffer will not complain of a
1088      discrepancy in file modification times.
1089
1090      This function is called in `set-visited-file-name' and other
1091      exceptional places where the usual test to avoid overwriting a
1092      changed file should not be done.
1093
1094  - Function: visited-file-modtime
1095      This function returns the buffer's recorded last file modification
1096      time, as a list of the form `(HIGH . LOW)'.  (This is the same
1097      format that `file-attributes' uses to return time values; see
1098      *Note File Attributes::.)
1099
1100  - Function: set-visited-file-modtime &optional time
1101      This function updates the buffer's record of the last modification
1102      time of the visited file, to the value specified by TIME if TIME
1103      is not `nil', and otherwise to the last modification time of the
1104      visited file.
1105
1106      If TIME is not `nil', it should have the form `(HIGH . LOW)' or
1107      `(HIGH LOW)', in either case containing two integers, each of
1108      which holds 16 bits of the time.
1109
1110      This function is useful if the buffer was not read from the file
1111      normally, or if the file itself has been changed for some known
1112      benign reason.
1113
1114  - Function: ask-user-about-supersession-threat filename
1115      This function is used to ask a user how to proceed after an
1116      attempt to modify an obsolete buffer visiting file FILENAME.  An
1117      "obsolete buffer" is an unmodified buffer for which the associated
1118      file on disk is newer than the last save-time of the buffer.  This
1119      means some other program has probably altered the file.
1120
1121      Depending on the user's answer, the function may return normally,
1122      in which case the modification of the buffer proceeds, or it may
1123      signal a `file-supersession' error with data `(FILENAME)', in which
1124      case the proposed buffer modification is not allowed.
1125
1126      This function is called automatically by XEmacs on the proper
1127      occasions.  It exists so you can customize XEmacs by redefining it.
1128      See the file `userlock.el' for the standard definition.
1129
1130      See also the file locking mechanism in *Note File Locks::.
1131
1132 \1f
1133 File: lispref.info,  Node: Read Only Buffers,  Next: The Buffer List,  Prev: Modification Time,  Up: Buffers
1134
1135 Read-Only Buffers
1136 =================
1137
1138    If a buffer is "read-only", then you cannot change its contents,
1139 although you may change your view of the contents by scrolling and
1140 narrowing.
1141
1142    Read-only buffers are used in two kinds of situations:
1143
1144    * A buffer visiting a write-protected file is normally read-only.
1145
1146      Here, the purpose is to show the user that editing the buffer with
1147      the aim of saving it in the file may be futile or undesirable.
1148      The user who wants to change the buffer text despite this can do
1149      so after clearing the read-only flag with `C-x C-q'.
1150
1151    * Modes such as Dired and Rmail make buffers read-only when altering
1152      the contents with the usual editing commands is probably a mistake.
1153
1154      The special commands of these modes bind `buffer-read-only' to
1155      `nil' (with `let') or bind `inhibit-read-only' to `t' around the
1156      places where they change the text.
1157
1158  - Variable: buffer-read-only
1159      This buffer-local variable specifies whether the buffer is
1160      read-only.  The buffer is read-only if this variable is non-`nil'.
1161
1162  - Variable: inhibit-read-only
1163      If this variable is non-`nil', then read-only buffers and read-only
1164      characters may be modified.  Read-only characters in a buffer are
1165      those that have non-`nil' `read-only' properties (either text
1166      properties or extent properties).  *Note Extent Properties::, for
1167      more information about text properties and extent properties.
1168
1169      If `inhibit-read-only' is `t', all `read-only' character
1170      properties have no effect.  If `inhibit-read-only' is a list, then
1171      `read-only' character properties have no effect if they are members
1172      of the list (comparison is done with `eq').
1173
1174  - Command: toggle-read-only
1175      This command changes whether the current buffer is read-only.  It
1176      is intended for interactive use; don't use it in programs.  At any
1177      given point in a program, you should know whether you want the
1178      read-only flag on or off; so you can set `buffer-read-only'
1179      explicitly to the proper value, `t' or `nil'.
1180
1181  - Function: barf-if-buffer-read-only
1182      This function signals a `buffer-read-only' error if the current
1183      buffer is read-only.  *Note Interactive Call::, for another way to
1184      signal an error if the current buffer is read-only.
1185