update.
[chise/xemacs-chise.git-] / info / lispref.info-24
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: User Name Completion,  Prev: File Name Completion,  Up: File Names
54
55 User Name Completion
56 --------------------
57
58    This section describes low-level subroutines for completing a user
59 name.  For other completion functions, see *Note Completion::.
60
61  - Function: user-name-all-completions partial-username
62      This function returns a list of all possible completions for a user
63      whose name starts with PARTIAL-USERNAME.  The order of the
64      completions is unpredictable and conveys no useful information.
65
66      The argument PARTIAL-USERNAME must be a partial user name
67      containing no tilde character and no slash.
68
69  - Function: user-name-completion username
70      This function completes the user name USERNAME.  It returns the
71      longest prefix common to all user names that start with USERNAME.
72
73      If only one match exists and USERNAME matches it exactly, the
74      function returns `t'.  The function returns `nil' if no user name
75      starting with USERNAME exists.
76
77  - Function: user-name-completion-1 username
78      This function completes the user name USERNAME, like
79      `user-name-completion', differing only in the return value.  This
80      function returns the cons of the completion returned by
81      `user-name-completion', and a boolean indicating whether that
82      completion was unique.
83
84 \1f
85 File: lispref.info,  Node: Contents of Directories,  Next: Create/Delete Dirs,  Prev: File Names,  Up: Files
86
87 Contents of Directories
88 =======================
89
90    A directory is a kind of file that contains other files entered under
91 various names.  Directories are a feature of the file system.
92
93    XEmacs can list the names of the files in a directory as a Lisp list,
94 or display the names in a buffer using the `ls' shell command.  In the
95 latter case, it can optionally display information about each file,
96 depending on the value of switches passed to the `ls' command.
97
98  - Function: directory-files directory &optional full-name match-regexp
99           nosort files-only
100      This function returns a list of the names of the files in the
101      directory DIRECTORY.  By default, the list is in alphabetical
102      order.
103
104      If FULL-NAME is non-`nil', the function returns the files'
105      absolute file names.  Otherwise, it returns just the names
106      relative to the specified directory.
107
108      If MATCH-REGEXP is non-`nil', this function returns only those
109      file names that contain that regular expression--the other file
110      names are discarded from the list.
111
112      If NOSORT is non-`nil', `directory-files' does not sort the list,
113      so you get the file names in no particular order.  Use this if you
114      want the utmost possible speed and don't care what order the files
115      are processed in.  If the order of processing is visible to the
116      user, then the user will probably be happier if you do sort the
117      names.
118
119      If FILES-ONLY is the symbol `t', then only the "files" in the
120      directory will be returned; subdirectories will be excluded.  If
121      FILES-ONLY is not `nil' and not `t', then only the subdirectories
122      will be returned.  Otherwise, if FILES-ONLY is `nil' (the default)
123      then both files and subdirectories will be returned.
124
125           (directory-files "~lewis")
126                => ("#foo#" "#foo.el#" "." ".."
127                    "dired-mods.el" "files.texi"
128                    "files.texi.~1~")
129
130      An error is signaled if DIRECTORY is not the name of a directory
131      that can be read.
132
133  - Function: insert-directory file switches &optional wildcard
134           full-directory-p
135      This function inserts (in the current buffer) a directory listing
136      for directory FILE, formatted with `ls' according to SWITCHES.  It
137      leaves point after the inserted text.
138
139      The argument FILE may be either a directory name or a file
140      specification including wildcard characters.  If WILDCARD is
141      non-`nil', that means treat FILE as a file specification with
142      wildcards.
143
144      If FULL-DIRECTORY-P is non-`nil', that means FILE is a directory
145      and switches do not contain `-d', so that the listing should show
146      the full contents of the directory.  (The `-d' option to `ls' says
147      to describe a directory itself rather than its contents.)
148
149      This function works by running a directory listing program whose
150      name is in the variable `insert-directory-program'.  If WILDCARD is
151      non-`nil', it also runs the shell specified by `shell-file-name',
152      to expand the wildcards.
153
154  - Variable: insert-directory-program
155      This variable's value is the program to run to generate a
156      directory listing for the function `insert-directory'.
157
158 \1f
159 File: lispref.info,  Node: Create/Delete Dirs,  Next: Magic File Names,  Prev: Contents of Directories,  Up: Files
160
161 Creating and Deleting Directories
162 =================================
163
164    Most XEmacs Lisp file-manipulation functions get errors when used on
165 files that are directories.  For example, you cannot delete a directory
166 with `delete-file'.  These special functions exist to create and delete
167 directories.
168
169  - Command: make-directory dirname &optional parents
170      This function creates a directory named DIRNAME.  Interactively,
171      the default choice of directory to create is the current default
172      directory for file names.  That is useful when you have visited a
173      file in a nonexistent directory.
174
175      Non-interactively, optional argument PARENTS says whether to
176      create parent directories if they don't exist. (Interactively, this
177      always happens.)
178
179  - Command: delete-directory dirname
180      This function deletes the directory named DIRNAME.  The function
181      `delete-file' does not work for files that are directories; you
182      must use `delete-directory' in that case.
183
184 \1f
185 File: lispref.info,  Node: Magic File Names,  Next: Partial Files,  Prev: Create/Delete Dirs,  Up: Files
186
187 Making Certain File Names "Magic"
188 =================================
189
190    You can implement special handling for certain file names.  This is
191 called making those names "magic".  You must supply a regular
192 expression to define the class of names (all those that match the
193 regular expression), plus a handler that implements all the primitive
194 XEmacs file operations for file names that do match.
195
196    The variable `file-name-handler-alist' holds a list of handlers,
197 together with regular expressions that determine when to apply each
198 handler.  Each element has this form:
199
200      (REGEXP . HANDLER)
201
202 All the XEmacs primitives for file access and file name transformation
203 check the given file name against `file-name-handler-alist'.  If the
204 file name matches REGEXP, the primitives handle that file by calling
205 HANDLER.
206
207    The first argument given to HANDLER is the name of the primitive;
208 the remaining arguments are the arguments that were passed to that
209 operation.  (The first of these arguments is typically the file name
210 itself.)  For example, if you do this:
211
212      (file-exists-p FILENAME)
213
214 and FILENAME has handler HANDLER, then HANDLER is called like this:
215
216      (funcall HANDLER 'file-exists-p FILENAME)
217
218    Here are the operations that a magic file name handler gets to
219 handle:
220
221 `add-name-to-file', `copy-file', `delete-directory', `delete-file',
222 `diff-latest-backup-file', `directory-file-name', `directory-files',
223 `dired-compress-file', `dired-uncache', `expand-file-name',
224 `file-accessible-directory-p', `file-attributes', `file-directory-p',
225 `file-executable-p', `file-exists-p', `file-local-copy', `file-modes',
226 `file-name-all-completions', `file-name-as-directory',
227 `file-name-completion', `file-name-directory', `file-name-nondirectory',
228 `file-name-sans-versions', `file-newer-than-file-p', `file-readable-p',
229 `file-regular-p', `file-symlink-p', `file-truename', `file-writable-p',
230 `get-file-buffer', `insert-directory', `insert-file-contents', `load',
231 `make-directory', `make-symbolic-link', `rename-file', `set-file-modes',
232 `set-visited-file-modtime', `unhandled-file-name-directory',
233 `verify-visited-file-modtime', `write-region'.
234
235    Handlers for `insert-file-contents' typically need to clear the
236 buffer's modified flag, with `(set-buffer-modified-p nil)', if the
237 VISIT argument is non-`nil'.  This also has the effect of unlocking the
238 buffer if it is locked.
239
240    The handler function must handle all of the above operations, and
241 possibly others to be added in the future.  It need not implement all
242 these operations itself--when it has nothing special to do for a
243 certain operation, it can reinvoke the primitive, to handle the
244 operation "in the usual way".  It should always reinvoke the primitive
245 for an operation it does not recognize.  Here's one way to do this:
246
247      (defun my-file-handler (operation &rest args)
248        ;; First check for the specific operations
249        ;; that we have special handling for.
250        (cond ((eq operation 'insert-file-contents) ...)
251              ((eq operation 'write-region) ...)
252              ...
253              ;; Handle any operation we don't know about.
254              (t (let ((inhibit-file-name-handlers
255                       (cons 'my-file-handler
256                             (and (eq inhibit-file-name-operation operation)
257                                  inhibit-file-name-handlers)))
258                      (inhibit-file-name-operation operation))
259                   (apply operation args)))))
260
261    When a handler function decides to call the ordinary Emacs primitive
262 for the operation at hand, it needs to prevent the primitive from
263 calling the same handler once again, thus leading to an infinite
264 recursion.  The example above shows how to do this, with the variables
265 `inhibit-file-name-handlers' and `inhibit-file-name-operation'.  Be
266 careful to use them exactly as shown above; the details are crucial for
267 proper behavior in the case of multiple handlers, and for operations
268 that have two file names that may each have handlers.
269
270  - Variable: inhibit-file-name-handlers
271      This variable holds a list of handlers whose use is presently
272      inhibited for a certain operation.
273
274  - Variable: inhibit-file-name-operation
275      The operation for which certain handlers are presently inhibited.
276
277  - Function: find-file-name-handler file operation
278      This function returns the handler function for file name FILE, or
279      `nil' if there is none.  The argument OPERATION should be the
280      operation to be performed on the file--the value you will pass to
281      the handler as its first argument when you call it.  The operation
282      is needed for comparison with `inhibit-file-name-operation'.
283
284  - Function: file-local-copy filename
285      This function copies file FILENAME to an ordinary non-magic file,
286      if it isn't one already.
287
288      If FILENAME specifies a "magic" file name, which programs outside
289      Emacs cannot directly read or write, this copies the contents to
290      an ordinary file and returns that file's name.
291
292      If FILENAME is an ordinary file name, not magic, then this function
293      does nothing and returns `nil'.
294
295  - Function: unhandled-file-name-directory filename
296      This function returns the name of a directory that is not magic.
297      It uses the directory part of FILENAME if that is not magic.
298      Otherwise, it asks the handler what to do.
299
300      This is useful for running a subprocess; every subprocess must
301      have a non-magic directory to serve as its current directory, and
302      this function is a good way to come up with one.
303
304 \1f
305 File: lispref.info,  Node: Partial Files,  Next: Format Conversion,  Prev: Magic File Names,  Up: Files
306
307 Partial Files
308 =============
309
310 * Menu:
311
312 * Intro to Partial Files::
313 * Creating a Partial File::
314 * Detached Partial Files::
315
316 \1f
317 File: lispref.info,  Node: Intro to Partial Files,  Next: Creating a Partial File,  Up: Partial Files
318
319 Intro to Partial Files
320 ----------------------
321
322    A "partial file" is a section of a buffer (called the "master
323 buffer") that is placed in its own buffer and treated as its own file.
324 Changes made to the partial file are not reflected in the master buffer
325 until the partial file is "saved" using the standard buffer save
326 commands.  Partial files can be "reverted" (from the master buffer)
327 just like normal files.  When a file part is active on a master buffer,
328 that section of the master buffer is marked as read-only.  Two file
329 parts on the same master buffer are not allowed to overlap.  Partial
330 file buffers are indicated by the words `File Part' in the modeline.
331
332    The master buffer knows about all the partial files that are active
333 on it, and thus killing or reverting the master buffer will be handled
334 properly.  When the master buffer is saved, if there are any unsaved
335 partial files active on it then the user will be given the opportunity
336 to first save these files.
337
338    When a partial file buffer is first modified, the master buffer is
339 automatically marked as modified so that saving the master buffer will
340 work correctly.
341
342 \1f
343 File: lispref.info,  Node: Creating a Partial File,  Next: Detached Partial Files,  Prev: Intro to Partial Files,  Up: Partial Files
344
345 Creating a Partial File
346 -----------------------
347
348  - Function: make-file-part &optional start end name buffer
349      Make a file part on buffer BUFFER out of the region.  Call it
350      NAME.  This command creates a new buffer containing the contents
351      of the region and marks the buffer as referring to the specified
352      buffer, called the "master buffer".  When the file-part buffer is
353      saved, its changes are integrated back into the master buffer.
354      When the master buffer is deleted, all file parts are deleted with
355      it.
356
357      When called from a function, expects four arguments, START, END,
358      NAME, and BUFFER, all of which are optional and default to the
359      beginning of BUFFER, the end of BUFFER, a name generated from
360      BUFFER name, and the current buffer, respectively.
361
362 \1f
363 File: lispref.info,  Node: Detached Partial Files,  Prev: Creating a Partial File,  Up: Partial Files
364
365 Detached Partial Files
366 ----------------------
367
368    Every partial file has an extent in the master buffer associated
369 with it (called the "master extent"), marking where in the master
370 buffer the partial file begins and ends.  If the text in master buffer
371 that is contained by the extent is deleted, then the extent becomes
372 "detached", meaning that it no longer refers to a specific region of
373 the master buffer.  This can happen either when the text is deleted
374 directly or when the master buffer is reverted.  Neither of these should
375 happen in normal usage because the master buffer should generally not be
376 edited directly.
377
378    Before doing any operation that references a partial file's master
379 extent, XEmacs checks to make sure that the extent is not detached.  If
380 this is the case, XEmacs warns the user of this and the master extent is
381 deleted out of the master buffer, disconnecting the file part.  The file
382 part's filename is cleared and thus must be explicitly specified if the
383 detached file part is to be saved.
384
385 \1f
386 File: lispref.info,  Node: Format Conversion,  Next: Files and MS-DOS,  Prev: Partial Files,  Up: Files
387
388 File Format Conversion
389 ======================
390
391    The variable `format-alist' defines a list of "file formats", which
392 describe textual representations used in files for the data (text,
393 text-properties, and possibly other information) in an Emacs buffer.
394 Emacs performs format conversion if appropriate when reading and writing
395 files.
396
397  - Variable: format-alist
398      This list contains one format definition for each defined file
399      format.
400
401    Each format definition is a list of this form:
402
403      (NAME DOC-STRING REGEXP FROM-FN TO-FN MODIFY MODE-FN)
404
405    Here is what the elements in a format definition mean:
406
407 NAME
408      The name of this format.
409
410 DOC-STRING
411      A documentation string for the format.
412
413 REGEXP
414      A regular expression which is used to recognize files represented
415      in this format.
416
417 FROM-FN
418      A function to call to decode data in this format (to convert file
419      data into the usual Emacs data representation).
420
421      The FROM-FN is called with two args, BEGIN and END, which specify
422      the part of the buffer it should convert.  It should convert the
423      text by editing it in place.  Since this can change the length of
424      the text, FROM-FN should return the modified end position.
425
426      One responsibility of FROM-FN is to make sure that the beginning
427      of the file no longer matches REGEXP.  Otherwise it is likely to
428      get called again.
429
430 TO-FN
431      A function to call to encode data in this format (to convert the
432      usual Emacs data representation into this format).
433
434      The TO-FN is called with two args, BEGIN and END, which specify
435      the part of the buffer it should convert.  There are two ways it
436      can do the conversion:
437
438         * By editing the buffer in place.  In this case, TO-FN should
439           return the end-position of the range of text, as modified.
440
441         * By returning a list of annotations.  This is a list of
442           elements of the form `(POSITION . STRING)', where POSITION is
443           an integer specifying the relative position in the text to be
444           written, and STRING is the annotation to add there.  The list
445           must be sorted in order of position when TO-FN returns it.
446
447           When `write-region' actually writes the text from the buffer
448           to the file, it intermixes the specified annotations at the
449           corresponding positions.  All this takes place without
450           modifying the buffer.
451
452 MODIFY
453      A flag, `t' if the encoding function modifies the buffer, and
454      `nil' if it works by returning a list of annotations.
455
456 MODE
457      A mode function to call after visiting a file converted from this
458      format.
459
460    The function `insert-file-contents' automatically recognizes file
461 formats when it reads the specified file.  It checks the text of the
462 beginning of the file against the regular expressions of the format
463 definitions, and if it finds a match, it calls the decoding function for
464 that format.  Then it checks all the known formats over again.  It
465 keeps checking them until none of them is applicable.
466
467    Visiting a file, with `find-file-noselect' or the commands that use
468 it, performs conversion likewise (because it calls
469 `insert-file-contents'); it also calls the mode function for each
470 format that it decodes.  It stores a list of the format names in the
471 buffer-local variable `buffer-file-format'.
472
473  - Variable: buffer-file-format
474      This variable states the format of the visited file.  More
475      precisely, this is a list of the file format names that were
476      decoded in the course of visiting the current buffer's file.  It
477      is always local in all buffers.
478
479    When `write-region' writes data into a file, it first calls the
480 encoding functions for the formats listed in `buffer-file-format', in
481 the order of appearance in the list.
482
483  - Function: format-write-file file format
484      This command writes the current buffer contents into the file FILE
485      in format FORMAT, and makes that format the default for future
486      saves of the buffer.  The argument FORMAT is a list of format
487      names.
488
489  - Function: format-find-file file format
490      This command finds the file FILE, converting it according to
491      format FORMAT.  It also makes FORMAT the default if the buffer is
492      saved later.
493
494      The argument FORMAT is a list of format names.  If FORMAT is
495      `nil', no conversion takes place.  Interactively, typing just
496      <RET> for FORMAT specifies `nil'.
497
498  - Function: format-insert-file file format &optional beg end
499      This command inserts the contents of file FILE, converting it
500      according to format FORMAT.  If BEG and END are non-`nil', they
501      specify which part of the file to read, as in
502      `insert-file-contents' (*note Reading from Files::).
503
504      The return value is like what `insert-file-contents' returns: a
505      list of the absolute file name and the length of the data inserted
506      (after conversion).
507
508      The argument FORMAT is a list of format names.  If FORMAT is
509      `nil', no conversion takes place.  Interactively, typing just
510      <RET> for FORMAT specifies `nil'.
511
512  - Function: format-find-file file format
513      This command finds the file FILE, converting it according to
514      format FORMAT.  It also makes FORMAT the default if the buffer is
515      saved later.
516
517      The argument FORMAT is a list of format names.  If FORMAT is
518      `nil', no conversion takes place.  Interactively, typing just
519      <RET> for FORMAT specifies `nil'.
520
521  - Function: format-insert-file file format &optional beg end
522      This command inserts the contents of file FILE, converting it
523      according to format FORMAT.  If BEG and END are non-`nil', they
524      specify which part of the file to read, as in
525      `insert-file-contents' (*note Reading from Files::).
526
527      The return value is like what `insert-file-contents' returns: a
528      list of the absolute file name and the length of the data inserted
529      (after conversion).
530
531      The argument FORMAT is a list of format names.  If FORMAT is
532      `nil', no conversion takes place.  Interactively, typing just
533      <RET> for FORMAT specifies `nil'.
534
535  - Variable: auto-save-file-format
536      This variable specifies the format to use for auto-saving.  Its
537      value is a list of format names, just like the value of
538      `buffer-file-format'; but it is used instead of
539      `buffer-file-format' for writing auto-save files.  This variable
540      is always local in all buffers.
541
542 \1f
543 File: lispref.info,  Node: Files and MS-DOS,  Prev: Format Conversion,  Up: Files
544
545 Files and MS-DOS
546 ================
547
548    Emacs on MS-DOS makes a distinction between text files and binary
549 files.  This is necessary because ordinary text files on MS-DOS use a
550 two character sequence between lines: carriage-return and linefeed
551 (CRLF).  Emacs expects just a newline character (a linefeed) between
552 lines.  When Emacs reads or writes a text file on MS-DOS, it needs to
553 convert the line separators.  This means it needs to know which files
554 are text files and which are binary.  It makes this decision when
555 visiting a file, and records the decision in the variable
556 `buffer-file-type' for use when the file is saved.
557
558    *Note MS-DOS Subprocesses::, for a related feature for subprocesses.
559
560  - Variable: buffer-file-type
561      This variable, automatically local in each buffer, records the
562      file type of the buffer's visited file.  The value is `nil' for
563      text, `t' for binary.
564
565  - Function: find-buffer-file-type filename
566      This function determines whether file FILENAME is a text file or a
567      binary file.  It returns `nil' for text, `t' for binary.
568
569  - User Option: file-name-buffer-file-type-alist
570      This variable holds an alist for distinguishing text files from
571      binary files.  Each element has the form (REGEXP . TYPE), where
572      REGEXP is matched against the file name, and TYPE may be is `nil'
573      for text, `t' for binary, or a function to call to compute which.
574      If it is a function, then it is called with a single argument (the
575      file name) and should return `t' or `nil'.
576
577  - User Option: default-buffer-file-type
578      This variable specifies the default file type for files whose names
579      don't indicate anything in particular.  Its value should be `nil'
580      for text, or `t' for binary.
581
582  - Command: find-file-text filename
583      Like `find-file', but treat the file as text regardless of its
584      name.
585
586  - Command: find-file-binary filename
587      Like `find-file', but treat the file as binary regardless of its
588      name.
589
590 \1f
591 File: lispref.info,  Node: Backups and Auto-Saving,  Next: Buffers,  Prev: Files,  Up: Top
592
593 Backups and Auto-Saving
594 ***********************
595
596    Backup files and auto-save files are two methods by which XEmacs
597 tries to protect the user from the consequences of crashes or of the
598 user's own errors.  Auto-saving preserves the text from earlier in the
599 current editing session; backup files preserve file contents prior to
600 the current session.
601
602 * Menu:
603
604 * Backup Files::   How backup files are made; how their names are chosen.
605 * Auto-Saving::    How auto-save files are made; how their names are chosen.
606 * Reverting::      `revert-buffer', and how to customize what it does.
607
608 \1f
609 File: lispref.info,  Node: Backup Files,  Next: Auto-Saving,  Up: Backups and Auto-Saving
610
611 Backup Files
612 ============
613
614    A "backup file" is a copy of the old contents of a file you are
615 editing.  XEmacs makes a backup file the first time you save a buffer
616 into its visited file.  Normally, this means that the backup file
617 contains the contents of the file as it was before the current editing
618 session.  The contents of the backup file normally remain unchanged once
619 it exists.
620
621    Backups are usually made by renaming the visited file to a new name.
622 Optionally, you can specify that backup files should be made by copying
623 the visited file.  This choice makes a difference for files with
624 multiple names; it also can affect whether the edited file remains owned
625 by the original owner or becomes owned by the user editing it.
626
627    By default, XEmacs makes a single backup file for each file edited.
628 You can alternatively request numbered backups; then each new backup
629 file gets a new name.  You can delete old numbered backups when you
630 don't want them any more, or XEmacs can delete them automatically.
631
632 * Menu:
633
634 * Making Backups::     How XEmacs makes backup files, and when.
635 * Rename or Copy::     Two alternatives: renaming the old file or copying it.
636 * Numbered Backups::   Keeping multiple backups for each source file.
637 * Backup Names::       How backup file names are computed; customization.
638
639 \1f
640 File: lispref.info,  Node: Making Backups,  Next: Rename or Copy,  Up: Backup Files
641
642 Making Backup Files
643 -------------------
644
645  - Function: backup-buffer
646      This function makes a backup of the file visited by the current
647      buffer, if appropriate.  It is called by `save-buffer' before
648      saving the buffer the first time.
649
650  - Variable: buffer-backed-up
651      This buffer-local variable indicates whether this buffer's file has
652      been backed up on account of this buffer.  If it is non-`nil', then
653      the backup file has been written.  Otherwise, the file should be
654      backed up when it is next saved (if backups are enabled).  This is
655      a permanent local; `kill-local-variables' does not alter it.
656
657  - User Option: make-backup-files
658      This variable determines whether or not to make backup files.  If
659      it is non-`nil', then XEmacs creates a backup of each file when it
660      is saved for the first time--provided that `backup-inhibited' is
661      `nil' (see below).
662
663      The following example shows how to change the `make-backup-files'
664      variable only in the `RMAIL' buffer and not elsewhere.  Setting it
665      `nil' stops XEmacs from making backups of the `RMAIL' file, which
666      may save disk space.  (You would put this code in your `.emacs'
667      file.)
668
669           (add-hook 'rmail-mode-hook
670                     (function (lambda ()
671                                 (make-local-variable
672                                  'make-backup-files)
673                                 (setq make-backup-files nil))))
674
675  - Variable: backup-enable-predicate
676      This variable's value is a function to be called on certain
677      occasions to decide whether a file should have backup files.  The
678      function receives one argument, a file name to consider.  If the
679      function returns `nil', backups are disabled for that file.
680      Otherwise, the other variables in this section say whether and how
681      to make backups.
682
683      The default value is this:
684
685           (lambda (name)
686             (or (< (length name) 5)
687                 (not (string-equal "/tmp/"
688                                    (substring name 0 5)))))
689
690  - Variable: backup-inhibited
691      If this variable is non-`nil', backups are inhibited.  It records
692      the result of testing `backup-enable-predicate' on the visited file
693      name.  It can also coherently be used by other mechanisms that
694      inhibit backups based on which file is visited.  For example, VC
695      sets this variable non-`nil' to prevent making backups for files
696      managed with a version control system.
697
698      This is a permanent local, so that changing the major mode does
699      not lose its value.  Major modes should not set this
700      variable--they should set `make-backup-files' instead.
701
702 \1f
703 File: lispref.info,  Node: Rename or Copy,  Next: Numbered Backups,  Prev: Making Backups,  Up: Backup Files
704
705 Backup by Renaming or by Copying?
706 ---------------------------------
707
708    There are two ways that XEmacs can make a backup file:
709
710    * XEmacs can rename the original file so that it becomes a backup
711      file, and then write the buffer being saved into a new file.
712      After this procedure, any other names (i.e., hard links) of the
713      original file now refer to the backup file.  The new file is owned
714      by the user doing the editing, and its group is the default for
715      new files written by the user in that directory.
716
717    * XEmacs can copy the original file into a backup file, and then
718      overwrite the original file with new contents.  After this
719      procedure, any other names (i.e., hard links) of the original file
720      still refer to the current version of the file.  The file's owner
721      and group will be unchanged.
722
723    The first method, renaming, is the default.
724
725    The variable `backup-by-copying', if non-`nil', says to use the
726 second method, which is to copy the original file and overwrite it with
727 the new buffer contents.  The variable `file-precious-flag', if
728 non-`nil', also has this effect (as a sideline of its main
729 significance).  *Note Saving Buffers::.
730
731  - Variable: backup-by-copying
732      If this variable is non-`nil', XEmacs always makes backup files by
733      copying.
734
735    The following two variables, when non-`nil', cause the second method
736 to be used in certain special cases.  They have no effect on the
737 treatment of files that don't fall into the special cases.
738
739  - Variable: backup-by-copying-when-linked
740      If this variable is non-`nil', XEmacs makes backups by copying for
741      files with multiple names (hard links).
742
743      This variable is significant only if `backup-by-copying' is `nil',
744      since copying is always used when that variable is non-`nil'.
745
746  - Variable: backup-by-copying-when-mismatch
747      If this variable is non-`nil', XEmacs makes backups by copying in
748      cases where renaming would change either the owner or the group of
749      the file.
750
751      The value has no effect when renaming would not alter the owner or
752      group of the file; that is, for files which are owned by the user
753      and whose group matches the default for a new file created there
754      by the user.
755
756      This variable is significant only if `backup-by-copying' is `nil',
757      since copying is always used when that variable is non-`nil'.
758
759 \1f
760 File: lispref.info,  Node: Numbered Backups,  Next: Backup Names,  Prev: Rename or Copy,  Up: Backup Files
761
762 Making and Deleting Numbered Backup Files
763 -----------------------------------------
764
765    If a file's name is `foo', the names of its numbered backup versions
766 are `foo.~V~', for various integers V, like this: `foo.~1~', `foo.~2~',
767 `foo.~3~', ..., `foo.~259~', and so on.
768
769  - User Option: version-control
770      This variable controls whether to make a single non-numbered backup
771      file or multiple numbered backups.
772
773     `nil'
774           Make numbered backups if the visited file already has
775           numbered backups; otherwise, do not.
776
777     `never'
778           Do not make numbered backups.
779
780     ANYTHING ELSE
781           Make numbered backups.
782
783    The use of numbered backups ultimately leads to a large number of
784 backup versions, which must then be deleted.  XEmacs can do this
785 automatically or it can ask the user whether to delete them.
786
787  - User Option: kept-new-versions
788      The value of this variable is the number of newest versions to keep
789      when a new numbered backup is made.  The newly made backup is
790      included in the count.  The default value is 2.
791
792  - User Option: kept-old-versions
793      The value of this variable is the number of oldest versions to keep
794      when a new numbered backup is made.  The default value is 2.
795
796    If there are backups numbered 1, 2, 3, 5, and 7, and both of these
797 variables have the value 2, then the backups numbered 1 and 2 are kept
798 as old versions and those numbered 5 and 7 are kept as new versions;
799 backup version 3 is excess.  The function `find-backup-file-name'
800 (*note Backup Names::) is responsible for determining which backup
801 versions to delete, but does not delete them itself.
802
803  - User Option: delete-old-versions
804      If this variable is non-`nil', then saving a file deletes excess
805      backup versions silently.  Otherwise, it asks the user whether to
806      delete them.
807
808  - User Option: dired-kept-versions
809      This variable specifies how many of the newest backup versions to
810      keep in the Dired command `.' (`dired-clean-directory').  That's
811      the same thing `kept-new-versions' specifies when you make a new
812      backup file.  The default value is 2.
813
814 \1f
815 File: lispref.info,  Node: Backup Names,  Prev: Numbered Backups,  Up: Backup Files
816
817 Naming Backup Files
818 -------------------
819
820    The functions in this section are documented mainly because you can
821 customize the naming conventions for backup files by redefining them.
822 If you change one, you probably need to change the rest.
823
824  - Function: backup-file-name-p filename
825      This function returns a non-`nil' value if FILENAME is a possible
826      name for a backup file.  A file with the name FILENAME need not
827      exist; the function just checks the name.
828
829           (backup-file-name-p "foo")
830                => nil
831           (backup-file-name-p "foo~")
832                => 3
833
834      The standard definition of this function is as follows:
835
836           (defun backup-file-name-p (file)
837             "Return non-nil if FILE is a backup file \
838           name (numeric or not)..."
839             (string-match "~$" file))
840
841      Thus, the function returns a non-`nil' value if the file name ends
842      with a `~'.  (We use a backslash to split the documentation
843      string's first line into two lines in the text, but produce just
844      one line in the string itself.)
845
846      This simple expression is placed in a separate function to make it
847      easy to redefine for customization.
848
849  - Function: make-backup-file-name filename
850      This function returns a string that is the name to use for a
851      non-numbered backup file for file FILENAME.  On Unix, this is just
852      FILENAME with a tilde appended.
853
854      The standard definition of this function is as follows:
855
856           (defun make-backup-file-name (file)
857             "Create the non-numeric backup file name for FILE.
858           ..."
859             (concat file "~"))
860
861      You can change the backup-file naming convention by redefining this
862      function.  The following example redefines `make-backup-file-name'
863      to prepend a `.' in addition to appending a tilde:
864
865           (defun make-backup-file-name (filename)
866             (concat "." filename "~"))
867           
868           (make-backup-file-name "backups.texi")
869                => ".backups.texi~"
870
871  - Function: find-backup-file-name filename
872      This function computes the file name for a new backup file for
873      FILENAME.  It may also propose certain existing backup files for
874      deletion.  `find-backup-file-name' returns a list whose CAR is the
875      name for the new backup file and whose CDR is a list of backup
876      files whose deletion is proposed.
877
878      Two variables, `kept-old-versions' and `kept-new-versions',
879      determine which backup versions should be kept.  This function
880      keeps those versions by excluding them from the CDR of the value.
881      *Note Numbered Backups::.
882
883      In this example, the value says that `~rms/foo.~5~' is the name to
884      use for the new backup file, and `~rms/foo.~3~' is an "excess"
885      version that the caller should consider deleting now.
886
887           (find-backup-file-name "~rms/foo")
888                => ("~rms/foo.~5~" "~rms/foo.~3~")
889
890  - Function: file-newest-backup filename
891      This function returns the name of the most recent backup file for
892      FILENAME, or `nil' if that file has no backup files.
893
894      Some file comparison commands use this function so that they can
895      automatically compare a file with its most recent backup.
896
897 \1f
898 File: lispref.info,  Node: Auto-Saving,  Next: Reverting,  Prev: Backup Files,  Up: Backups and Auto-Saving
899
900 Auto-Saving
901 ===========
902
903    XEmacs periodically saves all files that you are visiting; this is
904 called "auto-saving".  Auto-saving prevents you from losing more than a
905 limited amount of work if the system crashes.  By default, auto-saves
906 happen every 300 keystrokes, or after around 30 seconds of idle time.
907 *Note Auto-Save: (emacs)Auto-Save, for information on auto-save for
908 users.  Here we describe the functions used to implement auto-saving
909 and the variables that control them.
910
911  - Variable: buffer-auto-save-file-name
912      This buffer-local variable is the name of the file used for
913      auto-saving the current buffer.  It is `nil' if the buffer should
914      not be auto-saved.
915
916           buffer-auto-save-file-name
917           => "/xcssun/users/rms/lewis/#files.texi#"
918
919  - Command: auto-save-mode arg
920      When used interactively without an argument, this command is a
921      toggle switch: it turns on auto-saving of the current buffer if it
922      is off, and vice-versa.  With an argument ARG, the command turns
923      auto-saving on if the value of ARG is `t', a nonempty list, or a
924      positive integer.  Otherwise, it turns auto-saving off.
925
926  - Function: auto-save-file-name-p filename
927      This function returns a non-`nil' value if FILENAME is a string
928      that could be the name of an auto-save file.  It works based on
929      knowledge of the naming convention for auto-save files: a name that
930      begins and ends with hash marks (`#') is a possible auto-save file
931      name.  The argument FILENAME should not contain a directory part.
932
933           (make-auto-save-file-name)
934                => "/xcssun/users/rms/lewis/#files.texi#"
935           (auto-save-file-name-p "#files.texi#")
936                => 0
937           (auto-save-file-name-p "files.texi")
938                => nil
939
940      The standard definition of this function is as follows:
941
942           (defun auto-save-file-name-p (filename)
943             "Return non-nil if FILENAME can be yielded by..."
944             (string-match "^#.*#$" filename))
945
946      This function exists so that you can customize it if you wish to
947      change the naming convention for auto-save files.  If you redefine
948      it, be sure to redefine the function `make-auto-save-file-name'
949      correspondingly.
950
951  - Function: make-auto-save-file-name
952      This function returns the file name to use for auto-saving the
953      current buffer.  This is just the file name with hash marks (`#')
954      appended and prepended to it.  This function does not look at the
955      variable `auto-save-visited-file-name' (described below); you
956      should check that before calling this function.
957
958           (make-auto-save-file-name)
959                => "/xcssun/users/rms/lewis/#backup.texi#"
960
961      The standard definition of this function is as follows:
962
963           (defun make-auto-save-file-name ()
964             "Return file name to use for auto-saves \
965           of current buffer.
966           ..."
967             (if buffer-file-name
968                 (concat
969                  (file-name-directory buffer-file-name)
970                  "#"
971                  (file-name-nondirectory buffer-file-name)
972                  "#")
973               (expand-file-name
974                (concat "#%" (buffer-name) "#"))))
975
976      This exists as a separate function so that you can redefine it to
977      customize the naming convention for auto-save files.  Be sure to
978      change `auto-save-file-name-p' in a corresponding way.
979
980  - Variable: auto-save-visited-file-name
981      If this variable is non-`nil', XEmacs auto-saves buffers in the
982      files they are visiting.  That is, the auto-save is done in the
983      same file that you are editing.  Normally, this variable is `nil',
984      so auto-save files have distinct names that are created by
985      `make-auto-save-file-name'.
986
987      When you change the value of this variable, the value does not take
988      effect until the next time auto-save mode is reenabled in any given
989      buffer.  If auto-save mode is already enabled, auto-saves continue
990      to go in the same file name until `auto-save-mode' is called again.
991
992  - Function: recent-auto-save-p
993      This function returns `t' if the current buffer has been
994      auto-saved since the last time it was read in or saved.
995
996  - Function: set-buffer-auto-saved
997      This function marks the current buffer as auto-saved.  The buffer
998      will not be auto-saved again until the buffer text is changed
999      again.  The function returns `nil'.
1000
1001  - User Option: auto-save-interval
1002      The value of this variable is the number of characters that XEmacs
1003      reads from the keyboard between auto-saves.  Each time this many
1004      more characters are read, auto-saving is done for all buffers in
1005      which it is enabled.
1006
1007  - User Option: auto-save-timeout
1008      The value of this variable is the number of seconds of idle time
1009      that should cause auto-saving.  Each time the user pauses for this
1010      long, XEmacs auto-saves any buffers that need it.  (Actually, the
1011      specified timeout is multiplied by a factor depending on the size
1012      of the current buffer.)
1013
1014  - Variable: auto-save-hook
1015      This normal hook is run whenever an auto-save is about to happen.
1016
1017  - User Option: auto-save-default
1018      If this variable is non-`nil', buffers that are visiting files
1019      have auto-saving enabled by default.  Otherwise, they do not.
1020
1021  - Command: do-auto-save &optional no-message current-only
1022      This function auto-saves all buffers that need to be auto-saved.
1023      It saves all buffers for which auto-saving is enabled and that
1024      have been changed since the previous auto-save.
1025
1026      Normally, if any buffers are auto-saved, a message that says
1027      `Auto-saving...' is displayed in the echo area while auto-saving is
1028      going on.  However, if NO-MESSAGE is non-`nil', the message is
1029      inhibited.
1030
1031      If CURRENT-ONLY is non-`nil', only the current buffer is
1032      auto-saved.
1033
1034  - Function: delete-auto-save-file-if-necessary
1035      This function deletes the current buffer's auto-save file if
1036      `delete-auto-save-files' is non-`nil'.  It is called every time a
1037      buffer is saved.
1038
1039  - Variable: delete-auto-save-files
1040      This variable is used by the function
1041      `delete-auto-save-file-if-necessary'.  If it is non-`nil', Emacs
1042      deletes auto-save files when a true save is done (in the visited
1043      file).  This saves disk space and unclutters your directory.
1044
1045  - Function: rename-auto-save-file
1046      This function adjusts the current buffer's auto-save file name if
1047      the visited file name has changed.  It also renames an existing
1048      auto-save file.  If the visited file name has not changed, this
1049      function does nothing.
1050
1051  - Variable: buffer-saved-size
1052      The value of this buffer-local variable is the length of the
1053      current buffer as of the last time it was read in, saved, or
1054      auto-saved.  This is used to detect a substantial decrease in
1055      size, and turn off auto-saving in response.
1056
1057      If it is -1, that means auto-saving is temporarily shut off in this
1058      buffer due to a substantial deletion.  Explicitly saving the buffer
1059      stores a positive value in this variable, thus reenabling
1060      auto-saving.  Turning auto-save mode off or on also alters this
1061      variable.
1062
1063  - Variable: auto-save-list-file-name
1064      This variable (if non-`nil') specifies a file for recording the
1065      names of all the auto-save files.  Each time XEmacs does
1066      auto-saving, it writes two lines into this file for each buffer
1067      that has auto-saving enabled.  The first line gives the name of
1068      the visited file (it's empty if the buffer has none), and the
1069      second gives the name of the auto-save file.
1070
1071      If XEmacs exits normally, it deletes this file.  If XEmacs
1072      crashes, you can look in the file to find all the auto-save files
1073      that might contain work that was otherwise lost.  The
1074      `recover-session' command uses these files.
1075
1076      The default name for this file is in your home directory and
1077      starts with `.saves-'.  It also contains the XEmacs process ID and
1078      the host name.
1079
1080 \1f
1081 File: lispref.info,  Node: Reverting,  Prev: Auto-Saving,  Up: Backups and Auto-Saving
1082
1083 Reverting
1084 =========
1085
1086    If you have made extensive changes to a file and then change your
1087 mind about them, you can get rid of them by reading in the previous
1088 version of the file with the `revert-buffer' command.  *Note Reverting
1089 a Buffer: (emacs)Reverting.
1090
1091  - Command: revert-buffer &optional check-auto-save noconfirm
1092      This command replaces the buffer text with the text of the visited
1093      file on disk.  This action undoes all changes since the file was
1094      visited or saved.
1095
1096      If the argument CHECK-AUTO-SAVE is non-`nil', and the latest
1097      auto-save file is more recent than the visited file,
1098      `revert-buffer' asks the user whether to use that instead.
1099      Otherwise, it always uses the text of the visited file itself.
1100      Interactively, CHECK-AUTO-SAVE is set if there is a numeric prefix
1101      argument.
1102
1103      Normally, `revert-buffer' asks for confirmation before it changes
1104      the buffer; but if the argument NOCONFIRM is non-`nil',
1105      `revert-buffer' does not ask for confirmation.
1106
1107      Reverting tries to preserve marker positions in the buffer by
1108      using the replacement feature of `insert-file-contents'.  If the
1109      buffer contents and the file contents are identical before the
1110      revert operation, reverting preserves all the markers.  If they
1111      are not identical, reverting does change the buffer; then it
1112      preserves the markers in the unchanged text (if any) at the
1113      beginning and end of the buffer.  Preserving any additional
1114      markers would be problematical.
1115
1116    You can customize how `revert-buffer' does its work by setting these
1117 variables--typically, as buffer-local variables.
1118
1119  - Variable: revert-buffer-function
1120      The value of this variable is the function to use to revert this
1121      buffer.  If non-`nil', it is called as a function with no
1122      arguments to do the work of reverting.  If the value is `nil',
1123      reverting works the usual way.
1124
1125      Modes such as Dired mode, in which the text being edited does not
1126      consist of a file's contents but can be regenerated in some other
1127      fashion, give this variable a buffer-local value that is a
1128      function to regenerate the contents.
1129
1130  - Variable: revert-buffer-insert-file-contents-function
1131      The value of this variable, if non-`nil', is the function to use to
1132      insert the updated contents when reverting this buffer.  The
1133      function receives two arguments: first the file name to use;
1134      second, `t' if the user has asked to read the auto-save file.
1135
1136  - Variable: before-revert-hook
1137      This normal hook is run by `revert-buffer' before actually
1138      inserting the modified contents--but only if
1139      `revert-buffer-function' is `nil'.
1140
1141      Font Lock mode uses this hook to record that the buffer contents
1142      are no longer fontified.
1143
1144  - Variable: after-revert-hook
1145      This normal hook is run by `revert-buffer' after actually inserting
1146      the modified contents--but only if `revert-buffer-function' is
1147      `nil'.
1148
1149      Font Lock mode uses this hook to recompute the fonts for the
1150      updated buffer contents.
1151
1152 \1f
1153 File: lispref.info,  Node: Buffers,  Next: Windows,  Prev: Backups and Auto-Saving,  Up: Top
1154
1155 Buffers
1156 *******
1157
1158    A "buffer" is a Lisp object containing text to be edited.  Buffers
1159 are used to hold the contents of files that are being visited; there may
1160 also be buffers that are not visiting files.  While several buffers may
1161 exist at one time, exactly one buffer is designated the "current
1162 buffer" at any time.  Most editing commands act on the contents of the
1163 current buffer.  Each buffer, including the current buffer, may or may
1164 not be displayed in any windows.
1165
1166 * Menu:
1167
1168 * Buffer Basics::       What is a buffer?
1169 * Current Buffer::      Designating a buffer as current
1170                           so primitives will access its contents.
1171 * Buffer Names::        Accessing and changing buffer names.
1172 * Buffer File Name::    The buffer file name indicates which file is visited.
1173 * Buffer Modification:: A buffer is "modified" if it needs to be saved.
1174 * Modification Time::   Determining whether the visited file was changed
1175                          ``behind XEmacs's back''.
1176 * Read Only Buffers::   Modifying text is not allowed in a read-only buffer.
1177 * The Buffer List::     How to look at all the existing buffers.
1178 * Creating Buffers::    Functions that create buffers.
1179 * Killing Buffers::     Buffers exist until explicitly killed.
1180 * Indirect Buffers::    An indirect buffer shares text with some other buffer.
1181