Mercurial > emacs
comparison lispref/files.texi @ 25751:467b88fab665
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 17 Sep 1999 06:59:04 +0000 |
parents | a6db4671c7a0 |
children | ef5e7bbe6f19 |
comparison
equal
deleted
inserted
replaced
25750:f1968a807f56 | 25751:467b88fab665 |
---|---|
124 @samp{yes}, any changes previously made in the buffer are lost. | 124 @samp{yes}, any changes previously made in the buffer are lost. |
125 | 125 |
126 This function displays warning or advisory messages in various peculiar | 126 This function displays warning or advisory messages in various peculiar |
127 cases, unless the optional argument @var{nowarn} is non-@code{nil}. For | 127 cases, unless the optional argument @var{nowarn} is non-@code{nil}. For |
128 example, if it needs to create a buffer, and there is no file named | 128 example, if it needs to create a buffer, and there is no file named |
129 @var{filename}, it displays the message @samp{New file} in the echo | 129 @var{filename}, it displays the message @samp{(New file)} in the echo |
130 area, and leaves the buffer empty. | 130 area, and leaves the buffer empty. |
131 | 131 |
132 The @code{find-file-noselect} function normally calls | 132 The @code{find-file-noselect} function normally calls |
133 @code{after-find-file} after reading the file (@pxref{Subroutines of | 133 @code{after-find-file} after reading the file (@pxref{Subroutines of |
134 Visiting}). That function sets the buffer major mode, parses local | 134 Visiting}). That function sets the buffer major mode, parses local |
258 @cindex new file message | 258 @cindex new file message |
259 @cindex file open error | 259 @cindex file open error |
260 If reading the file got an error because the file does not exist, but | 260 If reading the file got an error because the file does not exist, but |
261 its directory does exist, the caller should pass a non-@code{nil} value | 261 its directory does exist, the caller should pass a non-@code{nil} value |
262 for @var{error}. In that case, @code{after-find-file} issues a warning: | 262 for @var{error}. In that case, @code{after-find-file} issues a warning: |
263 @samp{(New File)}. For more serious errors, the caller should usually not | 263 @samp{(New file)}. For more serious errors, the caller should usually not |
264 call @code{after-find-file}. | 264 call @code{after-find-file}. |
265 | 265 |
266 If @var{warn} is non-@code{nil}, then this function issues a warning | 266 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. | 267 if an auto-save file exists and is more recent than the visited file. |
268 | 268 |
310 the user. | 310 the user. |
311 | 311 |
312 The optional @var{exiting} argument, if non-@code{nil}, requests this | 312 The optional @var{exiting} argument, if non-@code{nil}, requests this |
313 function to offer also to save certain other buffers that are not | 313 function to offer also to save certain other buffers that are not |
314 visiting files. These are buffers that have a non-@code{nil} | 314 visiting files. These are buffers that have a non-@code{nil} |
315 buffer-local value of @code{buffer-offer-save}. (A user who says yes to | 315 buffer-local value of @code{buffer-offer-save}. (A user who says @samp{yes} to |
316 saving one of these is asked to specify a file name to use.) The | 316 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 | 317 @code{save-buffers-kill-emacs} function passes a non-@code{nil} value |
318 for this argument. | 318 for this argument. |
319 @end deffn | 319 @end deffn |
320 | 320 |
445 | 445 |
446 The function @code{insert-file-contents} checks the file contents | 446 The function @code{insert-file-contents} checks the file contents |
447 against the defined file formats, and converts the file contents if | 447 against the defined file formats, and converts the file contents if |
448 appropriate. @xref{Format Conversion}. It also calls the functions in | 448 appropriate. @xref{Format Conversion}. It also calls the functions in |
449 the list @code{after-insert-file-functions}; see @ref{Saving | 449 the list @code{after-insert-file-functions}; see @ref{Saving |
450 Properties}. | 450 Properties}. Normally, one of the functions in the |
451 @code{after-insert-file-functions} list determines the coding system | |
452 (@pxref{Coding Systems}) used for decoding the file's contents. | |
451 | 453 |
452 If @var{visit} is non-@code{nil}, this function additionally marks the | 454 If @var{visit} is non-@code{nil}, this function additionally marks the |
453 buffer as unmodified and sets up various fields in the buffer so that it | 455 buffer as unmodified and sets up various fields in the buffer so that it |
454 is visiting the file @var{filename}: these include the buffer's visited | 456 is visiting the file @var{filename}: these include the buffer's visited |
455 file name and its last save file modtime. This feature is used by | 457 file name and its last save file modtime. This feature is used by |
508 | 510 |
509 An error is signaled if @var{filename} specifies a nonwritable file, | 511 An error is signaled if @var{filename} specifies a nonwritable file, |
510 or a nonexistent file in a directory where files cannot be created. | 512 or a nonexistent file in a directory where files cannot be created. |
511 @end deffn | 513 @end deffn |
512 | 514 |
513 @deffn Command write-region start end filename &optional append visit confirm | 515 @deffn Command write-region start end filename &optional append visit mustbenew |
514 This function writes the region delimited by @var{start} and @var{end} | 516 This function writes the region delimited by @var{start} and @var{end} |
515 in the current buffer into the file specified by @var{filename}. | 517 in the current buffer into the file specified by @var{filename}. |
516 | 518 |
517 @c Emacs 19 feature | 519 @c Emacs 19 feature |
518 If @var{start} is a string, then @code{write-region} writes or appends | 520 If @var{start} is a string, then @code{write-region} writes or appends |
519 that string, rather than text from the buffer. | 521 that string, rather than text from the buffer. @var{end} is ignored in |
522 this case. | |
520 | 523 |
521 If @var{append} is non-@code{nil}, then the specified text is appended | 524 If @var{append} is non-@code{nil}, then the specified text is appended |
522 to the existing file contents (if any). | 525 to the existing file contents (if any). |
523 | 526 |
524 If @var{confirm} is non-@code{nil}, then @code{write-region} asks | 527 If @var{mustbenew} is non-@code{nil}, then @code{write-region} asks |
525 for confirmation if @var{filename} names an existing file. | 528 for confirmation if @var{filename} names an existing file. |
529 Starting in Emacs 21, if @var{mustbenew} is the symbol @code{excl}, | |
530 then @code{write-region} does not ask for confirmation, but instead | |
531 it signals an error @code{file-already-exists} if the file already | |
532 exists. | |
533 | |
534 The test for an existing file, when @var{mustbenew} is @code{excl}, uses | |
535 a special system feature. At least for files on a local disk, there is | |
536 no chance that some other program could create a file of the same name | |
537 before Emacs does, without Emacs's noticing. | |
526 | 538 |
527 If @var{visit} is @code{t}, then Emacs establishes an association | 539 If @var{visit} is @code{t}, then Emacs establishes an association |
528 between the buffer and the file: the buffer is then visiting that file. | 540 between the buffer and the file: the buffer is then visiting that file. |
529 It also sets the last file modification time for the current buffer to | 541 It also sets the last file modification time for the current buffer to |
530 @var{filename}'s modtime, and marks the buffer as not modified. This | 542 @var{filename}'s modtime, and marks the buffer as not modified. This |
613 if the buffer is modified. If the buffer is not modified, then | 625 if the buffer is modified. If the buffer is not modified, then |
614 the file should not be locked, so this function does nothing. It also | 626 the file should not be locked, so this function does nothing. It also |
615 does nothing if the current buffer is not visiting a file. | 627 does nothing if the current buffer is not visiting a file. |
616 @end defun | 628 @end defun |
617 | 629 |
630 File locking is not supported on some systems. On systems that do not | |
631 support it, the functions @code{lock-buffer}, @code{unlock-buffer} and | |
632 @code{file-locked-p} do nothing and return @code{nil}. | |
633 | |
618 @defun ask-user-about-lock file other-user | 634 @defun ask-user-about-lock file other-user |
619 This function is called when the user tries to modify @var{file}, but it | 635 This function is called when the user tries to modify @var{file}, but it |
620 is locked by another user named @var{other-user}. The default | 636 is locked by another user named @var{other-user}. The default |
621 definition of this function asks the user to say what to do. The value | 637 definition of this function asks the user to say what to do. The value |
622 this function returns determines what Emacs does next: | 638 this function returns determines what Emacs does next: |
708 @end defun | 724 @end defun |
709 | 725 |
710 @c Emacs 19 feature | 726 @c Emacs 19 feature |
711 @defun file-executable-p filename | 727 @defun file-executable-p filename |
712 This function returns @code{t} if a file named @var{filename} exists and | 728 This function returns @code{t} if a file named @var{filename} exists and |
713 you can execute it. It returns @code{nil} otherwise. If the file is a | 729 you can execute it. It returns @code{nil} otherwise. On Unix, if the |
714 directory, execute permission means you can check the existence and | 730 file is a directory, execute permission means you can check the |
715 attributes of files inside the directory, and open those files if their | 731 existence and attributes of files inside the directory, and open those |
716 modes permit. | 732 files if their modes permit. |
717 @end defun | 733 @end defun |
718 | 734 |
719 @defun file-writable-p filename | 735 @defun file-writable-p filename |
720 This function returns @code{t} if the file @var{filename} can be written | 736 This function returns @code{t} if the file @var{filename} can be written |
721 or created by you, and @code{nil} otherwise. A file is writable if the | 737 or created by you, and @code{nil} otherwise. A file is writable if the |
1079 | 1095 |
1080 @item (8489 20285) | 1096 @item (8489 20285) |
1081 last had its inode changed on Aug 19 00:09. | 1097 last had its inode changed on Aug 19 00:09. |
1082 | 1098 |
1083 @item 14906 | 1099 @item 14906 |
1084 is 14906 characters long. | 1100 is 14906 bytes long. (It may not contain 14906 characters, though, |
1101 if some of the bytes belong to multibyte sequences.) | |
1085 | 1102 |
1086 @item "-rw-rw-rw-" | 1103 @item "-rw-rw-rw-" |
1087 has a mode of read and write access for the owner, group, and world. | 1104 has a mode of read and write access for the owner, group, and world. |
1088 | 1105 |
1089 @item nil | 1106 @item nil |
1184 81908 -rw-rw-rw- 3 rms 29 Aug 18 20:32 foo3 | 1201 81908 -rw-rw-rw- 3 rms 29 Aug 18 20:32 foo3 |
1185 @end group | 1202 @end group |
1186 @end example | 1203 @end example |
1187 | 1204 |
1188 This function is meaningless on operating systems where multiple names | 1205 This function is meaningless on operating systems where multiple names |
1189 for one file are not allowed. | 1206 for one file are not allowed. Some systems implement multiple names |
1207 by copying the file instead. | |
1190 | 1208 |
1191 See also @code{file-nlinks} in @ref{File Attributes}. | 1209 See also @code{file-nlinks} in @ref{File Attributes}. |
1192 @end defun | 1210 @end defun |
1193 | 1211 |
1194 @deffn Command rename-file filename newname &optional ok-if-already-exists | 1212 @deffn Command rename-file filename newname &optional ok-if-already-exists |
1239 @var{filename} @var{newname}}. | 1257 @var{filename} @var{newname}}. |
1240 | 1258 |
1241 In an interactive call, this function prompts for @var{filename} and | 1259 In an interactive call, this function prompts for @var{filename} and |
1242 @var{newname} in the minibuffer; also, it requests confirmation if | 1260 @var{newname} in the minibuffer; also, it requests confirmation if |
1243 @var{newname} already exists. | 1261 @var{newname} already exists. |
1262 | |
1263 This function is not available on systems that don't support symbolic | |
1264 links. | |
1244 @end deffn | 1265 @end deffn |
1245 | 1266 |
1246 @defun define-logical-name varname string | 1267 @defun define-logical-name varname string |
1247 This function defines the logical name @var{name} to have the value | 1268 This function defines the logical name @var{name} to have the value |
1248 @var{string}. It is available only on VMS. | 1269 @var{string}. It is available only on VMS. |
1273 @end defun | 1294 @end defun |
1274 | 1295 |
1275 @cindex MS-DOS and file modes | 1296 @cindex MS-DOS and file modes |
1276 @cindex file modes and MS-DOS | 1297 @cindex file modes and MS-DOS |
1277 On MS-DOS, there is no such thing as an ``executable'' file mode bit. | 1298 On MS-DOS, there is no such thing as an ``executable'' file mode bit. |
1278 So Emacs considers a file executable if its name ends in @samp{.com}, | 1299 So Emacs considers a file executable if its name ends in one of the |
1279 @samp{.bat} or @samp{.exe}. This is reflected in the values returned | 1300 standard executable extensions, such as @file{.com}, @file{.bat}, |
1280 by @code{file-modes} and @code{file-attributes}. | 1301 @file{.exe}, and some others. Files that begin with the Unix-standard |
1302 @samp{#!} signature, such as shell and Perl scripts, are also considered | |
1303 as executable files. This is reflected in the values returned by | |
1304 @code{file-modes} and @code{file-attributes}. Directories are also | |
1305 reported with executable bit set, for compatibility with Unix. | |
1281 | 1306 |
1282 @node File Names | 1307 @node File Names |
1283 @section File Names | 1308 @section File Names |
1284 @cindex file names | 1309 @cindex file names |
1285 | 1310 |
1325 directory. Therefore, Emacs considers a file name as having two main | 1350 directory. Therefore, Emacs considers a file name as having two main |
1326 parts: the @dfn{directory name} part, and the @dfn{nondirectory} part | 1351 parts: the @dfn{directory name} part, and the @dfn{nondirectory} part |
1327 (or @dfn{file name within the directory}). Either part may be empty. | 1352 (or @dfn{file name within the directory}). Either part may be empty. |
1328 Concatenating these two parts reproduces the original file name. | 1353 Concatenating these two parts reproduces the original file name. |
1329 | 1354 |
1330 On Unix, the directory part is everything up to and including the last | 1355 On most systems, the directory part is everything up to and including |
1331 slash; the nondirectory part is the rest. The rules in VMS syntax are | 1356 the last slash; the nondirectory part is the rest. The rules in VMS |
1332 complicated. | 1357 syntax are complicated. |
1333 | 1358 |
1334 For some purposes, the nondirectory part is further subdivided into | 1359 For some purposes, the nondirectory part is further subdivided into |
1335 the name proper and the @dfn{version number}. On Unix, only backup | 1360 the name proper and the @dfn{version number}. On most systems, only |
1336 files have version numbers in their names. On VMS, every file has a | 1361 backup files have version numbers in their names. On VMS, every file |
1337 version number, but most of the time the file name actually used in | 1362 has a version number, but most of the time the file name actually used |
1338 Emacs omits the version number, so that version numbers in Emacs are | 1363 in Emacs omits the version number, so that version numbers in Emacs are |
1339 found mostly in directory lists. | 1364 found mostly in directory lists. |
1340 | 1365 |
1341 @defun file-name-directory filename | 1366 @defun file-name-directory filename |
1342 This function returns the directory part of @var{filename} (or | 1367 This function returns the directory part of @var{filename} (or |
1343 @code{nil} if @var{filename} does not include a directory part). On | 1368 @code{nil} if @var{filename} does not include a directory part). On |
1344 Unix, the function returns a string ending in a slash. On VMS, it | 1369 most systems, the function returns a string ending in a slash. On VMS, |
1345 returns a string ending in one of the three characters @samp{:}, | 1370 it returns a string ending in one of the three characters @samp{:}, |
1346 @samp{]}, or @samp{>}. | 1371 @samp{]}, or @samp{>}. |
1347 | 1372 |
1348 @example | 1373 @example |
1349 @group | 1374 @group |
1350 (file-name-directory "lewis/foo") ; @r{Unix example} | 1375 (file-name-directory "lewis/foo") ; @r{Unix example} |
1427 | 1452 |
1428 A @dfn{directory name} is the name of a directory. A directory is a | 1453 A @dfn{directory name} is the name of a directory. A directory is a |
1429 kind of file, and it has a file name, which is related to the directory | 1454 kind of file, and it has a file name, which is related to the directory |
1430 name but not identical to it. (This is not quite the same as the usual | 1455 name but not identical to it. (This is not quite the same as the usual |
1431 Unix terminology.) These two different names for the same entity are | 1456 Unix terminology.) These two different names for the same entity are |
1432 related by a syntactic transformation. On Unix, this is simple: a | 1457 related by a syntactic transformation. On most systems, this is simple: a |
1433 directory name ends in a slash, whereas the directory's name as a file | 1458 directory name ends in a slash, whereas the directory's name as a file |
1434 lacks that slash. On VMS, the relationship is more complicated. | 1459 lacks that slash. On VMS, the relationship is more complicated. |
1435 | 1460 |
1436 The difference between a directory name and its name as a file is | 1461 The difference between a directory name and its name as a file is |
1437 subtle but crucial. When an Emacs variable or function argument is | 1462 subtle but crucial. When an Emacs variable or function argument is |
1442 names. They do nothing special with environment variable substitutions | 1467 names. They do nothing special with environment variable substitutions |
1443 such as @samp{$HOME}, and the constructs @samp{~}, and @samp{..}. | 1468 such as @samp{$HOME}, and the constructs @samp{~}, and @samp{..}. |
1444 | 1469 |
1445 @defun file-name-as-directory filename | 1470 @defun file-name-as-directory filename |
1446 This function returns a string representing @var{filename} in a form | 1471 This function returns a string representing @var{filename} in a form |
1447 that the operating system will interpret as the name of a directory. In | 1472 that the operating system will interpret as the name of a directory. On |
1448 Unix, this means appending a slash to the string (if it does not already | 1473 most systems, this means appending a slash to the string (if it does not |
1449 end in one). On VMS, the function converts a string of the form | 1474 already end in one). On VMS, the function converts a string of the form |
1450 @file{[X]Y.DIR.1} to the form @file{[X.Y]}. | 1475 @file{[X]Y.DIR.1} to the form @file{[X.Y]}. |
1451 | 1476 |
1452 @example | 1477 @example |
1453 @group | 1478 @group |
1454 (file-name-as-directory "~rms/lewis") | 1479 (file-name-as-directory "~rms/lewis") |
1457 @end example | 1482 @end example |
1458 @end defun | 1483 @end defun |
1459 | 1484 |
1460 @defun directory-file-name dirname | 1485 @defun directory-file-name dirname |
1461 This function returns a string representing @var{dirname} in a form that | 1486 This function returns a string representing @var{dirname} in a form that |
1462 the operating system will interpret as the name of a file. On Unix, | 1487 the operating system will interpret as the name of a file. On most |
1463 this means removing the final slash from the string. On VMS, the | 1488 systems, this means removing the final slash from the string. On VMS, |
1464 function converts a string of the form @file{[X.Y]} to | 1489 the function converts a string of the form @file{[X.Y]} to |
1465 @file{[X]Y.DIR.1}. | 1490 @file{[X]Y.DIR.1}. |
1466 | 1491 |
1467 @example | 1492 @example |
1468 @group | 1493 @group |
1469 (directory-file-name "~lewis/") | 1494 (directory-file-name "~lewis/") |
1520 root directory. A file name can specify all the directory names | 1545 root directory. A file name can specify all the directory names |
1521 starting from the root of the tree; then it is called an @dfn{absolute} | 1546 starting from the root of the tree; then it is called an @dfn{absolute} |
1522 file name. Or it can specify the position of the file in the tree | 1547 file name. Or it can specify the position of the file in the tree |
1523 relative to a default directory; then it is called a @dfn{relative} | 1548 relative to a default directory; then it is called a @dfn{relative} |
1524 file name. On Unix, an absolute file name starts with a slash or a | 1549 file name. On Unix, an absolute file name starts with a slash or a |
1525 tilde (@samp{~}), and a relative one does not. The rules on VMS are | 1550 tilde (@samp{~}), and a relative one does not. On MS-DOS and |
1526 complicated. | 1551 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 | |
1553 @dfn{drive letter}. The rules on VMS are complicated. | |
1527 | 1554 |
1528 @defun file-name-absolute-p filename | 1555 @defun file-name-absolute-p filename |
1529 This function returns @code{t} if file @var{filename} is an absolute | 1556 This function returns @code{t} if file @var{filename} is an absolute |
1530 file name, @code{nil} otherwise. On VMS, this function understands both | 1557 file name, @code{nil} otherwise. On VMS, this function understands both |
1531 Unix syntax and VMS syntax. | 1558 Unix syntax and VMS syntax. |
1623 with @samp{~}. This variable is buffer-local in every buffer. | 1650 with @samp{~}. This variable is buffer-local in every buffer. |
1624 | 1651 |
1625 @code{expand-file-name} uses the default directory when its second | 1652 @code{expand-file-name} uses the default directory when its second |
1626 argument is @code{nil}. | 1653 argument is @code{nil}. |
1627 | 1654 |
1628 On Unix systems, the value is always a string ending with a slash. | 1655 Aside from VMS, the value is always a string ending with a slash. |
1629 | 1656 |
1630 @example | 1657 @example |
1631 @group | 1658 @group |
1632 default-directory | 1659 default-directory |
1633 @result{} "/user/lewis/manual/" | 1660 @result{} "/user/lewis/manual/" |
1678 | 1705 |
1679 @node Unique File Names | 1706 @node Unique File Names |
1680 @subsection Generating Unique File Names | 1707 @subsection Generating Unique File Names |
1681 | 1708 |
1682 Some programs need to write temporary files. Here is the usual way to | 1709 Some programs need to write temporary files. Here is the usual way to |
1683 construct a name for such a file: | 1710 construct a name for such a file, starting in Emacs 21: |
1711 | |
1712 @example | |
1713 (make-temp-file @var{name-of-application}) | |
1714 @end example | |
1715 | |
1716 @noindent | |
1717 The job of @code{make-temp-file} is to prevent two different users or | |
1718 two different jobs from trying to use the exact same file name. | |
1719 | |
1720 @defun make-temp-file prefix &optional dir-flag | |
1721 @tindex make-temp-file | |
1722 This function creates a temporary file and returns its name. | |
1723 The name starts with @var{prefix}; it also contains a number that is | |
1724 different in each Emacs job. If @var{prefix} is a relative file name, | |
1725 it is expanded against @code{temporary-file-directory}. | |
1726 | |
1727 @example | |
1728 @group | |
1729 (make-temp-file "foo") | |
1730 @result{} "/tmp/foo232J6v" | |
1731 @end group | |
1732 @end example | |
1733 | |
1734 When @code{make-temp-file} returns, the file has been created and is | |
1735 empty. At that point, you should write the intended contents into the | |
1736 file. | |
1737 | |
1738 If @var{dir-flag} is non-@code{nil}, @code{make-temp-file} creates | |
1739 an empty directory instead of an empty file. | |
1740 | |
1741 To prevent conflicts among different libraries running in the same | |
1742 Emacs, each Lisp program that uses @code{make-temp-file} should have its | |
1743 own @var{prefix}. The number added to the end of @var{prefix} | |
1744 distinguishes between the same application running in different Emacs | |
1745 jobs. Additional added characters permit a large number of distinct | |
1746 names even in one Emacs job. | |
1747 @end defun | |
1748 | |
1749 The default directory for temporary files is controlled by the | |
1750 variable @code{temporary-file-directory}. This variable gives the user | |
1751 a uniform way to specify the directory for all temporary files. Some | |
1752 programs use @code{small-temporary-file-directory} instead, if that is | |
1753 non-@code{nil}. To use it, you should expand the prefix against | |
1754 the proper directory before calling @code{make-temp-file}. | |
1755 | |
1756 In older Emacs versions where @code{make-temp-file} does not exist, | |
1757 you should use @code{make-temp-name} instead: | |
1684 | 1758 |
1685 @example | 1759 @example |
1686 (make-temp-name | 1760 (make-temp-name |
1687 (expand-file-name @var{name-of-application} | 1761 (expand-file-name @var{name-of-application} |
1688 temporary-file-directory)) | 1762 temporary-file-directory)) |
1689 @end example | 1763 @end example |
1690 | 1764 |
1691 @noindent | |
1692 The job of @code{make-temp-name} is to prevent two different users or | |
1693 two different jobs from trying to use the exact same file name. This | |
1694 example uses the variable @code{temporary-file-directory} to decide | |
1695 where to put the temporary file. All Emacs Lisp programs should | |
1696 use @code{temporary-file-directory} for this purpose, to give the user | |
1697 a uniform way to specify the directory for all temporary files. | |
1698 | |
1699 @defun make-temp-name string | 1765 @defun make-temp-name string |
1700 This function generates a string that can be used as a unique file name. | 1766 This function generates a string that can be used as a unique file name. |
1701 The name starts with @var{string}, and contains a number that is | 1767 The name starts with @var{string}, and contains a number that is |
1702 different in each Emacs job. | 1768 different in each Emacs job. It is like @code{make-temp-file} except |
1703 | 1769 that it just constructs a name, and does not create a file. On MS-DOS, |
1704 @example | 1770 the @var{string} prefix can be truncated to fit into the 8+3 file-name |
1705 @group | 1771 limits. |
1706 (make-temp-name "/tmp/foo") | |
1707 @result{} "/tmp/foo232J6v" | |
1708 @end group | |
1709 @end example | |
1710 | |
1711 To prevent conflicts among different libraries running in the same | |
1712 Emacs, each Lisp program that uses @code{make-temp-name} should have its | |
1713 own @var{string}. The number added to the end of @var{string} | |
1714 distinguishes between the same application running in different Emacs | |
1715 jobs. Additional added characters permit a large number of distinct | |
1716 names even in one Emacs job. | |
1717 @end defun | 1772 @end defun |
1718 | 1773 |
1719 @defvar temporary-file-directory | 1774 @defvar temporary-file-directory |
1720 @cindex @code{TMPDIR} environment variable. | 1775 @cindex @code{TMPDIR} environment variable |
1721 @cindex @code{TMP} environment variable. | 1776 @cindex @code{TMP} environment variable |
1777 @cindex @code{TEMP} environment variable | |
1722 This variable specifies the directory name for creating temporary files. | 1778 This variable specifies the directory name for creating temporary files. |
1723 Its value should be a directory name (@pxref{Directory Names}), but it | 1779 Its value should be a directory name (@pxref{Directory Names}), but it |
1724 is good for Lisp programs to cope if the value is a directory's file | 1780 is good for Lisp programs to cope if the value is a directory's file |
1725 name instead. Using the value as the second argument to | 1781 name instead. Using the value as the second argument to |
1726 @code{expand-file-name} is a good way to achieve that. | 1782 @code{expand-file-name} is a good way to achieve that. |
1727 | 1783 |
1728 The default value is determined in a reasonable way for your operating | 1784 The default value is determined in a reasonable way for your operating |
1729 system; on GNU and Unix systems it is based on the @code{TMP} and | 1785 system; it is based on the @code{TMPDIR}, @code{TMP} and @code{TEMP} |
1730 @code{TMPDIR} environment variables. | 1786 environment variables, with a fall-back to a system-dependent name if |
1787 none of these variables is defined. | |
1731 | 1788 |
1732 Even if you do not use @code{make-temp-name} to choose the temporary | 1789 Even if you do not use @code{make-temp-name} to choose the temporary |
1733 file's name, you should still use this variable to decide which | 1790 file's name, you should still use this variable to decide which |
1734 directory to put the file in. | 1791 directory to put the file in. However, if you expect the file to be |
1792 small, you should use @code{small-temporary-file-directory} first if | |
1793 that is non-@code{nil}. | |
1794 @end defvar | |
1795 | |
1796 @tindex small-temporary-file-directory | |
1797 @defvar small-temporary-file-directory | |
1798 This variable (new in Emacs 21) specifies the directory name for | |
1799 creating certain temporary files, which are likely to be small. | |
1800 | |
1801 If you want to write a temporary file which is likely to be small, you | |
1802 should compute the directory like this: | |
1803 | |
1804 @example | |
1805 (make-temp-file | |
1806 (expand-file-name @var{prefix} | |
1807 (or small-temporary-file-directory | |
1808 temporary-file-directory))) | |
1809 @end example | |
1735 @end defvar | 1810 @end defvar |
1736 | 1811 |
1737 @node File Name Completion | 1812 @node File Name Completion |
1738 @subsection File Name Completion | 1813 @subsection File Name Completion |
1739 @cindex file name completion subroutines | 1814 @cindex file name completion subroutines |
1951 should specify @code{t} when @var{file} is a directory and switches do | 2026 should specify @code{t} when @var{file} is a directory and switches do |
1952 not contain @samp{-d}. (The @samp{-d} option to @code{ls} says to | 2027 not contain @samp{-d}. (The @samp{-d} option to @code{ls} says to |
1953 describe a directory itself as a file, rather than showing its | 2028 describe a directory itself as a file, rather than showing its |
1954 contents.) | 2029 contents.) |
1955 | 2030 |
1956 This function works by running a directory listing program whose name is | 2031 On most systems, this function works by running a directory listing |
1957 in the variable @code{insert-directory-program}. If @var{wildcard} is | 2032 program whose name is in the variable @code{insert-directory-program}. |
1958 non-@code{nil}, it also runs the shell specified by | 2033 If @var{wildcard} is non-@code{nil}, it also runs the shell specified by |
1959 @code{shell-file-name}, to expand the wildcards. | 2034 @code{shell-file-name}, to expand the wildcards. |
2035 | |
2036 MS-DOS and MS-Windows systems usually lack the standard Unix program | |
2037 @code{ls}, so this function emulates the standard Unix program @code{ls} | |
2038 with Lisp code. | |
1960 @end defun | 2039 @end defun |
1961 | 2040 |
1962 @defvar insert-directory-program | 2041 @defvar insert-directory-program |
1963 This variable's value is the program to run to generate a directory listing | 2042 This variable's value is the program to run to generate a directory listing |
1964 for the function @code{insert-directory}. | 2043 for the function @code{insert-directory}. It is ignored on systems |
2044 which generate the listing with Lisp code. | |
1965 @end defvar | 2045 @end defvar |
1966 | 2046 |
1967 @node Create/Delete Dirs | 2047 @node Create/Delete Dirs |
1968 @section Creating and Deleting Directories | 2048 @section Creating and Deleting Directories |
1969 @c Emacs 19 features | 2049 @c Emacs 19 features |
2068 @code{verify-visited-file-modtime},@* | 2148 @code{verify-visited-file-modtime},@* |
2069 @code{write-region}. | 2149 @code{write-region}. |
2070 @end ifinfo | 2150 @end ifinfo |
2071 @iftex | 2151 @iftex |
2072 @noindent | 2152 @noindent |
2153 @flushleft | |
2073 @code{add-name-to-file}, @code{copy-file}, @code{delete-directory}, | 2154 @code{add-name-to-file}, @code{copy-file}, @code{delete-directory}, |
2074 @code{delete-file}, | 2155 @code{delete-file}, |
2075 @code{diff-latest-backup-file}, | 2156 @code{diff-latest-backup-file}, |
2076 @code{directory-file-name}, | 2157 @code{directory-file-name}, |
2077 @code{directory-files}, | 2158 @code{directory-files}, |
2101 @code{set-visited-file-modtime}, @code{shell-command}, | 2182 @code{set-visited-file-modtime}, @code{shell-command}, |
2102 @code{unhandled-file-name-directory}, | 2183 @code{unhandled-file-name-directory}, |
2103 @code{vc-regis@discretionary{}{}{}tered}, | 2184 @code{vc-regis@discretionary{}{}{}tered}, |
2104 @code{verify-visited-file-modtime}, | 2185 @code{verify-visited-file-modtime}, |
2105 @code{write-region}. | 2186 @code{write-region}. |
2187 @end flushleft | |
2106 @end iftex | 2188 @end iftex |
2107 | 2189 |
2108 Handlers for @code{insert-file-contents} typically need to clear the | 2190 Handlers for @code{insert-file-contents} typically need to clear the |
2109 buffer's modified flag, with @code{(set-buffer-modified-p nil)}, if the | 2191 buffer's modified flag, with @code{(set-buffer-modified-p nil)}, if the |
2110 @var{visit} argument is non-@code{nil}. This also has the effect of | 2192 @var{visit} argument is non-@code{nil}. This also has the effect of |