Mercurial > hg > xemacs-beta
comparison man/lispref/files.texi @ 444:576fb035e263 r21-2-37
Import from CVS: tag r21-2-37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:36:19 +0200 |
parents | 3ecd8885ac67 |
children | 9fae6227ede5 |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
1 @c -*-texinfo-*- | 1 @c -*-texinfo-*- |
2 @c This is part of the XEmacs Lisp Reference Manual. | 2 @c This is part of the XEmacs Lisp Reference Manual. |
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
4 @c See the file lispref.texi for copying conditions. | 4 @c See the file lispref.texi for copying conditions. |
5 @setfilename ../../info/files.info | 5 @setfilename ../../info/files.info |
6 @node Files, Backups and Auto-Saving, Documentation, Top | 6 @node Files, Backups and Auto-Saving, Documentation, Top |
7 @chapter Files | 7 @chapter Files |
8 | 8 |
84 temporary buffer. Visiting the file is not necessary and takes longer. | 84 temporary buffer. Visiting the file is not necessary and takes longer. |
85 @xref{Reading from Files}. | 85 @xref{Reading from Files}. |
86 | 86 |
87 @deffn Command find-file filename | 87 @deffn Command find-file filename |
88 This command selects a buffer visiting the file @var{filename}, | 88 This command selects a buffer visiting the file @var{filename}, |
89 using an existing buffer if there is one, and otherwise creating a | 89 using an existing buffer if there is one, and otherwise creating a |
90 new buffer and reading the file into it. It also returns that buffer. | 90 new buffer and reading the file into it. It also returns that buffer. |
91 | 91 |
92 The body of the @code{find-file} function is very simple and looks | 92 The body of the @code{find-file} function is very simple and looks |
93 like this: | 93 like this: |
94 | 94 |
119 If @code{find-file-noselect} needs to create a buffer, and there is no | 119 If @code{find-file-noselect} needs to create a buffer, and there is no |
120 file named @var{filename}, it displays the message @samp{New file} in | 120 file named @var{filename}, it displays the message @samp{New file} in |
121 the echo area, and leaves the buffer empty. | 121 the echo area, and leaves the buffer empty. |
122 | 122 |
123 @c XEmacs feature | 123 @c XEmacs feature |
124 If @var{no-warn} is non-@code{nil}, various warnings that XEmacs normally | 124 If @var{nowarn} is non-@code{nil}, various warnings that XEmacs normally |
125 gives (e.g. if another buffer is already visiting @var{filename} but | 125 gives (e.g. if another buffer is already visiting @var{filename} but |
126 @var{filename} has been removed from disk since that buffer was created) | 126 @var{filename} has been removed from disk since that buffer was created) |
127 are suppressed. | 127 are suppressed. |
128 | 128 |
129 The @code{find-file-noselect} function calls @code{after-find-file} | 129 The @code{find-file-noselect} function calls @code{after-find-file} |
159 | 159 |
160 When this command is called interactively, it prompts for | 160 When this command is called interactively, it prompts for |
161 @var{filename}. | 161 @var{filename}. |
162 @end deffn | 162 @end deffn |
163 | 163 |
164 @deffn Command view-file filename | 164 @deffn Command view-file filename &optional other-window-p |
165 This command visits @var{filename} in View mode, and displays it in a | 165 This command visits @var{filename} in View mode, and displays it in a |
166 recursive edit, returning to the previous buffer when done. View mode | 166 recursive edit, returning to the previous buffer when done. View mode |
167 is a mode that allows you to skim rapidly through the file but does not | 167 is a mode that allows you to skim rapidly through the file but does not |
168 let you modify it. Entering View mode runs the normal hook | 168 let you modify it. Entering View mode runs the normal hook |
169 @code{view-mode-hook}. @xref{Hooks}. | 169 @code{view-mode-hook}. @xref{Hooks}. |
170 | 170 |
171 When @code{view-file} is called interactively, it prompts for | 171 When @code{view-file} is called interactively, it prompts for |
172 @var{filename}. | 172 @var{filename}. |
173 | |
174 With non-@code{nil} prefix arg @var{other-window-p}, visit @var{filename} | |
175 in another window. | |
173 @end deffn | 176 @end deffn |
174 | 177 |
175 @defvar find-file-hooks | 178 @defvar find-file-hooks |
176 The value of this variable is a list of functions to be called after a | 179 The value of this variable is a list of functions to be called after a |
177 file is visited. The file's local-variables specification (if any) will | 180 file is visited. The file's local-variables specification (if any) will |
401 | 404 |
402 You can copy a file from the disk and insert it into a buffer | 405 You can copy a file from the disk and insert it into a buffer |
403 using the @code{insert-file-contents} function. Don't use the user-level | 406 using the @code{insert-file-contents} function. Don't use the user-level |
404 command @code{insert-file} in a Lisp program, as that sets the mark. | 407 command @code{insert-file} in a Lisp program, as that sets the mark. |
405 | 408 |
406 @defun insert-file-contents filename &optional visit beg end replace | 409 @defun insert-file-contents filename &optional visit start end replace |
407 This function inserts the contents of file @var{filename} into the | 410 This function inserts the contents of file @var{filename} into the |
408 current buffer after point. It returns a list of the absolute file name | 411 current buffer after point. It returns a list of the absolute file name |
409 and the length of the data inserted. An error is signaled if | 412 and the length of the data inserted. An error is signaled if |
410 @var{filename} is not the name of a file that can be read. | 413 @var{filename} is not the name of a file that can be read. |
411 | 414 |
419 buffer as unmodified and sets up various fields in the buffer so that it | 422 buffer as unmodified and sets up various fields in the buffer so that it |
420 is visiting the file @var{filename}: these include the buffer's visited | 423 is visiting the file @var{filename}: these include the buffer's visited |
421 file name and its last save file modtime. This feature is used by | 424 file name and its last save file modtime. This feature is used by |
422 @code{find-file-noselect} and you probably should not use it yourself. | 425 @code{find-file-noselect} and you probably should not use it yourself. |
423 | 426 |
424 If @var{beg} and @var{end} are non-@code{nil}, they should be integers | 427 If @var{start} and @var{end} are non-@code{nil}, they should be integers |
425 specifying the portion of the file to insert. In this case, @var{visit} | 428 specifying the portion of the file to insert. In this case, @var{visit} |
426 must be @code{nil}. For example, | 429 must be @code{nil}. For example, |
427 | 430 |
428 @example | 431 @example |
429 (insert-file-contents filename nil 0 500) | 432 (insert-file-contents filename nil 0 500) |
546 if the buffer is modified. If the buffer is not modified, then | 549 if the buffer is modified. If the buffer is not modified, then |
547 the file should not be locked, so this function does nothing. It also | 550 the file should not be locked, so this function does nothing. It also |
548 does nothing if the current buffer is not visiting a file. | 551 does nothing if the current buffer is not visiting a file. |
549 @end defun | 552 @end defun |
550 | 553 |
551 @defun ask-user-about-lock file other-user | 554 @defun ask-user-about-lock filename other-user |
552 This function is called when the user tries to modify @var{file}, but it | 555 This function is called when the user tries to modify @var{filename}, |
553 is locked by another user named @var{other-user}. The value it returns | 556 but it is locked by another user named @var{other-user}. The value it |
554 determines what happens next: | 557 returns determines what happens next: |
555 | 558 |
556 @itemize @bullet | 559 @itemize @bullet |
557 @item | 560 @item |
558 A value of @code{t} says to grab the lock on the file. Then | 561 A value of @code{t} says to grab the lock on the file. Then |
559 this user may edit the file and @var{other-user} loses the lock. | 562 this user may edit the file and @var{other-user} loses the lock. |
568 case the change that the user was about to make does not take place. | 571 case the change that the user was about to make does not take place. |
569 | 572 |
570 The error message for this error looks like this: | 573 The error message for this error looks like this: |
571 | 574 |
572 @example | 575 @example |
573 @error{} File is locked: @var{file} @var{other-user} | 576 @error{} File is locked: @var{filename} @var{other-user} |
574 @end example | 577 @end example |
575 | 578 |
576 @noindent | 579 @noindent |
577 where @code{file} is the name of the file and @var{other-user} is the | 580 where @var{filename} is the name of the file and @var{other-user} is the |
578 name of the user who has locked the file. | 581 name of the user who has locked the file. |
579 @end itemize | 582 @end itemize |
580 | 583 |
581 The default definition of this function asks the user to choose what | 584 The default definition of this function asks the user to choose what |
582 to do. If you wish, you can replace the @code{ask-user-about-lock} | 585 to do. If you wish, you can replace the @code{ask-user-about-lock} |
747 function returns the file name to which it is linked. This may be the | 750 function returns the file name to which it is linked. This may be the |
748 name of a text file, a directory, or even another symbolic link, or it | 751 name of a text file, a directory, or even another symbolic link, or it |
749 may be a nonexistent file name. | 752 may be a nonexistent file name. |
750 | 753 |
751 If the file @var{filename} is not a symbolic link (or there is no such file), | 754 If the file @var{filename} is not a symbolic link (or there is no such file), |
752 @code{file-symlink-p} returns @code{nil}. | 755 @code{file-symlink-p} returns @code{nil}. |
753 | 756 |
754 @example | 757 @example |
755 @group | 758 @group |
756 (file-symlink-p "foo") | 759 (file-symlink-p "foo") |
757 @result{} nil | 760 @result{} nil |
966 For example, here are the file attributes for @file{files.texi}: | 969 For example, here are the file attributes for @file{files.texi}: |
967 | 970 |
968 @example | 971 @example |
969 @group | 972 @group |
970 (file-attributes "files.texi") | 973 (file-attributes "files.texi") |
971 @result{} (nil | 974 @result{} (nil |
972 1 | 975 1 |
973 2235 | 976 2235 |
974 75 | 977 75 |
975 (8489 20284) | 978 (8489 20284) |
976 (8489 20284) | 979 (8489 20284) |
977 (8489 20285) | 980 (8489 20285) |
978 14906 | 981 14906 |
979 "-rw-rw-rw-" | 982 "-rw-rw-rw-" |
980 nil | 983 nil |
981 129500 | 984 129500 |
982 -32252) | 985 -32252) |
983 @end group | 986 @end group |
984 @end example | 987 @end example |
985 | 988 |
1035 @cindex setting modes of files | 1038 @cindex setting modes of files |
1036 | 1039 |
1037 The functions in this section rename, copy, delete, link, and set the | 1040 The functions in this section rename, copy, delete, link, and set the |
1038 modes of files. | 1041 modes of files. |
1039 | 1042 |
1040 In the functions that have an argument @var{newname}, if a file by the | 1043 In the functions that have arguments @var{newname} and |
1041 name of @var{newname} already exists, the actions taken depend on the | 1044 @var{ok-if-already-exists}, if a file by the name of @var{newname} |
1042 value of the argument @var{ok-if-already-exists}: | 1045 already exists, the actions taken depend on the value of |
1046 @var{ok-if-already-exists}: | |
1043 | 1047 |
1044 @itemize @bullet | 1048 @itemize @bullet |
1045 @item | 1049 @item |
1046 Signal a @code{file-already-exists} error if | 1050 Signal a @code{file-already-exists} error if |
1047 @var{ok-if-already-exists} is @code{nil}. | 1051 @var{ok-if-already-exists} is @code{nil}. |
1048 | 1052 |
1049 @item | 1053 @item |
1050 Request confirmation if @var{ok-if-already-exists} is a number. | 1054 Request confirmation if @var{ok-if-already-exists} is a number. This is |
1055 what happens when the function is invoked interactively. | |
1051 | 1056 |
1052 @item | 1057 @item |
1053 Replace the old file without confirmation if @var{ok-if-already-exists} | 1058 Replace the old file without confirmation if @var{ok-if-already-exists} |
1054 is any other value. | 1059 is any other value. |
1055 @end itemize | 1060 @end itemize |
1056 | 1061 |
1057 @deffn Command add-name-to-file oldname newname &optional ok-if-already-exists | 1062 @deffn Command add-name-to-file filename newname &optional ok-if-already-exists |
1058 @cindex file with multiple names | 1063 @cindex file with multiple names |
1059 @cindex file hard link | 1064 @cindex file hard link |
1060 This function gives the file named @var{oldname} the additional name | 1065 This function gives the file named @var{filename} the additional name |
1061 @var{newname}. This means that @var{newname} becomes a new ``hard | 1066 @var{newname}. This means that @var{newname} becomes a new ``hard |
1062 link'' to @var{oldname}. | 1067 link'' to @var{filename}. Both these arguments must be strings. |
1063 | 1068 |
1064 In the first part of the following example, we list two files, | 1069 In the first part of the following example, we list two files, |
1065 @file{foo} and @file{foo3}. | 1070 @file{foo} and @file{foo3}. |
1066 | 1071 |
1067 @example | 1072 @example |
1114 -rw-rw-rw- 3 rms 29 Aug 18 20:32 foo2 | 1119 -rw-rw-rw- 3 rms 29 Aug 18 20:32 foo2 |
1115 -rw-rw-rw- 3 rms 29 Aug 18 20:32 foo3 | 1120 -rw-rw-rw- 3 rms 29 Aug 18 20:32 foo3 |
1116 @end group | 1121 @end group |
1117 @end example | 1122 @end example |
1118 | 1123 |
1119 This function is meaningless on VMS, where multiple names for one file | 1124 This function is meaningless on non-Unix systems, where multiple names |
1120 are not allowed. | 1125 for one file are not allowed. |
1121 | 1126 |
1122 See also @code{file-nlinks} in @ref{File Attributes}. | 1127 See also @code{file-nlinks} in @ref{File Attributes}. |
1123 @end deffn | 1128 @end deffn |
1124 | 1129 |
1125 @deffn Command rename-file filename newname &optional ok-if-already-exists | 1130 @deffn Command rename-file filename newname &optional ok-if-already-exists |
1133 In an interactive call, this function prompts for @var{filename} and | 1138 In an interactive call, this function prompts for @var{filename} and |
1134 @var{newname} in the minibuffer; also, it requests confirmation if | 1139 @var{newname} in the minibuffer; also, it requests confirmation if |
1135 @var{newname} already exists. | 1140 @var{newname} already exists. |
1136 @end deffn | 1141 @end deffn |
1137 | 1142 |
1138 @deffn Command copy-file oldname newname &optional ok-if-exists time | 1143 @deffn Command copy-file filename newname &optional ok-if-already-exists time |
1139 This command copies the file @var{oldname} to @var{newname}. An | 1144 This command copies the file @var{filename} to @var{newname}. An |
1140 error is signaled if @var{oldname} does not exist. | 1145 error is signaled if @var{filename} does not exist. |
1141 | 1146 |
1142 If @var{time} is non-@code{nil}, then this functions gives the new | 1147 If @var{time} is non-@code{nil}, then this functions gives the new |
1143 file the same last-modified time that the old one has. (This works on | 1148 file the same last-modified time that the old one has. (This works on |
1144 only some operating systems.) | 1149 only some operating systems.) |
1145 | 1150 |
1159 its directory is writable.) | 1164 its directory is writable.) |
1160 | 1165 |
1161 See also @code{delete-directory} in @ref{Create/Delete Dirs}. | 1166 See also @code{delete-directory} in @ref{Create/Delete Dirs}. |
1162 @end deffn | 1167 @end deffn |
1163 | 1168 |
1164 @deffn Command make-symbolic-link filename newname &optional ok-if-exists | 1169 @deffn Command make-symbolic-link filename newname &optional ok-if-already-exists |
1165 @pindex ln | 1170 @pindex ln |
1166 @kindex file-already-exists | 1171 @kindex file-already-exists |
1167 This command makes a symbolic link to @var{filename}, named | 1172 This command makes a symbolic link to @var{filename}, named |
1168 @var{newname}. This is like the shell command @samp{ln -s | 1173 @var{newname}. This is like the shell command @samp{ln -s |
1169 @var{filename} @var{newname}}. | 1174 @var{filename} @var{newname}}. |
1170 | 1175 |
1171 In an interactive call, this function prompts for @var{filename} and | 1176 In an interactive call, this function prompts for @var{filename} and |
1172 @var{newname} in the minibuffer; also, it requests confirmation if | 1177 @var{newname} in the minibuffer; also, it requests confirmation if |
1173 @var{newname} already exists. | 1178 @var{newname} already exists. |
1174 @end deffn | 1179 @end deffn |
1175 | |
1176 @defun define-logical-name varname string | |
1177 This function defines the logical name @var{name} to have the value | |
1178 @var{string}. It is available only on VMS. | |
1179 @end defun | |
1180 | 1180 |
1181 @defun set-file-modes filename mode | 1181 @defun set-file-modes filename mode |
1182 This function sets mode bits of @var{filename} to @var{mode} (which must | 1182 This function sets mode bits of @var{filename} to @var{mode} (which must |
1183 be an integer). Only the low 12 bits of @var{mode} are used. | 1183 be an integer). Only the low 12 bits of @var{mode} are used. |
1184 @end defun | 1184 @end defun |
1224 | 1224 |
1225 The functions in this section do not actually access files, so they | 1225 The functions in this section do not actually access files, so they |
1226 can operate on file names that do not refer to an existing file or | 1226 can operate on file names that do not refer to an existing file or |
1227 directory. | 1227 directory. |
1228 | 1228 |
1229 On VMS, all these functions understand both VMS file-name syntax and | 1229 On MS-DOS, these functions understand MS-DOS file-name syntax as well as |
1230 Unix syntax. This is so that all the standard Lisp libraries can | 1230 Unix syntax. This is so that all the standard Lisp libraries can specify |
1231 specify file names in Unix syntax and work properly on VMS without | 1231 file names in Unix syntax and work properly on all systems without |
1232 change. On MS-DOS, these functions understand MS-DOS file-name syntax | 1232 change. Similarly for other operating systems. |
1233 as well as Unix syntax. | |
1234 | 1233 |
1235 @menu | 1234 @menu |
1236 * File Name Components:: The directory part of a file name, and the rest. | 1235 * File Name Components:: The directory part of a file name, and the rest. |
1237 * Directory Names:: A directory's name as a directory | 1236 * Directory Names:: A directory's name as a directory |
1238 is different from its name as a file. | 1237 is different from its name as a file. |
1255 parts: the @dfn{directory name} part, and the @dfn{nondirectory} part | 1254 parts: the @dfn{directory name} part, and the @dfn{nondirectory} part |
1256 (or @dfn{file name within the directory}). Either part may be empty. | 1255 (or @dfn{file name within the directory}). Either part may be empty. |
1257 Concatenating these two parts reproduces the original file name. | 1256 Concatenating these two parts reproduces the original file name. |
1258 | 1257 |
1259 On Unix, the directory part is everything up to and including the last | 1258 On Unix, the directory part is everything up to and including the last |
1260 slash; the nondirectory part is the rest. The rules in VMS syntax are | 1259 slash; the nondirectory part is the rest. |
1261 complicated. | |
1262 | 1260 |
1263 For some purposes, the nondirectory part is further subdivided into | 1261 For some purposes, the nondirectory part is further subdivided into |
1264 the name proper and the @dfn{version number}. On Unix, only backup | 1262 the name proper and the @dfn{version number}. On Unix, only backup |
1265 files have version numbers in their names; on VMS, every file has a | 1263 files have version numbers in their names. |
1266 version number, but most of the time the file name actually used in | |
1267 XEmacs omits the version number. Version numbers are found mostly in | |
1268 directory lists. | |
1269 | 1264 |
1270 @defun file-name-directory filename | 1265 @defun file-name-directory filename |
1271 This function returns the directory part of @var{filename} (or | 1266 This function returns the directory part of @var{filename} (or |
1272 @code{nil} if @var{filename} does not include a directory part). On | 1267 @code{nil} if @var{filename} does not include a directory part). On |
1273 Unix, the function returns a string ending in a slash. On VMS, it | 1268 Unix, the function returns a string ending in a slash. |
1274 returns a string ending in one of the three characters @samp{:}, | |
1275 @samp{]}, or @samp{>}. | |
1276 | 1269 |
1277 @example | 1270 @example |
1278 @group | 1271 @group |
1279 (file-name-directory "lewis/foo") ; @r{Unix example} | 1272 (file-name-directory "lewis/foo") ; @r{Unix example} |
1280 @result{} "lewis/" | 1273 @result{} "lewis/" |
1281 @end group | 1274 @end group |
1282 @group | 1275 @group |
1283 (file-name-directory "foo") ; @r{Unix example} | 1276 (file-name-directory "foo") ; @r{Unix example} |
1284 @result{} nil | 1277 @result{} nil |
1285 @end group | 1278 @end group |
1286 @group | |
1287 (file-name-directory "[X]FOO.TMP") ; @r{VMS example} | |
1288 @result{} "[X]" | |
1289 @end group | |
1290 @end example | 1279 @end example |
1291 @end defun | 1280 @end defun |
1292 | 1281 |
1293 @defun file-name-nondirectory filename | 1282 @defun file-name-nondirectory filename |
1294 This function returns the nondirectory part of @var{filename}. | 1283 This function returns the nondirectory part of @var{filename}. |
1299 @result{} "foo" | 1288 @result{} "foo" |
1300 @end group | 1289 @end group |
1301 @group | 1290 @group |
1302 (file-name-nondirectory "foo") | 1291 (file-name-nondirectory "foo") |
1303 @result{} "foo" | 1292 @result{} "foo" |
1304 @end group | |
1305 @group | |
1306 ;; @r{The following example is accurate only on VMS.} | |
1307 (file-name-nondirectory "[X]FOO.TMP") | |
1308 @result{} "FOO.TMP" | |
1309 @end group | 1293 @end group |
1310 @end example | 1294 @end example |
1311 @end defun | 1295 @end defun |
1312 | 1296 |
1313 @defun file-name-sans-versions filename &optional keep-backup-version | 1297 @defun file-name-sans-versions filename &optional keep-backup-version |
1328 @result{} "~rms/foo" | 1312 @result{} "~rms/foo" |
1329 @end group | 1313 @end group |
1330 @group | 1314 @group |
1331 (file-name-sans-versions "~rms/foo") | 1315 (file-name-sans-versions "~rms/foo") |
1332 @result{} "~rms/foo" | 1316 @result{} "~rms/foo" |
1333 @end group | |
1334 @group | |
1335 ;; @r{The following example applies to VMS only.} | |
1336 (file-name-sans-versions "foo;23") | |
1337 @result{} "foo" | |
1338 @end group | 1317 @end group |
1339 @end example | 1318 @end example |
1340 @end defun | 1319 @end defun |
1341 | 1320 |
1342 @defun file-name-sans-extension filename | 1321 @defun file-name-sans-extension filename |
1361 kind of file, and it has a file name, which is related to the directory | 1340 kind of file, and it has a file name, which is related to the directory |
1362 name but not identical to it. (This is not quite the same as the usual | 1341 name but not identical to it. (This is not quite the same as the usual |
1363 Unix terminology.) These two different names for the same entity are | 1342 Unix terminology.) These two different names for the same entity are |
1364 related by a syntactic transformation. On Unix, this is simple: a | 1343 related by a syntactic transformation. On Unix, this is simple: a |
1365 directory name ends in a slash, whereas the directory's name as a file | 1344 directory name ends in a slash, whereas the directory's name as a file |
1366 lacks that slash. On VMS, the relationship is more complicated. | 1345 lacks that slash. |
1367 | 1346 |
1368 The difference between a directory name and its name as a file is | 1347 The difference between a directory name and its name as a file is |
1369 subtle but crucial. When an XEmacs variable or function argument is | 1348 subtle but crucial. When an XEmacs variable or function argument is |
1370 described as being a directory name, a file name of a directory is not | 1349 described as being a directory name, a file name of a directory is not |
1371 acceptable. | 1350 acceptable. |
1375 such as @samp{$HOME}, and the constructs @samp{~}, and @samp{..}. | 1354 such as @samp{$HOME}, and the constructs @samp{~}, and @samp{..}. |
1376 | 1355 |
1377 @defun file-name-as-directory filename | 1356 @defun file-name-as-directory filename |
1378 This function returns a string representing @var{filename} in a form | 1357 This function returns a string representing @var{filename} in a form |
1379 that the operating system will interpret as the name of a directory. In | 1358 that the operating system will interpret as the name of a directory. In |
1380 Unix, this means appending a slash to the string. On VMS, the function | 1359 Unix, this means appending a slash to the string. |
1381 converts a string of the form @file{[X]Y.DIR.1} to the form | |
1382 @file{[X.Y]}. | |
1383 | 1360 |
1384 @example | 1361 @example |
1385 @group | 1362 @group |
1386 (file-name-as-directory "~rms/lewis") | 1363 (file-name-as-directory "~rms/lewis") |
1387 @result{} "~rms/lewis/" | 1364 @result{} "~rms/lewis/" |
1390 @end defun | 1367 @end defun |
1391 | 1368 |
1392 @defun directory-file-name dirname | 1369 @defun directory-file-name dirname |
1393 This function returns a string representing @var{dirname} in a form | 1370 This function returns a string representing @var{dirname} in a form |
1394 that the operating system will interpret as the name of a file. On | 1371 that the operating system will interpret as the name of a file. On |
1395 Unix, this means removing a final slash from the string. On VMS, the | 1372 Unix, this means removing a final slash from the string. |
1396 function converts a string of the form @file{[X.Y]} to | |
1397 @file{[X]Y.DIR.1}. | |
1398 | 1373 |
1399 @example | 1374 @example |
1400 @group | 1375 @group |
1401 (directory-file-name "~lewis/") | 1376 (directory-file-name "~lewis/") |
1402 @result{} "~lewis" | 1377 @result{} "~lewis" |
1413 abbreviation instead. | 1388 abbreviation instead. |
1414 | 1389 |
1415 If you wish to convert a directory name to its abbreviation, use this | 1390 If you wish to convert a directory name to its abbreviation, use this |
1416 function: | 1391 function: |
1417 | 1392 |
1418 @defun abbreviate-file-name dirname &optional hack-homedir | 1393 @defun abbreviate-file-name filename &optional hack-homedir |
1419 This function applies abbreviations from @code{directory-abbrev-alist} | 1394 This function applies abbreviations from @code{directory-abbrev-alist} |
1420 to its argument, and substitutes @samp{~} for the user's home | 1395 to its argument, and substitutes @samp{~} for the user's home |
1421 directory. | 1396 directory. |
1422 | 1397 |
1423 @c XEmacs feature? | 1398 @c XEmacs feature? |
1466 root directory. A file name can specify all the directory names | 1441 root directory. A file name can specify all the directory names |
1467 starting from the root of the tree; then it is called an @dfn{absolute} | 1442 starting from the root of the tree; then it is called an @dfn{absolute} |
1468 file name. Or it can specify the position of the file in the tree | 1443 file name. Or it can specify the position of the file in the tree |
1469 relative to a default directory; then it is called a @dfn{relative} | 1444 relative to a default directory; then it is called a @dfn{relative} |
1470 file name. On Unix, an absolute file name starts with a slash or a | 1445 file name. On Unix, an absolute file name starts with a slash or a |
1471 tilde (@samp{~}), and a relative one does not. The rules on VMS are | 1446 tilde (@samp{~}), and a relative one does not. |
1472 complicated. | |
1473 | 1447 |
1474 @defun file-name-absolute-p filename | 1448 @defun file-name-absolute-p filename |
1475 This function returns @code{t} if file @var{filename} is an absolute | 1449 This function returns @code{t} if file @var{filename} is an absolute |
1476 file name, @code{nil} otherwise. On VMS, this function understands both | 1450 file name, @code{nil} otherwise. |
1477 Unix syntax and VMS syntax. | |
1478 | 1451 |
1479 @example | 1452 @example |
1480 @group | 1453 @group |
1481 (file-name-absolute-p "~rms/foo") | 1454 (file-name-absolute-p "~rms/foo") |
1482 @result{} t | 1455 @result{} t |
1620 @group | 1593 @group |
1621 (substitute-in-file-name "/usr/local/$HOME/foo") | 1594 (substitute-in-file-name "/usr/local/$HOME/foo") |
1622 @result{} "/xcssun/users/rms/foo" | 1595 @result{} "/xcssun/users/rms/foo" |
1623 @end group | 1596 @end group |
1624 @end example | 1597 @end example |
1625 | |
1626 On VMS, @samp{$} substitution is not done, so this function does nothing | |
1627 on VMS except discard superfluous initial components as shown above. | |
1628 @end defun | 1598 @end defun |
1629 | 1599 |
1630 @node Unique File Names | 1600 @node Unique File Names |
1631 @subsection Generating Unique File Names | 1601 @subsection Generating Unique File Names |
1632 | 1602 |
1664 @result{} "/tmp/fooGaAQjC" | 1634 @result{} "/tmp/fooGaAQjC" |
1665 @end group | 1635 @end group |
1666 @end example | 1636 @end example |
1667 | 1637 |
1668 In addition, this function makes an attempt to choose a name that does | 1638 In addition, this function makes an attempt to choose a name that does |
1669 not specify an existing file. To make this work, @var{prefix} should be | 1639 not specify an existing file. To make this work, @var{prefix} should be |
1670 an absolute file name. | 1640 an absolute file name. |
1671 | 1641 |
1672 To avoid confusion, each Lisp application should preferably use a unique | 1642 To avoid confusion, each Lisp application should preferably use a unique |
1673 @var{prefix} to @code{make-temp-name}. | 1643 @var{prefix} to @code{make-temp-name}. |
1674 @end defun | 1644 @end defun |
1680 | 1650 |
1681 This section describes low-level subroutines for completing a file | 1651 This section describes low-level subroutines for completing a file |
1682 name. For other completion functions, see @ref{Completion}. | 1652 name. For other completion functions, see @ref{Completion}. |
1683 | 1653 |
1684 @defun file-name-all-completions partial-filename directory | 1654 @defun file-name-all-completions partial-filename directory |
1685 This function returns a list of all possible completions for a file | 1655 This function returns a list of all possible completions for files |
1686 whose name starts with @var{partial-filename} in directory | 1656 whose name starts with @var{partial-filename} in directory |
1687 @var{directory}. The order of the completions is the order of the files | 1657 @var{directory}. The order of the completions is the order of the files |
1688 in the directory, which is unpredictable and conveys no useful | 1658 in the directory, which is unpredictable and conveys no useful |
1689 information. | 1659 information. |
1690 | 1660 |
1691 The argument @var{partial-filename} must be a file name containing no | 1661 The argument @var{partial-filename} must be a file name containing no |
1692 directory part and no slash. The current buffer's default directory is | 1662 directory part and no slash. The current buffer's default directory is |
1693 prepended to @var{directory}, if @var{directory} is not absolute. | 1663 prepended to @var{directory}, if @var{directory} is not absolute. |
1694 | 1664 |
1665 File names which end with any member of @code{completion-ignored-extensions} | |
1666 are not considered as possible completions for @var{partial-filename} unless | |
1667 there is no other possible completion. @code{completion-ignored-extensions} | |
1668 is not applied to the names of directories. | |
1669 | |
1695 In the following example, suppose that the current default directory, | 1670 In the following example, suppose that the current default directory, |
1696 @file{~rms/lewis}, has five files whose names begin with @samp{f}: | 1671 @file{~rms/lewis}, has five files whose names begin with @samp{f}: |
1697 @file{foo}, @file{file~}, @file{file.c}, @file{file.c.~1~}, and | 1672 @file{foo}, @file{file~}, @file{file.c}, @file{file.c.~1~}, and |
1698 @file{file.c.~2~}.@refill | 1673 @file{file.c.~2~}.@refill |
1699 | 1674 |
1700 @example | 1675 @example |
1701 @group | 1676 @group |
1702 (file-name-all-completions "f" "") | 1677 (file-name-all-completions "f" "") |
1703 @result{} ("foo" "file~" "file.c.~2~" | 1678 @result{} ("foo" "file~" "file.c.~2~" |
1704 "file.c.~1~" "file.c") | 1679 "file.c.~1~" "file.c") |
1705 @end group | 1680 @end group |
1706 | 1681 |
1707 @group | 1682 @group |
1708 (file-name-all-completions "fo" "") | 1683 (file-name-all-completions "fo" "") |
1709 @result{} ("foo") | 1684 @result{} ("foo") |
1710 @end group | 1685 @end group |
1711 @end example | 1686 @end example |
1712 @end defun | 1687 @end defun |
1713 | 1688 |
1714 @defun file-name-completion filename directory | 1689 @defun file-name-completion partial-filename directory |
1715 This function completes the file name @var{filename} in directory | 1690 This function completes the file name @var{partial-filename} in directory |
1716 @var{directory}. It returns the longest prefix common to all file names | 1691 @var{directory}. It returns the longest prefix common to all file names |
1717 in directory @var{directory} that start with @var{filename}. | 1692 in directory @var{directory} that start with @var{partial-filename}. |
1718 | 1693 |
1719 If only one match exists and @var{filename} matches it exactly, the | 1694 If only one match exists and @var{partial-filename} matches it exactly, the |
1720 function returns @code{t}. The function returns @code{nil} if directory | 1695 function returns @code{t}. The function returns @code{nil} if directory |
1721 @var{directory} contains no name starting with @var{filename}. | 1696 @var{directory} contains no name starting with @var{partial-filename}. |
1697 | |
1698 File names which end with any member of @code{completion-ignored-extensions} | |
1699 are not considered as possible completions for @var{partial-filename} unless | |
1700 there is no other possible completion. @code{completion-ignored-extensions} | |
1701 is not applied to the names of directories. | |
1722 | 1702 |
1723 In the following example, suppose that the current default directory | 1703 In the following example, suppose that the current default directory |
1724 has five files whose names begin with @samp{f}: @file{foo}, | 1704 has five files whose names begin with @samp{f}: @file{foo}, |
1725 @file{file~}, @file{file.c}, @file{file.c.~1~}, and | 1705 @file{file~}, @file{file.c}, @file{file.c.~1~}, and |
1726 @file{file.c.~2~}.@refill | 1706 @file{file.c.~2~}.@refill |
1771 | 1751 |
1772 This section describes low-level subroutines for completing a user | 1752 This section describes low-level subroutines for completing a user |
1773 name. For other completion functions, see @ref{Completion}. | 1753 name. For other completion functions, see @ref{Completion}. |
1774 | 1754 |
1775 @defun user-name-all-completions partial-username | 1755 @defun user-name-all-completions partial-username |
1776 This function returns a list of all possible completions for a user | 1756 This function returns a list of all possible completions for a user name |
1777 whose name starts with @var{partial-username}. The order of the | 1757 starting with @var{partial-username}. The order of the completions is |
1778 completions is unpredictable and conveys no useful information. | 1758 unpredictable and conveys no useful information. |
1779 | 1759 |
1780 The argument @var{partial-username} must be a partial user name | 1760 The argument @var{partial-username} must be a partial user name |
1781 containing no tilde character and no slash. | 1761 containing no tilde character and no slash. |
1782 @end defun | 1762 @end defun |
1783 | 1763 |
1784 @defun user-name-completion username | 1764 @defun user-name-completion partial-username |
1785 This function completes the user name @var{username}. It returns the | 1765 This function completes a user name from @var{partial-username}. It |
1786 longest prefix common to all user names that start with @var{username}. | 1766 returns the longest prefix common to all user names that start with |
1787 | 1767 @var{partial-username}. |
1788 If only one match exists and @var{username} matches it exactly, the | 1768 |
1789 function returns @code{t}. The function returns @code{nil} if no user | 1769 If only one match exists and @var{partial-username} matches it exactly, |
1790 name starting with @var{username} exists. | 1770 the function returns @code{t}. The function returns @code{nil} if no |
1791 @end defun | 1771 user name starting with @var{partial-username} exists. |
1792 | 1772 @end defun |
1793 @defun user-name-completion-1 username | 1773 |
1794 This function completes the user name @var{username}, like | 1774 @defun user-name-completion-1 partial-username |
1795 @code{user-name-completion}, differing only in the return value. | 1775 This function completes the partial user name @var{partial-username}, |
1776 like @code{user-name-completion}, differing only in the return value. | |
1796 This function returns the cons of the completion returned by | 1777 This function returns the cons of the completion returned by |
1797 @code{user-name-completion}, and a boolean indicating whether that | 1778 @code{user-name-completion}, and a boolean indicating whether that |
1798 completion was unique. | 1779 completion was unique. |
1799 @end defun | 1780 @end defun |
1800 | 1781 |
1841 | 1822 |
1842 @example | 1823 @example |
1843 @group | 1824 @group |
1844 (directory-files "~lewis") | 1825 (directory-files "~lewis") |
1845 @result{} ("#foo#" "#foo.el#" "." ".." | 1826 @result{} ("#foo#" "#foo.el#" "." ".." |
1846 "dired-mods.el" "files.texi" | 1827 "dired-mods.el" "files.texi" |
1847 "files.texi.~1~") | 1828 "files.texi.~1~") |
1848 @end group | 1829 @end group |
1849 @end example | 1830 @end example |
1850 | 1831 |
1851 An error is signaled if @var{directory} is not the name of a directory | 1832 An error is signaled if @var{directory} is not the name of a directory |
2000 (cond ((eq operation 'insert-file-contents) @dots{}) | 1981 (cond ((eq operation 'insert-file-contents) @dots{}) |
2001 ((eq operation 'write-region) @dots{}) | 1982 ((eq operation 'write-region) @dots{}) |
2002 @dots{} | 1983 @dots{} |
2003 ;; @r{Handle any operation we don't know about.} | 1984 ;; @r{Handle any operation we don't know about.} |
2004 (t (let ((inhibit-file-name-handlers | 1985 (t (let ((inhibit-file-name-handlers |
2005 (cons 'my-file-handler | 1986 (cons 'my-file-handler |
2006 (and (eq inhibit-file-name-operation operation) | 1987 (and (eq inhibit-file-name-operation operation) |
2007 inhibit-file-name-handlers))) | 1988 inhibit-file-name-handlers))) |
2008 (inhibit-file-name-operation operation)) | 1989 (inhibit-file-name-operation operation)) |
2009 (apply operation args))))) | 1990 (apply operation args))))) |
2010 @end smallexample | 1991 @end smallexample |
2026 | 2007 |
2027 @defvar inhibit-file-name-operation | 2008 @defvar inhibit-file-name-operation |
2028 The operation for which certain handlers are presently inhibited. | 2009 The operation for which certain handlers are presently inhibited. |
2029 @end defvar | 2010 @end defvar |
2030 | 2011 |
2031 @defun find-file-name-handler file operation | 2012 @defun find-file-name-handler filename &optional operation |
2032 This function returns the handler function for file name @var{file}, or | 2013 This function returns the handler function for file name @var{filename}, or |
2033 @code{nil} if there is none. The argument @var{operation} should be the | 2014 @code{nil} if there is none. The argument @var{operation} should be the |
2034 operation to be performed on the file---the value you will pass to the | 2015 operation to be performed on the file---the value you will pass to the |
2035 handler as its first argument when you call it. The operation is needed | 2016 handler as its first argument when you call it. The operation is needed |
2036 for comparison with @code{inhibit-file-name-operation}. | 2017 for comparison with @code{inhibit-file-name-operation}. |
2037 @end defun | 2018 @end defun |
2093 work correctly. | 2074 work correctly. |
2094 | 2075 |
2095 @node Creating a Partial File | 2076 @node Creating a Partial File |
2096 @subsection Creating a Partial File | 2077 @subsection Creating a Partial File |
2097 | 2078 |
2098 @defun make-file-part &optional start end name buffer | 2079 @deffn Command make-file-part &optional start end name buffer |
2099 Make a file part on buffer @var{buffer} out of the region. Call it | 2080 Make a file part on buffer @var{buffer} out of the region. Call it |
2100 @var{name}. This command creates a new buffer containing the contents | 2081 @var{name}. This command creates a new buffer containing the contents |
2101 of the region and marks the buffer as referring to the specified buffer, | 2082 of the region and marks the buffer as referring to the specified buffer, |
2102 called the @dfn{master buffer}. When the file-part buffer is saved, its | 2083 called the @dfn{master buffer}. When the file-part buffer is saved, its |
2103 changes are integrated back into the master buffer. When the master | 2084 changes are integrated back into the master buffer. When the master |
2104 buffer is deleted, all file parts are deleted with it. | 2085 buffer is deleted, all file parts are deleted with it. |
2105 | 2086 |
2106 When called from a function, expects four arguments, @var{start}, | 2087 When called from a function, expects four arguments, @var{start}, |
2107 @var{end}, @var{name}, and @var{buffer}, all of which are optional and | 2088 @var{end}, @var{name}, and @var{buffer}, all of which are optional and |
2108 default to the beginning of @var{buffer}, the end of @var{buffer}, a | 2089 default to the beginning of @var{buffer}, the end of @var{buffer}, a |
2109 name generated from @var{buffer} name, and the current buffer, | 2090 name generated from @var{buffer}'s name, and the current buffer, |
2110 respectively. | 2091 respectively. |
2111 @end defun | 2092 @end deffn |
2112 | 2093 |
2113 @node Detached Partial Files | 2094 @node Detached Partial Files |
2114 @subsection Detached Partial Files | 2095 @subsection Detached Partial Files |
2115 | 2096 |
2116 Every partial file has an extent in the master buffer associated with it | 2097 Every partial file has an extent in the master buffer associated with it |
2235 | 2216 |
2236 When @code{write-region} writes data into a file, it first calls the | 2217 When @code{write-region} writes data into a file, it first calls the |
2237 encoding functions for the formats listed in @code{buffer-file-format}, | 2218 encoding functions for the formats listed in @code{buffer-file-format}, |
2238 in the order of appearance in the list. | 2219 in the order of appearance in the list. |
2239 | 2220 |
2240 @defun format-write-file file format | 2221 @deffn Command format-write-file file format |
2241 This command writes the current buffer contents into the file @var{file} | 2222 This command writes the current buffer contents into the file @var{file} |
2242 in format @var{format}, and makes that format the default for future | 2223 in format @var{format}, and makes that format the default for future |
2243 saves of the buffer. The argument @var{format} is a list of format | 2224 saves of the buffer. The argument @var{format} is a list of format |
2244 names. | 2225 names. |
2245 @end defun | 2226 @end deffn |
2246 | 2227 |
2247 @defun format-find-file file format | 2228 @deffn Command format-find-file file format |
2248 This command finds the file @var{file}, converting it according to | 2229 This command finds the file @var{file}, converting it according to |
2249 format @var{format}. It also makes @var{format} the default if the | 2230 format @var{format}. It also makes @var{format} the default if the |
2250 buffer is saved later. | 2231 buffer is saved later. |
2251 | 2232 |
2252 The argument @var{format} is a list of format names. If @var{format} is | 2233 The argument @var{format} is a list of format names. If @var{format} is |
2253 @code{nil}, no conversion takes place. Interactively, typing just | 2234 @code{nil}, no conversion takes place. Interactively, typing just |
2254 @key{RET} for @var{format} specifies @code{nil}. | 2235 @key{RET} for @var{format} specifies @code{nil}. |
2255 @end defun | 2236 @end deffn |
2256 | 2237 |
2257 @defun format-insert-file file format &optional beg end | 2238 @deffn Command format-insert-file file format &optional start end |
2258 This command inserts the contents of file @var{file}, converting it | 2239 This command inserts the contents of file @var{file}, converting it |
2259 according to format @var{format}. If @var{beg} and @var{end} are | 2240 according to format @var{format}. If @var{start} and @var{end} are |
2260 non-@code{nil}, they specify which part of the file to read, as in | 2241 non-@code{nil}, they specify which part of the file to read, as in |
2261 @code{insert-file-contents} (@pxref{Reading from Files}). | 2242 @code{insert-file-contents} (@pxref{Reading from Files}). |
2262 | 2243 |
2263 The return value is like what @code{insert-file-contents} returns: a | 2244 The return value is like what @code{insert-file-contents} returns: a |
2264 list of the absolute file name and the length of the data inserted | 2245 list of the absolute file name and the length of the data inserted |
2265 (after conversion). | 2246 (after conversion). |
2266 | 2247 |
2267 The argument @var{format} is a list of format names. If @var{format} is | 2248 The argument @var{format} is a list of format names. If @var{format} is |
2268 @code{nil}, no conversion takes place. Interactively, typing just | 2249 @code{nil}, no conversion takes place. Interactively, typing just |
2269 @key{RET} for @var{format} specifies @code{nil}. | 2250 @key{RET} for @var{format} specifies @code{nil}. |
2270 @end defun | 2251 @end deffn |
2271 | |
2272 @defun format-find-file file format | |
2273 This command finds the file @var{file}, converting it according to | |
2274 format @var{format}. It also makes @var{format} the default if the | |
2275 buffer is saved later. | |
2276 | |
2277 The argument @var{format} is a list of format names. If @var{format} is | |
2278 @code{nil}, no conversion takes place. Interactively, typing just | |
2279 @key{RET} for @var{format} specifies @code{nil}. | |
2280 @end defun | |
2281 | |
2282 @defun format-insert-file file format &optional beg end | |
2283 This command inserts the contents of file @var{file}, converting it | |
2284 according to format @var{format}. If @var{beg} and @var{end} are | |
2285 non-@code{nil}, they specify which part of the file to read, | |
2286 as in @code{insert-file-contents} (@pxref{Reading from Files}). | |
2287 | |
2288 The return value is like what @code{insert-file-contents} returns: a | |
2289 list of the absolute file name and the length of the data inserted | |
2290 (after conversion). | |
2291 | |
2292 The argument @var{format} is a list of format names. If @var{format} is | |
2293 @code{nil}, no conversion takes place. Interactively, typing just | |
2294 @key{RET} for @var{format} specifies @code{nil}. | |
2295 @end defun | |
2296 | 2252 |
2297 @defvar auto-save-file-format | 2253 @defvar auto-save-file-format |
2298 This variable specifies the format to use for auto-saving. Its value is | 2254 This variable specifies the format to use for auto-saving. Its value is |
2299 a list of format names, just like the value of | 2255 a list of format names, just like the value of |
2300 @code{buffer-file-format}; but it is used instead of | 2256 @code{buffer-file-format}; but it is used instead of |