comparison lispref/files.texi @ 26696:ef5e7bbe6f19

Current version from /gd/gnu/elisp.
author Dave Love <fx@gnu.org>
date Fri, 03 Dec 1999 19:11:12 +0000
parents 467b88fab665
children 2d8554ed8748
comparison
equal deleted inserted replaced
26695:778a88ba7c10 26696:ef5e7bbe6f19
17 names. A file name is actually a string. Most of these functions 17 names. A file name is actually a string. Most of these functions
18 expand file name arguments by calling @code{expand-file-name}, so that 18 expand file name arguments by calling @code{expand-file-name}, so that
19 @file{~} is handled correctly, as are relative file names (including 19 @file{~} is handled correctly, as are relative file names (including
20 @samp{../}). These functions don't recognize environment variable 20 @samp{../}). These functions don't recognize environment variable
21 substitutions such as @samp{$HOME}. @xref{File Name Expansion}. 21 substitutions such as @samp{$HOME}. @xref{File Name Expansion}.
22
23 When file I/O functions signal Lisp errors, they usually use the
24 condition @code{file-error} (@pxref{Handling Errors}). The error
25 message is in most cases obtained from the operating system, according
26 to locale @code{system-message-locale}, and decoded using coding system
27 @code{locale-coding-system} (@pxref{Locales}).
22 28
23 @menu 29 @menu
24 * Visiting Files:: Reading files into Emacs buffers for editing. 30 * Visiting Files:: Reading files into Emacs buffers for editing.
25 * Saving Buffers:: Writing changed buffers back into files. 31 * Saving Buffers:: Writing changed buffers back into files.
26 * Reading from Files:: Reading files into buffers without visiting. 32 * Reading from Files:: Reading files into buffers without visiting.
248 254
249 This function is used by @code{find-file-noselect}. 255 This function is used by @code{find-file-noselect}.
250 It uses @code{generate-new-buffer} (@pxref{Creating Buffers}). 256 It uses @code{generate-new-buffer} (@pxref{Creating Buffers}).
251 @end defun 257 @end defun
252 258
253 @defun after-find-file &optional error warn 259 @defun after-find-file &optional error warn noauto after-find-file-from-revert-buffer nomodes
254 This function sets the buffer major mode, and parses local variables 260 This function sets the buffer major mode, and parses local variables
255 (@pxref{Auto Major Mode}). It is called by @code{find-file-noselect} 261 (@pxref{Auto Major Mode}). It is called by @code{find-file-noselect}
256 and by the default revert function (@pxref{Reverting}). 262 and by the default revert function (@pxref{Reverting}).
257 263
258 @cindex new file message 264 @cindex new file message
263 @samp{(New file)}. For more serious errors, the caller should usually not 269 @samp{(New file)}. For more serious errors, the caller should usually not
264 call @code{after-find-file}. 270 call @code{after-find-file}.
265 271
266 If @var{warn} is non-@code{nil}, then this function issues a warning 272 If @var{warn} is non-@code{nil}, then this function issues a warning
267 if an auto-save file exists and is more recent than the visited file. 273 if an auto-save file exists and is more recent than the visited file.
274
275 If @var{noauto} is non-@code{nil}, that says not to enable or disable
276 Auto-Save mode. The mode remains enabled if it was enabled before.
277
278 If @var{after-find-file-from-revert-buffer} is non-@code{nil}, that
279 means this call was from @code{revert-buffer}. This has no direct
280 effect, but some mode functions and hook functions check the value
281 of this variable.
282
283 If @var{nomodes} is non-@code{nil}, that means don't alter the buffer's
284 major mode, don't process local variables specifications in the file,
285 and don't run @code{find-file-hooks}. This feature is used by
286 @code{revert-buffer} in some cases.
268 287
269 The last thing @code{after-find-file} does is call all the functions 288 The last thing @code{after-find-file} does is call all the functions
270 in the list @code{find-file-hooks}. 289 in the list @code{find-file-hooks}.
271 @end defun 290 @end defun
272 291
316 saving one of these is asked to specify a file name to use.) The 335 saving one of these is asked to specify a file name to use.) The
317 @code{save-buffers-kill-emacs} function passes a non-@code{nil} value 336 @code{save-buffers-kill-emacs} function passes a non-@code{nil} value
318 for this argument. 337 for this argument.
319 @end deffn 338 @end deffn
320 339
321 @deffn Command write-file filename 340 @deffn Command write-file filename &optional confirm
322 This function writes the current buffer into file @var{filename}, makes 341 This function writes the current buffer into file @var{filename}, makes
323 the buffer visit that file, and marks it not modified. Then it renames 342 the buffer visit that file, and marks it not modified. Then it renames
324 the buffer based on @var{filename}, appending a string like @samp{<2>} 343 the buffer based on @var{filename}, appending a string like @samp{<2>}
325 if necessary to make a unique buffer name. It does most of this work by 344 if necessary to make a unique buffer name. It does most of this work by
326 calling @code{set-visited-file-name} (@pxref{Buffer File Name}) and 345 calling @code{set-visited-file-name} (@pxref{Buffer File Name}) and
327 @code{save-buffer}. 346 @code{save-buffer}.
347
348 If @var{confirm} is non-@code{nil}, that means to ask for confirmation
349 before overwriting an existing file.
328 @end deffn 350 @end deffn
329 351
330 Saving a buffer runs several hooks. It also performs format 352 Saving a buffer runs several hooks. It also performs format
331 conversion (@pxref{Format Conversion}), and may save text properties in 353 conversion (@pxref{Format Conversion}), and may save text properties in
332 ``annotations'' (@pxref{Saving Properties}). 354 ``annotations'' (@pxref{Saving Properties}).
510 532
511 An error is signaled if @var{filename} specifies a nonwritable file, 533 An error is signaled if @var{filename} specifies a nonwritable file,
512 or a nonexistent file in a directory where files cannot be created. 534 or a nonexistent file in a directory where files cannot be created.
513 @end deffn 535 @end deffn
514 536
515 @deffn Command write-region start end filename &optional append visit mustbenew 537 @deffn Command write-region start end filename &optional append visit lockname mustbenew
516 This function writes the region delimited by @var{start} and @var{end} 538 This function writes the region delimited by @var{start} and @var{end}
517 in the current buffer into the file specified by @var{filename}. 539 in the current buffer into the file specified by @var{filename}.
518 540
519 @c Emacs 19 feature 541 @c Emacs 19 feature
520 If @var{start} is a string, then @code{write-region} writes or appends 542 If @var{start} is a string, then @code{write-region} writes or appends
550 @var{visit} is used in the echo area message and also for file locking; 572 @var{visit} is used in the echo area message and also for file locking;
551 @var{visit} is stored in @code{buffer-file-name}. This feature is used 573 @var{visit} is stored in @code{buffer-file-name}. This feature is used
552 to implement @code{file-precious-flag}; don't use it yourself unless you 574 to implement @code{file-precious-flag}; don't use it yourself unless you
553 really know what you're doing. 575 really know what you're doing.
554 576
577 The optional argument @var{lockname}, if non-@code{nil}, specifies the
578 file name to use for purposes of locking and unlocking, overriding
579 @var{filename} and @var{visit} for that purpose.
580
555 The function @code{write-region} converts the data which it writes to 581 The function @code{write-region} converts the data which it writes to
556 the appropriate file formats specified by @code{buffer-file-format}. 582 the appropriate file formats specified by @code{buffer-file-format}.
557 @xref{Format Conversion}. It also calls the functions in the list 583 @xref{Format Conversion}. It also calls the functions in the list
558 @code{write-region-annotate-functions}; see @ref{Saving Properties}. 584 @code{write-region-annotate-functions}; see @ref{Saving Properties}.
559 585
690 @cindex file accessibility 716 @cindex file accessibility
691 717
692 These functions test for permission to access a file in specific ways. 718 These functions test for permission to access a file in specific ways.
693 719
694 @defun file-exists-p filename 720 @defun file-exists-p filename
695 This function returns @code{t} if a file named @var{filename} appears 721 This function returns @code{t} if a file named @var{filename} appears to
696 to exist. This does not mean you can necessarily read the file, only 722 exist. This does not mean you can necessarily read the file, only that
697 that you can find out its attributes. (On Unix, this is true if the 723 you can find out its attributes. (On Unix and GNU/Linux, this is true
698 file exists and you have execute permission on the containing 724 if the file exists and you have execute permission on the containing
699 directories, regardless of the protection of the file itself.) 725 directories, regardless of the protection of the file itself.)
700 726
701 If the file does not exist, or if fascist access control policies 727 If the file does not exist, or if fascist access control policies
702 prevent you from finding the attributes of the file, this function 728 prevent you from finding the attributes of the file, this function
703 returns @code{nil}. 729 returns @code{nil}.
724 @end defun 750 @end defun
725 751
726 @c Emacs 19 feature 752 @c Emacs 19 feature
727 @defun file-executable-p filename 753 @defun file-executable-p filename
728 This function returns @code{t} if a file named @var{filename} exists and 754 This function returns @code{t} if a file named @var{filename} exists and
729 you can execute it. It returns @code{nil} otherwise. On Unix, if the 755 you can execute it. It returns @code{nil} otherwise. On Unix and
730 file is a directory, execute permission means you can check the 756 GNU/Linux, if the file is a directory, execute permission means you can
731 existence and attributes of files inside the directory, and open those 757 check the existence and attributes of files inside the directory, and
732 files if their modes permit. 758 open those files if their modes permit.
733 @end defun 759 @end defun
734 760
735 @defun file-writable-p filename 761 @defun file-writable-p filename
736 This function returns @code{t} if the file @var{filename} can be written 762 This function returns @code{t} if the file @var{filename} can be written
737 or created by you, and @code{nil} otherwise. A file is writable if the 763 or created by you, and @code{nil} otherwise. A file is writable if the
904 @subsection Truenames 930 @subsection Truenames
905 @cindex truename (of file) 931 @cindex truename (of file)
906 932
907 @c Emacs 19 features 933 @c Emacs 19 features
908 The @dfn{truename} of a file is the name that you get by following 934 The @dfn{truename} of a file is the name that you get by following
909 symbolic links until none remain, then simplifying away @samp{.}@: and 935 symbolic links at all levels until none remain, then simplifying away
910 @samp{..}@: appearing as components. Strictly speaking, a file need not 936 @samp{.}@: and @samp{..}@: appearing as name components. This results
911 have a unique truename; the number of distinct truenames a file has is 937 in a sort of canonical name for the file. A file does not always have a
912 equal to the number of hard links to the file. However, truenames are 938 unique truename; the number of distinct truenames a file has is equal to
913 useful because they eliminate symbolic links as a cause of name 939 the number of hard links to the file. However, truenames are useful
914 variation. 940 because they eliminate symbolic links as a cause of name variation.
915 941
916 @defun file-truename filename 942 @defun file-truename filename
917 The function @code{file-truename} returns the true name of the file 943 The function @code{file-truename} returns the truename of the file
918 @var{filename}. This is the name that you get by following symbolic 944 @var{filename}. The argument must be an absolute file name.
919 links until none remain. The argument must be an absolute file name. 945 @end defun
920 @end defun 946
947 @defun file-chase-links filename
948 This function follows symbolic links, starting with @var{filename},
949 until it finds a file name which is not the name of a symbolic link.
950 Then it returns that file name.
951 @end defun
952
953 To illustrate the difference between @code{file-chase-links} and
954 @code{file-truename}, suppose that @file{/usr/foo} is a symbolic link to
955 the directory @file{/home/foo}, and @file{/home/foo/hello} is an
956 ordinary file (or at least, not a symbolic link) or nonexistent. Then
957 we would have:
958
959 @example
960 (file-chase-links "/usr/foo/hello")
961 ;; @r{This does not follow the links in the parent directories.}
962 @result{} "/usr/foo/hello"
963 (file-truename "/usr/foo/hello")
964 ;; @r{Assuming that @file{/home} is not a symbolic link.}
965 @result{} "/home/foo/hello"
966 @end example
921 967
922 @xref{Buffer File Name}, for related information. 968 @xref{Buffer File Name}, for related information.
923 969
924 @node File Attributes 970 @node File Attributes
925 @comment node-name, next, previous, up 971 @comment node-name, next, previous, up
1240 @pindex rm 1286 @pindex rm
1241 This command deletes the file @var{filename}, like the shell command 1287 This command deletes the file @var{filename}, like the shell command
1242 @samp{rm @var{filename}}. If the file has multiple names, it continues 1288 @samp{rm @var{filename}}. If the file has multiple names, it continues
1243 to exist under the other names. 1289 to exist under the other names.
1244 1290
1245 A suitable kind of @code{file-error} error is signaled if the file 1291 A suitable kind of @code{file-error} error is signaled if the file does
1246 does not exist, or is not deletable. (On Unix, a file is deletable if 1292 not exist, or is not deletable. (On Unix and GNU/Linux, a file is
1247 its directory is writable.) 1293 deletable if its directory is writable.)
1248 1294
1249 See also @code{delete-directory} in @ref{Create/Delete Dirs}. 1295 See also @code{delete-directory} in @ref{Create/Delete Dirs}.
1250 @end deffn 1296 @end deffn
1251 1297
1252 @deffn Command make-symbolic-link filename newname &optional ok-if-exists 1298 @deffn Command make-symbolic-link filename newname &optional ok-if-exists
1276 1322
1277 @c Emacs 19 feature 1323 @c Emacs 19 feature
1278 @defun set-default-file-modes mode 1324 @defun set-default-file-modes mode
1279 This function sets the default file protection for new files created by 1325 This function sets the default file protection for new files created by
1280 Emacs and its subprocesses. Every file created with Emacs initially has 1326 Emacs and its subprocesses. Every file created with Emacs initially has
1281 this protection. On Unix, the default protection is the bitwise 1327 this protection. On Unix and GNU/Linux, the default protection is the
1282 complement of the ``umask'' value. 1328 bitwise complement of the ``umask'' value.
1283 1329
1284 The argument @var{mode} must be an integer. On most systems, only the 1330 The argument @var{mode} must be an integer. On most systems, only the
1285 low 9 bits of @var{mode} are meaningful. 1331 low 9 bits of @var{mode} are meaningful.
1286 1332
1287 Saving a modified version of an existing file does not count as creating 1333 Saving a modified version of an existing file does not count as creating
1404 @result{} "FOO.TMP" 1450 @result{} "FOO.TMP"
1405 @end group 1451 @end group
1406 @end example 1452 @end example
1407 @end defun 1453 @end defun
1408 1454
1409 @defun file-name-sans-versions filename 1455 @defun file-name-sans-versions filename &optional keep-backup-version
1410 This function returns @var{filename} with any file version numbers, 1456 This function returns @var{filename} with any file version numbers,
1411 backup version numbers, or trailing tildes deleted. 1457 backup version numbers, or trailing tildes discarded.
1458
1459 If @var{keep-backup-version} is non-@code{nil}, then true file version
1460 numbers understood as such by the file system are discarded from the
1461 return value, but backup version numbers are kept.
1412 1462
1413 @example 1463 @example
1414 @group 1464 @group
1415 (file-name-sans-versions "~rms/foo.~1~") 1465 (file-name-sans-versions "~rms/foo.~1~")
1416 @result{} "~rms/foo" 1466 @result{} "~rms/foo"
1543 1593
1544 All the directories in the file system form a tree starting at the 1594 All the directories in the file system form a tree starting at the
1545 root directory. A file name can specify all the directory names 1595 root directory. A file name can specify all the directory names
1546 starting from the root of the tree; then it is called an @dfn{absolute} 1596 starting from the root of the tree; then it is called an @dfn{absolute}
1547 file name. Or it can specify the position of the file in the tree 1597 file name. Or it can specify the position of the file in the tree
1548 relative to a default directory; then it is called a @dfn{relative} 1598 relative to a default directory; then it is called a @dfn{relative} file
1549 file name. On Unix, an absolute file name starts with a slash or a 1599 name. On Unix and GNU/Linux, an absolute file name starts with a slash
1550 tilde (@samp{~}), and a relative one does not. On MS-DOS and 1600 or a tilde (@samp{~}), and a relative one does not. On MS-DOS and
1551 MS-Windows, an absolute file name starts with a slash or a backslash, or 1601 MS-Windows, an absolute file name starts with a slash or a backslash, or
1552 with a drive specification @samp{@var{x}:/}, where @var{x} is the 1602 with a drive specification @samp{@var{x}:/}, where @var{x} is the
1553 @dfn{drive letter}. The rules on VMS are complicated. 1603 @dfn{drive letter}. The rules on VMS are complicated.
1554 1604
1555 @defun file-name-absolute-p filename 1605 @defun file-name-absolute-p filename
1556 This function returns @code{t} if file @var{filename} is an absolute 1606 This function returns @code{t} if file @var{filename} is an absolute
1557 file name, @code{nil} otherwise. On VMS, this function understands both 1607 file name, @code{nil} otherwise. On VMS, this function understands both
1558 Unix syntax and VMS syntax. 1608 Unix syntax and VMS syntax.
1623 Note that @code{expand-file-name} does @emph{not} expand environment 1673 Note that @code{expand-file-name} does @emph{not} expand environment
1624 variables; only @code{substitute-in-file-name} does that. 1674 variables; only @code{substitute-in-file-name} does that.
1625 @end defun 1675 @end defun
1626 1676
1627 @c Emacs 19 feature 1677 @c Emacs 19 feature
1628 @defun file-relative-name filename directory 1678 @defun file-relative-name filename &optional directory
1629 This function does the inverse of expansion---it tries to return a 1679 This function does the inverse of expansion---it tries to return a
1630 relative name that is equivalent to @var{filename} when interpreted 1680 relative name that is equivalent to @var{filename} when interpreted
1631 relative to @var{directory}. 1681 relative to @var{directory}. If @var{directory} is omitted or
1682 @code{nil}, it defaults to the current buffer's default directory.
1632 1683
1633 On some operating systems, an absolute file name begins with a device 1684 On some operating systems, an absolute file name begins with a device
1634 name. On such systems, @var{filename} has no relative equivalent based 1685 name. On such systems, @var{filename} has no relative equivalent based
1635 on @var{directory} if they start with two different device names. In 1686 on @var{directory} if they start with two different device names. In
1636 this case, @code{file-relative-name} returns @var{filename} in absolute 1687 this case, @code{file-relative-name} returns @var{filename} in absolute
2051 Most Emacs Lisp file-manipulation functions get errors when used on 2102 Most Emacs Lisp file-manipulation functions get errors when used on
2052 files that are directories. For example, you cannot delete a directory 2103 files that are directories. For example, you cannot delete a directory
2053 with @code{delete-file}. These special functions exist to create and 2104 with @code{delete-file}. These special functions exist to create and
2054 delete directories. 2105 delete directories.
2055 2106
2056 @defun make-directory dirname 2107 @defun make-directory dirname &optional parents
2057 This function creates a directory named @var{dirname}. 2108 This function creates a directory named @var{dirname}.
2109 If @var{parents} is non-@code{nil}, that means to create
2110 the parent directories first, if they don't already exist.
2058 @end defun 2111 @end defun
2059 2112
2060 @defun delete-directory dirname 2113 @defun delete-directory dirname
2061 This function deletes the directory named @var{dirname}. The function 2114 This function deletes the directory named @var{dirname}. The function
2062 @code{delete-file} does not work for files that are directories; you 2115 @code{delete-file} does not work for files that are directories; you