Merge from emacs-23
[bpt/emacs.git] / doc / lispref / files.texi
index 640d4ac..e2d2203 100644 (file)
@@ -1,7 +1,8 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001,
-@c   2002, 2003, 2004, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+@c   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+@c   Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../../info/files
 @node Files, Backups and Auto-Saving, Documentation, Top
@@ -38,9 +39,9 @@ to locale @code{system-message-locale}, and decoded using coding system
 * Changing Files::           Renaming files, changing protection, etc.
 * File Names::               Decomposing and expanding file names.
 * Contents of Directories::  Getting a list of the files in a directory.
-* Create/Delete Dirs::      Creating and Deleting Directories.
-* Magic File Names::        Defining "magic" special handling
-                              for certain file names.
+* Create/Delete Dirs::       Creating and Deleting Directories.
+* Magic File Names::         Defining "magic" special handling
+                               for certain file names.
 * Format Conversion::        Conversion to and from various file formats.
 @end menu
 
@@ -203,14 +204,14 @@ the @code{find-file} commands ignore their @var{wildcards} argument
 and never treat wildcard characters specially.
 @end defopt
 
-@defvar find-file-hook
+@defopt find-file-hook
 The value of this variable is a list of functions to be called after a
 file is visited.  The file's local-variables specification (if any) will
 have been processed before the hooks are run.  The buffer visiting the
 file is current when the hook functions are run.
 
 This variable is a normal hook.  @xref{Hooks}.
-@end defvar
+@end defopt
 
 @defvar find-file-not-found-functions
 The value of this variable is a list of functions to be called when
@@ -500,7 +501,10 @@ the list @code{after-insert-file-functions}.  @xref{Format Conversion}.
 Normally, one of the functions in the
 @code{after-insert-file-functions} list determines the coding system
 (@pxref{Coding Systems}) used for decoding the file's contents,
-including end-of-line conversion.
+including end-of-line conversion.  However, if the file contains null
+bytes, it is by default visited without any code conversions; see
+@ref{Lisp and Coding Systems, inhibit-null-byte-detection}, for how to
+control this behavior.
 
 If @var{visit} is non-@code{nil}, this function additionally marks the
 buffer as unmodified and sets up various fields in the buffer so that it
@@ -752,7 +756,7 @@ otherwise noted.
 @menu
 * Testing Accessibility::   Is a given file readable?  Writable?
 * Kinds of Files::          Is it a directory?  A symbolic link?
-* Truenames::              Eliminating symbolic links from a file name.
+* Truenames::               Eliminating symbolic links from a file name.
 * File Attributes::         How large is it?  Any other names?  Etc.
 * Locating Files::          How to find a file in standard places.
 @end menu
@@ -1173,14 +1177,20 @@ The file's @acronym{GID}, likewise.
 The time of last access, as a list of two integers.
 The first integer has the high-order 16 bits of time,
 the second has the low 16 bits.  (This is similar to the
-value of @code{current-time}; see @ref{Time of Day}.)
+value of @code{current-time}; see @ref{Time of Day}.)  Note that on
+some FAT-based filesystems, only the date of last access is recorded,
+so this time will always hold the midnight of the day of last access.
 
+@cindex modification time of file
 @item
 The time of last modification as a list of two integers (as above).
-@cindex modification time of file
+This is the last time when the file's contents were modified.
 
 @item
 The time of last status change as a list of two integers (as above).
+This is the time of the last change to the file's access mode bits,
+its owner and group, and other information recorded in the filesystem
+for the file, beyond the file's contents.
 
 @item
 The size of the file in bytes.  If the size is too large to fit in a
@@ -1195,18 +1205,22 @@ as in @samp{ls -l}.
 deleted and recreated; @code{nil} otherwise.
 
 @item
-The file's inode number.  If possible, this is an integer.  If the inode
-number is too large to be represented as an integer in Emacs Lisp, then
-the value has the form @code{(@var{high} . @var{low})}, where @var{low}
-holds the low 16 bits.
+The file's inode number.  If possible, this is an integer.  If the
+inode number is too large to be represented as an integer in Emacs
+Lisp, but still fits into a 32-bit integer, then the value has the
+form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16
+bits.  If the inode is wider than 32 bits, the value is of the form
+@code{(@var{high} @var{middle} . @var{low})}, where @code{high} holds
+the high 24 bits, @var{middle} the next 24 bits, and @var{low} the low
+16 bits.
 
 @item
-The file system number of the file system that the file is in.
-Depending on the magnitude of the value, this can be either an integer
-or a cons cell, in the same manner as the inode number.  This element
-and the file's inode number together give enough information to
-distinguish any two files on the system---no two files can have the same
-values for both of these numbers.
+The filesystem number of the device that the file is on.  Depending on
+the magnitude of the value, this can be either an integer or a cons
+cell, in the same manner as the inode number.  This element and the
+file's inode number together give enough information to distinguish
+any two files on the system---no two files can have the same values
+for both of these numbers.
 @end enumerate
 
 For example, here are the file attributes for @file{files.texi}:
@@ -1215,11 +1229,12 @@ For example, here are the file attributes for @file{files.texi}:
 @group
 (file-attributes "files.texi" 'string)
      @result{}  (nil 1 "lh" "users"
-          (8489 20284)
-          (8489 20284)
-          (8489 20285)
-          14906 "-rw-rw-rw-"
-          nil 129500 -32252)
+          (19145 42977)
+          (19141 59576)
+          (18340 17300)
+          122295 "-rw-rw-rw-"
+          nil  (5888 2 . 43978)
+          (15479 . 46724))
 @end group
 @end example
 
@@ -1240,18 +1255,19 @@ is owned by the user with name "lh".
 @item "users"
 is in the group with name "users".
 
-@item (8489 20284)
-was last accessed on Aug 19 00:09.
+@item (19145 42977)
+was last accessed on Oct 5 2009, at 10:01:37.
 
-@item (8489 20284)
-was last modified on Aug 19 00:09.
+@item (19141 59576)
+last had its contents modified on Oct 2 2009, at 13:49:12.
 
-@item (8489 20285)
-last had its inode changed on Aug 19 00:09.
+@item (18340 17300)
+last had its status changed on Feb 2 2008, at 12:19:00.
 
-@item 14906
-is 14906 bytes long.  (It may not contain 14906 characters, though,
-if some of the bytes belong to multibyte sequences.)
+@item 122295
+is 122295 bytes long.  (It may not contain 122295 characters, though,
+if some of the bytes belong to multibyte sequences, and also if the
+end-of-line format is CR-LF.)
 
 @item "-rw-rw-rw-"
 has a mode of read and write access for the owner, group, and world.
@@ -1259,13 +1275,25 @@ has a mode of read and write access for the owner, group, and world.
 @item nil
 would retain the same @acronym{GID} if it were recreated.
 
-@item 129500
-has an inode number of 129500.
-@item -32252
-is on file system number -32252.
+@item (5888 2 . 43978)
+has an inode number of 6473924464520138.
+
+@item (15479 . 46724)
+is on the file-system device whose number is 1014478468.
 @end table
 @end defun
 
+@cindex MS-DOS and file modes
+@cindex file modes and MS-DOS
+  On MS-DOS, there is no such thing as an ``executable'' file mode bit.
+So Emacs considers a file executable if its name ends in one of the
+standard executable extensions, such as @file{.com}, @file{.bat},
+@file{.exe}, and some others.  Files that begin with the Unix-standard
+@samp{#!} signature, such as shell and Perl scripts, are also considered
+as executable files.  This is reflected in the values returned by
+@code{file-modes} and @code{file-attributes}.  Directories are also
+reported with executable bit set, for compatibility with Unix.
+
 @node Locating Files
 @subsection How to Locate Files in Standard Places
 @cindex locate file in path
@@ -1487,17 +1515,20 @@ levels of parent directories.
 See also @code{delete-directory} in @ref{Create/Delete Dirs}.
 @end deffn
 
-@defun define-logical-name varname string
-This function defines the logical name @var{varname} to have the value
-@var{string}.  It is available only on VMS.
-@end defun
-
-@defun set-file-modes filename mode
+@deffn Command set-file-modes filename mode
 This function sets mode bits of @var{filename} to @var{mode} (which
-must be an integer).  Only the low 12 bits of @var{mode} are used.
+must be an integer when the function is called non-interactively).
+Only the low 12 bits of @var{mode} are used.
+
+Interactively, @var{mode} is read from the minibuffer using
+@code{read-file-modes}, which accepts mode bits either as a number or
+as a character string representing the mode bits symbolically.  See
+the description of @code{read-file-modes} below for the supported
+forms of symbolic notation for mode bits.
+
 This function recursively follows symbolic links at all levels for
 @var{filename}.
-@end defun
+@end deffn
 
 @c Emacs 19 feature
 @defun set-default-file-modes mode
@@ -1526,6 +1557,36 @@ the default file protection has no effect.
 This function returns the current default protection value.
 @end defun
 
+@defun read-file-modes &optional prompt base-file
+This function reads file mode bits from the minibuffer.  The optional
+argument @var{prompt} specifies a non-default prompt.  Second optional
+argument @var{base-file} is the name of a file on whose permissions to
+base the mode bits that this function returns, if what the user types
+specifies mode bits relative to permissions of an existing file.
+
+If user input represents an octal number, this function returns that
+number.  If it is a complete symbolic specification of mode bits, as
+in @code{"u=rwx"}, the function converts it to the equivalent numeric
+value using @code{file-modes-symbolic-to-number} and returns the
+result.  If the specification is relative, as in @code{"o+g"}, then
+the permissions on which the specification is based are taken from the
+mode bits of @var{base-file}.  If @var{base-file} is omitted or
+@code{nil}, the function uses @code{0} as the base mode bits.  The
+complete and relative specifications can be combined, as in
+@code{"u+r,g+rx,o+r,g-w"}.  @xref{File Permissions,,, coreutils, The
+@sc{gnu} @code{Coreutils} Manual}, for detailed description of
+symbolic mode bits specifications.
+@end defun
+
+@defun file-modes-symbolic-to-number modes &optional base-modes
+This subroutine converts a symbolic specification of file mode bits in
+@var{modes} into the equivalent numeric value.  If the symbolic
+specification is based on an existing file, that file's mode bits are
+taken from the optional argument @var{base-modes}; if that argument is
+omitted or @code{nil}, it defaults to zero, i.e.@: no access rights at
+all.
+@end defun
+
 @defun set-file-times filename &optional time
 This function sets the access and modification times of @var{filename}
 to @var{time}.  The return value is @code{t} if the times are successfully
@@ -1534,17 +1595,6 @@ time and must be in the format returned by @code{current-time}
 (@pxref{Time of Day}).
 @end defun
 
-@cindex MS-DOS and file modes
-@cindex file modes and MS-DOS
-  On MS-DOS, there is no such thing as an ``executable'' file mode bit.
-So Emacs considers a file executable if its name ends in one of the
-standard executable extensions, such as @file{.com}, @file{.bat},
-@file{.exe}, and some others.  Files that begin with the Unix-standard
-@samp{#!} signature, such as shell and Perl scripts, are also considered
-as executable files.  This is reflected in the values returned by
-@code{file-modes} and @code{file-attributes}.  Directories are also
-reported with executable bit set, for compatibility with Unix.
-
 @node File Names
 @section File Names
 @cindex file names
@@ -1565,10 +1615,9 @@ directory.
   On MS-DOS and MS-Windows, these functions (like the function that
 actually operate on files) accept MS-DOS or MS-Windows file-name syntax,
 where backslashes separate the components, as well as Unix syntax; but
-they always return Unix syntax.  On VMS, these functions (and the ones
-that operate on files) understand both VMS file-name syntax and Unix
-syntax.  This enables Lisp programs to specify file names in Unix syntax
-and work properly on all systems without change.
+they always return Unix syntax.  This enables Lisp programs to specify
+file names in Unix syntax and work properly on all systems without
+change.
 
 @menu
 * File Name Components::  The directory part of a file name, and the rest.
@@ -1597,15 +1646,11 @@ Concatenating these two parts reproduces the original file name.
 
   On most systems, the directory part is everything up to and including
 the last slash (backslash is also allowed in input on MS-DOS or
-MS-Windows); the nondirectory part is the rest.  The rules in VMS syntax
-are complicated.
+MS-Windows); the nondirectory part is the rest.
 
   For some purposes, the nondirectory part is further subdivided into
 the name proper and the @dfn{version number}.  On most systems, only
-backup files have version numbers in their names.  On VMS, every file
-has a version number, but most of the time the file name actually used
-in Emacs omits the version number, so that version numbers in Emacs are
-found mostly in directory lists.
+backup files have version numbers in their names.
 
 @defun file-name-directory filename
 This function returns the directory part of @var{filename}, as a
@@ -1613,9 +1658,7 @@ directory name (@pxref{Directory Names}), or @code{nil} if
 @var{filename} does not include a directory part.
 
 On GNU and Unix systems, a string returned by this function always
-ends in a slash.  On MS-DOS it can also end in a colon.  On VMS, it
-returns a string ending in one of the three characters @samp{:},
-@samp{]}, or @samp{>}.
+ends in a slash.  On MS-DOS it can also end in a colon.
 
 @example
 @group
@@ -1626,10 +1669,6 @@ returns a string ending in one of the three characters @samp{:},
 (file-name-directory "foo")        ; @r{Unix example}
      @result{} nil
 @end group
-@group
-(file-name-directory "[X]FOO.TMP") ; @r{VMS example}
-     @result{} "[X]"
-@end group
 @end example
 @end defun
 
@@ -1649,11 +1688,6 @@ This function returns the nondirectory part of @var{filename}.
 (file-name-nondirectory "lewis/")
      @result{} ""
 @end group
-@group
-;; @r{The following example is accurate only on VMS.}
-(file-name-nondirectory "[X]FOO.TMP")
-     @result{} "FOO.TMP"
-@end group
 @end example
 @end defun
 
@@ -1678,11 +1712,6 @@ return value, but backup version numbers are kept.
 (file-name-sans-versions "~rms/foo")
      @result{} "~rms/foo"
 @end group
-@group
-;; @r{The following example applies to VMS only.}
-(file-name-sans-versions "foo;23")
-     @result{} "foo"
-@end group
 @end example
 @end defun
 
@@ -1690,8 +1719,8 @@ return value, but backup version numbers are kept.
 This function returns @var{filename}'s final ``extension,'' if any,
 after applying @code{file-name-sans-versions} to remove any
 version/backup part.  The extension, in a file name, is the part that
-starts with the last @samp{.} in the last name component (minus
-any version/backup part).
+follows the last @samp{.} in the last name component (minus any
+version/backup part).
 
 This function returns @code{nil} for extensionless file names such as
 @file{foo}.  It returns @code{""} for null extensions, as in
@@ -1729,20 +1758,6 @@ Note that the @samp{.~3~} in the two last examples is the backup part,
 not an extension.
 @end defun
 
-@ignore
-Andrew Innes says that this
-
-@c @defvar directory-sep-char
-This variable holds the character that Emacs normally uses to separate
-file name components.  The default value is @code{?/}, but on MS-Windows
-you can set it to @code{?\\}; then the functions that transform file names
-use backslashes in their output.
-
-File names using backslashes work as input to Lisp primitives even on
-MS-DOS and MS-Windows, even if @code{directory-sep-char} has its default
-value of @code{?/}.
-@end defvar
-@end ignore
 
 @node Relative File Names
 @subsection Absolute and Relative File Names
@@ -1758,12 +1773,11 @@ name.  On Unix and GNU/Linux, an absolute file name starts with a slash
 or a tilde (@samp{~}), and a relative one does not.  On MS-DOS and
 MS-Windows, an absolute file name starts with a slash or a backslash, or
 with a drive specification @samp{@var{x}:/}, where @var{x} is the
-@dfn{drive letter}.  The rules on VMS are complicated.
+@dfn{drive letter}.
 
 @defun file-name-absolute-p filename
 This function returns @code{t} if file @var{filename} is an absolute
-file name, @code{nil} otherwise.  On VMS, this function understands both
-Unix syntax and VMS syntax.
+file name, @code{nil} otherwise.
 
 @example
 @group
@@ -1819,8 +1833,8 @@ the directory name but not identical to it.  (This is not quite the
 same as the usual Unix terminology.)  These two different names for
 the same entity are related by a syntactic transformation.  On GNU and
 Unix systems, this is simple: a directory name ends in a slash,
-whereas the directory's name as a file lacks that slash.  On MS-DOS and
-VMS, the relationship is more complicated.
+whereas the directory's name as a file lacks that slash.  On MS-DOS
+the relationship is more complicated.
 
   The difference between a directory name and its name as a file is
 subtle but crucial.  When an Emacs variable or function argument is
@@ -1836,8 +1850,7 @@ such as @samp{$HOME}, and the constructs @samp{~}, @samp{.} and @samp{..}.
 This function returns a string representing @var{filename} in a form
 that the operating system will interpret as the name of a directory.  On
 most systems, this means appending a slash to the string (if it does not
-already end in one).  On VMS, the function converts a string of the form
-@file{[X]Y.DIR.1} to the form @file{[X.Y]}.
+already end in one).
 
 @example
 @group
@@ -1851,8 +1864,7 @@ already end in one).  On VMS, the function converts a string of the form
 This function returns a string representing @var{dirname} in a form that
 the operating system will interpret as the name of a file.  On most
 systems, this means removing the final slash (or backslash) from the
-string.  On VMS, the function converts a string of the form @file{[X.Y]}
-to @file{[X]Y.DIR.1}.
+string.
 
 @example
 @group
@@ -1902,12 +1914,12 @@ annoying to see the directory's ``real'' name.  If you define the link
 name as an abbreviation for the ``real'' name, Emacs shows users the
 abbreviation instead.
 
-@defvar directory-abbrev-alist
+@defopt directory-abbrev-alist
 The variable @code{directory-abbrev-alist} contains an alist of
 abbreviations to use for file directories.  Each element has the form
 @code{(@var{from} . @var{to})}, and says to replace @var{from} with
 @var{to} when it appears in a directory name.  The @var{from} string is
-actually a regular expression; it should always start with @samp{^}.
+actually a regular expression; it ought to always start with @samp{\`}.
 The @var{to} string should be an ordinary absolute directory name.  Do
 not use @samp{~} to stand for a home directory in that string.  The
 function @code{abbreviate-file-name} performs these substitutions.
@@ -1920,11 +1932,11 @@ and so on are normally accessed through symbolic links named @file{/fsf}
 and so on.
 
 @example
-(("^/home/fsf" . "/fsf")
- ("^/home/gp" . "/gp")
- ("^/home/gd" . "/gd"))
+(("\\`/home/fsf" . "/fsf")
+ ("\\`/home/gp" . "/gp")
+ ("\\`/home/gd" . "/gd"))
 @end example
-@end defvar
+@end defopt
 
   To convert a directory name to its abbreviation, use this
 function:
@@ -1932,9 +1944,13 @@ function:
 @defun abbreviate-file-name filename
 @anchor{Definition of abbreviate-file-name}
 This function applies abbreviations from @code{directory-abbrev-alist}
-to its argument, and substitutes @samp{~} for the user's home
-directory.  You can use it for directory names and for file names,
-because it recognizes abbreviations even as part of the name.
+to its argument, and also substitutes @samp{~} for the user's home
+directory if the argument names a file in the home directory or one of
+its subdirectories.  (If the home directory is a root directory, it is
+not replaced with @samp{~}, because this does not make the result
+shorter on many systems.)  You can use it for directory names and for
+file names, because it recognizes abbreviations even as part of the
+name.
 @end defun
 
 @node File Name Expansion
@@ -2037,7 +2053,7 @@ with @samp{~}.  This variable is buffer-local in every buffer.
 @code{expand-file-name} uses the default directory when its second
 argument is @code{nil}.
 
-Aside from VMS, the value is always a string ending with a slash.
+The value is always a string ending with a slash.
 
 @example
 @group
@@ -2097,8 +2113,6 @@ through the immediately preceding @samp{/}).
 @end group
 @end example
 
-On VMS, @samp{$} substitution is not done, so this function does nothing
-on VMS except discard superfluous initial components as shown above.
 @end defun
 
 @node Unique File Names
@@ -2176,7 +2190,7 @@ should be an absolute file name.  On MS-DOS, this function can
 truncate the @var{string} prefix to fit into the 8+3 file-name limits.
 @end defun
 
-@defvar temporary-file-directory
+@defopt temporary-file-directory
 @cindex @code{TMPDIR} environment variable
 @cindex @code{TMP} environment variable
 @cindex @code{TEMP} environment variable
@@ -2196,9 +2210,9 @@ file, you should still use this variable to decide which directory to
 put the file in.  However, if you expect the file to be small, you
 should use @code{small-temporary-file-directory} first if that is
 non-@code{nil}.
-@end defvar
+@end defopt
 
-@defvar small-temporary-file-directory
+@defopt small-temporary-file-directory
 This variable specifies the directory name for
 creating certain temporary files, which are likely to be small.
 
@@ -2211,7 +2225,7 @@ should compute the directory like this:
                     (or small-temporary-file-directory
                         temporary-file-directory)))
 @end example
-@end defvar
+@end defopt
 
 @node File Name Completion
 @subsection File Name Completion
@@ -2417,11 +2431,6 @@ corresponding argument to @code{file-attributes} (@pxref{Definition
 of file-attributes}).
 @end defun
 
-@defun file-name-all-versions file dirname
-This function returns a list of all versions of the file named
-@var{file} in directory @var{dirname}.  It is only available on VMS.
-@end defun
-
 @defun file-expand-wildcards pattern &optional full
 This function expands the wildcard pattern @var{pattern}, returning
 a list of file names that match it.
@@ -2477,8 +2486,8 @@ which generate the listing with Lisp code.
 @end defvar
 
 @node Create/Delete Dirs
-@section Creating and Deleting Directories
-@cindex creating and deleting directories
+@section Creating, Copying and Deleting Directories
+@cindex creating, copying and deleting directories
 @c Emacs 19 features
 
   Most Emacs Lisp file-manipulation functions get errors when used on
@@ -2486,22 +2495,43 @@ files that are directories.  For example, you cannot delete a directory
 with @code{delete-file}.  These special functions exist to create and
 delete directories.
 
-@defun make-directory dirname &optional parents
-This function creates a directory named @var{dirname}.
-If @var{parents} is non-@code{nil}, as is always the case in an
+@findex mkdir
+@deffn Command make-directory dirname &optional parents
+This command creates a directory named @var{dirname}.  If
+@var{parents} is non-@code{nil}, as is always the case in an
 interactive call, that means to create the parent directories first,
 if they don't already exist.
-@end defun
 
-@defun delete-directory dirname
-This function deletes the directory named @var{dirname}.  The function
+@code{mkdir} is an alias for this.
+@end deffn
+
+@deffn Command copy-directory dirname newname &optional keep-time parents
+This command copies the directory named @var{dirname} to
+@var{newname}.  If @var{newname} names an existing directory,
+@var{dirname} will be copied to a subdirectory there.
+
+It always sets the file modes of the copied files to match the
+corresponding original file.
+
+The third arg @var{keep-time} non-@code{nil} means to preserve the
+modification time of the copied files.  A prefix arg makes
+@var{keep-time} non-@code{nil}.
+
+Noninteractively, the last argument @var{parents} says whether to
+create parent directories if they don't exist.  Interactively,
+this happens by default.
+@end deffn
+
+@deffn Command delete-directory dirname &optional recursive
+This command deletes the directory named @var{dirname}.  The function
 @code{delete-file} does not work for files that are directories; you
-must use @code{delete-directory} for them.  If the directory contains
-any files, @code{delete-directory} signals an error.
+must use @code{delete-directory} for them.  If @var{recursive} is
+@code{nil}, and the directory contains any files,
+@code{delete-directory} signals an error.
 
-This function only follows symbolic links at the level of parent
-directories.
-@end defun
+@code{delete-directory} only follows symbolic links at the level of
+parent directories.
+@end deffn
 
 @node Magic File Names
 @section Making Certain File Names ``Magic''
@@ -2518,6 +2548,7 @@ expression to define the class of names (all those that match the
 regular expression), plus a handler that implements all the primitive
 Emacs file operations for file names that do match.
 
+@vindex file-name-handler-alist
   The variable @code{file-name-handler-alist} holds a list of handlers,
 together with regular expressions that determine when to apply each
 handler.  Each element has this form:
@@ -2581,8 +2612,8 @@ first, before handlers for jobs such as remote file access.
 @noindent
 @code{access-file}, @code{add-name-to-file},
 @code{byte-compiler-base-file-name},@*
-@code{copy-file}, @code{delete-directory},
-@code{delete-file},
+@code{copy-directory}, @code{copy-file},
+@code{delete-directory}, @code{delete-file},
 @code{diff-latest-backup-file},
 @code{directory-file-name},
 @code{directory-files},
@@ -2604,7 +2635,7 @@ first, before handlers for jobs such as remote file access.
 @code{file-readable-p}, @code{file-regular-p}, @code{file-symlink-p},
 @code{file-truename}, @code{file-writable-p},
 @code{find-backup-file-name},
-@code{find-file-noselect},@*
+@c Not sure why it was here:   @code{find-file-noselect},@*
 @code{get-file-buffer},
 @code{insert-directory},
 @code{insert-file-contents},@*
@@ -2628,8 +2659,8 @@ first, before handlers for jobs such as remote file access.
 @flushleft
 @code{access-file}, @code{add-name-to-file},
 @code{byte-com@discretionary{}{}{}piler-base-file-name},
-@code{copy-file}, @code{delete-directory},
-@code{delete-file},
+@code{copy-directory}, @code{copy-file},
+@code{delete-directory}, @code{delete-file},
 @code{diff-latest-backup-file},
 @code{directory-file-name},
 @code{directory-files},
@@ -2651,7 +2682,7 @@ first, before handlers for jobs such as remote file access.
 @code{file-readable-p}, @code{file-regular-p}, @code{file-symlink-p},
 @code{file-truename}, @code{file-writable-p},
 @code{find-backup-file-name},
-@code{find-file-noselect},
+@c Not sure why it was here:   @code{find-file-noselect},
 @code{get-file-buffer},
 @code{insert-directory},
 @code{insert-file-contents},
@@ -2800,18 +2831,46 @@ making connections when they don't exist.
 @end defun
 
 @defun unhandled-file-name-directory filename
-This function returns the name of a directory that is not magic.
-It uses the directory part of @var{filename} if that is not magic.
-For a magic file name, it invokes the file name handler, which
-therefore decides what value to return.  If @var{filename} is not
-accessible from a local process, then the file name handler should
-indicate it by returning nil.
+This function returns the name of a directory that is not magic.  It
+uses the directory part of @var{filename} if that is not magic.  For a
+magic file name, it invokes the file name handler, which therefore
+decides what value to return.  If @var{filename} is not accessible
+from a local process, then the file name handler should indicate it by
+returning @code{nil}.
 
 This is useful for running a subprocess; every subprocess must have a
 non-magic directory to serve as its current directory, and this function
 is a good way to come up with one.
 @end defun
 
+@defopt remote-file-name-inhibit-cache
+Whether to use the remote file-name cache for read access.
+
+File attributes of remote files are cached for better performance.  If
+they are changed out of Emacs' control, the cached values become
+invalid, and must be reread.
+
+When set to @code{nil}, cached values are always used.  This shall be
+set with care.  When set to @code{t}, cached values are never used.
+ALthough this is the safest value, it could result in performance
+degradation.
+
+A compromise is to set it to a positive number.  This means that
+cached values are used for that amount of seconds since they were
+cached.
+
+In case a remote file is checked regularly, it might be reasonable to
+let-bind this variable to a value less then the time period between
+two checks.  Example:
+
+@example
+(defun display-time-file-nonempty-p (file)
+  (let ((remote-file-name-inhibit-cache (- display-time-interval 5)))
+    (and (file-exists-p file)
+         (< 0 (nth 7 (file-attributes (file-chase-links file)))))))
+@end example
+@end defopt
+
 @node Format Conversion
 @section File Format Conversion
 
@@ -2828,7 +2887,7 @@ namely @code{insert-file-contents} for reading a file into a buffer,
 and @code{write-region} for writing a buffer into a file.
 
 @menu
-* Overview: Format Conversion Overview.     @code{insert-file-contents} and @code{write-region}
+* Overview: Format Conversion Overview.     @code{insert-file-contents} and @code{write-region}.
 * Round-Trip: Format Conversion Round-Trip. Using @code{format-alist}.
 * Piecemeal: Format Conversion Piecemeal.   Specifying non-paired conversion.
 @end menu
@@ -2876,7 +2935,7 @@ This list contains one format definition for each defined file format.
 Each format definition is a list of this form:
 
 @example
-(@var{name} @var{doc-string} @var{regexp} @var{from-fn} @var{to-fn} @var{modify} @var{mode-fn})
+(@var{name} @var{doc-string} @var{regexp} @var{from-fn} @var{to-fn} @var{modify} @var{mode-fn} @var{preserve})
 @end example
 @end defvar
 
@@ -2893,7 +2952,7 @@ A documentation string for the format.
 
 @item regexp
 A regular expression which is used to recognize files represented in
-this format.
+this format.  If @code{nil}, the format is never applied automatically.
 
 @item from-fn
 A shell command or function to decode data in this format (to convert
@@ -2949,6 +3008,10 @@ A flag, @code{t} if the encoding function modifies the buffer, and
 A minor-mode function to call after visiting a file converted from this
 format.  The function is called with one argument, the integer 1;
 that tells a minor-mode function to enable the mode.
+
+@item preserve
+A flag, @code{t} if @code{format-write-file} should not remove this format
+from @code{buffer-file-format}.
 @end table
 
 The function @code{insert-file-contents} automatically recognizes file
@@ -2976,13 +3039,17 @@ encoding functions for the formats listed in @code{buffer-file-format},
 in the order of appearance in the list.
 
 @deffn Command format-write-file file format &optional confirm
-This command writes the current buffer contents into the file
-@var{file} in format @var{format}, and makes that format the default
-for future saves of the buffer.  The argument @var{format} is a list
-of format names.  Except for the @var{format} argument, this command
-is similar to @code{write-file}.  In particular, @var{confirm} has the
-same meaning and interactive treatment as the corresponding argument
-to @code{write-file}.  @xref{Definition of write-file}.
+This command writes the current buffer contents into the file @var{file}
+in a format based on @var{format}, which is a list of format names.  It
+constructs the actual format starting from @var{format}, then appending
+any elements from the value of @code{buffer-file-format} with a non-nil
+@var{preserve} flag (see above), if they are not already present in
+@var{format}.  It then updates @code{buffer-file-format} with this
+format, making it the default for future saves.  Except for the
+@var{format} argument, this command is similar to @code{write-file}.  In
+particular, @var{confirm} has the same meaning and interactive treatment
+as the corresponding argument to @code{write-file}.  @xref{Definition of
+write-file}.
 @end deffn
 
 @deffn Command format-find-file file format
@@ -3057,18 +3124,17 @@ place without modifying the buffer.
 @c ??? for `write-region-annotate-functions', below?  --ttn
 
   In contrast, when reading, the annotations intermixed with the text
-are handled immediately.  @code{insert-file-contents} sets point to the
-beginning of some text to be converted, then calls the conversion
+are handled immediately.  @code{insert-file-contents} sets point to
+the beginning of some text to be converted, then calls the conversion
 functions with the length of that text.  These functions should always
-return with point at the beginning of the inserted text.  This approach
-makes sense for reading because annotations removed by the first
-converter can't be mistakenly processed by a later converter.
-
-  Each conversion function should scan for the annotations it
-recognizes, remove the annotation, modify the buffer text (to set a text
-property, for example), and return the updated length of the text, as it
-stands after those changes.  The value returned by one function becomes
-the argument to the next function.
+return with point at the beginning of the inserted text.  This
+approach makes sense for reading because annotations removed by the
+first converter can't be mistakenly processed by a later converter.
+Each conversion function should scan for the annotations it
+recognizes, remove the annotation, modify the buffer text (to set a
+text property, for example), and return the updated length of the
+text, as it stands after those changes.  The value returned by one
+function becomes the argument to the next function.
 
 @defvar write-region-annotate-functions
 A list of functions for @code{write-region} to call.  Each function in
@@ -3076,13 +3142,30 @@ the list is called with two arguments: the start and end of the region
 to be written.  These functions should not alter the contents of the
 buffer.  Instead, they should return annotations.
 
-@c ??? Following adapted from comment in `build_annotations' (fileio.c).
-@c ??? Perhaps this is intended for internal use only?
-@c ??? Someone who understands this, please reword it. --ttn
-As a special case, if a function returns with a different buffer
-current, Emacs takes it to mean the current buffer contains altered text
-to be output, and discards all previous annotations because they should
-have been dealt with by this function.
+As a special case, a function may return with a different buffer
+current.  Emacs takes this to mean that the current buffer contains
+altered text to be output.  It therefore changes the @var{start} and
+@var{end} arguments of the @code{write-region} call, giving them the
+values of @code{point-min} and @code{point-max} in the new buffer,
+respectively.  It also discards all previous annotations, because they
+should have been dealt with by this function.
+@end defvar
+
+@defvar write-region-post-annotation-function
+The value of this variable, if non-@code{nil}, should be a function.
+This function is called, with no arguments, after @code{write-region}
+has completed.
+
+If any function in @code{write-region-annotate-functions} returns with
+a different buffer current, Emacs calls
+@code{write-region-post-annotation-function} more than once.  Emacs
+calls it with the last buffer that was current, and again with the
+buffer before that, and so on back to the original buffer.
+
+Thus, a function in @code{write-region-annotate-functions} can create
+a buffer, give this variable the local value of @code{kill-buffer} in
+that buffer, set up the buffer with altered text, and make the buffer
+current.  The buffer will be killed after @code{write-region} is done.
 @end defvar
 
 @defvar after-insert-file-functions