comparison lispref/files.texi @ 7088:5a93e6fb43a4

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 25 Apr 1994 01:13:27 +0000
parents 771fa0ddb356
children 7db892210924
comparison
equal deleted inserted replaced
7087:57553b30baed 7088:5a93e6fb43a4
25 * File Names:: Decomposing and expanding file names. 25 * File Names:: Decomposing and expanding file names.
26 * Contents of Directories:: Getting a list of the files in a directory. 26 * Contents of Directories:: Getting a list of the files in a directory.
27 * Create/Delete Dirs:: Creating and Deleting Directories. 27 * Create/Delete Dirs:: Creating and Deleting Directories.
28 * Magic File Names:: Defining "magic" special handling 28 * Magic File Names:: Defining "magic" special handling
29 for certain file names. 29 for certain file names.
30 * Files and MS-DOS:: Distinguishing text and binary files on MS-DOS.
30 @end menu 31 @end menu
31 32
32 @node Visiting Files 33 @node Visiting Files
33 @section Visiting Files 34 @section Visiting Files
34 @cindex finding files 35 @cindex finding files
1173 1174
1174 @defun default-file-modes 1175 @defun default-file-modes
1175 This function returns the current default protection value. 1176 This function returns the current default protection value.
1176 @end defun 1177 @end defun
1177 1178
1179 @cindex MS-DOS and file modes
1180 @cindex file modes and MS-DOS
1181 On MS-DOS, there is no such thing as an ``executable'' file mode bit.
1182 So Emacs considers a file executable if its name ends in @samp{.com},
1183 @samp{.bat} or @samp{.exe}. This is reflected in the values returned
1184 by @code{file-modes} and @code{file-attributes}.
1185
1178 @node File Names 1186 @node File Names
1179 @section File Names 1187 @section File Names
1180 @cindex file names 1188 @cindex file names
1181 1189
1182 Files are generally referred to by their names, in Emacs as elsewhere. 1190 Files are generally referred to by their names, in Emacs as elsewhere.
1193 directory. 1201 directory.
1194 1202
1195 On VMS, all these functions understand both VMS file name syntax and 1203 On VMS, all these functions understand both VMS file name syntax and
1196 Unix syntax. This is so that all the standard Lisp libraries can 1204 Unix syntax. This is so that all the standard Lisp libraries can
1197 specify file names in Unix syntax and work properly on VMS without 1205 specify file names in Unix syntax and work properly on VMS without
1198 change. 1206 change. On MS-DOS, these functions understand MS-DOS file name syntax
1207 as well as Unix syntax.
1199 1208
1200 @menu 1209 @menu
1201 * File Name Components:: The directory part of a file name, and the rest. 1210 * File Name Components:: The directory part of a file name, and the rest.
1202 * Directory Names:: A directory's name as a directory 1211 * Directory Names:: A directory's name as a directory
1203 is different from its name as a file. 1212 is different from its name as a file.
1842 @code{file-modes}, @code{file-name-all-completions}, 1851 @code{file-modes}, @code{file-name-all-completions},
1843 @code{file-name-as-directory}, @code{file-name-completion}, 1852 @code{file-name-as-directory}, @code{file-name-completion},
1844 @code{file-name-directory}, @code{file-name-nondirectory}, 1853 @code{file-name-directory}, @code{file-name-nondirectory},
1845 @code{file-name-sans-versions}, @code{file-newer-than-file-p}, 1854 @code{file-name-sans-versions}, @code{file-newer-than-file-p},
1846 @code{file-readable-p}, @code{file-symlink-p}, @code{file-truename}, 1855 @code{file-readable-p}, @code{file-symlink-p}, @code{file-truename},
1847 @code{file-writable-p}, @code{insert-directory}, 1856 @code{file-writable-p},@*
1857 @code{insert-directory},
1848 @code{insert-file-contents}, @code{load}, @code{make-directory}, 1858 @code{insert-file-contents}, @code{load}, @code{make-directory},
1849 @code{make-symbolic-link}, @code{rename-file}, @code{set-file-modes}, 1859 @code{make-symbolic-link}, @code{rename-file}, @code{set-file-modes},
1850 @code{set-visited-file-modtime}, @code{unhandled-file-name-directory}, 1860 @code{set-visited-file-modtime}, @code{unhandled-file-name-directory},
1851 @code{verify-visited-file-modtime}, @code{write-region}. 1861 @code{verify-visited-file-modtime}, @code{write-region}.
1852 1862
1853 The handler function must handle all of the above operations, and 1863 The handler function must handle all of the above operations, and
1854 possibly others to be added in the future. Therefore, it should always 1864 possibly others to be added in the future. Therefore, it should always
1855 reinvoke the ordinary Lisp primitive when it receives an operation it 1865 reinvoke the ordinary Lisp primitive when it receives an operation it
1856 does not recognize. Here's one way to do this: 1866 does not recognize. Here's one way to do this:
1857 1867
1858 @example 1868 @smallexample
1859 (defun my-file-handler (operation &rest args) 1869 (defun my-file-handler (operation &rest args)
1860 ;; @r{First check for the specific operations} 1870 ;; @r{First check for the specific operations}
1861 ;; @r{that we have special handling for.} 1871 ;; @r{that we have special handling for.}
1862 (cond ((eq operation 'insert-file-contents) @dots{}) 1872 (cond ((eq operation 'insert-file-contents) @dots{})
1863 ((eq operation 'write-region) @dots{}) 1873 ((eq operation 'write-region) @dots{})
1864 @dots{} 1874 @dots{}
1865 ;; @r{Handle any operation we don't know about.} 1875 ;; @r{Handle any operation we don't know about.}
1866 (t (let (file-name-handler-alist) 1876 (t (let ((inhibit-file-name-handlers
1877 (cons 'ange-ftp-file-handler
1878 (and (eq inhibit-file-name-operation operation)
1879 inhibit-file-name-handlers)))
1880 (inhibit-file-name-operation operation))
1867 (apply operation args))))) 1881 (apply operation args)))))
1868 @end example 1882 @end smallexample
1869 1883
1870 @defun find-file-name-handler file 1884 When a handler function decides to call the ordinary Emacs primitive for
1885 the operation at hand, it needs to prevent the primitive from calling
1886 the same handler once again, thus leading to an infinite recursion. The
1887 example above shows how to do this, with the variables
1888 @code{inhibit-file-name-handlers} and
1889 @code{inhibit-file-name-operation}. Be careful to use them exactly as
1890 shown above; the details are crucial for proper behavior in the case of
1891 multiple handlers, and for operations that have two file names that may
1892 each have handlers.
1893
1894 @defvar inhibit-file-name-handlers
1895 This variable holds a list of handlers whose use is presently inhibited
1896 for a certain operation.
1897 @end defvar
1898
1899 @defvar inhibit-file-name-operation
1900 The operation for which certain handlers are presently inhibited.
1901 @end defvar
1902
1903 @defun find-file-name-handler file operation
1871 This function returns the handler function for file name @var{file}, or 1904 This function returns the handler function for file name @var{file}, or
1872 @code{nil} if there is none. 1905 @code{nil} if there is none. The argument @var{operation} should be the
1906 operation to be performed on the file---the value you will pass to the
1907 handler as its first argument when you call it. The operation is needed
1908 for comparison with @code{inhibit-file-name-operation}.
1873 @end defun 1909 @end defun
1874 1910
1875 @defun file-local-copy filename 1911 @defun file-local-copy filename
1876 This function copies file @var{filename} to the local site, if it isn't 1912 This function copies file @var{filename} to the local site, if it isn't
1877 there already. If @var{filename} specifies a ``magic'' file name which 1913 there already. If @var{filename} specifies a ``magic'' file name which
1889 1925
1890 This is useful for running a subprocess; every subprocess must have a 1926 This is useful for running a subprocess; every subprocess must have a
1891 non-magic directory to serve as its current directory, and this function 1927 non-magic directory to serve as its current directory, and this function
1892 is a good way to come up with one. 1928 is a good way to come up with one.
1893 @end defun 1929 @end defun
1930
1931 @node Files and MS-DOS
1932 @section Files and MS-DOS
1933 @cindex MS-DOS file types
1934 @cindex file types on MS-DOS
1935 @cindex text files and binary files
1936 @cindex binary files and text files
1937
1938 Emacs on MS-DOS makes a distinction between text files and binary
1939 files. This is necessary because ordinary text files on MS-DOS use two
1940 characters between lines: carriage-return and linefeed. Emacs expects
1941 just a newline character (a linefeed) between lines. When Emacs reads
1942 or writes a text file on MS-DOS, it needs to convert the line
1943 separators. This means it needs to know which files are text files and
1944 which are binary. It makes this decision when visiting a file, and
1945 records the decision in the variable @code{buffer-file-type} for when
1946 the file is saved.
1947
1948 @defvar buffer-file-type
1949 This variable, automatically local in each buffer, records the file type
1950 of the buffer's visited file.
1951 @end defvar
1952
1953 @defun find-buffer-file-type filename
1954 This function determines whether file @var{filename} is a text file
1955 or a binary file. It returns @code{nil} for text, @code{t} for binary.
1956 @end defun
1957
1958 @defopt file-name-buffer-file-type-alist
1959 This variable holds an alist for distinguishing text files from binary
1960 files. Each element has the form (@var{regexp} . @var{type}), where
1961 @var{regexp} is matched against the file name, and @var{type} may be is
1962 @code{nil} for text, @code{t} for binary, or a function to call to
1963 compute which. If it is a function, then it is called with a single
1964 argument (the file name) and should return @code{t} or @code{nil}.
1965 @end defopt
1966
1967 @defopt default-buffer-file-type
1968 This variable specifies the default file type for files whose names
1969 don't indicate anything in particular. Its value should be @code{nil}
1970 for text, or @code{t} for binary.
1971 @end defopt
1972
1973 @deffn Command find-file-text filename
1974 Like @code{find-file}, but treat the file as text regardless of its name.
1975 @end deffn
1976
1977 @deffn Command find-file-binary filename
1978 Like @code{find-file}, but treat the file as binary regardless of its
1979 name.
1980 @end deffn