aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Teirlinck2004-04-14 02:44:21 +0000
committerLuc Teirlinck2004-04-14 02:44:21 +0000
commit19efcb46346e5eb24211348c6b04bc89f68ed74a (patch)
tree74ec43b6ace6735ccdfa4bbb748fc0df59b835be
parentd2072c54c9e48c5ac2222ac3b8ee73b74a5df4d6 (diff)
downloademacs-19efcb46346e5eb24211348c6b04bc89f68ed74a.tar.gz
emacs-19efcb46346e5eb24211348c6b04bc89f68ed74a.zip
Various changes in addition to:
(Visiting Functions): `find-file-hook' is now a normal hook. (File Name Expansion): Explain difference between the way that `expand-file-name' and `file-truename' treat `..'. (Contents of Directories): Mention optional ID-FORMAT argument to `directory-files-and-attributes'. (Format Conversion): Mention new optional CONFIRM argument to `format-write-file'.
-rw-r--r--lispref/files.texi351
1 files changed, 246 insertions, 105 deletions
diff --git a/lispref/files.texi b/lispref/files.texi
index f2c3638ac5f..045b5741108 100644
--- a/lispref/files.texi
+++ b/lispref/files.texi
@@ -95,11 +95,11 @@ This command selects a buffer visiting the file @var{filename},
95using an existing buffer if there is one, and otherwise creating a 95using an existing buffer if there is one, and otherwise creating a
96new buffer and reading the file into it. It also returns that buffer. 96new buffer and reading the file into it. It also returns that buffer.
97 97
98The body of the @code{find-file} function is very simple and looks 98Aside from some technical details, the body of the @code{find-file}
99like this: 99function is basically equivalent to:
100 100
101@example 101@example
102(switch-to-buffer (find-file-noselect filename)) 102(switch-to-buffer (find-file-noselect filename nil nil wildcards))
103@end example 103@end example
104 104
105@noindent 105@noindent
@@ -193,12 +193,14 @@ When @code{view-file} is called interactively, it prompts for
193@end deffn 193@end deffn
194 194
195@tindex find-file-wildcards 195@tindex find-file-wildcards
196@defvar find-file-wildcards 196@defopt find-file-wildcards
197If this variable is non-@code{nil}, then the various @code{find-file} 197If this variable is non-@code{nil}, then the various @code{find-file}
198commands check for wildcard characters and visit all the files that 198commands check for wildcard characters and visit all the files that
199match them. If this is @code{nil}, then wildcard characters are 199match them (when invoked interactively or when their @var{wildcards}
200not treated specially. 200argument is non-@code{nil}). If this option is @code{nil}, then
201@end defvar 201the @code{find-file} commands ignore their @var{wildcards} argument
202and never treat wildcard characters specially.
203@end defopt
202 204
203@defvar find-file-hook 205@defvar find-file-hook
204The value of this variable is a list of functions to be called after a 206The value of this variable is a list of functions to be called after a
@@ -206,8 +208,7 @@ file is visited. The file's local-variables specification (if any) will
206have been processed before the hooks are run. The buffer visiting the 208have been processed before the hooks are run. The buffer visiting the
207file is current when the hook functions are run. 209file is current when the hook functions are run.
208 210
209This variable works just like a normal hook, but we think that renaming 211This variable is a normal hook. @xref{Hooks}.
210it would not be advisable. @xref{Hooks}.
211@end defvar 212@end defvar
212 213
213@defvar find-file-not-found-functions 214@defvar find-file-not-found-functions
@@ -322,16 +323,21 @@ backed up when the buffer is next saved.
322With an argument of 16 or 64, reflecting 2 or 3 @kbd{C-u}'s, the 323With an argument of 16 or 64, reflecting 2 or 3 @kbd{C-u}'s, the
323@code{save-buffer} function unconditionally backs up the previous 324@code{save-buffer} function unconditionally backs up the previous
324version of the file before saving it. 325version of the file before saving it.
326
327@item
328With an argument of 0, unconditionally do @emph{not} make any backup file.
325@end itemize 329@end itemize
326@end deffn 330@end deffn
327 331
332@anchor{Definition of save-some-buffers}
328@deffn Command save-some-buffers &optional save-silently-p pred 333@deffn Command save-some-buffers &optional save-silently-p pred
329This command saves some modified file-visiting buffers. Normally it 334This command saves some modified file-visiting buffers. Normally it
330asks the user about each buffer. But if @var{save-silently-p} is 335asks the user about each buffer. But if @var{save-silently-p} is
331non-@code{nil}, it saves all the file-visiting buffers without querying 336non-@code{nil}, it saves all the file-visiting buffers without querying
332the user. 337the user.
333 338
334The optional @var{pred} argument controls which buffers to ask about. 339The optional @var{pred} argument controls which buffers to ask about
340(or to save silently if @var{save-silently-p} is non-@code{nil}).
335If it is @code{nil}, that means to ask only about file-visiting buffers. 341If it is @code{nil}, that means to ask only about file-visiting buffers.
336If it is @code{t}, that means also offer to save certain other non-file 342If it is @code{t}, that means also offer to save certain other non-file
337buffers---those that have a non-@code{nil} buffer-local value of 343buffers---those that have a non-@code{nil} buffer-local value of
@@ -346,6 +352,7 @@ whether to offer to save that buffer. If it returns a non-@code{nil}
346value in a certain buffer, that means do offer to save that buffer. 352value in a certain buffer, that means do offer to save that buffer.
347@end deffn 353@end deffn
348 354
355@anchor{Definition of write-file}
349@deffn Command write-file filename &optional confirm 356@deffn Command write-file filename &optional confirm
350This function writes the current buffer into file @var{filename}, makes 357This function writes the current buffer into file @var{filename}, makes
351the buffer visit that file, and marks it not modified. Then it renames 358the buffer visit that file, and marks it not modified. Then it renames
@@ -355,7 +362,13 @@ calling @code{set-visited-file-name} (@pxref{Buffer File Name}) and
355@code{save-buffer}. 362@code{save-buffer}.
356 363
357If @var{confirm} is non-@code{nil}, that means to ask for confirmation 364If @var{confirm} is non-@code{nil}, that means to ask for confirmation
358before overwriting an existing file. 365before overwriting an existing file. Interactively, confirmation is
366required, unless the user supplies a prefix argument.
367
368If @var{filename} is an existing directory, or a symbolic link to one,
369@code{write-file} uses the name of the visited file, in directory
370@var{filename}. If the buffer is not visiting a file, it uses the
371buffer name instead.
359@end deffn 372@end deffn
360 373
361 Saving a buffer runs several hooks. It also performs format 374 Saving a buffer runs several hooks. It also performs format
@@ -378,8 +391,9 @@ To do so, execute the following code:
378@end example 391@end example
379 392
380You might wish to save the file modes value returned by 393You might wish to save the file modes value returned by
381@code{backup-buffer} and use that to set the mode bits of the file that 394@code{backup-buffer} and use that (if non-@code{nil}) to set the mode
382you write. This is what @code{save-buffer} normally does. 395bits of the file that you write. This is what @code{save-buffer}
396normally does. @xref{Making Backups,, Making Backup Files}.
383 397
384The hook functions in @code{write-file-functions} are also responsible for 398The hook functions in @code{write-file-functions} are also responsible for
385encoding the data (if desired): they must choose a suitable coding 399encoding the data (if desired): they must choose a suitable coding
@@ -428,7 +442,7 @@ One use of this hook is in Fast Lock mode; it uses this hook to save the
428highlighting information in a cache file. 442highlighting information in a cache file.
429@end defopt 443@end defopt
430 444
431@defvar file-precious-flag 445@defopt file-precious-flag
432If this variable is non-@code{nil}, then @code{save-buffer} protects 446If this variable is non-@code{nil}, then @code{save-buffer} protects
433against I/O errors while saving by writing the new file to a temporary 447against I/O errors while saving by writing the new file to a temporary
434name instead of the name it is supposed to have, and then renaming it to 448name instead of the name it is supposed to have, and then renaming it to
@@ -442,7 +456,7 @@ all hard links between the file you save and other file names.
442 456
443Some modes give this variable a non-@code{nil} buffer-local value 457Some modes give this variable a non-@code{nil} buffer-local value
444in particular buffers. 458in particular buffers.
445@end defvar 459@end defopt
446 460
447@defopt require-final-newline 461@defopt require-final-newline
448This variable determines whether files may be written out that do 462This variable determines whether files may be written out that do
@@ -541,12 +555,22 @@ function returns @code{nil}.
541 555
542An error is signaled if @var{filename} specifies a nonwritable file, 556An error is signaled if @var{filename} specifies a nonwritable file,
543or a nonexistent file in a directory where files cannot be created. 557or a nonexistent file in a directory where files cannot be created.
558
559When called from Lisp, this function is completely equivalent to:
560
561@example
562(write-region start end filename t)
563@end example
544@end deffn 564@end deffn
545 565
546@deffn Command write-region start end filename &optional append visit lockname mustbenew 566@deffn Command write-region start end filename &optional append visit lockname mustbenew
547This function writes the region delimited by @var{start} and @var{end} 567This function writes the region delimited by @var{start} and @var{end}
548in the current buffer into the file specified by @var{filename}. 568in the current buffer into the file specified by @var{filename}.
549 569
570If @var{start} is @code{nil}, then the command writes the entire buffer
571contents (@emph{not} just the accessible portion) to the file and
572ignores @var{end}.
573
550@c Emacs 19 feature 574@c Emacs 19 feature
551If @var{start} is a string, then @code{write-region} writes or appends 575If @var{start} is a string, then @code{write-region} writes or appends
552that string, rather than text from the buffer. @var{end} is ignored in 576that string, rather than text from the buffer. @var{end} is ignored in
@@ -601,6 +625,7 @@ feature is useful for programs that use files for internal purposes,
601files that the user does not need to know about. 625files that the user does not need to know about.
602@end deffn 626@end deffn
603 627
628@anchor{Definition of with-temp-file}
604@defmac with-temp-file file body... 629@defmac with-temp-file file body...
605The @code{with-temp-file} macro evaluates the @var{body} forms with a 630The @code{with-temp-file} macro evaluates the @var{body} forms with a
606temporary buffer as the current buffer; then, at the end, it writes the 631temporary buffer as the current buffer; then, at the end, it writes the
@@ -612,7 +637,8 @@ in @var{body}.
612The current buffer is restored even in case of an abnormal exit via 637The current buffer is restored even in case of an abnormal exit via
613@code{throw} or error (@pxref{Nonlocal Exits}). 638@code{throw} or error (@pxref{Nonlocal Exits}).
614 639
615See also @code{with-temp-buffer} in @ref{Current Buffer}. 640See also @code{with-temp-buffer} in @ref{Definition of
641with-temp-buffer,, The Current Buffer}.
616@end defmac 642@end defmac
617 643
618@node File Locks 644@node File Locks
@@ -725,7 +751,10 @@ or directories unless otherwise noted.
725@cindex accessibility of a file 751@cindex accessibility of a file
726@cindex file accessibility 752@cindex file accessibility
727 753
728 These functions test for permission to access a file in specific ways. 754 These functions test for permission to access a file in specific
755ways. Unless explicitly stated otherwise, they recursively follow
756symbolic links for their file name arguments, at all levels (at the
757level of the file itself and at all levels of parent directories).
729 758
730@defun file-exists-p filename 759@defun file-exists-p filename
731This function returns @code{t} if a file named @var{filename} appears 760This function returns @code{t} if a file named @var{filename} appears
@@ -829,7 +858,13 @@ using @var{string} as the error message text.
829 858
830@defun file-ownership-preserved-p filename 859@defun file-ownership-preserved-p filename
831This function returns @code{t} if deleting the file @var{filename} and 860This function returns @code{t} if deleting the file @var{filename} and
832then creating it anew would keep the file's owner unchanged. 861then creating it anew would keep the file's owner unchanged. It also
862returns @code{t} for nonexistent files.
863
864If @var{filename} is a symbolic link, then, unlike the other functions
865discussed here, @code{file-ownership-preserved-p} does @emph{not}
866replace @var{filename} with its target. However, it does recursively
867follow symbolic links at all levels of parent directories.
833@end defun 868@end defun
834 869
835@defun file-newer-than-file-p filename1 filename2 870@defun file-newer-than-file-p filename1 filename2
@@ -837,8 +872,8 @@ then creating it anew would keep the file's owner unchanged.
837@cindex file modification time 872@cindex file modification time
838This function returns @code{t} if the file @var{filename1} is 873This function returns @code{t} if the file @var{filename1} is
839newer than file @var{filename2}. If @var{filename1} does not 874newer than file @var{filename2}. If @var{filename1} does not
840exist, it returns @code{nil}. If @var{filename2} does not exist, 875exist, it returns @code{nil}. If @var{filename1} does exist, but
841it returns @code{t}. 876@var{filename2} does not, it returns @code{t}.
842 877
843In the following example, assume that the file @file{aug-19} was written 878In the following example, assume that the file @file{aug-19} was written
844on the 19th, @file{aug-20} was written on the 20th, and the file 879on the 19th, @file{aug-20} was written on the 20th, and the file
@@ -877,9 +912,10 @@ as directories, symbolic links, and ordinary files.
877@defun file-symlink-p filename 912@defun file-symlink-p filename
878@cindex file symbolic links 913@cindex file symbolic links
879If the file @var{filename} is a symbolic link, the 914If the file @var{filename} is a symbolic link, the
880@code{file-symlink-p} function returns the link target as a string. 915@code{file-symlink-p} function returns the (non-recursive) link target
881(Determining the file name that the link points to from the target is 916as a string. (Determining the file name that the link points to from
882nontrivial.) 917the target is nontrivial.) First, this function recursively follows
918symbolic links at all levels of parent directories.
883 919
884If the file @var{filename} is not a symbolic link (or there is no such file), 920If the file @var{filename} is not a symbolic link (or there is no such file),
885@code{file-symlink-p} returns @code{nil}. 921@code{file-symlink-p} returns @code{nil}.
@@ -906,6 +942,9 @@ If the file @var{filename} is not a symbolic link (or there is no such file),
906@c !!! file-symlink-p: should show output of ls -l for comparison 942@c !!! file-symlink-p: should show output of ls -l for comparison
907@end defun 943@end defun
908 944
945The next two functions recursively follow symbolic links at
946all levels for @var{filename}.
947
909@defun file-directory-p filename 948@defun file-directory-p filename
910This function returns @code{t} if @var{filename} is the name of an 949This function returns @code{t} if @var{filename} is the name of an
911existing directory, @code{nil} otherwise. 950existing directory, @code{nil} otherwise.
@@ -957,14 +996,31 @@ because they eliminate symbolic links as a cause of name variation.
957@defun file-truename filename 996@defun file-truename filename
958The function @code{file-truename} returns the truename of the file 997The function @code{file-truename} returns the truename of the file
959@var{filename}. The argument must be an absolute file name. 998@var{filename}. The argument must be an absolute file name.
999
1000This function does not expand environment variables. Only
1001@code{substitute-in-file-name} does that. @xref{Definition of
1002substitute-in-file-name}.
1003
1004If you may need to follow symbolic links preceding @samp{..}@:
1005appearing as a name component, you should make sure to call
1006@code{file-truename} without prior direct or indirect calls to
1007@code{expand-file-name}, as otherwise the file name component
1008immediately preceding @samp{..} will be ``simplified away'' before
1009@code{file-truename} is called. To eliminate the need for a call to
1010@code{expand-file-name}, @code{file-truename} handles @samp{~} in the
1011same way that @code{expand-file-name} does. @xref{File Name
1012Expansion,, Functions that Expand Filenames}.
960@end defun 1013@end defun
961 1014
962@defun file-chase-links filename &optional limit 1015@defun file-chase-links filename &optional limit
963This function follows symbolic links, starting with @var{filename}, 1016This function follows symbolic links, starting with @var{filename},
964until it finds a file name which is not the name of a symbolic link. 1017until it finds a file name which is not the name of a symbolic link.
965Then it returns that file name. If you specify a number for 1018Then it returns that file name. This function does @emph{not} follow
966@var{limit}, then after chasing through that many links, the function 1019symbolic links at the level of parent directories.
967just returns what it as even if that is still a symbolic link. 1020
1021If you specify a number for @var{limit}, then after chasing through
1022that many links, the function just returns what it has even if that is
1023still a symbolic link.
968@end defun 1024@end defun
969 1025
970 To illustrate the difference between @code{file-chase-links} and 1026 To illustrate the difference between @code{file-chase-links} and
@@ -1007,6 +1063,10 @@ The highest value returnable is 4095 (7777 octal), meaning that
1007everyone has read, write, and execute permission, that the @acronym{SUID} bit 1063everyone has read, write, and execute permission, that the @acronym{SUID} bit
1008is set for both others and group, and that the sticky bit is set. 1064is set for both others and group, and that the sticky bit is set.
1009 1065
1066If @var{filename} does not exist, @code{file-modes} returns @code{nil}.
1067
1068This function recursively follows symbolic links at all levels.
1069
1010@example 1070@example
1011@group 1071@group
1012(file-modes "~/junk/diffs") 1072(file-modes "~/junk/diffs")
@@ -1034,6 +1094,11 @@ is set for both others and group, and that the sticky bit is set.
1034@end example 1094@end example
1035@end defun 1095@end defun
1036 1096
1097If the @var{filename} argument to the next two functions is a symbolic
1098link, then these function do @emph{not} replace it with its target.
1099However, they both recursively follow symbolic links at all levels of
1100parent directories.
1101
1037@defun file-nlinks filename 1102@defun file-nlinks filename
1038This functions returns the number of names (i.e., hard links) that 1103This functions returns the number of names (i.e., hard links) that
1039file @var{filename} has. If the file does not exist, then this function 1104file @var{filename} has. If the file does not exist, then this function
@@ -1059,6 +1124,7 @@ link to.
1059@end example 1124@end example
1060@end defun 1125@end defun
1061 1126
1127@anchor{Definition of file-attributes}
1062@defun file-attributes filename &optional id-format 1128@defun file-attributes filename &optional id-format
1063This function returns a list of attributes of file @var{filename}. If 1129This function returns a list of attributes of file @var{filename}. If
1064the specified file cannot be opened, it returns @code{nil}. 1130the specified file cannot be opened, it returns @code{nil}.
@@ -1213,7 +1279,12 @@ Replace the old file without confirmation if @var{ok-if-already-exists}
1213is any other value. 1279is any other value.
1214@end itemize 1280@end itemize
1215 1281
1216@defun add-name-to-file oldname newname &optional ok-if-already-exists 1282The next four commands all recursively follow symbolic links at all
1283levels of parent directories for their first argument, but, if that
1284argument is itself a symbolic link, then only @code{copy-file}
1285replaces it with its (recursive) target.
1286
1287@deffn Command add-name-to-file oldname newname &optional ok-if-already-exists
1217@cindex file with multiple names 1288@cindex file with multiple names
1218@cindex file hard link 1289@cindex file hard link
1219This function gives the file named @var{oldname} the additional name 1290This function gives the file named @var{oldname} the additional name
@@ -1279,7 +1350,7 @@ for one file are not allowed. Some systems implement multiple names
1279by copying the file instead. 1350by copying the file instead.
1280 1351
1281See also @code{file-nlinks} in @ref{File Attributes}. 1352See also @code{file-nlinks} in @ref{File Attributes}.
1282@end defun 1353@end deffn
1283 1354
1284@deffn Command rename-file filename newname &optional ok-if-already-exists 1355@deffn Command rename-file filename newname &optional ok-if-already-exists
1285This command renames the file @var{filename} as @var{newname}. 1356This command renames the file @var{filename} as @var{newname}.
@@ -1288,10 +1359,6 @@ If @var{filename} has additional names aside from @var{filename}, it
1288continues to have those names. In fact, adding the name @var{newname} 1359continues to have those names. In fact, adding the name @var{newname}
1289with @code{add-name-to-file} and then deleting @var{filename} has the 1360with @code{add-name-to-file} and then deleting @var{filename} has the
1290same effect as renaming, aside from momentary intermediate states. 1361same effect as renaming, aside from momentary intermediate states.
1291
1292In an interactive call, this function prompts for @var{filename} and
1293@var{newname} in the minibuffer; also, it requests confirmation if
1294@var{newname} already exists.
1295@end deffn 1362@end deffn
1296 1363
1297@deffn Command copy-file oldname newname &optional ok-if-exists time 1364@deffn Command copy-file oldname newname &optional ok-if-exists time
@@ -1307,9 +1374,19 @@ some operating systems.) If setting the time gets an error,
1307 1374
1308This function copies the file modes, too. 1375This function copies the file modes, too.
1309 1376
1310In an interactive call, this function prompts for @var{filename} and 1377In an interactive call, a prefix argument specifies a non-@code{nil}
1311@var{newname} in the minibuffer; also, it requests confirmation if 1378value for @var{time}.
1312@var{newname} already exists. 1379@end deffn
1380
1381@deffn Command make-symbolic-link filename newname &optional ok-if-exists
1382@pindex ln
1383@kindex file-already-exists
1384This command makes a symbolic link to @var{filename}, named
1385@var{newname}. This is like the shell command @samp{ln -s
1386@var{filename} @var{newname}}.
1387
1388This function is not available on systems that don't support symbolic
1389links.
1313@end deffn 1390@end deffn
1314 1391
1315@deffn Command delete-file filename 1392@deffn Command delete-file filename
@@ -1322,22 +1399,11 @@ A suitable kind of @code{file-error} error is signaled if the file does
1322not exist, or is not deletable. (On Unix and GNU/Linux, a file is 1399not exist, or is not deletable. (On Unix and GNU/Linux, a file is
1323deletable if its directory is writable.) 1400deletable if its directory is writable.)
1324 1401
1325See also @code{delete-directory} in @ref{Create/Delete Dirs}. 1402If @var{filename} is a symbolic link, @code{delete-file} does not
1326@end deffn 1403replace it with its target, but it does follow symbolic links at all
1327 1404levels of parent directories.
1328@deffn Command make-symbolic-link filename newname &optional ok-if-exists
1329@pindex ln
1330@kindex file-already-exists
1331This command makes a symbolic link to @var{filename}, named
1332@var{newname}. This is like the shell command @samp{ln -s
1333@var{filename} @var{newname}}.
1334 1405
1335In an interactive call, this function prompts for @var{filename} and 1406See also @code{delete-directory} in @ref{Create/Delete Dirs}.
1336@var{newname} in the minibuffer; also, it requests confirmation if
1337@var{newname} already exists.
1338
1339This function is not available on systems that don't support symbolic
1340links.
1341@end deffn 1407@end deffn
1342 1408
1343@defun define-logical-name varname string 1409@defun define-logical-name varname string
@@ -1346,8 +1412,10 @@ This function defines the logical name @var{varname} to have the value
1346@end defun 1412@end defun
1347 1413
1348@defun set-file-modes filename mode 1414@defun set-file-modes filename mode
1349This function sets mode bits of @var{filename} to @var{mode} (which must 1415This function sets mode bits of @var{filename} to @var{mode} (which
1350be an integer). Only the low 12 bits of @var{mode} are used. 1416must be an integer). Only the low 12 bits of @var{mode} are used.
1417This function recursively follows symbolic links at all levels for
1418@var{filename}.
1351@end defun 1419@end defun
1352 1420
1353@c Emacs 19 feature 1421@c Emacs 19 feature
@@ -1500,18 +1568,6 @@ This function returns the nondirectory part of @var{filename}.
1500@end example 1568@end example
1501@end defun 1569@end defun
1502 1570
1503@defun file-name-extension filename &optional period
1504This function returns @var{filename}'s final ``extension,'' if any,
1505after applying @code{file-name-sans-versions} to remove any
1506version/backup part. It returns @code{nil} for extensionless file
1507names such as @file{foo}. If @var{period} is non-@code{nil}, then the
1508returned value includes the period that delimits the extension, and if
1509@var{filename} has no extension, the value is @code{""}. If the last
1510component of a file name begins with a @samp{.}, that @samp{.} doesn't
1511count as the beginning of an extension, so, for example,
1512@file{.emacs}'s ``extension'' is @code{nil}, not @samp{.emacs}.
1513@end defun
1514
1515@defun file-name-sans-versions filename &optional keep-backup-version 1571@defun file-name-sans-versions filename &optional keep-backup-version
1516This function returns @var{filename} with any file version numbers, 1572This function returns @var{filename} with any file version numbers,
1517backup version numbers, or trailing tildes discarded. 1573backup version numbers, or trailing tildes discarded.
@@ -1541,11 +1597,29 @@ return value, but backup version numbers are kept.
1541@end example 1597@end example
1542@end defun 1598@end defun
1543 1599
1600@defun file-name-extension filename &optional period
1601This function returns @var{filename}'s final ``extension'', if any,
1602after applying @code{file-name-sans-versions} to remove any
1603version/backup part. The extension, in a file name, is the part that
1604starts with the last @samp{.} in the last name component (minus
1605any version/backup part).
1606
1607This function returns @code{nil} for extensionless file names such as
1608@file{foo}. It returns @code{""} for null extensions, as in
1609@file{foo.}. If the last component of a file name begins with a
1610@samp{.}, that @samp{.} doesn't count as the beginning of an
1611extension. Thus, @file{.emacs}'s ``extension'' is @code{nil}, not
1612@samp{.emacs}.
1613
1614If @var{period} is non-@code{nil}, then the returned value includes
1615the period that delimits the extension, and if @var{filename} has no
1616extension, the value is @code{""}.
1617@end defun
1618
1544@defun file-name-sans-extension filename 1619@defun file-name-sans-extension filename
1545This function returns @var{filename} minus its ``extension,'' if any. 1620This function returns @var{filename} minus its extension, if any. The
1546The extension, in a file name, is the part that starts with the last 1621version/backup part, if present, is only removed if the file has an
1547@samp{.} in the last name component, except if that @samp{.} is the 1622extension. For example,
1548first character of the file name's last component. For example,
1549 1623
1550@example 1624@example
1551(file-name-sans-extension "foo.lose.c") 1625(file-name-sans-extension "foo.lose.c")
@@ -1556,7 +1630,14 @@ first character of the file name's last component. For example,
1556 @result{} "/my/home/.emacs" 1630 @result{} "/my/home/.emacs"
1557(file-name-sans-extension "/my/home/.emacs.el") 1631(file-name-sans-extension "/my/home/.emacs.el")
1558 @result{} "/my/home/.emacs" 1632 @result{} "/my/home/.emacs"
1633(file-name-sans-extension "~/foo.el.~3~")
1634 @result{} "~/foo"
1635(file-name-sans-extension "~/foo.~3~")
1636 @result{} "~/foo.~3~"
1559@end example 1637@end example
1638
1639Note that the @samp{.~3~} in the two last examples is the backup part,
1640not an extension.
1560@end defun 1641@end defun
1561 1642
1562@ignore 1643@ignore
@@ -1623,9 +1704,9 @@ actually a kind of file, so it has a file name, which is related to
1623the directory name but not identical to it. (This is not quite the 1704the directory name but not identical to it. (This is not quite the
1624same as the usual Unix terminology.) These two different names for 1705same as the usual Unix terminology.) These two different names for
1625the same entity are related by a syntactic transformation. On GNU and 1706the same entity are related by a syntactic transformation. On GNU and
1626Unix systems, this is simple: a directory name ends in a slash (or 1707Unix systems, this is simple: a directory name ends in a slash,
1627backslash), whereas the directory's name as a file lacks that slash. 1708whereas the directory's name as a file lacks that slash. On MSDOS and
1628On MSDOS and VMS, the relationship is more complicated. 1709VMS, the relationship is more complicated.
1629 1710
1630 The difference between a directory name and its name as a file is 1711 The difference between a directory name and its name as a file is
1631subtle but crucial. When an Emacs variable or function argument is 1712subtle but crucial. When an Emacs variable or function argument is
@@ -1635,7 +1716,7 @@ always a directory name.
1635 1716
1636 The following two functions convert between directory names and file 1717 The following two functions convert between directory names and file
1637names. They do nothing special with environment variable substitutions 1718names. They do nothing special with environment variable substitutions
1638such as @samp{$HOME}, and the constructs @samp{~}, and @samp{..}. 1719such as @samp{$HOME}, and the constructs @samp{~}, @samp{.} and @samp{..}.
1639 1720
1640@defun file-name-as-directory filename 1721@defun file-name-as-directory filename
1641This function returns a string representing @var{filename} in a form 1722This function returns a string representing @var{filename} in a form
@@ -1713,7 +1794,9 @@ abbreviations to use for file directories. Each element has the form
1713@code{(@var{from} . @var{to})}, and says to replace @var{from} with 1794@code{(@var{from} . @var{to})}, and says to replace @var{from} with
1714@var{to} when it appears in a directory name. The @var{from} string is 1795@var{to} when it appears in a directory name. The @var{from} string is
1715actually a regular expression; it should always start with @samp{^}. 1796actually a regular expression; it should always start with @samp{^}.
1716The function @code{abbreviate-file-name} performs these substitutions. 1797The @var{to} string should be an ordinary absolute directory name. Do
1798not use @samp{~} to stand for a home directory in that string. The
1799function @code{abbreviate-file-name} performs these substitutions.
1717 1800
1718You can set this variable in @file{site-init.el} to describe the 1801You can set this variable in @file{site-init.el} to describe the
1719abbreviations appropriate for your site. 1802abbreviations appropriate for your site.
@@ -1732,6 +1815,7 @@ and so on.
1732 To convert a directory name to its abbreviation, use this 1815 To convert a directory name to its abbreviation, use this
1733function: 1816function:
1734 1817
1818@anchor{Definition of abbreviate-file-name}
1735@defun abbreviate-file-name filename 1819@defun abbreviate-file-name filename
1736This function applies abbreviations from @code{directory-abbrev-alist} 1820This function applies abbreviations from @code{directory-abbrev-alist}
1737to its argument, and substitutes @samp{~} for the user's home 1821to its argument, and substitutes @samp{~} for the user's home
@@ -1749,6 +1833,9 @@ you must specify the default directory name as well as the file name to
1749be expanded. Expansion also simplifies file names by eliminating 1833be expanded. Expansion also simplifies file names by eliminating
1750redundancies such as @file{./} and @file{@var{name}/../}. 1834redundancies such as @file{./} and @file{@var{name}/../}.
1751 1835
1836In the next two functions, the @var{directory} argument can be either
1837a directory name or a directory file name. @xref{Directory Names}.
1838
1752@defun expand-file-name filename &optional directory 1839@defun expand-file-name filename &optional directory
1753This function converts @var{filename} to an absolute file name. If 1840This function converts @var{filename} to an absolute file name. If
1754@var{directory} is supplied, it is the default directory to start with 1841@var{directory} is supplied, it is the default directory to start with
@@ -1776,6 +1863,12 @@ used. For example:
1776@end group 1863@end group
1777@end example 1864@end example
1778 1865
1866If the part of the combined file name before the first slash is
1867@samp{~}, it expands to the value of the @env{HOME} environment
1868variable (usually your home directory). If the part before the first
1869slash is @samp{~@var{user}} and if @var{user} is a valid login name,
1870it expands to @var{user}'s home directory.
1871
1779Filenames containing @samp{.} or @samp{..} are simplified to their 1872Filenames containing @samp{.} or @samp{..} are simplified to their
1780canonical form: 1873canonical form:
1781 1874
@@ -1788,6 +1881,27 @@ canonical form:
1788 1881
1789Note that @code{expand-file-name} does @emph{not} expand environment 1882Note that @code{expand-file-name} does @emph{not} expand environment
1790variables; only @code{substitute-in-file-name} does that. 1883variables; only @code{substitute-in-file-name} does that.
1884
1885Note also that @code{expand-file-name} does not follow symbolic links
1886at any level. This results in a difference between the way
1887@code{file-truename} and @code{expand-file-name} treat @samp{..}.
1888Assuming that @samp{/tmp/bar} is a symbolic link to the directory
1889@samp{/tmp/foo/bar} we get:
1890
1891@example
1892@group
1893(file-truename "/tmp/bar/../myfile")
1894 @result{} "/tmp/foo/myfile"
1895@end group
1896@group
1897(expand-file-name "/tmp/bar/../myfile")
1898 @result{} "/tmp/myfile"
1899@end group
1900@end example
1901
1902If you may need to follow symbolic links preceding @samp{..}, you
1903should make sure to call @code{file-truename} without prior direct or
1904indirect calls to @code{expand-file-name}. @xref{Truenames}.
1791@end defun 1905@end defun
1792 1906
1793@c Emacs 19 feature 1907@c Emacs 19 feature
@@ -1829,8 +1943,9 @@ default-directory
1829@end example 1943@end example
1830@end defvar 1944@end defvar
1831 1945
1946@anchor{Definition of substitute-in-file-name}
1832@defun substitute-in-file-name filename 1947@defun substitute-in-file-name filename
1833This function replaces environment variables references in 1948This function replaces environment variable references in
1834@var{filename} with the environment variable values. Following 1949@var{filename} with the environment variable values. Following
1835standard Unix shell syntax, @samp{$} is the prefix to substitute an 1950standard Unix shell syntax, @samp{$} is the prefix to substitute an
1836environment variable value. If the input contains @samp{$$}, that is 1951environment variable value. If the input contains @samp{$$}, that is
@@ -1862,8 +1977,9 @@ the user's home directory name, has value @samp{/xcssun/users/rms}.
1862@end group 1977@end group
1863@end example 1978@end example
1864 1979
1865After substitution, if a @samp{~} or a @samp{/} appears following a 1980After substitution, if a @samp{~} or a @samp{/} appears immediately
1866@samp{/}, everything before the following @samp{/} is discarded: 1981after another @samp{/}, the function discards everything before it (up
1982through the immediately preceding @samp{/}).
1867 1983
1868@example 1984@example
1869@group 1985@group
@@ -1895,7 +2011,7 @@ construct a name for such a file, starting in Emacs 21:
1895The job of @code{make-temp-file} is to prevent two different users or 2011The job of @code{make-temp-file} is to prevent two different users or
1896two different jobs from trying to use the exact same file name. 2012two different jobs from trying to use the exact same file name.
1897 2013
1898@defun make-temp-file prefix &optional dir-flag 2014@defun make-temp-file prefix &optional dir-flag suffix
1899@tindex make-temp-file 2015@tindex make-temp-file
1900This function creates a temporary file and returns its name. 2016This function creates a temporary file and returns its name.
1901The name starts with @var{prefix}; it also contains a number that is 2017The name starts with @var{prefix}; it also contains a number that is
@@ -1913,8 +2029,12 @@ When @code{make-temp-file} returns, the file has been created and is
1913empty. At that point, you should write the intended contents into the 2029empty. At that point, you should write the intended contents into the
1914file. 2030file.
1915 2031
1916If @var{dir-flag} is non-@code{nil}, @code{make-temp-file} creates 2032If @var{dir-flag} is non-@code{nil}, @code{make-temp-file} creates an
1917an empty directory instead of an empty file. 2033empty directory instead of an empty file. It returns the file name,
2034not the directory name, of that directory. @xref{Directory Names}.
2035
2036If @var{suffix} is non-@code{nil}, @code{make-temp-file} adds it at
2037the end of the file name.
1918 2038
1919To prevent conflicts among different libraries running in the same 2039To prevent conflicts among different libraries running in the same
1920Emacs, each Lisp program that uses @code{make-temp-file} should have its 2040Emacs, each Lisp program that uses @code{make-temp-file} should have its
@@ -1944,9 +2064,10 @@ you should use @code{make-temp-name} instead:
1944This function generates a string that can be used as a unique file name. 2064This function generates a string that can be used as a unique file name.
1945The name starts with @var{string}, and contains a number that is 2065The name starts with @var{string}, and contains a number that is
1946different in each Emacs job. It is like @code{make-temp-file} except 2066different in each Emacs job. It is like @code{make-temp-file} except
1947that it just constructs a name, and does not create a file. On MS-DOS, 2067that it just constructs a name, and does not create a file. Another
1948the @var{string} prefix can be truncated to fit into the 8+3 file-name 2068difference is that @var{string} should be an absolute file name. On
1949limits. 2069MS-DOS, this function can truncate the @var{string} prefix to fit into
2070the 8+3 file-name limits.
1950@end defun 2071@end defun
1951 2072
1952@defvar temporary-file-directory 2073@defvar temporary-file-directory
@@ -1964,11 +2085,11 @@ system; it is based on the @code{TMPDIR}, @code{TMP} and @code{TEMP}
1964environment variables, with a fall-back to a system-dependent name if 2085environment variables, with a fall-back to a system-dependent name if
1965none of these variables is defined. 2086none of these variables is defined.
1966 2087
1967Even if you do not use @code{make-temp-name} to choose the temporary 2088Even if you do not use @code{make-temp-file} to create the temporary
1968file's name, you should still use this variable to decide which 2089file, you should still use this variable to decide which directory to
1969directory to put the file in. However, if you expect the file to be 2090put the file in. However, if you expect the file to be small, you
1970small, you should use @code{small-temporary-file-directory} first if 2091should use @code{small-temporary-file-directory} first if that is
1971that is non-@code{nil}. 2092non-@code{nil}.
1972@end defvar 2093@end defvar
1973 2094
1974@tindex small-temporary-file-directory 2095@tindex small-temporary-file-directory
@@ -2066,8 +2187,8 @@ has five files whose names begin with @samp{f}: @file{foo},
2066@defopt completion-ignored-extensions 2187@defopt completion-ignored-extensions
2067@code{file-name-completion} usually ignores file names that end in any 2188@code{file-name-completion} usually ignores file names that end in any
2068string in this list. It does not ignore them when all the possible 2189string in this list. It does not ignore them when all the possible
2069completions end in one of these suffixes or when a buffer showing all 2190completions end in one of these suffixes. This variable has no effect
2070possible completions is displayed.@refill 2191on @code{file-name-all-completions}.@refill
2071 2192
2072A typical value might look like this: 2193A typical value might look like this:
2073 2194
@@ -2176,17 +2297,20 @@ An error is signaled if @var{directory} is not the name of a directory
2176that can be read. 2297that can be read.
2177@end defun 2298@end defun
2178 2299
2179@defun directory-files-and-attributes directory &optional full-name match-regexp nosort 2300@defun directory-files-and-attributes directory &optional full-name match-regexp nosort id-format
2180This is similar to @code{directory-files} in deciding which files 2301This is similar to @code{directory-files} in deciding which files
2181to report on and how to report their names. However, instead 2302to report on and how to report their names. However, instead
2182of returning a list of file names, it returns for each file a 2303of returning a list of file names, it returns for each file a
2183list @code{(@var{filename} . @var{attributes})}, where @var{attributes} 2304list @code{(@var{filename} . @var{attributes})}, where @var{attributes}
2184is what @code{file-attributes} would return for that file. 2305is what @code{file-attributes} would return for that file.
2306The optional argument @var{id-format} has the same meaning as the
2307corresponding argument to @code{file-attributes} (@pxref{Definition
2308of file-attributes}).
2185@end defun 2309@end defun
2186 2310
2187@defun file-name-all-versions file dirname 2311@defun file-name-all-versions file dirname
2188This function returns a list of all versions of the file named 2312This function returns a list of all versions of the file named
2189@var{file} in directory @var{dirname}. 2313@var{file} in directory @var{dirname}. It is only available on VMS.
2190@end defun 2314@end defun
2191 2315
2192@tindex file-expand-wildcards 2316@tindex file-expand-wildcards
@@ -2207,6 +2331,8 @@ normally also relative to the current default directory. However, if
2207This function inserts (in the current buffer) a directory listing for 2331This function inserts (in the current buffer) a directory listing for
2208directory @var{file}, formatted with @code{ls} according to 2332directory @var{file}, formatted with @code{ls} according to
2209@var{switches}. It leaves point after the inserted text. 2333@var{switches}. It leaves point after the inserted text.
2334@var{switches} may be a string of options, or a list of strings
2335representing individual options.
2210 2336
2211The argument @var{file} may be either a directory name or a file 2337The argument @var{file} may be either a directory name or a file
2212specification including wildcard characters. If @var{wildcard} is 2338specification including wildcard characters. If @var{wildcard} is
@@ -2228,6 +2354,12 @@ If @var{wildcard} is non-@code{nil}, it also runs the shell specified by
2228MS-DOS and MS-Windows systems usually lack the standard Unix program 2354MS-DOS and MS-Windows systems usually lack the standard Unix program
2229@code{ls}, so this function emulates the standard Unix program @code{ls} 2355@code{ls}, so this function emulates the standard Unix program @code{ls}
2230with Lisp code. 2356with Lisp code.
2357
2358As a technical detail, when @var{switches} contains the long
2359@samp{--dired} option, @code{insert-directory} treats it specially,
2360for the sake of dired. However, the normally equivalent short
2361@samp{-D} option is just passed on to @code{insert-directory-program},
2362as any other option.
2231@end defun 2363@end defun
2232 2364
2233@defvar insert-directory-program 2365@defvar insert-directory-program
@@ -2247,8 +2379,9 @@ delete directories.
2247 2379
2248@defun make-directory dirname &optional parents 2380@defun make-directory dirname &optional parents
2249This function creates a directory named @var{dirname}. 2381This function creates a directory named @var{dirname}.
2250If @var{parents} is non-@code{nil}, that means to create 2382If @var{parents} is non-@code{nil}, as is always the case in an
2251the parent directories first, if they don't already exist. 2383interactive call, that means to create the parent directories first,
2384if they don't already exist.
2252@end defun 2385@end defun
2253 2386
2254@defun delete-directory dirname 2387@defun delete-directory dirname
@@ -2256,6 +2389,9 @@ This function deletes the directory named @var{dirname}. The function
2256@code{delete-file} does not work for files that are directories; you 2389@code{delete-file} does not work for files that are directories; you
2257must use @code{delete-directory} for them. If the directory contains 2390must use @code{delete-directory} for them. If the directory contains
2258any files, @code{delete-directory} signals an error. 2391any files, @code{delete-directory} signals an error.
2392
2393This function only follows symbolic links at the level of parent
2394directories.
2259@end defun 2395@end defun
2260 2396
2261@node Magic File Names 2397@node Magic File Names
@@ -2287,10 +2423,10 @@ check the given file name against @code{file-name-handler-alist}. If
2287the file name matches @var{regexp}, the primitives handle that file by 2423the file name matches @var{regexp}, the primitives handle that file by
2288calling @var{handler}. 2424calling @var{handler}.
2289 2425
2290The first argument given to @var{handler} is the name of the primitive; 2426The first argument given to @var{handler} is the name of the
2291the remaining arguments are the arguments that were passed to that 2427primitive, as a symbol; the remaining arguments are the arguments that
2292primitive. (The first of these arguments is most often the file name 2428were passed to that primitive. (The first of these arguments is most
2293itself.) For example, if you do this: 2429often the file name itself.) For example, if you do this:
2294 2430
2295@example 2431@example
2296(file-exists-p @var{filename}) 2432(file-exists-p @var{filename})
@@ -2501,7 +2637,7 @@ of the local copy file.
2501@end defun 2637@end defun
2502 2638
2503@defun file-remote-p filename 2639@defun file-remote-p filename
2504This functions return @code{t} if @var{filename} is a remote file---that is, 2640This function returns @code{t} if @var{filename} is a remote file---that is,
2505a magic file name that handles @code{file-local-copy}. 2641a magic file name that handles @code{file-local-copy}.
2506@end defun 2642@end defun
2507 2643
@@ -2631,11 +2767,14 @@ When @code{write-region} writes data into a file, it first calls the
2631encoding functions for the formats listed in @code{buffer-file-format}, 2767encoding functions for the formats listed in @code{buffer-file-format},
2632in the order of appearance in the list. 2768in the order of appearance in the list.
2633 2769
2634@deffn Command format-write-file file format 2770@deffn Command format-write-file file format &optional confirm
2635This command writes the current buffer contents into the file @var{file} 2771This command writes the current buffer contents into the file
2636in format @var{format}, and makes that format the default for future 2772@var{file} in format @var{format}, and makes that format the default
2637saves of the buffer. The argument @var{format} is a list of format 2773for future saves of the buffer. The argument @var{format} is a list
2638names. 2774of format names. Except for the @var{format} argument, this command
2775is similar to @code{write-file}. In particular, @var{confirm} has the
2776same meaning and interactive treatment as the corresponding argument
2777to @code{write-file}. @xref{Definition of write-file}.
2639@end deffn 2778@end deffn
2640 2779
2641@deffn Command format-find-file file format 2780@deffn Command format-find-file file format
@@ -2667,8 +2806,10 @@ The argument @var{format} is a list of format names. If @var{format} is
2667This variable specifies the format to use for auto-saving. Its value is 2806This variable specifies the format to use for auto-saving. Its value is
2668a list of format names, just like the value of 2807a list of format names, just like the value of
2669@code{buffer-file-format}; however, it is used instead of 2808@code{buffer-file-format}; however, it is used instead of
2670@code{buffer-file-format} for writing auto-save files. This variable is 2809@code{buffer-file-format} for writing auto-save files. If the value
2671always buffer-local in all buffers. 2810is @code{t}, the default, auto-saving uses the same format as a
2811regular save in the same buffer. This variable is always buffer-local
2812in all buffers.
2672@end defvar 2813@end defvar
2673 2814
2674@ignore 2815@ignore