comparison lispref/files.texi @ 12067:73dc8205d259

*** empty log message ***
author Karl Heuer <kwzh@gnu.org>
date Mon, 05 Jun 1995 12:23:13 +0000
parents 0b86aef0c387
children a6eb5f12b0f3
comparison
equal deleted inserted replaced
12066:b9b0b3f96dc2 12067:73dc8205d259
32 * File Names:: Decomposing and expanding file names. 32 * File Names:: Decomposing and expanding file names.
33 * Contents of Directories:: Getting a list of the files in a directory. 33 * Contents of Directories:: Getting a list of the files in a directory.
34 * Create/Delete Dirs:: Creating and Deleting Directories. 34 * Create/Delete Dirs:: Creating and Deleting Directories.
35 * Magic File Names:: Defining "magic" special handling 35 * Magic File Names:: Defining "magic" special handling
36 for certain file names. 36 for certain file names.
37 * Format Conversion:: Conversion to and from various file formats.
37 * Files and MS-DOS:: Distinguishing text and binary files on MS-DOS. 38 * Files and MS-DOS:: Distinguishing text and binary files on MS-DOS.
38 @end menu 39 @end menu
39 40
40 @node Visiting Files 41 @node Visiting Files
41 @section Visiting Files 42 @section Visiting Files
424 If the argument @var{replace} is non-@code{nil}, it means to replace the 425 If the argument @var{replace} is non-@code{nil}, it means to replace the
425 contents of the buffer (actually, just the accessible portion) with the 426 contents of the buffer (actually, just the accessible portion) with the
426 contents of the file. This is better than simply deleting the buffer 427 contents of the file. This is better than simply deleting the buffer
427 contents and inserting the whole file, because (1) it preserves some 428 contents and inserting the whole file, because (1) it preserves some
428 marker positions and (2) it puts less data in the undo list. 429 marker positions and (2) it puts less data in the undo list.
430
431 The function @code{insert-file-contents} checks the file contents
432 against the defined file formats, and converts the file contents if
433 appropriate. @xref{Format Conversion}.
429 @end defun 434 @end defun
430 435
431 If you want to pass a file name to another process so that another 436 If you want to pass a file name to another process so that another
432 program can read the file, use the function @code{file-local-copy}; see 437 program can read the file, use the function @code{file-local-copy}; see
433 @ref{Magic File Names}. 438 @ref{Magic File Names}.
486 Normally, @code{write-region} displays a message @samp{Wrote file 491 Normally, @code{write-region} displays a message @samp{Wrote file
487 @var{filename}} in the echo area. If @var{visit} is neither @code{t} 492 @var{filename}} in the echo area. If @var{visit} is neither @code{t}
488 nor @code{nil} nor a string, then this message is inhibited. This 493 nor @code{nil} nor a string, then this message is inhibited. This
489 feature is useful for programs that use files for internal purposes, 494 feature is useful for programs that use files for internal purposes,
490 files that the user does not need to know about. 495 files that the user does not need to know about.
496
497 The function @code{write-region} converts the data which it writes to
498 the appropriate file formats specified by @code{buffer-file-format}.
499 @xref{Format Conversion}.
491 @end deffn 500 @end deffn
492 501
493 @node File Locks 502 @node File Locks
494 @section File Locks 503 @section File Locks
495 @cindex file locks 504 @cindex file locks
682 @noindent 691 @noindent
683 we can deduce that any attempt to read a file in @file{/foo/} will 692 we can deduce that any attempt to read a file in @file{/foo/} will
684 give an error. 693 give an error.
685 @end defun 694 @end defun
686 695
696 @defun file-ownership-preserved-p filename
697 This function returns @code{t} if deleting the file @var{filename} and
698 then creating it anew would keep the file's owner unchanged.
699 @end defun
700
687 @defun file-newer-than-file-p filename1 filename2 701 @defun file-newer-than-file-p filename1 filename2
688 @cindex file age 702 @cindex file age
689 @cindex file modification time 703 @cindex file modification time
690 This function returns @code{t} if the file @var{filename1} is 704 This function returns @code{t} if the file @var{filename1} is
691 newer than file @var{filename2}. If @var{filename1} does not 705 newer than file @var{filename2}. If @var{filename1} does not
783 (file-directory-p 797 (file-directory-p
784 (substitute-in-file-name "$HOME")) 798 (substitute-in-file-name "$HOME"))
785 @result{} t 799 @result{} t
786 @end group 800 @end group
787 @end example 801 @end example
802 @end defun
803
804 @defun file-regular-p filename
805 This function returns @code{t} if the file @var{filename} exists and is
806 a regular file (not a directory, symbolic link, named pipe, terminal, or
807 other I/O device).
788 @end defun 808 @end defun
789 809
790 @node Truenames 810 @node Truenames
791 @subsection Truenames 811 @subsection Truenames
792 @cindex truename (of file) 812 @cindex truename (of file)
1305 ;; @r{The following example applies to VMS only.} 1325 ;; @r{The following example applies to VMS only.}
1306 (file-name-sans-versions "foo;23") 1326 (file-name-sans-versions "foo;23")
1307 @result{} "foo" 1327 @result{} "foo"
1308 @end group 1328 @end group
1309 @end example 1329 @end example
1330 @end defun
1331
1332 @defun file-name-sans-extension filename
1333 This function returns @var{filename} sans its final ``extension'', if
1334 any. The extension, in a file name, is the part that follows the last
1335 @samp{.}.
1310 @end defun 1336 @end defun
1311 1337
1312 @node Directory Names 1338 @node Directory Names
1313 @comment node-name, next, previous, up 1339 @comment node-name, next, previous, up
1314 @subsection Directory Names 1340 @subsection Directory Names
1942 This is useful for running a subprocess; every subprocess must have a 1968 This is useful for running a subprocess; every subprocess must have a
1943 non-magic directory to serve as its current directory, and this function 1969 non-magic directory to serve as its current directory, and this function
1944 is a good way to come up with one. 1970 is a good way to come up with one.
1945 @end defun 1971 @end defun
1946 1972
1973 @node Format Conversion
1974 @section File Format Conversion
1975
1976 @cindex file format conversion
1977 @cindex encoding file formats
1978 @cindex decoding file formats
1979 The variable @code{format-alist} defines a list of @dfn{file formats},
1980 which are textual representations used in files for the data (text,
1981 text-properties, and possibly other information) in an Emacs buffer.
1982 Emacs performs format conversion when reading and writing files.
1983
1984 @defvar format-alist
1985 This list contains one format definition for each defined file format.
1986 @end defvar
1987
1988 @cindex format definition
1989 Each format definition is a list of this form:
1990
1991 @example
1992 (@var{name} @var{doc-string} @var{regexp} @var{from-fn} @var{to-fn} @var{modify} @var{mode-fn})
1993 @end example
1994
1995 Here is what the elements in a format definition mean:
1996
1997 @table @var
1998 @item name
1999 The name of this format.
2000
2001 @item doc-string
2002 A documentation string for the format.
2003
2004 @item regexp
2005 A regular expression which is used to recognize files represented in
2006 this format.
2007
2008 @item from-fn
2009 A function to call to decode data in this format (to convert file data into
2010 the usual Emacs data representation).
2011
2012 The @var{from-fn} is called with two args, @var{begin} and @var{end},
2013 which specify the part of the buffer it should convert. It should convert
2014 the text by editing it in place. Since this can change the length of the
2015 text, @var{from-fn} should return the modified end position.
2016
2017 One responsibility of @var{from-fm} is to make sure that the beginning
2018 of the file no longer matches @var{regexp}. Otherwise it is likely to
2019 get called again.
2020
2021 @item to-fn
2022 A function to call to encode data in this format (to convert
2023 the usual Emacs data representation into this format).
2024
2025 The @var{to-fn} is called with two args, @var{begin} and @var{end},
2026 which specify the part of the buffer it should convert. There are
2027 two ways it can do the conversion:
2028
2029 @itemize @bullet
2030 @item
2031 By editing the buffer in place. In this case, @var{to-fn} should
2032 return the end-position of the range of text, as modified.
2033
2034 @item
2035 By returning a list of annotations. This is a list of elements of the
2036 form @code{(@var{position} . @var{string})}, where @var{position} is an
2037 integer specifying the relative position in the text to be written, and
2038 @var{string} is the annotation to add there. The list must be sorted in
2039 order of position when @var{to-fn} returns it.
2040
2041 When @code{write-region} actually writes the text from the buffer to the
2042 file, it intermixes the specified annotations at the corresponding
2043 positions. All this takes place without modifying the buffer.
2044 @end itemize
2045
2046 @item modify
2047 A flag, @code{t} if the encoding function modifies the buffer, and
2048 @code{nil} if it works by returning a list of annotations.
2049
2050 @item mode
2051 A mode function to call after visiting a file converted from this
2052 format.
2053 @end table
2054
2055 The function @code{insert-file-contents} automatically recognizes file
2056 formats when it reads the specified file. It checks the text of the
2057 beginning of the file against the regular expressions of the format
2058 definitions, and if it finds a match, it calls the decoding function for
2059 that format. Then it checks all the known formats over again.
2060 It keeps checking them until none of them is applicable.
2061
2062 Visiting a file, with @code{find-file-noselect} or the commands that use
2063 it, performs conversion likewise (because it calls
2064 @code{insert-file-contents}); but it also calls the mode function for
2065 each format that it decodes. It stores a list of the format names
2066 in the buffer-local variable @code{buffer-file-format}.
2067
2068 @defvar buffer-file-format
2069 This variable holds a list of the file formats that were decoded in the
2070 course of visiting the current buffer's file. It is always local in all
2071 buffers.
2072 @end defvar
2073
2074 When @code{write-region} writes data into a file, it first calls the
2075 encoding functions for the formats listed in @code{buffer-file-format}.
2076
2077 @defun format-write-file file format
2078 This command writes the current buffer contents into the file @var{file}
2079 in format @var{format}, and makes that format the default for future
2080 saves of the buffer.
2081 @end defun
2082
2083 @defvar auto-save-file-format
2084 This variable specifies the format to use for auto-saving. Its value is
2085 a list of format names, just like the value of
2086 @code{buffer-file-format}; but it is used instead of
2087 @code{buffer-file-format} for writing auto-save files. This variable
2088 is always local in all buffers.
2089 @end defvar
2090
1947 @node Files and MS-DOS 2091 @node Files and MS-DOS
1948 @section Files and MS-DOS 2092 @section Files and MS-DOS
1949 @cindex MS-DOS file types 2093 @cindex MS-DOS file types
1950 @cindex file types on MS-DOS 2094 @cindex file types on MS-DOS
1951 @cindex text files and binary files 2095 @cindex text files and binary files