comparison lispref/files.texi @ 15765:8cc15b664c4c

New node Standard File Names. Document set-visited-file-name. Add some magic file name operations. Binary file types apply to MSDOS.
author Richard M. Stallman <rms@gnu.org>
date Tue, 23 Jul 1996 15:46:12 +0000
parents 9c9debb5950f
children f415fdc67ad3
comparison
equal deleted inserted replaced
15764:870d35f9e086 15765:8cc15b664c4c
390 If the value of the variable is @code{nil}, then @code{save-buffer} 390 If the value of the variable is @code{nil}, then @code{save-buffer}
391 doesn't add newlines at all. @code{nil} is the default value, but a few 391 doesn't add newlines at all. @code{nil} is the default value, but a few
392 major modes set it to @code{t} in particular buffers. 392 major modes set it to @code{t} in particular buffers.
393 @end defopt 393 @end defopt
394 394
395 @deffn Command set-visited-file-name filename &optional no-query
396 This function changes the visited file name of the current buffer to
397 @var{filename}. It also renames the buffer based on @var{filename},
398 appending a string like @samp{<2>} if necessary to make a unique buffer
399 name. It marks the buffer as @emph{modified},a since the contents do not
400 (as far as Emacs knows) match the actual file's contents.
401
402 If the specified file already exists, @code{set-visited-file-name}
403 asks for confirmation unless @var{no-query} is non-@code{nil}.
404 @end deffn
405
395 @node Reading from Files 406 @node Reading from Files
396 @comment node-name, next, previous, up 407 @comment node-name, next, previous, up
397 @section Reading from Files 408 @section Reading from Files
398 409
399 You can copy a file from the disk and insert it into a buffer 410 You can copy a file from the disk and insert it into a buffer
1232 is different from its name as a file. 1243 is different from its name as a file.
1233 * Relative File Names:: Some file names are relative to a current directory. 1244 * Relative File Names:: Some file names are relative to a current directory.
1234 * File Name Expansion:: Converting relative file names to absolute ones. 1245 * File Name Expansion:: Converting relative file names to absolute ones.
1235 * Unique File Names:: Generating names for temporary files. 1246 * Unique File Names:: Generating names for temporary files.
1236 * File Name Completion:: Finding the completions for a given file name. 1247 * File Name Completion:: Finding the completions for a given file name.
1248 * Standard File Names:: If your package uses a fixed file name,
1249 how to handle various operating systems simply.
1237 @end menu 1250 @end menu
1238 1251
1239 @node File Name Components 1252 @node File Name Components
1240 @subsection File Name Components 1253 @subsection File Name Components
1241 @cindex directory part (of file name) 1254 @cindex directory part (of file name)
1736 @result{} (".o" ".elc" "~" ".dvi") 1749 @result{} (".o" ".elc" "~" ".dvi")
1737 @end group 1750 @end group
1738 @end example 1751 @end example
1739 @end defopt 1752 @end defopt
1740 1753
1754 @node Standard File Names
1755 @subsection Standard File Names
1756
1757 Most of the file names used in Lisp programs are entered by the user.
1758 But occasionally a Lisp program needs to specify a standard file name
1759 for a particular use---typically, to hold customization information
1760 about each user. For example, abbrev definitions are stored (by
1761 default) in the file @file{~/.abbrev_defs}; the @code{completion}
1762 package stores completions in the file @file{~/.completions}. These are
1763 two of the many standard file names used by parts of Emacs for certain
1764 purposes.
1765
1766 Various operating systems have their own conventions for valid file
1767 names and for which file names to use for user profile data. A Lisp
1768 program which reads a file using a standard file name ought to use, on
1769 each type of system, a file name suitable for that system. The function
1770 @code{convert-standard-filename} makes this easy to do.
1771
1772 @defun convert-standard-filename filename
1773 This function alters the file name @var{filename} to fit the conventions
1774 of the operating system in use, and returns the result as a new string.
1775 @end defun
1776
1777 The recommended way to specify a standard file name in a Lisp program
1778 is to choose a name which fits the conventions of GNU and Unix systems,
1779 usually with a nondirectory part that starts with a period, and pass it
1780 to @code{convert-standard-filename} instead of using it directly. Here
1781 is an example from the @code{completion} package:
1782
1783 @example
1784 (defvar save-completions-file-name
1785 (convert-standard-filename "~/.completions")
1786 "*The file name to save completions to.")
1787 @end example
1788
1789 On GNU and Unix systems, and on some other systems as well,
1790 @code{convert-standard-filename} returns its argument unchanged. On
1791 some other systems, it alters the name to fit the systems's conventions.
1792
1793 For example, on MS-DOS the alterations made by this function include
1794 converting a leading @samp{.} to @samp{_}, converting a @samp{_} in the
1795 middle of the name to @samp{.} if there is no other @samp{.}, inserting
1796 a @samp{.} after eight characters if there is none, and truncating to
1797 three characters after the @samp{.}. (It makes other changes as well.)
1798 Thus, @file{.abbrev_defs} becomes @file{_abbrev.def}, and
1799 @file{.completions} becomes @file{_complet.ion}.
1800
1741 @node Contents of Directories 1801 @node Contents of Directories
1742 @section Contents of Directories 1802 @section Contents of Directories
1743 @cindex directory-oriented functions 1803 @cindex directory-oriented functions
1744 @cindex file names in directory 1804 @cindex file names in directory
1745 1805
1882 @noindent 1942 @noindent
1883 @code{add-name-to-file}, @code{copy-file}, @code{delete-directory}, 1943 @code{add-name-to-file}, @code{copy-file}, @code{delete-directory},
1884 @code{delete-file},@* 1944 @code{delete-file},@*
1885 @code{diff-latest-backup-file}, 1945 @code{diff-latest-backup-file},
1886 @code{directory-file-name}, 1946 @code{directory-file-name},
1887 @code{directory-files}, 1947 @code{directory-files}, @code{dired-call-process},
1888 @code{dired-compress-file}, @code{dired-uncache}, 1948 @code{dired-compress-file}, @code{dired-uncache},
1889 @code{expand-file-name},@* 1949 @code{expand-file-name},@*
1890 @code{file-accessible-directory-p}, 1950 @code{file-accessible-directory-p},
1891 @code{file-attributes}, @code{file-directory-p}, 1951 @code{file-attributes}, @code{file-directory-p},
1892 @code{file-executable-p}, @code{file-exists-p}, @code{file-local-copy}, 1952 @code{file-executable-p}, @code{file-exists-p}, @code{file-local-copy},
1893 @code{file-modes}, @code{file-name-all-completions}, 1953 @code{file-modes}, @code{file-name-all-completions},
1894 @code{file-name-as-directory}, @code{file-name-completion}, 1954 @code{file-name-as-directory}, @code{file-name-completion},
1895 @code{file-name-directory}, @code{file-name-nondirectory}, 1955 @code{file-name-directory}, @code{file-name-nondirectory},
1896 @code{file-name-sans-versions}, @code{file-newer-than-file-p}, 1956 @code{file-name-sans-versions}, @code{file-newer-than-file-p},
1957 @code{file-ownership-preserved-p},
1897 @code{file-readable-p}, @code{file-regular-p}, @code{file-symlink-p}, 1958 @code{file-readable-p}, @code{file-regular-p}, @code{file-symlink-p},
1898 @code{file-truename}, @code{file-writable-p}, 1959 @code{file-truename}, @code{file-writable-p},
1960 @code{find-backup-file-name},
1899 @code{get-file-buffer}, 1961 @code{get-file-buffer},
1900 @code{insert-directory}, 1962 @code{insert-directory}, @code{insert-file-contents},
1901 @code{insert-file-contents}, @code{load}, @code{make-directory}, 1963 @code{load}, @code{make-directory},
1902 @code{make-symbolic-link}, @code{rename-file}, @code{set-file-modes}, 1964 @code{make-symbolic-link}, @code{rename-file}, @code{set-file-modes},
1903 @code{set-visited-file-modtime}, @code{unhandled-file-name-directory}, 1965 @code{set-visited-file-modtime}, @code{shell-command}.
1966 @code{unhandled-file-name-directory}, @code{vc-registered},
1904 @code{verify-visited-file-modtime}, @code{write-region}. 1967 @code{verify-visited-file-modtime}, @code{write-region}.
1905 1968
1906 Handlers for @code{insert-file-contents} typically need to clear the 1969 Handlers for @code{insert-file-contents} typically need to clear the
1907 buffer's modified flag, with @code{(set-buffer-modified-p nil)}, if the 1970 buffer's modified flag, with @code{(set-buffer-modified-p nil)}, if the
1908 @var{visit} argument is non-@code{nil}. This also has the effect of 1971 @var{visit} argument is non-@code{nil}. This also has the effect of
2131 @section Files and MS-DOS 2194 @section Files and MS-DOS
2132 @cindex MS-DOS file types 2195 @cindex MS-DOS file types
2133 @cindex file types on MS-DOS 2196 @cindex file types on MS-DOS
2134 @cindex text files and binary files 2197 @cindex text files and binary files
2135 @cindex binary files and text files 2198 @cindex binary files and text files
2136 2199 @cindex Windows file types
2137 Emacs on MS-DOS makes a distinction between text files and binary 2200
2138 files. This is necessary because ordinary text files on MS-DOS use a 2201 Emacs on MS-DOS and on Windows NT or 95 makes a distinction between
2139 two character sequence between lines: carriage-return and linefeed 2202 text files and binary files. This is necessary because ordinary text
2140 (@sc{crlf}). Emacs expects just a newline character (a linefeed) between 2203 files on MS-DOS use a two character sequence between lines:
2141 lines. When Emacs reads or writes a text file on MS-DOS, it needs to 2204 carriage-return and linefeed (@sc{crlf}). Emacs expects just a newline
2142 convert the line separators. This means it needs to know which files 2205 character (a linefeed) between lines. When Emacs reads or writes a text
2143 are text files and which are binary. It makes this decision when 2206 file on MS-DOS, it needs to convert the line separators. This means it
2144 visiting a file, and records the decision in the variable 2207 needs to know which files are text files and which are binary. It makes
2145 @code{buffer-file-type} for use when the file is saved. 2208 this decision when visiting a file, and records the decision in the
2209 variable @code{buffer-file-type} for use when the file is saved.
2146 2210
2147 @xref{MS-DOS Subprocesses}, for a related feature for subprocesses. 2211 @xref{MS-DOS Subprocesses}, for a related feature for subprocesses.
2148 2212
2149 @defvar buffer-file-type 2213 @defvar buffer-file-type
2150 This variable, automatically local in each buffer, records the file type 2214 This variable, automatically local in each buffer, records the file type