Mercurial > emacs
comparison src/fileio.c @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 8fbfb61ab3f4 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 /* File IO for GNU Emacs. | 1 /* File IO for GNU Emacs. |
2 Copyright (C) 1985,86,87,88,93,94,95,96,97,98,99,2000, 2001 | 2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996, |
3 Free Software Foundation, Inc. | 3 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
4 2005, 2006 Free Software Foundation, Inc. | |
4 | 5 |
5 This file is part of GNU Emacs. | 6 This file is part of GNU Emacs. |
6 | 7 |
7 GNU Emacs is free software; you can redistribute it and/or modify | 8 GNU Emacs is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 16 GNU General Public License for more details. |
16 | 17 |
17 You should have received a copy of the GNU General Public License | 18 You should have received a copy of the GNU General Public License |
18 along with GNU Emacs; see the file COPYING. If not, write to | 19 along with GNU Emacs; see the file COPYING. If not, write to |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 Boston, MA 02111-1307, USA. */ | 21 Boston, MA 02110-1301, USA. */ |
21 | 22 |
22 #include <config.h> | 23 #include <config.h> |
23 | 24 |
24 #ifdef HAVE_FCNTL_H | 25 #ifdef HAVE_FCNTL_H |
25 #include <fcntl.h> | 26 #include <fcntl.h> |
43 | 44 |
44 #if !defined (S_ISREG) && defined (S_IFREG) | 45 #if !defined (S_ISREG) && defined (S_IFREG) |
45 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | 46 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
46 #endif | 47 #endif |
47 | 48 |
48 #ifdef VMS | 49 #ifdef HAVE_PWD_H |
49 #include "vms-pwd.h" | |
50 #else | |
51 #include <pwd.h> | 50 #include <pwd.h> |
52 #endif | 51 #endif |
53 | 52 |
54 #include <ctype.h> | 53 #include <ctype.h> |
55 | 54 |
132 #endif | 131 #endif |
133 #endif | 132 #endif |
134 | 133 |
135 #include "commands.h" | 134 #include "commands.h" |
136 extern int use_dialog_box; | 135 extern int use_dialog_box; |
136 extern int use_file_dialog; | |
137 | 137 |
138 #ifndef O_WRONLY | 138 #ifndef O_WRONLY |
139 #define O_WRONLY 1 | 139 #define O_WRONLY 1 |
140 #endif | 140 #endif |
141 | 141 |
143 #define O_RDONLY 0 | 143 #define O_RDONLY 0 |
144 #endif | 144 #endif |
145 | 145 |
146 #ifndef S_ISLNK | 146 #ifndef S_ISLNK |
147 # define lstat stat | 147 # define lstat stat |
148 #endif | |
149 | |
150 #ifndef FILE_SYSTEM_CASE | |
151 #define FILE_SYSTEM_CASE(filename) (filename) | |
148 #endif | 152 #endif |
149 | 153 |
150 /* Nonzero during writing of auto-save files */ | 154 /* Nonzero during writing of auto-save files */ |
151 int auto_saving; | 155 int auto_saving; |
152 | 156 |
153 /* Set by auto_save_1 to mode of original file so Fwrite_region will create | 157 /* Set by auto_save_1 to mode of original file so Fwrite_region will create |
154 a new file with the same mode as the original */ | 158 a new file with the same mode as the original */ |
155 int auto_save_mode_bits; | 159 int auto_save_mode_bits; |
156 | 160 |
161 /* The symbol bound to coding-system-for-read when | |
162 insert-file-contents is called for recovering a file. This is not | |
163 an actual coding system name, but just an indicator to tell | |
164 insert-file-contents to use `emacs-mule' with a special flag for | |
165 auto saving and recovering a file. */ | |
166 Lisp_Object Qauto_save_coding; | |
167 | |
157 /* Coding system for file names, or nil if none. */ | 168 /* Coding system for file names, or nil if none. */ |
158 Lisp_Object Vfile_name_coding_system; | 169 Lisp_Object Vfile_name_coding_system; |
159 | 170 |
160 /* Coding system for file names used only when | 171 /* Coding system for file names used only when |
161 Vfile_name_coding_system is nil. */ | 172 Vfile_name_coding_system is nil. */ |
163 | 174 |
164 /* Alist of elements (REGEXP . HANDLER) for file names | 175 /* Alist of elements (REGEXP . HANDLER) for file names |
165 whose I/O is done with a special handler. */ | 176 whose I/O is done with a special handler. */ |
166 Lisp_Object Vfile_name_handler_alist; | 177 Lisp_Object Vfile_name_handler_alist; |
167 | 178 |
168 /* Format for auto-save files */ | 179 /* Property name of a file name handler, |
169 Lisp_Object Vauto_save_file_format; | 180 which gives a list of operations it handles.. */ |
181 Lisp_Object Qoperations; | |
170 | 182 |
171 /* Lisp functions for translating file formats */ | 183 /* Lisp functions for translating file formats */ |
172 Lisp_Object Qformat_decode, Qformat_annotate_function; | 184 Lisp_Object Qformat_decode, Qformat_annotate_function; |
173 | 185 |
174 /* Function to be called to decide a coding system of a reading file. */ | 186 /* Function to be called to decide a coding system of a reading file. */ |
175 Lisp_Object Vset_auto_coding_function; | 187 Lisp_Object Vset_auto_coding_function; |
176 | 188 |
177 /* Functions to be called to process text properties in inserted file. */ | 189 /* Functions to be called to process text properties in inserted file. */ |
178 Lisp_Object Vafter_insert_file_functions; | 190 Lisp_Object Vafter_insert_file_functions; |
179 | 191 |
192 /* Lisp function for setting buffer-file-coding-system and the | |
193 multibyteness of the current buffer after inserting a file. */ | |
194 Lisp_Object Qafter_insert_file_set_coding; | |
195 | |
180 /* Functions to be called to create text property annotations for file. */ | 196 /* Functions to be called to create text property annotations for file. */ |
181 Lisp_Object Vwrite_region_annotate_functions; | 197 Lisp_Object Vwrite_region_annotate_functions; |
198 Lisp_Object Qwrite_region_annotate_functions; | |
182 | 199 |
183 /* During build_annotations, each time an annotation function is called, | 200 /* During build_annotations, each time an annotation function is called, |
184 this holds the annotations made by the previous functions. */ | 201 this holds the annotations made by the previous functions. */ |
185 Lisp_Object Vwrite_region_annotations_so_far; | 202 Lisp_Object Vwrite_region_annotations_so_far; |
186 | 203 |
191 Lisp_Object Vread_file_name_function; | 208 Lisp_Object Vread_file_name_function; |
192 | 209 |
193 /* Current predicate used by read_file_name_internal. */ | 210 /* Current predicate used by read_file_name_internal. */ |
194 Lisp_Object Vread_file_name_predicate; | 211 Lisp_Object Vread_file_name_predicate; |
195 | 212 |
213 /* Nonzero means completion ignores case when reading file name. */ | |
214 int read_file_name_completion_ignore_case; | |
215 | |
196 /* Nonzero means, when reading a filename in the minibuffer, | 216 /* Nonzero means, when reading a filename in the minibuffer, |
197 start out by inserting the default directory into the minibuffer. */ | 217 start out by inserting the default directory into the minibuffer. */ |
198 int insert_default_directory; | 218 int insert_default_directory; |
199 | 219 |
200 /* On VMS, nonzero means write new files with record format stmlf. | 220 /* On VMS, nonzero means write new files with record format stmlf. |
203 | 223 |
204 /* On NT, specifies the directory separator character, used (eg.) when | 224 /* On NT, specifies the directory separator character, used (eg.) when |
205 expanding file names. This can be bound to / or \. */ | 225 expanding file names. This can be bound to / or \. */ |
206 Lisp_Object Vdirectory_sep_char; | 226 Lisp_Object Vdirectory_sep_char; |
207 | 227 |
228 #ifdef HAVE_FSYNC | |
229 /* Nonzero means skip the call to fsync in Fwrite-region. */ | |
230 int write_region_inhibit_fsync; | |
231 #endif | |
232 | |
208 extern Lisp_Object Vuser_login_name; | 233 extern Lisp_Object Vuser_login_name; |
209 | 234 |
210 #ifdef WINDOWSNT | 235 #ifdef WINDOWSNT |
211 extern Lisp_Object Vw32_get_true_file_attributes; | 236 extern Lisp_Object Vw32_get_true_file_attributes; |
212 #endif | 237 #endif |
213 | 238 |
214 extern int minibuf_level; | 239 extern int minibuf_level; |
215 | 240 |
216 extern int minibuffer_auto_raise; | 241 extern int minibuffer_auto_raise; |
242 | |
243 extern int history_delete_duplicates; | |
217 | 244 |
218 /* These variables describe handlers that have "already" had a chance | 245 /* These variables describe handlers that have "already" had a chance |
219 to handle the current operation. | 246 to handle the current operation. |
220 | 247 |
221 Vinhibit_file_name_handlers is a list of file name handlers. | 248 Vinhibit_file_name_handlers is a list of file name handlers. |
308 Lisp_Object Qfile_directory_p; | 335 Lisp_Object Qfile_directory_p; |
309 Lisp_Object Qfile_regular_p; | 336 Lisp_Object Qfile_regular_p; |
310 Lisp_Object Qfile_accessible_directory_p; | 337 Lisp_Object Qfile_accessible_directory_p; |
311 Lisp_Object Qfile_modes; | 338 Lisp_Object Qfile_modes; |
312 Lisp_Object Qset_file_modes; | 339 Lisp_Object Qset_file_modes; |
340 Lisp_Object Qset_file_times; | |
313 Lisp_Object Qfile_newer_than_file_p; | 341 Lisp_Object Qfile_newer_than_file_p; |
314 Lisp_Object Qinsert_file_contents; | 342 Lisp_Object Qinsert_file_contents; |
315 Lisp_Object Qwrite_region; | 343 Lisp_Object Qwrite_region; |
316 Lisp_Object Qverify_visited_file_modtime; | 344 Lisp_Object Qverify_visited_file_modtime; |
317 Lisp_Object Qset_visited_file_modtime; | 345 Lisp_Object Qset_visited_file_modtime; |
346 { | 374 { |
347 Lisp_Object elt; | 375 Lisp_Object elt; |
348 elt = XCAR (chain); | 376 elt = XCAR (chain); |
349 if (CONSP (elt)) | 377 if (CONSP (elt)) |
350 { | 378 { |
351 Lisp_Object string; | 379 Lisp_Object string = XCAR (elt); |
352 int match_pos; | 380 int match_pos; |
353 string = XCAR (elt); | 381 Lisp_Object handler = XCDR (elt); |
382 Lisp_Object operations = Qnil; | |
383 | |
384 if (SYMBOLP (handler)) | |
385 operations = Fget (handler, Qoperations); | |
386 | |
354 if (STRINGP (string) | 387 if (STRINGP (string) |
355 && (match_pos = fast_string_match (string, filename)) > pos) | 388 && (match_pos = fast_string_match (string, filename)) > pos |
389 && (NILP (operations) || ! NILP (Fmemq (operation, operations)))) | |
356 { | 390 { |
357 Lisp_Object handler, tem; | 391 Lisp_Object tem; |
358 | 392 |
359 handler = XCDR (elt); | 393 handler = XCDR (elt); |
360 tem = Fmemq (handler, inhibited_handlers); | 394 tem = Fmemq (handler, inhibited_handlers); |
361 if (NILP (tem)) | 395 if (NILP (tem)) |
362 { | 396 { |
395 call the corresponding file handler. */ | 429 call the corresponding file handler. */ |
396 handler = Ffind_file_name_handler (filename, Qfile_name_directory); | 430 handler = Ffind_file_name_handler (filename, Qfile_name_directory); |
397 if (!NILP (handler)) | 431 if (!NILP (handler)) |
398 return call2 (handler, Qfile_name_directory, filename); | 432 return call2 (handler, Qfile_name_directory, filename); |
399 | 433 |
400 #ifdef FILE_SYSTEM_CASE | |
401 filename = FILE_SYSTEM_CASE (filename); | 434 filename = FILE_SYSTEM_CASE (filename); |
402 #endif | |
403 beg = SDATA (filename); | 435 beg = SDATA (filename); |
404 #ifdef DOS_NT | 436 #ifdef DOS_NT |
405 beg = strcpy (alloca (strlen (beg) + 1), beg); | 437 beg = strcpy (alloca (strlen (beg) + 1), beg); |
406 #endif | 438 #endif |
407 p = beg + SBYTES (filename); | 439 p = beg + SBYTES (filename); |
445 } | 477 } |
446 } | 478 } |
447 CORRECT_DIR_SEPS (beg); | 479 CORRECT_DIR_SEPS (beg); |
448 #endif /* DOS_NT */ | 480 #endif /* DOS_NT */ |
449 | 481 |
450 if (STRING_MULTIBYTE (filename)) | 482 return make_specified_string (beg, -1, p - beg, STRING_MULTIBYTE (filename)); |
451 return make_string (beg, p - beg); | |
452 return make_unibyte_string (beg, p - beg); | |
453 } | 483 } |
454 | 484 |
455 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, | 485 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, |
456 Sfile_name_nondirectory, 1, 1, 0, | 486 Sfile_name_nondirectory, 1, 1, 0, |
457 doc: /* Return file name FILENAME sans its directory. | 487 doc: /* Return file name FILENAME sans its directory. |
486 && (p == beg + 2 || (p == beg + 4 && IS_DIRECTORY_SEP (*beg)))) | 516 && (p == beg + 2 || (p == beg + 4 && IS_DIRECTORY_SEP (*beg)))) |
487 #endif | 517 #endif |
488 ) | 518 ) |
489 p--; | 519 p--; |
490 | 520 |
491 if (STRING_MULTIBYTE (filename)) | 521 return make_specified_string (p, -1, end - p, STRING_MULTIBYTE (filename)); |
492 return make_string (p, end - p); | |
493 return make_unibyte_string (p, end - p); | |
494 } | 522 } |
495 | 523 |
496 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory, | 524 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory, |
497 Sunhandled_file_name_directory, 1, 1, 0, | 525 Sunhandled_file_name_directory, 1, 1, 0, |
498 doc: /* Return a directly usable directory name somehow associated with FILENAME. | 526 doc: /* Return a directly usable directory name somehow associated with FILENAME. |
629 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); | 657 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); |
630 if (!NILP (handler)) | 658 if (!NILP (handler)) |
631 return call2 (handler, Qfile_name_as_directory, file); | 659 return call2 (handler, Qfile_name_as_directory, file); |
632 | 660 |
633 buf = (char *) alloca (SBYTES (file) + 10); | 661 buf = (char *) alloca (SBYTES (file) + 10); |
634 return build_string (file_name_as_directory (buf, SDATA (file))); | 662 file_name_as_directory (buf, SDATA (file)); |
663 return make_specified_string (buf, -1, strlen (buf), | |
664 STRING_MULTIBYTE (file)); | |
635 } | 665 } |
636 | 666 |
637 /* | 667 /* |
638 * Convert from directory name to filename. | 668 * Convert from directory name to filename. |
639 * On VMS: | 669 * On VMS: |
829 buf = (char *) alloca (SBYTES (directory) + 20 + 255); | 859 buf = (char *) alloca (SBYTES (directory) + 20 + 255); |
830 #else | 860 #else |
831 buf = (char *) alloca (SBYTES (directory) + 20); | 861 buf = (char *) alloca (SBYTES (directory) + 20); |
832 #endif | 862 #endif |
833 directory_file_name (SDATA (directory), buf); | 863 directory_file_name (SDATA (directory), buf); |
834 return build_string (buf); | 864 return make_specified_string (buf, -1, strlen (buf), |
865 STRING_MULTIBYTE (directory)); | |
835 } | 866 } |
836 | 867 |
837 static char make_temp_name_tbl[64] = | 868 static char make_temp_name_tbl[64] = |
838 { | 869 { |
839 'A','B','C','D','E','F','G','H', | 870 'A','B','C','D','E','F','G','H', |
868 make_temp_name (prefix, base64_p) | 899 make_temp_name (prefix, base64_p) |
869 Lisp_Object prefix; | 900 Lisp_Object prefix; |
870 int base64_p; | 901 int base64_p; |
871 { | 902 { |
872 Lisp_Object val; | 903 Lisp_Object val; |
873 int len; | 904 int len, clen; |
874 int pid; | 905 int pid; |
875 unsigned char *p, *data; | 906 unsigned char *p, *data; |
876 char pidbuf[20]; | 907 char pidbuf[20]; |
877 int pidlen; | 908 int pidlen; |
878 | 909 |
903 pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6; | 934 pidbuf[2] = make_temp_name_tbl[pid & 63], pid >>= 6; |
904 pidlen = 3; | 935 pidlen = 3; |
905 #endif | 936 #endif |
906 } | 937 } |
907 | 938 |
908 len = SCHARS (prefix); | 939 len = SBYTES (prefix); clen = SCHARS (prefix); |
909 val = make_uninit_string (len + 3 + pidlen); | 940 val = make_uninit_multibyte_string (clen + 3 + pidlen, len + 3 + pidlen); |
941 if (!STRING_MULTIBYTE (prefix)) | |
942 STRING_SET_UNIBYTE (val); | |
910 data = SDATA (val); | 943 data = SDATA (val); |
911 bcopy(SDATA (prefix), data, len); | 944 bcopy(SDATA (prefix), data, len); |
912 p = data + len; | 945 p = data + len; |
913 | 946 |
914 bcopy (pidbuf, p, pidlen); | 947 bcopy (pidbuf, p, pidlen); |
993 | 1026 |
994 | 1027 |
995 DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, | 1028 DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, |
996 doc: /* Convert filename NAME to absolute, and canonicalize it. | 1029 doc: /* Convert filename NAME to absolute, and canonicalize it. |
997 Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative | 1030 Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative |
998 (does not start with slash); if DEFAULT-DIRECTORY is nil or missing, | 1031 \(does not start with slash); if DEFAULT-DIRECTORY is nil or missing, |
999 the current buffer's value of default-directory is used. | 1032 the current buffer's value of `default-directory' is used. |
1000 File name components that are `.' are removed, and | 1033 File name components that are `.' are removed, and |
1001 so are file name components followed by `..', along with the `..' itself; | 1034 so are file name components followed by `..', along with the `..' itself; |
1002 note that these simplifications are done without checking the resulting | 1035 note that these simplifications are done without checking the resulting |
1003 file names in the file system. | 1036 file names in the file system. |
1004 An initial `~/' expands to your home directory. | 1037 An initial `~/' expands to your home directory. |
1025 int drive = 0; | 1058 int drive = 0; |
1026 int collapse_newdir = 1; | 1059 int collapse_newdir = 1; |
1027 int is_escaped = 0; | 1060 int is_escaped = 0; |
1028 #endif /* DOS_NT */ | 1061 #endif /* DOS_NT */ |
1029 int length; | 1062 int length; |
1030 Lisp_Object handler; | 1063 Lisp_Object handler, result; |
1064 int multibyte; | |
1031 | 1065 |
1032 CHECK_STRING (name); | 1066 CHECK_STRING (name); |
1033 | 1067 |
1034 /* If the file name has special constructs in it, | 1068 /* If the file name has special constructs in it, |
1035 call the corresponding file handler. */ | 1069 call the corresponding file handler. */ |
1101 GCPRO1 (name); | 1135 GCPRO1 (name); |
1102 default_directory = Fexpand_file_name (default_directory, Qnil); | 1136 default_directory = Fexpand_file_name (default_directory, Qnil); |
1103 UNGCPRO; | 1137 UNGCPRO; |
1104 } | 1138 } |
1105 | 1139 |
1106 #ifdef VMS | |
1107 /* Filenames on VMS are always upper case. */ | |
1108 name = Fupcase (name); | |
1109 #endif | |
1110 #ifdef FILE_SYSTEM_CASE | |
1111 name = FILE_SYSTEM_CASE (name); | 1140 name = FILE_SYSTEM_CASE (name); |
1112 #endif | |
1113 | |
1114 nm = SDATA (name); | 1141 nm = SDATA (name); |
1142 multibyte = STRING_MULTIBYTE (name); | |
1115 | 1143 |
1116 #ifdef DOS_NT | 1144 #ifdef DOS_NT |
1117 /* We will force directory separators to be either all \ or /, so make | 1145 /* We will force directory separators to be either all \ or /, so make |
1118 a local copy to modify, even if there ends up being no change. */ | 1146 a local copy to modify, even if there ends up being no change. */ |
1119 nm = strcpy (alloca (strlen (nm) + 1), nm); | 1147 nm = strcpy (alloca (strlen (nm) + 1), nm); |
1208 colon = 0; | 1236 colon = 0; |
1209 } | 1237 } |
1210 slash = p; | 1238 slash = p; |
1211 } | 1239 } |
1212 if (p[0] == '-') | 1240 if (p[0] == '-') |
1213 #ifndef VMS4_4 | 1241 #ifdef NO_HYPHENS_IN_FILENAMES |
1214 /* VMS pre V4.4,convert '-'s in filenames. */ | |
1215 if (lbrack == rbrack) | 1242 if (lbrack == rbrack) |
1216 { | 1243 { |
1217 if (dots < 2) /* this is to allow negative version numbers */ | 1244 /* Avoid clobbering negative version numbers. */ |
1245 if (dots < 2) | |
1218 p[0] = '_'; | 1246 p[0] = '_'; |
1219 } | 1247 } |
1220 else | 1248 else |
1221 #endif /* VMS4_4 */ | 1249 #endif /* NO_HYPHENS_IN_FILENAMES */ |
1222 if (lbrack > rbrack && | 1250 if (lbrack > rbrack && |
1223 ((p[-1] == '.' || p[-1] == '[' || p[-1] == '<') && | 1251 ((p[-1] == '.' || p[-1] == '[' || p[-1] == '<') && |
1224 (p[1] == '.' || p[1] == ']' || p[1] == '>'))) | 1252 (p[1] == '.' || p[1] == ']' || p[1] == '>'))) |
1225 lose = 1; | 1253 lose = 1; |
1226 #ifndef VMS4_4 | 1254 #ifdef NO_HYPHENS_IN_FILENAMES |
1227 else | 1255 else |
1228 p[0] = '_'; | 1256 p[0] = '_'; |
1229 #endif /* VMS4_4 */ | 1257 #endif /* NO_HYPHENS_IN_FILENAMES */ |
1230 /* count open brackets, reset close bracket pointer */ | 1258 /* count open brackets, reset close bracket pointer */ |
1231 if (p[0] == '[' || p[0] == '<') | 1259 if (p[0] == '[' || p[0] == '<') |
1232 lbrack++, brack = 0; | 1260 lbrack++, brack = 0; |
1233 /* count close brackets, set close bracket pointer */ | 1261 /* count close brackets, set close bracket pointer */ |
1234 if (p[0] == ']' || p[0] == '>') | 1262 if (p[0] == ']' || p[0] == '>') |
1273 } | 1301 } |
1274 if (!lose) | 1302 if (!lose) |
1275 { | 1303 { |
1276 #ifdef VMS | 1304 #ifdef VMS |
1277 if (index (nm, '/')) | 1305 if (index (nm, '/')) |
1278 return build_string (sys_translate_unix (nm)); | 1306 { |
1307 nm = sys_translate_unix (nm); | |
1308 return make_specified_string (nm, -1, strlen (nm), multibyte); | |
1309 } | |
1279 #endif /* VMS */ | 1310 #endif /* VMS */ |
1280 #ifdef DOS_NT | 1311 #ifdef DOS_NT |
1281 /* Make sure directories are all separated with / or \ as | 1312 /* Make sure directories are all separated with / or \ as |
1282 desired, but avoid allocation of a new string when not | 1313 desired, but avoid allocation of a new string when not |
1283 required. */ | 1314 required. */ |
1284 CORRECT_DIR_SEPS (nm); | 1315 CORRECT_DIR_SEPS (nm); |
1285 #ifdef WINDOWSNT | 1316 #ifdef WINDOWSNT |
1286 if (IS_DIRECTORY_SEP (nm[1])) | 1317 if (IS_DIRECTORY_SEP (nm[1])) |
1287 { | 1318 { |
1288 if (strcmp (nm, SDATA (name)) != 0) | 1319 if (strcmp (nm, SDATA (name)) != 0) |
1289 name = build_string (nm); | 1320 name = make_specified_string (nm, -1, strlen (nm), multibyte); |
1290 } | 1321 } |
1291 else | 1322 else |
1292 #endif | 1323 #endif |
1293 /* drive must be set, so this is okay */ | 1324 /* drive must be set, so this is okay */ |
1294 if (strcmp (nm - 2, SDATA (name)) != 0) | 1325 if (strcmp (nm - 2, SDATA (name)) != 0) |
1295 { | 1326 { |
1296 name = make_string (nm - 2, p - nm + 2); | 1327 char temp[] = " :"; |
1297 SSET (name, 0, DRIVE_LETTER (drive)); | 1328 |
1298 SSET (name, 1, ':'); | 1329 name = make_specified_string (nm, -1, p - nm, multibyte); |
1330 temp[0] = DRIVE_LETTER (drive); | |
1331 name = concat2 (build_string (temp), name); | |
1299 } | 1332 } |
1300 return name; | 1333 return name; |
1301 #else /* not DOS_NT */ | 1334 #else /* not DOS_NT */ |
1302 if (nm == SDATA (name)) | 1335 if (nm == SDATA (name)) |
1303 return name; | 1336 return name; |
1304 return build_string (nm); | 1337 return make_specified_string (nm, -1, strlen (nm), multibyte); |
1305 #endif /* not DOS_NT */ | 1338 #endif /* not DOS_NT */ |
1306 } | 1339 } |
1307 } | 1340 } |
1308 | 1341 |
1309 /* At this point, nm might or might not be an absolute file name. We | 1342 /* At this point, nm might or might not be an absolute file name. We |
1411 && !index (nm, ':') | 1444 && !index (nm, ':') |
1412 #endif | 1445 #endif |
1413 && !newdir) | 1446 && !newdir) |
1414 { | 1447 { |
1415 newdir = SDATA (default_directory); | 1448 newdir = SDATA (default_directory); |
1449 multibyte |= STRING_MULTIBYTE (default_directory); | |
1416 #ifdef DOS_NT | 1450 #ifdef DOS_NT |
1417 /* Note if special escape prefix is present, but remove for now. */ | 1451 /* Note if special escape prefix is present, but remove for now. */ |
1418 if (newdir[0] == '/' && newdir[1] == ':') | 1452 if (newdir[0] == '/' && newdir[1] == ':') |
1419 { | 1453 { |
1420 is_escaped = 1; | 1454 is_escaped = 1; |
1441 Because of the admonition against calling expand-file-name | 1475 Because of the admonition against calling expand-file-name |
1442 when we have pointers into lisp strings, we accomplish this | 1476 when we have pointers into lisp strings, we accomplish this |
1443 indirectly by prepending newdir to nm if necessary, and using | 1477 indirectly by prepending newdir to nm if necessary, and using |
1444 cwd (or the wd of newdir's drive) as the new newdir. */ | 1478 cwd (or the wd of newdir's drive) as the new newdir. */ |
1445 | 1479 |
1446 if (IS_DRIVE (newdir[0]) && newdir[1] == ':') | 1480 if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1])) |
1447 { | 1481 { |
1448 drive = newdir[0]; | 1482 drive = newdir[0]; |
1449 newdir += 2; | 1483 newdir += 2; |
1450 } | 1484 } |
1451 if (!IS_DIRECTORY_SEP (nm[0])) | 1485 if (!IS_DIRECTORY_SEP (nm[0])) |
1464 else | 1498 else |
1465 getwd (newdir); | 1499 getwd (newdir); |
1466 } | 1500 } |
1467 | 1501 |
1468 /* Strip off drive name from prefix, if present. */ | 1502 /* Strip off drive name from prefix, if present. */ |
1469 if (IS_DRIVE (newdir[0]) && newdir[1] == ':') | 1503 if (IS_DRIVE (newdir[0]) && IS_DEVICE_SEP (newdir[1])) |
1470 { | 1504 { |
1471 drive = newdir[0]; | 1505 drive = newdir[0]; |
1472 newdir += 2; | 1506 newdir += 2; |
1473 } | 1507 } |
1474 | 1508 |
1595 p++, o--; | 1629 p++, o--; |
1596 /* else [foo.-] ==> [-] */ | 1630 /* else [foo.-] ==> [-] */ |
1597 } | 1631 } |
1598 else | 1632 else |
1599 { | 1633 { |
1600 #ifndef VMS4_4 | 1634 #ifdef NO_HYPHENS_IN_FILENAMES |
1601 if (*p == '-' && | 1635 if (*p == '-' && |
1602 o[-1] != '[' && o[-1] != '<' && o[-1] != '.' && | 1636 o[-1] != '[' && o[-1] != '<' && o[-1] != '.' && |
1603 p[1] != ']' && p[1] != '>' && p[1] != '.') | 1637 p[1] != ']' && p[1] != '>' && p[1] != '.') |
1604 *p = '_'; | 1638 *p = '_'; |
1605 #endif /* VMS4_4 */ | 1639 #endif /* NO_HYPHENS_IN_FILENAMES */ |
1606 *o++ = *p++; | 1640 *o++ = *p++; |
1607 } | 1641 } |
1608 #else /* not VMS */ | 1642 #else /* not VMS */ |
1609 if (!IS_DIRECTORY_SEP (*p)) | 1643 if (!IS_DIRECTORY_SEP (*p)) |
1610 { | 1644 { |
1611 *o++ = *p++; | 1645 *o++ = *p++; |
1612 } | 1646 } |
1613 else if (IS_DIRECTORY_SEP (p[0]) | 1647 else if (p[1] == '.' |
1614 && p[1] == '.' | |
1615 && (IS_DIRECTORY_SEP (p[2]) | 1648 && (IS_DIRECTORY_SEP (p[2]) |
1616 || p[2] == 0)) | 1649 || p[2] == 0)) |
1617 { | 1650 { |
1618 /* If "/." is the entire filename, keep the "/". Otherwise, | 1651 /* If "/." is the entire filename, keep the "/". Otherwise, |
1619 just delete the whole "/.". */ | 1652 just delete the whole "/.". */ |
1620 if (o == target && p[2] == '\0') | 1653 if (o == target && p[2] == '\0') |
1621 *o++ = *p; | 1654 *o++ = *p; |
1622 p += 2; | 1655 p += 2; |
1623 } | 1656 } |
1624 else if (IS_DIRECTORY_SEP (p[0]) && p[1] == '.' && p[2] == '.' | 1657 else if (p[1] == '.' && p[2] == '.' |
1625 /* `/../' is the "superroot" on certain file systems. */ | 1658 /* `/../' is the "superroot" on certain file systems. |
1659 Turned off on DOS_NT systems because they have no | |
1660 "superroot" and because this causes us to produce | |
1661 file names like "d:/../foo" which fail file-related | |
1662 functions of the underlying OS. (To reproduce, try a | |
1663 long series of "../../" in default_directory, longer | |
1664 than the number of levels from the root.) */ | |
1665 #ifndef DOS_NT | |
1626 && o != target | 1666 && o != target |
1667 #endif | |
1627 && (IS_DIRECTORY_SEP (p[3]) || p[3] == 0)) | 1668 && (IS_DIRECTORY_SEP (p[3]) || p[3] == 0)) |
1628 { | 1669 { |
1629 while (o != target && (--o) && !IS_DIRECTORY_SEP (*o)) | 1670 while (o != target && (--o) && !IS_DIRECTORY_SEP (*o)) |
1630 ; | 1671 ; |
1631 /* Keep initial / only if this is the whole name. */ | 1672 /* Keep initial / only if this is the whole name. */ |
1632 if (o == target && IS_ANY_SEP (*o) && p[3] == 0) | 1673 if (o == target && IS_ANY_SEP (*o) && p[3] == 0) |
1633 ++o; | 1674 ++o; |
1634 p += 3; | 1675 p += 3; |
1635 } | 1676 } |
1636 else if (p > target | 1677 else if (p > target && IS_DIRECTORY_SEP (p[1])) |
1637 && IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])) | 1678 /* Collapse multiple `/' in a row. */ |
1638 { | 1679 p++; |
1639 /* Collapse multiple `/' in a row. */ | |
1640 *o++ = *p++; | |
1641 while (IS_DIRECTORY_SEP (*p)) | |
1642 ++p; | |
1643 } | |
1644 else | 1680 else |
1645 { | 1681 { |
1646 *o++ = *p++; | 1682 *o++ = *p++; |
1647 } | 1683 } |
1648 #endif /* not VMS */ | 1684 #endif /* not VMS */ |
1668 target[1] = ':'; | 1704 target[1] = ':'; |
1669 } | 1705 } |
1670 CORRECT_DIR_SEPS (target); | 1706 CORRECT_DIR_SEPS (target); |
1671 #endif /* DOS_NT */ | 1707 #endif /* DOS_NT */ |
1672 | 1708 |
1673 return make_string (target, o - target); | 1709 result = make_specified_string (target, -1, o - target, multibyte); |
1710 | |
1711 /* Again look to see if the file name has special constructs in it | |
1712 and perhaps call the corresponding file handler. This is needed | |
1713 for filenames such as "/foo/../user@host:/bar/../baz". Expanding | |
1714 the ".." component gives us "/user@host:/bar/../baz" which needs | |
1715 to be expanded again. */ | |
1716 handler = Ffind_file_name_handler (result, Qexpand_file_name); | |
1717 if (!NILP (handler)) | |
1718 return call3 (handler, Qexpand_file_name, result, default_directory); | |
1719 | |
1720 return result; | |
1674 } | 1721 } |
1675 | 1722 |
1676 #if 0 | 1723 #if 0 |
1677 /* PLEASE DO NOT DELETE THIS COMMENTED-OUT VERSION! | 1724 /* PLEASE DO NOT DELETE THIS COMMENTED-OUT VERSION! |
1678 This is the old version of expand-file-name, before it was thoroughly | 1725 This is the old version of expand-file-name, before it was thoroughly |
1686 | 1733 |
1687 /* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'. */ | 1734 /* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'. */ |
1688 DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, | 1735 DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, |
1689 "Convert FILENAME to absolute, and canonicalize it.\n\ | 1736 "Convert FILENAME to absolute, and canonicalize it.\n\ |
1690 Second arg DEFAULT is directory to start with if FILENAME is relative\n\ | 1737 Second arg DEFAULT is directory to start with if FILENAME is relative\n\ |
1691 (does not start with slash); if DEFAULT is nil or missing,\n\ | 1738 \(does not start with slash); if DEFAULT is nil or missing,\n\ |
1692 the current buffer's value of default-directory is used.\n\ | 1739 the current buffer's value of default-directory is used.\n\ |
1693 Filenames containing `.' or `..' as components are simplified;\n\ | 1740 Filenames containing `.' or `..' as components are simplified;\n\ |
1694 initial `~/' expands to your home directory.\n\ | 1741 initial `~/' expands to your home directory.\n\ |
1695 See also the function `substitute-in-file-name'.") | 1742 See also the function `substitute-in-file-name'.") |
1696 (name, defalt) | 1743 (name, defalt) |
2005 | 2052 |
2006 return make_string (target, o - target); | 2053 return make_string (target, o - target); |
2007 } | 2054 } |
2008 #endif | 2055 #endif |
2009 | 2056 |
2057 /* If /~ or // appears, discard everything through first slash. */ | |
2058 static int | |
2059 file_name_absolute_p (filename) | |
2060 const unsigned char *filename; | |
2061 { | |
2062 return | |
2063 (IS_DIRECTORY_SEP (*filename) || *filename == '~' | |
2064 #ifdef VMS | |
2065 /* ??? This criterion is probably wrong for '<'. */ | |
2066 || index (filename, ':') || index (filename, '<') | |
2067 || (*filename == '[' && (filename[1] != '-' | |
2068 || (filename[2] != '.' && filename[2] != ']')) | |
2069 && filename[1] != '.') | |
2070 #endif /* VMS */ | |
2071 #ifdef DOS_NT | |
2072 || (IS_DRIVE (*filename) && IS_DEVICE_SEP (filename[1]) | |
2073 && IS_DIRECTORY_SEP (filename[2])) | |
2074 #endif | |
2075 ); | |
2076 } | |
2077 | |
2078 static unsigned char * | |
2079 search_embedded_absfilename (nm, endp) | |
2080 unsigned char *nm, *endp; | |
2081 { | |
2082 unsigned char *p, *s; | |
2083 | |
2084 for (p = nm + 1; p < endp; p++) | |
2085 { | |
2086 if ((0 | |
2087 #ifdef VMS | |
2088 || p[-1] == ':' || p[-1] == ']' || p[-1] == '>' | |
2089 #endif /* VMS */ | |
2090 || IS_DIRECTORY_SEP (p[-1])) | |
2091 && file_name_absolute_p (p) | |
2092 #if defined (APOLLO) || defined (WINDOWSNT) || defined(CYGWIN) | |
2093 /* // at start of file name is meaningful in Apollo, | |
2094 WindowsNT and Cygwin systems. */ | |
2095 && !(IS_DIRECTORY_SEP (p[0]) && p - 1 == nm) | |
2096 #endif /* not (APOLLO || WINDOWSNT || CYGWIN) */ | |
2097 ) | |
2098 { | |
2099 for (s = p; *s && (!IS_DIRECTORY_SEP (*s) | |
2100 #ifdef VMS | |
2101 && *s != ':' | |
2102 #endif /* VMS */ | |
2103 ); s++); | |
2104 if (p[0] == '~' && s > p + 1) /* we've got "/~something/" */ | |
2105 { | |
2106 unsigned char *o = alloca (s - p + 1); | |
2107 struct passwd *pw; | |
2108 bcopy (p, o, s - p); | |
2109 o [s - p] = 0; | |
2110 | |
2111 /* If we have ~user and `user' exists, discard | |
2112 everything up to ~. But if `user' does not exist, leave | |
2113 ~user alone, it might be a literal file name. */ | |
2114 if ((pw = getpwnam (o + 1))) | |
2115 return p; | |
2116 else | |
2117 xfree (pw); | |
2118 } | |
2119 else | |
2120 return p; | |
2121 } | |
2122 } | |
2123 return NULL; | |
2124 } | |
2125 | |
2010 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, | 2126 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, |
2011 Ssubstitute_in_file_name, 1, 1, 0, | 2127 Ssubstitute_in_file_name, 1, 1, 0, |
2012 doc: /* Substitute environment variables referred to in FILENAME. | 2128 doc: /* Substitute environment variables referred to in FILENAME. |
2013 `$FOO' where FOO is an environment variable name means to substitute | 2129 `$FOO' where FOO is an environment variable name means to substitute |
2014 the value of that variable. The variable name should be terminated | 2130 the value of that variable. The variable name should be terminated |
2026 register unsigned char *s, *p, *o, *x, *endp; | 2142 register unsigned char *s, *p, *o, *x, *endp; |
2027 unsigned char *target = NULL; | 2143 unsigned char *target = NULL; |
2028 int total = 0; | 2144 int total = 0; |
2029 int substituted = 0; | 2145 int substituted = 0; |
2030 unsigned char *xnm; | 2146 unsigned char *xnm; |
2031 struct passwd *pw; | |
2032 Lisp_Object handler; | 2147 Lisp_Object handler; |
2033 | 2148 |
2034 CHECK_STRING (filename); | 2149 CHECK_STRING (filename); |
2035 | 2150 |
2036 /* If the file name has special constructs in it, | 2151 /* If the file name has special constructs in it, |
2046 substituted = (strcmp (nm, SDATA (filename)) != 0); | 2161 substituted = (strcmp (nm, SDATA (filename)) != 0); |
2047 #endif | 2162 #endif |
2048 endp = nm + SBYTES (filename); | 2163 endp = nm + SBYTES (filename); |
2049 | 2164 |
2050 /* If /~ or // appears, discard everything through first slash. */ | 2165 /* If /~ or // appears, discard everything through first slash. */ |
2051 | 2166 p = search_embedded_absfilename (nm, endp); |
2052 for (p = nm; p != endp; p++) | 2167 if (p) |
2053 { | 2168 /* Start over with the new string, so we check the file-name-handler |
2054 if ((p[0] == '~' | 2169 again. Important with filenames like "/home/foo//:/hello///there" |
2055 #if defined (APOLLO) || defined (WINDOWSNT) || defined(CYGWIN) | 2170 which whould substitute to "/:/hello///there" rather than "/there". */ |
2056 /* // at start of file name is meaningful in Apollo, | 2171 return Fsubstitute_in_file_name |
2057 WindowsNT and Cygwin systems. */ | 2172 (make_specified_string (p, -1, endp - p, |
2058 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != nm) | 2173 STRING_MULTIBYTE (filename))); |
2059 #else /* not (APOLLO || WINDOWSNT || CYGWIN) */ | 2174 |
2060 || IS_DIRECTORY_SEP (p[0]) | |
2061 #endif /* not (APOLLO || WINDOWSNT || CYGWIN) */ | |
2062 ) | |
2063 && p != nm | |
2064 && (0 | |
2065 #ifdef VMS | 2175 #ifdef VMS |
2066 || p[-1] == ':' || p[-1] == ']' || p[-1] == '>' | 2176 return filename; |
2067 #endif /* VMS */ | |
2068 || IS_DIRECTORY_SEP (p[-1]))) | |
2069 { | |
2070 for (s = p; *s && (!IS_DIRECTORY_SEP (*s) | |
2071 #ifdef VMS | |
2072 && *s != ':' | |
2073 #endif /* VMS */ | |
2074 ); s++); | |
2075 if (p[0] == '~' && s > p + 1) /* we've got "/~something/" */ | |
2076 { | |
2077 o = (unsigned char *) alloca (s - p + 1); | |
2078 bcopy ((char *) p, o, s - p); | |
2079 o [s - p] = 0; | |
2080 | |
2081 pw = (struct passwd *) getpwnam (o + 1); | |
2082 } | |
2083 /* If we have ~/ or ~user and `user' exists, discard | |
2084 everything up to ~. But if `user' does not exist, leave | |
2085 ~user alone, it might be a literal file name. */ | |
2086 if (IS_DIRECTORY_SEP (p[0]) || s == p + 1 || pw) | |
2087 { | |
2088 nm = p; | |
2089 substituted = 1; | |
2090 } | |
2091 } | |
2092 #ifdef DOS_NT | |
2093 /* see comment in expand-file-name about drive specifiers */ | |
2094 else if (IS_DRIVE (p[0]) && p[1] == ':' | |
2095 && p > nm && IS_DIRECTORY_SEP (p[-1])) | |
2096 { | |
2097 nm = p; | |
2098 substituted = 1; | |
2099 } | |
2100 #endif /* DOS_NT */ | |
2101 } | |
2102 | |
2103 #ifdef VMS | |
2104 return build_string (nm); | |
2105 #else | 2177 #else |
2106 | 2178 |
2107 /* See if any variables are substituted into the string | 2179 /* See if any variables are substituted into the string |
2108 and find the total length of their values in `total' */ | 2180 and find the total length of their values in `total' */ |
2109 | 2181 |
2225 } | 2297 } |
2226 | 2298 |
2227 *x = 0; | 2299 *x = 0; |
2228 | 2300 |
2229 /* If /~ or // appears, discard everything through first slash. */ | 2301 /* If /~ or // appears, discard everything through first slash. */ |
2230 | 2302 while ((p = search_embedded_absfilename (xnm, x))) |
2231 for (p = xnm; p != x; p++) | 2303 /* This time we do not start over because we've already expanded envvars |
2232 if ((p[0] == '~' | 2304 and replaced $$ with $. Maybe we should start over as well, but we'd |
2233 #if defined (APOLLO) || defined (WINDOWSNT) || defined(CYGWIN) | 2305 need to quote some $ to $$ first. */ |
2234 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != xnm) | 2306 xnm = p; |
2235 #else /* not (APOLLO || WINDOWSNT || CYGWIN) */ | 2307 |
2236 || IS_DIRECTORY_SEP (p[0]) | 2308 return make_specified_string (xnm, -1, x - xnm, STRING_MULTIBYTE (filename)); |
2237 #endif /* not (APOLLO || WINDOWSNT || CYGWIN) */ | |
2238 ) | |
2239 && p != xnm && IS_DIRECTORY_SEP (p[-1])) | |
2240 xnm = p; | |
2241 #ifdef DOS_NT | |
2242 else if (IS_DRIVE (p[0]) && p[1] == ':' | |
2243 && p > xnm && IS_DIRECTORY_SEP (p[-1])) | |
2244 xnm = p; | |
2245 #endif | |
2246 | |
2247 if (STRING_MULTIBYTE (filename)) | |
2248 return make_string (xnm, x - xnm); | |
2249 return make_unibyte_string (xnm, x - xnm); | |
2250 | 2309 |
2251 badsubst: | 2310 badsubst: |
2252 error ("Bad format environment-variable substitution"); | 2311 error ("Bad format environment-variable substitution"); |
2253 missingclose: | 2312 missingclose: |
2254 error ("Missing \"}\" in environment-variable substitution"); | 2313 error ("Missing \"}\" in environment-variable substitution"); |
2314 | 2373 |
2315 encoded_filename = ENCODE_FILE (absname); | 2374 encoded_filename = ENCODE_FILE (absname); |
2316 | 2375 |
2317 /* stat is a good way to tell whether the file exists, | 2376 /* stat is a good way to tell whether the file exists, |
2318 regardless of what access permissions it has. */ | 2377 regardless of what access permissions it has. */ |
2319 if (stat (SDATA (encoded_filename), &statbuf) >= 0) | 2378 if (lstat (SDATA (encoded_filename), &statbuf) >= 0) |
2320 { | 2379 { |
2321 if (! interactive) | 2380 if (! interactive) |
2322 Fsignal (Qfile_already_exists, | 2381 Fsignal (Qfile_already_exists, |
2323 Fcons (build_string ("File already exists"), | 2382 Fcons (build_string ("File already exists"), |
2324 Fcons (absname, Qnil))); | 2383 Fcons (absname, Qnil))); |
2343 statptr->st_mode = 0; | 2402 statptr->st_mode = 0; |
2344 } | 2403 } |
2345 return; | 2404 return; |
2346 } | 2405 } |
2347 | 2406 |
2348 DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 4, | 2407 DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 6, |
2349 "fCopy file: \nFCopy %s to file: \np\nP", | 2408 "fCopy file: \nGCopy %s to file: \np\nP", |
2350 doc: /* Copy FILE to NEWNAME. Both args must be strings. | 2409 doc: /* Copy FILE to NEWNAME. Both args must be strings. |
2351 If NEWNAME names a directory, copy FILE there. | 2410 If NEWNAME names a directory, copy FILE there. |
2352 Signals a `file-already-exists' error if file NEWNAME already exists, | 2411 Signals a `file-already-exists' error if file NEWNAME already exists, |
2353 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil. | 2412 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil. |
2354 A number as third arg means request confirmation if NEWNAME already exists. | 2413 A number as third arg means request confirmation if NEWNAME already exists. |
2355 This is what happens in interactive use with M-x. | 2414 This is what happens in interactive use with M-x. |
2356 Fourth arg KEEP-TIME non-nil means give the new file the same | 2415 Always sets the file modes of the output file to match the input file. |
2416 | |
2417 Fourth arg KEEP-TIME non-nil means give the output file the same | |
2357 last-modified time as the old one. (This works on only some systems.) | 2418 last-modified time as the old one. (This works on only some systems.) |
2358 A prefix arg makes KEEP-TIME non-nil. */) | 2419 |
2359 (file, newname, ok_if_already_exists, keep_time) | 2420 A prefix arg makes KEEP-TIME non-nil. |
2360 Lisp_Object file, newname, ok_if_already_exists, keep_time; | 2421 |
2422 The optional fifth arg MUSTBENEW, if non-nil, insists on a check | |
2423 for an existing file with the same name. If MUSTBENEW is `excl', | |
2424 that means to get an error if the file already exists; never overwrite. | |
2425 If MUSTBENEW is neither nil nor `excl', that means ask for | |
2426 confirmation before overwriting, but do go ahead and overwrite the file | |
2427 if the user confirms. | |
2428 | |
2429 If PRESERVE-UID-GID is non-nil, we try to transfer the | |
2430 uid and gid of FILE to NEWNAME. */) | |
2431 (file, newname, ok_if_already_exists, keep_time, mustbenew, preserve_uid_gid) | |
2432 Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew; | |
2433 Lisp_Object preserve_uid_gid; | |
2361 { | 2434 { |
2362 int ifd, ofd, n; | 2435 int ifd, ofd, n; |
2363 char buf[16 * 1024]; | 2436 char buf[16 * 1024]; |
2364 struct stat st, out_st; | 2437 struct stat st, out_st; |
2365 Lisp_Object handler; | 2438 Lisp_Object handler; |
2371 encoded_file = encoded_newname = Qnil; | 2444 encoded_file = encoded_newname = Qnil; |
2372 GCPRO4 (file, newname, encoded_file, encoded_newname); | 2445 GCPRO4 (file, newname, encoded_file, encoded_newname); |
2373 CHECK_STRING (file); | 2446 CHECK_STRING (file); |
2374 CHECK_STRING (newname); | 2447 CHECK_STRING (newname); |
2375 | 2448 |
2449 if (!NILP (mustbenew) && !EQ (mustbenew, Qexcl)) | |
2450 barf_or_query_if_file_exists (newname, "overwrite", 1, 0, 1); | |
2451 | |
2376 if (!NILP (Ffile_directory_p (newname))) | 2452 if (!NILP (Ffile_directory_p (newname))) |
2377 newname = Fexpand_file_name (file, newname); | 2453 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname); |
2378 else | 2454 else |
2379 newname = Fexpand_file_name (newname, Qnil); | 2455 newname = Fexpand_file_name (newname, Qnil); |
2380 | 2456 |
2381 file = Fexpand_file_name (file, Qnil); | 2457 file = Fexpand_file_name (file, Qnil); |
2382 | 2458 |
2441 | 2517 |
2442 /* We can only copy regular files and symbolic links. Other files are not | 2518 /* We can only copy regular files and symbolic links. Other files are not |
2443 copyable by us. */ | 2519 copyable by us. */ |
2444 input_file_statable_p = (fstat (ifd, &st) >= 0); | 2520 input_file_statable_p = (fstat (ifd, &st) >= 0); |
2445 | 2521 |
2446 #if !defined (DOS_NT) || __DJGPP__ > 1 | 2522 #if !defined (MSDOS) || __DJGPP__ > 1 |
2447 if (out_st.st_mode != 0 | 2523 if (out_st.st_mode != 0 |
2448 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino) | 2524 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino) |
2449 { | 2525 { |
2450 errno = 0; | 2526 errno = 0; |
2451 report_file_error ("Input and output files are the same", | 2527 report_file_error ("Input and output files are the same", |
2471 /* Create the copy file with the same record format as the input file */ | 2547 /* Create the copy file with the same record format as the input file */ |
2472 ofd = sys_creat (SDATA (encoded_newname), 0666, ifd); | 2548 ofd = sys_creat (SDATA (encoded_newname), 0666, ifd); |
2473 #else | 2549 #else |
2474 #ifdef MSDOS | 2550 #ifdef MSDOS |
2475 /* System's default file type was set to binary by _fmode in emacs.c. */ | 2551 /* System's default file type was set to binary by _fmode in emacs.c. */ |
2476 ofd = creat (SDATA (encoded_newname), S_IREAD | S_IWRITE); | 2552 ofd = emacs_open (SDATA (encoded_newname), |
2477 #else /* not MSDOS */ | 2553 O_WRONLY | O_TRUNC | O_CREAT |
2478 ofd = creat (SDATA (encoded_newname), 0666); | 2554 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0), |
2555 S_IREAD | S_IWRITE); | |
2556 #else /* not MSDOS */ | |
2557 ofd = emacs_open (SDATA (encoded_newname), | |
2558 O_WRONLY | O_TRUNC | O_CREAT | |
2559 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0), | |
2560 0666); | |
2479 #endif /* not MSDOS */ | 2561 #endif /* not MSDOS */ |
2480 #endif /* VMS */ | 2562 #endif /* VMS */ |
2481 if (ofd < 0) | 2563 if (ofd < 0) |
2482 report_file_error ("Opening output file", Fcons (newname, Qnil)); | 2564 report_file_error ("Opening output file", Fcons (newname, Qnil)); |
2483 | 2565 |
2487 QUIT; | 2569 QUIT; |
2488 while ((n = emacs_read (ifd, buf, sizeof buf)) > 0) | 2570 while ((n = emacs_read (ifd, buf, sizeof buf)) > 0) |
2489 if (emacs_write (ofd, buf, n) != n) | 2571 if (emacs_write (ofd, buf, n) != n) |
2490 report_file_error ("I/O error", Fcons (newname, Qnil)); | 2572 report_file_error ("I/O error", Fcons (newname, Qnil)); |
2491 immediate_quit = 0; | 2573 immediate_quit = 0; |
2574 | |
2575 #ifndef MSDOS | |
2576 /* Preserve the original file modes, and if requested, also its | |
2577 owner and group. */ | |
2578 if (input_file_statable_p) | |
2579 { | |
2580 if (! NILP (preserve_uid_gid)) | |
2581 fchown (ofd, st.st_uid, st.st_gid); | |
2582 fchmod (ofd, st.st_mode & 07777); | |
2583 } | |
2584 #endif /* not MSDOS */ | |
2492 | 2585 |
2493 /* Closing the output clobbers the file times on some systems. */ | 2586 /* Closing the output clobbers the file times on some systems. */ |
2494 if (emacs_close (ofd) < 0) | 2587 if (emacs_close (ofd) < 0) |
2495 report_file_error ("I/O error", Fcons (newname, Qnil)); | 2588 report_file_error ("I/O error", Fcons (newname, Qnil)); |
2496 | 2589 |
2505 atime, mtime)) | 2598 atime, mtime)) |
2506 Fsignal (Qfile_date_error, | 2599 Fsignal (Qfile_date_error, |
2507 Fcons (build_string ("Cannot set file date"), | 2600 Fcons (build_string ("Cannot set file date"), |
2508 Fcons (newname, Qnil))); | 2601 Fcons (newname, Qnil))); |
2509 } | 2602 } |
2510 #ifndef MSDOS | 2603 } |
2511 chmod (SDATA (encoded_newname), st.st_mode & 07777); | 2604 |
2512 #else /* MSDOS */ | 2605 emacs_close (ifd); |
2606 | |
2513 #if defined (__DJGPP__) && __DJGPP__ > 1 | 2607 #if defined (__DJGPP__) && __DJGPP__ > 1 |
2608 if (input_file_statable_p) | |
2609 { | |
2514 /* In DJGPP v2.0 and later, fstat usually returns true file mode bits, | 2610 /* In DJGPP v2.0 and later, fstat usually returns true file mode bits, |
2515 and if it can't, it tells so. Otherwise, under MSDOS we usually | 2611 and if it can't, it tells so. Otherwise, under MSDOS we usually |
2516 get only the READ bit, which will make the copied file read-only, | 2612 get only the READ bit, which will make the copied file read-only, |
2517 so it's better not to chmod at all. */ | 2613 so it's better not to chmod at all. */ |
2518 if ((_djstat_flags & _STFAIL_WRITEBIT) == 0) | 2614 if ((_djstat_flags & _STFAIL_WRITEBIT) == 0) |
2519 chmod (SDATA (encoded_newname), st.st_mode & 07777); | 2615 chmod (SDATA (encoded_newname), st.st_mode & 07777); |
2616 } | |
2520 #endif /* DJGPP version 2 or newer */ | 2617 #endif /* DJGPP version 2 or newer */ |
2521 #endif /* MSDOS */ | 2618 #endif /* not WINDOWSNT */ |
2522 } | |
2523 | |
2524 emacs_close (ifd); | |
2525 #endif /* WINDOWSNT */ | |
2526 | 2619 |
2527 /* Discard the unwind protects. */ | 2620 /* Discard the unwind protects. */ |
2528 specpdl_ptr = specpdl + count; | 2621 specpdl_ptr = specpdl + count; |
2529 | 2622 |
2530 UNGCPRO; | 2623 UNGCPRO; |
2597 Lisp_Object handler; | 2690 Lisp_Object handler; |
2598 Lisp_Object encoded_file; | 2691 Lisp_Object encoded_file; |
2599 struct gcpro gcpro1; | 2692 struct gcpro gcpro1; |
2600 | 2693 |
2601 GCPRO1 (filename); | 2694 GCPRO1 (filename); |
2602 if (!NILP (Ffile_directory_p (filename))) | 2695 if (!NILP (Ffile_directory_p (filename)) |
2696 && NILP (Ffile_symlink_p (filename))) | |
2603 Fsignal (Qfile_error, | 2697 Fsignal (Qfile_error, |
2604 Fcons (build_string ("Removing old name: is a directory"), | 2698 Fcons (build_string ("Removing old name: is a directory"), |
2605 Fcons (filename, Qnil))); | 2699 Fcons (filename, Qnil))); |
2606 UNGCPRO; | 2700 UNGCPRO; |
2607 filename = Fexpand_file_name (filename, Qnil); | 2701 filename = Fexpand_file_name (filename, Qnil); |
2628 | 2722 |
2629 int | 2723 int |
2630 internal_delete_file (filename) | 2724 internal_delete_file (filename) |
2631 Lisp_Object filename; | 2725 Lisp_Object filename; |
2632 { | 2726 { |
2633 return NILP (internal_condition_case_1 (Fdelete_file, filename, | 2727 Lisp_Object tem; |
2634 Qt, internal_delete_file_1)); | 2728 tem = internal_condition_case_1 (Fdelete_file, filename, |
2729 Qt, internal_delete_file_1); | |
2730 return NILP (tem); | |
2635 } | 2731 } |
2636 | 2732 |
2637 DEFUN ("rename-file", Frename_file, Srename_file, 2, 3, | 2733 DEFUN ("rename-file", Frename_file, Srename_file, 2, 3, |
2638 "fRename file: \nFRename %s to file: \np", | 2734 "fRename file: \nGRename %s to file: \np", |
2639 doc: /* Rename FILE as NEWNAME. Both args strings. | 2735 doc: /* Rename FILE as NEWNAME. Both args must be strings. |
2640 If file has names other than FILE, it continues to have those names. | 2736 If file has names other than FILE, it continues to have those names. |
2641 Signals a `file-already-exists' error if a file NEWNAME already exists | 2737 Signals a `file-already-exists' error if a file NEWNAME already exists |
2642 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | 2738 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. |
2643 A number as third arg means request confirmation if NEWNAME already exists. | 2739 A number as third arg means request confirmation if NEWNAME already exists. |
2644 This is what happens in interactive use with M-x. */) | 2740 This is what happens in interactive use with M-x. */) |
2647 { | 2743 { |
2648 #ifdef NO_ARG_ARRAY | 2744 #ifdef NO_ARG_ARRAY |
2649 Lisp_Object args[2]; | 2745 Lisp_Object args[2]; |
2650 #endif | 2746 #endif |
2651 Lisp_Object handler; | 2747 Lisp_Object handler; |
2652 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 2748 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
2653 Lisp_Object encoded_file, encoded_newname; | 2749 Lisp_Object encoded_file, encoded_newname, symlink_target; |
2654 | 2750 |
2655 encoded_file = encoded_newname = Qnil; | 2751 symlink_target = encoded_file = encoded_newname = Qnil; |
2656 GCPRO4 (file, newname, encoded_file, encoded_newname); | 2752 GCPRO5 (file, newname, encoded_file, encoded_newname, symlink_target); |
2657 CHECK_STRING (file); | 2753 CHECK_STRING (file); |
2658 CHECK_STRING (newname); | 2754 CHECK_STRING (newname); |
2659 file = Fexpand_file_name (file, Qnil); | 2755 file = Fexpand_file_name (file, Qnil); |
2660 newname = Fexpand_file_name (newname, Qnil); | 2756 |
2757 if (!NILP (Ffile_directory_p (newname))) | |
2758 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname); | |
2759 else | |
2760 newname = Fexpand_file_name (newname, Qnil); | |
2661 | 2761 |
2662 /* If the file name has special constructs in it, | 2762 /* If the file name has special constructs in it, |
2663 call the corresponding file handler. */ | 2763 call the corresponding file handler. */ |
2664 handler = Ffind_file_name_handler (file, Qrename_file); | 2764 handler = Ffind_file_name_handler (file, Qrename_file); |
2665 if (NILP (handler)) | 2765 if (NILP (handler)) |
2688 || 0 > unlink (SDATA (encoded_file))) | 2788 || 0 > unlink (SDATA (encoded_file))) |
2689 #endif | 2789 #endif |
2690 { | 2790 { |
2691 if (errno == EXDEV) | 2791 if (errno == EXDEV) |
2692 { | 2792 { |
2693 Fcopy_file (file, newname, | 2793 #ifdef S_IFLNK |
2694 /* We have already prompted if it was an integer, | 2794 symlink_target = Ffile_symlink_p (file); |
2695 so don't have copy-file prompt again. */ | 2795 if (! NILP (symlink_target)) |
2696 NILP (ok_if_already_exists) ? Qnil : Qt, Qt); | 2796 Fmake_symbolic_link (symlink_target, newname, |
2797 NILP (ok_if_already_exists) ? Qnil : Qt); | |
2798 else | |
2799 #endif | |
2800 Fcopy_file (file, newname, | |
2801 /* We have already prompted if it was an integer, | |
2802 so don't have copy-file prompt again. */ | |
2803 NILP (ok_if_already_exists) ? Qnil : Qt, | |
2804 Qt, Qnil, Qt); | |
2805 | |
2697 Fdelete_file (file); | 2806 Fdelete_file (file); |
2698 } | 2807 } |
2699 else | 2808 else |
2700 #ifdef NO_ARG_ARRAY | 2809 #ifdef NO_ARG_ARRAY |
2701 { | 2810 { |
2710 UNGCPRO; | 2819 UNGCPRO; |
2711 return Qnil; | 2820 return Qnil; |
2712 } | 2821 } |
2713 | 2822 |
2714 DEFUN ("add-name-to-file", Fadd_name_to_file, Sadd_name_to_file, 2, 3, | 2823 DEFUN ("add-name-to-file", Fadd_name_to_file, Sadd_name_to_file, 2, 3, |
2715 "fAdd name to file: \nFName to add to %s: \np", | 2824 "fAdd name to file: \nGName to add to %s: \np", |
2716 doc: /* Give FILE additional name NEWNAME. Both args strings. | 2825 doc: /* Give FILE additional name NEWNAME. Both args must be strings. |
2717 Signals a `file-already-exists' error if a file NEWNAME already exists | 2826 Signals a `file-already-exists' error if a file NEWNAME already exists |
2718 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | 2827 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. |
2719 A number as third arg means request confirmation if NEWNAME already exists. | 2828 A number as third arg means request confirmation if NEWNAME already exists. |
2720 This is what happens in interactive use with M-x. */) | 2829 This is what happens in interactive use with M-x. */) |
2721 (file, newname, ok_if_already_exists) | 2830 (file, newname, ok_if_already_exists) |
2731 GCPRO4 (file, newname, encoded_file, encoded_newname); | 2840 GCPRO4 (file, newname, encoded_file, encoded_newname); |
2732 encoded_file = encoded_newname = Qnil; | 2841 encoded_file = encoded_newname = Qnil; |
2733 CHECK_STRING (file); | 2842 CHECK_STRING (file); |
2734 CHECK_STRING (newname); | 2843 CHECK_STRING (newname); |
2735 file = Fexpand_file_name (file, Qnil); | 2844 file = Fexpand_file_name (file, Qnil); |
2736 newname = Fexpand_file_name (newname, Qnil); | 2845 |
2846 if (!NILP (Ffile_directory_p (newname))) | |
2847 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname); | |
2848 else | |
2849 newname = Fexpand_file_name (newname, Qnil); | |
2737 | 2850 |
2738 /* If the file name has special constructs in it, | 2851 /* If the file name has special constructs in it, |
2739 call the corresponding file handler. */ | 2852 call the corresponding file handler. */ |
2740 handler = Ffind_file_name_handler (file, Qadd_name_to_file); | 2853 handler = Ffind_file_name_handler (file, Qadd_name_to_file); |
2741 if (!NILP (handler)) | 2854 if (!NILP (handler)) |
2773 return Qnil; | 2886 return Qnil; |
2774 } | 2887 } |
2775 | 2888 |
2776 #ifdef S_IFLNK | 2889 #ifdef S_IFLNK |
2777 DEFUN ("make-symbolic-link", Fmake_symbolic_link, Smake_symbolic_link, 2, 3, | 2890 DEFUN ("make-symbolic-link", Fmake_symbolic_link, Smake_symbolic_link, 2, 3, |
2778 "FMake symbolic link to file: \nFMake symbolic link to file %s: \np", | 2891 "FMake symbolic link to file: \nGMake symbolic link to file %s: \np", |
2779 doc: /* Make a symbolic link to FILENAME, named LINKNAME. Both args strings. | 2892 doc: /* Make a symbolic link to FILENAME, named LINKNAME. |
2893 Both args must be strings. | |
2780 Signals a `file-already-exists' error if a file LINKNAME already exists | 2894 Signals a `file-already-exists' error if a file LINKNAME already exists |
2781 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | 2895 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. |
2782 A number as third arg means request confirmation if LINKNAME already exists. | 2896 A number as third arg means request confirmation if LINKNAME already exists. |
2783 This happens for interactive use with M-x. */) | 2897 This happens for interactive use with M-x. */) |
2784 (filename, linkname, ok_if_already_exists) | 2898 (filename, linkname, ok_if_already_exists) |
2798 /* If the link target has a ~, we must expand it to get | 2912 /* If the link target has a ~, we must expand it to get |
2799 a truly valid file name. Otherwise, do not expand; | 2913 a truly valid file name. Otherwise, do not expand; |
2800 we want to permit links to relative file names. */ | 2914 we want to permit links to relative file names. */ |
2801 if (SREF (filename, 0) == '~') | 2915 if (SREF (filename, 0) == '~') |
2802 filename = Fexpand_file_name (filename, Qnil); | 2916 filename = Fexpand_file_name (filename, Qnil); |
2803 linkname = Fexpand_file_name (linkname, Qnil); | 2917 |
2918 if (!NILP (Ffile_directory_p (linkname))) | |
2919 linkname = Fexpand_file_name (Ffile_name_nondirectory (filename), linkname); | |
2920 else | |
2921 linkname = Fexpand_file_name (linkname, Qnil); | |
2804 | 2922 |
2805 /* If the file name has special constructs in it, | 2923 /* If the file name has special constructs in it, |
2806 call the corresponding file handler. */ | 2924 call the corresponding file handler. */ |
2807 handler = Ffind_file_name_handler (filename, Qmake_symbolic_link); | 2925 handler = Ffind_file_name_handler (filename, Qmake_symbolic_link); |
2808 if (!NILP (handler)) | 2926 if (!NILP (handler)) |
2904 doc: /* Return t if file FILENAME specifies an absolute file name. | 3022 doc: /* Return t if file FILENAME specifies an absolute file name. |
2905 On Unix, this is a name starting with a `/' or a `~'. */) | 3023 On Unix, this is a name starting with a `/' or a `~'. */) |
2906 (filename) | 3024 (filename) |
2907 Lisp_Object filename; | 3025 Lisp_Object filename; |
2908 { | 3026 { |
2909 const unsigned char *ptr; | |
2910 | |
2911 CHECK_STRING (filename); | 3027 CHECK_STRING (filename); |
2912 ptr = SDATA (filename); | 3028 return file_name_absolute_p (SDATA (filename)) ? Qt : Qnil; |
2913 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~' | |
2914 #ifdef VMS | |
2915 /* ??? This criterion is probably wrong for '<'. */ | |
2916 || index (ptr, ':') || index (ptr, '<') | |
2917 || (*ptr == '[' && (ptr[1] != '-' || (ptr[2] != '.' && ptr[2] != ']')) | |
2918 && ptr[1] != '.') | |
2919 #endif /* VMS */ | |
2920 #ifdef DOS_NT | |
2921 || (IS_DRIVE (*ptr) && ptr[1] == ':' && IS_DIRECTORY_SEP (ptr[2])) | |
2922 #endif | |
2923 ) | |
2924 return Qt; | |
2925 else | |
2926 return Qnil; | |
2927 } | 3029 } |
2928 | 3030 |
2929 /* Return nonzero if file FILENAME exists and can be executed. */ | 3031 /* Return nonzero if file FILENAME exists and can be executed. */ |
2930 | 3032 |
2931 static int | 3033 static int |
2984 #endif | 3086 #endif |
2985 #endif /* not MSDOS */ | 3087 #endif /* not MSDOS */ |
2986 } | 3088 } |
2987 | 3089 |
2988 DEFUN ("file-exists-p", Ffile_exists_p, Sfile_exists_p, 1, 1, 0, | 3090 DEFUN ("file-exists-p", Ffile_exists_p, Sfile_exists_p, 1, 1, 0, |
2989 doc: /* Return t if file FILENAME exists. (This does not mean you can read it.) | 3091 doc: /* Return t if file FILENAME exists (whether or not you can read it.) |
2990 See also `file-readable-p' and `file-attributes'. */) | 3092 See also `file-readable-p' and `file-attributes'. |
3093 This returns nil for a symlink to a nonexistent file. | |
3094 Use `file-symlink-p' to test for such links. */) | |
2991 (filename) | 3095 (filename) |
2992 Lisp_Object filename; | 3096 Lisp_Object filename; |
2993 { | 3097 { |
2994 Lisp_Object absname; | 3098 Lisp_Object absname; |
2995 Lisp_Object handler; | 3099 Lisp_Object handler; |
3131 } | 3235 } |
3132 | 3236 |
3133 DEFUN ("access-file", Faccess_file, Saccess_file, 2, 2, 0, | 3237 DEFUN ("access-file", Faccess_file, Saccess_file, 2, 2, 0, |
3134 doc: /* Access file FILENAME, and get an error if that does not work. | 3238 doc: /* Access file FILENAME, and get an error if that does not work. |
3135 The second argument STRING is used in the error message. | 3239 The second argument STRING is used in the error message. |
3136 If there is no error, we return nil. */) | 3240 If there is no error, returns nil. */) |
3137 (filename, string) | 3241 (filename, string) |
3138 Lisp_Object filename, string; | 3242 Lisp_Object filename, string; |
3139 { | 3243 { |
3140 Lisp_Object handler, encoded_filename, absname; | 3244 Lisp_Object handler, encoded_filename, absname; |
3141 int fd; | 3245 int fd; |
3161 return Qnil; | 3265 return Qnil; |
3162 } | 3266 } |
3163 | 3267 |
3164 DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0, | 3268 DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0, |
3165 doc: /* Return non-nil if file FILENAME is the name of a symbolic link. | 3269 doc: /* Return non-nil if file FILENAME is the name of a symbolic link. |
3166 The value is the name of the file to which it is linked. | 3270 The value is the link target, as a string. |
3167 Otherwise returns nil. */) | 3271 Otherwise it returns nil. |
3272 | |
3273 This function returns t when given the name of a symlink that | |
3274 points to a nonexistent file. */) | |
3168 (filename) | 3275 (filename) |
3169 Lisp_Object filename; | 3276 Lisp_Object filename; |
3170 { | 3277 { |
3171 #ifdef S_IFLNK | |
3172 char *buf; | |
3173 int bufsize; | |
3174 int valsize; | |
3175 Lisp_Object val; | |
3176 Lisp_Object handler; | 3278 Lisp_Object handler; |
3177 | 3279 |
3178 CHECK_STRING (filename); | 3280 CHECK_STRING (filename); |
3179 filename = Fexpand_file_name (filename, Qnil); | 3281 filename = Fexpand_file_name (filename, Qnil); |
3180 | 3282 |
3181 /* If the file name has special constructs in it, | 3283 /* If the file name has special constructs in it, |
3182 call the corresponding file handler. */ | 3284 call the corresponding file handler. */ |
3183 handler = Ffind_file_name_handler (filename, Qfile_symlink_p); | 3285 handler = Ffind_file_name_handler (filename, Qfile_symlink_p); |
3184 if (!NILP (handler)) | 3286 if (!NILP (handler)) |
3185 return call2 (handler, Qfile_symlink_p, filename); | 3287 return call2 (handler, Qfile_symlink_p, filename); |
3288 | |
3289 #ifdef S_IFLNK | |
3290 { | |
3291 char *buf; | |
3292 int bufsize; | |
3293 int valsize; | |
3294 Lisp_Object val; | |
3186 | 3295 |
3187 filename = ENCODE_FILE (filename); | 3296 filename = ENCODE_FILE (filename); |
3188 | 3297 |
3189 bufsize = 50; | 3298 bufsize = 50; |
3190 buf = NULL; | 3299 buf = NULL; |
3216 if (buf[0] == '/' && index (buf, ':')) | 3325 if (buf[0] == '/' && index (buf, ':')) |
3217 val = concat2 (build_string ("/:"), val); | 3326 val = concat2 (build_string ("/:"), val); |
3218 xfree (buf); | 3327 xfree (buf); |
3219 val = DECODE_FILE (val); | 3328 val = DECODE_FILE (val); |
3220 return val; | 3329 return val; |
3330 } | |
3221 #else /* not S_IFLNK */ | 3331 #else /* not S_IFLNK */ |
3222 return Qnil; | 3332 return Qnil; |
3223 #endif /* not S_IFLNK */ | 3333 #endif /* not S_IFLNK */ |
3224 } | 3334 } |
3225 | 3335 |
3276 UNGCPRO; | 3386 UNGCPRO; |
3277 return tem ? Qnil : Qt; | 3387 return tem ? Qnil : Qt; |
3278 } | 3388 } |
3279 | 3389 |
3280 DEFUN ("file-regular-p", Ffile_regular_p, Sfile_regular_p, 1, 1, 0, | 3390 DEFUN ("file-regular-p", Ffile_regular_p, Sfile_regular_p, 1, 1, 0, |
3281 doc: /* Return t if file FILENAME is the name of a regular file. | 3391 doc: /* Return t if FILENAME names a regular file. |
3282 This is the sort of file that holds an ordinary stream of data bytes. */) | 3392 This is the sort of file that holds an ordinary stream of data bytes. |
3393 Symbolic links to regular files count as regular files. | |
3394 See `file-symlink-p' to distinguish symlinks. */) | |
3283 (filename) | 3395 (filename) |
3284 Lisp_Object filename; | 3396 Lisp_Object filename; |
3285 { | 3397 { |
3286 register Lisp_Object absname; | 3398 register Lisp_Object absname; |
3287 struct stat st; | 3399 struct stat st; |
3317 return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; | 3429 return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; |
3318 #endif | 3430 #endif |
3319 } | 3431 } |
3320 | 3432 |
3321 DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0, | 3433 DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0, |
3322 doc: /* Return mode bits of file named FILENAME, as an integer. */) | 3434 doc: /* Return mode bits of file named FILENAME, as an integer. |
3435 Return nil, if file does not exist or is not accessible. */) | |
3323 (filename) | 3436 (filename) |
3324 Lisp_Object filename; | 3437 Lisp_Object filename; |
3325 { | 3438 { |
3326 Lisp_Object absname; | 3439 Lisp_Object absname; |
3327 struct stat st; | 3440 struct stat st; |
3399 umask (realmask); | 3512 umask (realmask); |
3400 | 3513 |
3401 XSETINT (value, (~ realmask) & 0777); | 3514 XSETINT (value, (~ realmask) & 0777); |
3402 return value; | 3515 return value; |
3403 } | 3516 } |
3404 | 3517 |
3518 extern int lisp_time_argument P_ ((Lisp_Object, time_t *, int *)); | |
3519 | |
3520 DEFUN ("set-file-times", Fset_file_times, Sset_file_times, 1, 2, 0, | |
3521 doc: /* Set times of file FILENAME to TIME. | |
3522 Set both access and modification times. | |
3523 Return t on success, else nil. | |
3524 Use the current time if TIME is nil. TIME is in the format of | |
3525 `current-time'. */) | |
3526 (filename, time) | |
3527 Lisp_Object filename, time; | |
3528 { | |
3529 Lisp_Object absname, encoded_absname; | |
3530 Lisp_Object handler; | |
3531 time_t sec; | |
3532 int usec; | |
3533 | |
3534 if (! lisp_time_argument (time, &sec, &usec)) | |
3535 error ("Invalid time specification"); | |
3536 | |
3537 absname = Fexpand_file_name (filename, current_buffer->directory); | |
3538 | |
3539 /* If the file name has special constructs in it, | |
3540 call the corresponding file handler. */ | |
3541 handler = Ffind_file_name_handler (absname, Qset_file_times); | |
3542 if (!NILP (handler)) | |
3543 return call3 (handler, Qset_file_times, absname, time); | |
3544 | |
3545 encoded_absname = ENCODE_FILE (absname); | |
3546 | |
3547 { | |
3548 EMACS_TIME t; | |
3549 | |
3550 EMACS_SET_SECS (t, sec); | |
3551 EMACS_SET_USECS (t, usec); | |
3552 | |
3553 if (set_file_times (SDATA (encoded_absname), t, t)) | |
3554 { | |
3555 #ifdef DOS_NT | |
3556 struct stat st; | |
3557 | |
3558 /* Setting times on a directory always fails. */ | |
3559 if (stat (SDATA (encoded_absname), &st) == 0 | |
3560 && (st.st_mode & S_IFMT) == S_IFDIR) | |
3561 return Qnil; | |
3562 #endif | |
3563 report_file_error ("Setting file times", Fcons (absname, Qnil)); | |
3564 return Qnil; | |
3565 } | |
3566 } | |
3567 | |
3568 return Qt; | |
3569 } | |
3405 | 3570 |
3406 #ifdef __NetBSD__ | 3571 #ifdef __NetBSD__ |
3407 #define unix 42 | 3572 #define unix 42 |
3408 #endif | 3573 #endif |
3409 | 3574 |
3553 | 3718 |
3554 | 3719 |
3555 DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, | 3720 DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, |
3556 1, 5, 0, | 3721 1, 5, 0, |
3557 doc: /* Insert contents of file FILENAME after point. | 3722 doc: /* Insert contents of file FILENAME after point. |
3558 Returns list of absolute file name and number of bytes inserted. | 3723 Returns list of absolute file name and number of characters inserted. |
3559 If second argument VISIT is non-nil, the buffer's visited filename | 3724 If second argument VISIT is non-nil, the buffer's visited filename |
3560 and last save file modtime are set, and it is marked unmodified. | 3725 and last save file modtime are set, and it is marked unmodified. |
3561 If visiting and the file does not exist, visiting is completed | 3726 If visiting and the file does not exist, visiting is completed |
3562 before the error is signaled. | 3727 before the error is signaled. |
3563 The optional third and fourth arguments BEG and END | 3728 The optional third and fourth arguments BEG and END |
3596 unsigned char buffer[1 << 14]; | 3761 unsigned char buffer[1 << 14]; |
3597 int replace_handled = 0; | 3762 int replace_handled = 0; |
3598 int set_coding_system = 0; | 3763 int set_coding_system = 0; |
3599 int coding_system_decided = 0; | 3764 int coding_system_decided = 0; |
3600 int read_quit = 0; | 3765 int read_quit = 0; |
3766 Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark; | |
3767 int we_locked_file = 0; | |
3601 | 3768 |
3602 if (current_buffer->base_buffer && ! NILP (visit)) | 3769 if (current_buffer->base_buffer && ! NILP (visit)) |
3603 error ("Cannot do file visiting in an indirect buffer"); | 3770 error ("Cannot do file visiting in an indirect buffer"); |
3604 | 3771 |
3605 if (!NILP (current_buffer->read_only)) | 3772 if (!NILP (current_buffer->read_only)) |
3734 if (st.st_size == 0) | 3901 if (st.st_size == 0) |
3735 XSETINT (end, READ_BUF_SIZE); | 3902 XSETINT (end, READ_BUF_SIZE); |
3736 } | 3903 } |
3737 } | 3904 } |
3738 | 3905 |
3739 if (BEG < Z) | 3906 if (EQ (Vcoding_system_for_read, Qauto_save_coding)) |
3907 { | |
3908 /* We use emacs-mule for auto saving... */ | |
3909 setup_coding_system (Qemacs_mule, &coding); | |
3910 /* ... but with the special flag to indicate to read in a | |
3911 multibyte sequence for eight-bit-control char as is. */ | |
3912 coding.flags = 1; | |
3913 coding.src_multibyte = 0; | |
3914 coding.dst_multibyte | |
3915 = !NILP (current_buffer->enable_multibyte_characters); | |
3916 coding.eol_type = CODING_EOL_LF; | |
3917 coding_system_decided = 1; | |
3918 } | |
3919 else if (BEG < Z) | |
3740 { | 3920 { |
3741 /* Decide the coding system to use for reading the file now | 3921 /* Decide the coding system to use for reading the file now |
3742 because we can't use an optimized method for handling | 3922 because we can't use an optimized method for handling |
3743 `coding:' tag if the current buffer is not empty. */ | 3923 `coding:' tag if the current buffer is not empty. */ |
3744 Lisp_Object val; | 3924 Lisp_Object val; |
3745 val = Qnil; | 3925 val = Qnil; |
3746 | 3926 |
3747 if (!NILP (Vcoding_system_for_read)) | 3927 if (!NILP (Vcoding_system_for_read)) |
3748 val = Vcoding_system_for_read; | 3928 val = Vcoding_system_for_read; |
3749 else if (! NILP (replace)) | |
3750 /* In REPLACE mode, we can use the same coding system | |
3751 that was used to visit the file. */ | |
3752 val = current_buffer->buffer_file_coding_system; | |
3753 else | 3929 else |
3754 { | 3930 { |
3755 /* Don't try looking inside a file for a coding system | 3931 /* Don't try looking inside a file for a coding system |
3756 specification if it is not seekable. */ | 3932 specification if it is not seekable. */ |
3757 if (! not_regular && ! NILP (Vset_auto_coding_function)) | 3933 if (! not_regular && ! NILP (Vset_auto_coding_function)) |
3789 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | 3965 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); |
3790 | 3966 |
3791 buffer = Fget_buffer_create (build_string (" *code-converting-work*")); | 3967 buffer = Fget_buffer_create (build_string (" *code-converting-work*")); |
3792 buf = XBUFFER (buffer); | 3968 buf = XBUFFER (buffer); |
3793 | 3969 |
3970 delete_all_overlays (buf); | |
3794 buf->directory = current_buffer->directory; | 3971 buf->directory = current_buffer->directory; |
3795 buf->read_only = Qnil; | 3972 buf->read_only = Qnil; |
3796 buf->filename = Qnil; | 3973 buf->filename = Qnil; |
3797 buf->undo_list = Qt; | 3974 buf->undo_list = Qt; |
3798 buf->overlays_before = Qnil; | 3975 eassert (buf->overlays_before == NULL); |
3799 buf->overlays_after = Qnil; | 3976 eassert (buf->overlays_after == NULL); |
3800 | 3977 |
3801 set_buffer_internal (buf); | 3978 set_buffer_internal (buf); |
3802 Ferase_buffer (); | 3979 Ferase_buffer (); |
3803 buf->enable_multibyte_characters = Qnil; | 3980 buf->enable_multibyte_characters = Qnil; |
3804 | 3981 |
4145 or should be <= 0 if we couldn't read the file. */ | 4322 or should be <= 0 if we couldn't read the file. */ |
4146 | 4323 |
4147 if (how_much < 0) | 4324 if (how_much < 0) |
4148 { | 4325 { |
4149 xfree (conversion_buffer); | 4326 xfree (conversion_buffer); |
4150 | 4327 coding_free_composition_data (&coding); |
4151 if (how_much == -1) | 4328 if (how_much == -1) |
4152 error ("IO error reading %s: %s", | 4329 error ("IO error reading %s: %s", |
4153 SDATA (orig_filename), emacs_strerror (errno)); | 4330 SDATA (orig_filename), emacs_strerror (errno)); |
4154 else if (how_much == -2) | 4331 else if (how_much == -2) |
4155 error ("maximum buffer size exceeded"); | 4332 error ("maximum buffer size exceeded"); |
4167 there's no need to replace anything. */ | 4344 there's no need to replace anything. */ |
4168 | 4345 |
4169 if (bufpos == inserted) | 4346 if (bufpos == inserted) |
4170 { | 4347 { |
4171 xfree (conversion_buffer); | 4348 xfree (conversion_buffer); |
4349 coding_free_composition_data (&coding); | |
4172 emacs_close (fd); | 4350 emacs_close (fd); |
4173 specpdl_ptr--; | 4351 specpdl_ptr--; |
4174 /* Truncate the buffer to the size of the file. */ | 4352 /* Truncate the buffer to the size of the file. */ |
4175 del_range_byte (same_at_start, same_at_end, 0); | 4353 del_range_byte (same_at_start, same_at_end, 0); |
4176 inserted = 0; | 4354 inserted = 0; |
4212 XWINDOW (selected_window)->start_at_line_beg = Fbolp (); | 4390 XWINDOW (selected_window)->start_at_line_beg = Fbolp (); |
4213 | 4391 |
4214 /* Replace the chars that we need to replace, | 4392 /* Replace the chars that we need to replace, |
4215 and update INSERTED to equal the number of bytes | 4393 and update INSERTED to equal the number of bytes |
4216 we are taking from the file. */ | 4394 we are taking from the file. */ |
4217 inserted -= (Z_BYTE - same_at_end) + (same_at_start - BEG_BYTE); | 4395 inserted -= (ZV_BYTE - same_at_end) + (same_at_start - BEGV_BYTE); |
4218 | 4396 |
4219 if (same_at_end != same_at_start) | 4397 if (same_at_end != same_at_start) |
4220 { | 4398 { |
4221 del_range_byte (same_at_start, same_at_end, 0); | 4399 del_range_byte (same_at_start, same_at_end, 0); |
4222 temp = GPT; | 4400 temp = GPT; |
4226 { | 4404 { |
4227 temp = BYTE_TO_CHAR (same_at_start); | 4405 temp = BYTE_TO_CHAR (same_at_start); |
4228 } | 4406 } |
4229 /* Insert from the file at the proper position. */ | 4407 /* Insert from the file at the proper position. */ |
4230 SET_PT_BOTH (temp, same_at_start); | 4408 SET_PT_BOTH (temp, same_at_start); |
4231 insert_1 (conversion_buffer + same_at_start - BEG_BYTE, inserted, | 4409 insert_1 (conversion_buffer + same_at_start - BEGV_BYTE, inserted, |
4232 0, 0, 0); | 4410 0, 0, 0); |
4233 if (coding.cmp_data && coding.cmp_data->used) | 4411 if (coding.cmp_data && coding.cmp_data->used) |
4234 coding_restore_composition (&coding, Fcurrent_buffer ()); | 4412 coding_restore_composition (&coding, Fcurrent_buffer ()); |
4235 coding_free_composition_data (&coding); | 4413 coding_free_composition_data (&coding); |
4236 | 4414 |
4257 } | 4435 } |
4258 else | 4436 else |
4259 /* For a special file, all we can do is guess. */ | 4437 /* For a special file, all we can do is guess. */ |
4260 total = READ_BUF_SIZE; | 4438 total = READ_BUF_SIZE; |
4261 | 4439 |
4262 if (NILP (visit) && total > 0) | 4440 if (NILP (visit) && inserted > 0) |
4263 prepare_to_modify_buffer (PT, PT, NULL); | 4441 { |
4442 #ifdef CLASH_DETECTION | |
4443 if (!NILP (current_buffer->file_truename) | |
4444 /* Make binding buffer-file-name to nil effective. */ | |
4445 && !NILP (current_buffer->filename) | |
4446 && SAVE_MODIFF >= MODIFF) | |
4447 we_locked_file = 1; | |
4448 #endif /* CLASH_DETECTION */ | |
4449 prepare_to_modify_buffer (GPT, GPT, NULL); | |
4450 } | |
4264 | 4451 |
4265 move_gap (PT); | 4452 move_gap (PT); |
4266 if (GAP_SIZE < total) | 4453 if (GAP_SIZE < total) |
4267 make_gap (total - GAP_SIZE); | 4454 make_gap (total - GAP_SIZE); |
4268 | 4455 |
4348 how_much += this; | 4535 how_much += this; |
4349 inserted += this; | 4536 inserted += this; |
4350 } | 4537 } |
4351 } | 4538 } |
4352 | 4539 |
4540 /* Now we have read all the file data into the gap. | |
4541 If it was empty, undo marking the buffer modified. */ | |
4542 | |
4543 if (inserted == 0) | |
4544 { | |
4545 #ifdef CLASH_DETECTION | |
4546 if (we_locked_file) | |
4547 unlock_file (current_buffer->file_truename); | |
4548 #endif | |
4549 Vdeactivate_mark = old_Vdeactivate_mark; | |
4550 } | |
4551 else | |
4552 Vdeactivate_mark = Qt; | |
4553 | |
4353 /* Make the text read part of the buffer. */ | 4554 /* Make the text read part of the buffer. */ |
4354 GAP_SIZE -= inserted; | 4555 GAP_SIZE -= inserted; |
4355 GPT += inserted; | 4556 GPT += inserted; |
4356 GPT_BYTE += inserted; | 4557 GPT_BYTE += inserted; |
4357 ZV += inserted; | 4558 ZV += inserted; |
4393 enable-multibyte-characters directly here without taking | 4594 enable-multibyte-characters directly here without taking |
4394 care of marker adjustment and byte combining problem. By | 4595 care of marker adjustment and byte combining problem. By |
4395 this way, we can run Lisp program safely before decoding | 4596 this way, we can run Lisp program safely before decoding |
4396 the inserted text. */ | 4597 the inserted text. */ |
4397 Lisp_Object unwind_data; | 4598 Lisp_Object unwind_data; |
4398 int count = SPECPDL_INDEX (); | 4599 int count = SPECPDL_INDEX (); |
4399 | 4600 |
4400 unwind_data = Fcons (current_buffer->enable_multibyte_characters, | 4601 unwind_data = Fcons (current_buffer->enable_multibyte_characters, |
4401 Fcons (current_buffer->undo_list, | 4602 Fcons (current_buffer->undo_list, |
4402 Fcurrent_buffer ())); | 4603 Fcurrent_buffer ())); |
4403 current_buffer->enable_multibyte_characters = Qnil; | 4604 current_buffer->enable_multibyte_characters = Qnil; |
4404 current_buffer->undo_list = Qt; | 4605 current_buffer->undo_list = Qt; |
4405 record_unwind_protect (decide_coding_unwind, unwind_data); | 4606 record_unwind_protect (decide_coding_unwind, unwind_data); |
4406 | 4607 |
4407 if (inserted > 0 && ! NILP (Vset_auto_coding_function)) | 4608 if (inserted > 0 && ! NILP (Vset_auto_coding_function)) |
4408 { | 4609 { |
4420 args[2] = visit, args[3] = beg, args[4] = end, args[5] = Qnil; | 4621 args[2] = visit, args[3] = beg, args[4] = end, args[5] = Qnil; |
4421 coding_systems = Ffind_operation_coding_system (6, args); | 4622 coding_systems = Ffind_operation_coding_system (6, args); |
4422 if (CONSP (coding_systems)) | 4623 if (CONSP (coding_systems)) |
4423 val = XCAR (coding_systems); | 4624 val = XCAR (coding_systems); |
4424 } | 4625 } |
4425 | |
4426 unbind_to (count, Qnil); | 4626 unbind_to (count, Qnil); |
4427 inserted = Z_BYTE - BEG_BYTE; | 4627 inserted = Z_BYTE - BEG_BYTE; |
4428 } | 4628 } |
4429 | 4629 |
4430 /* The following kludgy code is to avoid some compiler bug. | 4630 /* The following kludgy code is to avoid some compiler bug. |
4431 We can't simply do | 4631 We can't simply do |
4432 setup_coding_system (val, &coding); | 4632 setup_coding_system (val, &coding); |
4433 on some system. */ | 4633 on some system. */ |
4434 { | 4634 { |
4435 struct coding_system temp_coding; | 4635 struct coding_system temp_coding; |
4436 setup_coding_system (val, &temp_coding); | 4636 setup_coding_system (Fcheck_coding_system (val), &temp_coding); |
4437 bcopy (&temp_coding, &coding, sizeof coding); | 4637 bcopy (&temp_coding, &coding, sizeof coding); |
4438 } | 4638 } |
4439 /* Ensure we set Vlast_coding_system_used. */ | 4639 /* Ensure we set Vlast_coding_system_used. */ |
4440 set_coding_system = 1; | 4640 set_coding_system = 1; |
4441 | 4641 |
4471 } | 4671 } |
4472 else | 4672 else |
4473 adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, | 4673 adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, |
4474 inserted); | 4674 inserted); |
4475 } | 4675 } |
4676 | |
4677 /* Now INSERTED is measured in characters. */ | |
4476 | 4678 |
4477 #ifdef DOS_NT | 4679 #ifdef DOS_NT |
4478 /* Use the conversion type to determine buffer-file-type | 4680 /* Use the conversion type to determine buffer-file-type |
4479 (find-buffer-file-type is now used to help determine the | 4681 (find-buffer-file-type is now used to help determine the |
4480 conversion). */ | 4682 conversion). */ |
4517 Fsignal (Qfile_error, | 4719 Fsignal (Qfile_error, |
4518 Fcons (build_string ("not a regular file"), | 4720 Fcons (build_string ("not a regular file"), |
4519 Fcons (orig_filename, Qnil))); | 4721 Fcons (orig_filename, Qnil))); |
4520 } | 4722 } |
4521 | 4723 |
4724 if (set_coding_system) | |
4725 Vlast_coding_system_used = coding.symbol; | |
4726 | |
4727 if (! NILP (Ffboundp (Qafter_insert_file_set_coding))) | |
4728 { | |
4729 insval = call2 (Qafter_insert_file_set_coding, make_number (inserted), | |
4730 visit); | |
4731 if (! NILP (insval)) | |
4732 { | |
4733 CHECK_NUMBER (insval); | |
4734 inserted = XFASTINT (insval); | |
4735 } | |
4736 } | |
4737 | |
4522 /* Decode file format */ | 4738 /* Decode file format */ |
4523 if (inserted > 0) | 4739 if (inserted > 0) |
4524 { | 4740 { |
4525 int empty_undo_list_p = 0; | 4741 int empty_undo_list_p = 0; |
4526 | 4742 |
4539 inserted = XFASTINT (insval); | 4755 inserted = XFASTINT (insval); |
4540 | 4756 |
4541 if (!NILP (visit)) | 4757 if (!NILP (visit)) |
4542 current_buffer->undo_list = empty_undo_list_p ? Qnil : Qt; | 4758 current_buffer->undo_list = empty_undo_list_p ? Qnil : Qt; |
4543 } | 4759 } |
4544 | |
4545 if (set_coding_system) | |
4546 Vlast_coding_system_used = coding.symbol; | |
4547 | 4760 |
4548 /* Call after-change hooks for the inserted text, aside from the case | 4761 /* Call after-change hooks for the inserted text, aside from the case |
4549 of normal visiting (not with REPLACE), which is done in a new buffer | 4762 of normal visiting (not with REPLACE), which is done in a new buffer |
4550 "before" the buffer is changed. */ | 4763 "before" the buffer is changed. */ |
4551 if (inserted > 0 && total > 0 | 4764 if (inserted > 0 && total > 0 |
4620 Lisp_Object start, end, filename, append, visit, lockname; | 4833 Lisp_Object start, end, filename, append, visit, lockname; |
4621 struct coding_system *coding; | 4834 struct coding_system *coding; |
4622 { | 4835 { |
4623 Lisp_Object val; | 4836 Lisp_Object val; |
4624 | 4837 |
4625 if (auto_saving) | 4838 if (auto_saving |
4626 val = Qnil; | 4839 && NILP (Fstring_equal (current_buffer->filename, |
4840 current_buffer->auto_save_file_name))) | |
4841 { | |
4842 /* We use emacs-mule for auto saving... */ | |
4843 setup_coding_system (Qemacs_mule, coding); | |
4844 /* ... but with the special flag to indicate not to strip off | |
4845 leading code of eight-bit-control chars. */ | |
4846 coding->flags = 1; | |
4847 goto done_setup_coding; | |
4848 } | |
4627 else if (!NILP (Vcoding_system_for_write)) | 4849 else if (!NILP (Vcoding_system_for_write)) |
4628 { | 4850 { |
4629 val = Vcoding_system_for_write; | 4851 val = Vcoding_system_for_write; |
4630 if (coding_system_require_warning | 4852 if (coding_system_require_warning |
4631 && !NILP (Ffboundp (Vselect_safe_coding_system_function))) | 4853 && !NILP (Ffboundp (Vselect_safe_coding_system_function))) |
4729 instead of any buffer contents; END is ignored. | 4951 instead of any buffer contents; END is ignored. |
4730 | 4952 |
4731 Optional fourth argument APPEND if non-nil means | 4953 Optional fourth argument APPEND if non-nil means |
4732 append to existing file contents (if any). If it is an integer, | 4954 append to existing file contents (if any). If it is an integer, |
4733 seek to that offset in the file before writing. | 4955 seek to that offset in the file before writing. |
4734 Optional fifth argument VISIT if t means | 4956 Optional fifth argument VISIT, if t or a string, means |
4735 set the last-save-file-modtime of buffer to this file's modtime | 4957 set the last-save-file-modtime of buffer to this file's modtime |
4736 and mark buffer not modified. | 4958 and mark buffer not modified. |
4737 If VISIT is a string, it is a second file name; | 4959 If VISIT is a string, it is a second file name; |
4738 the output goes to FILENAME, but the buffer is marked as visiting VISIT. | 4960 the output goes to FILENAME, but the buffer is marked as visiting VISIT. |
4739 VISIT is also the file name to lock and unlock for clash detection. | 4961 VISIT is also the file name to lock and unlock for clash detection. |
4823 } | 5045 } |
4824 UNGCPRO; | 5046 UNGCPRO; |
4825 return val; | 5047 return val; |
4826 } | 5048 } |
4827 | 5049 |
5050 record_unwind_protect (save_restriction_restore, save_restriction_save ()); | |
5051 | |
4828 /* Special kludge to simplify auto-saving. */ | 5052 /* Special kludge to simplify auto-saving. */ |
4829 if (NILP (start)) | 5053 if (NILP (start)) |
4830 { | 5054 { |
4831 XSETFASTINT (start, BEG); | 5055 XSETFASTINT (start, BEG); |
4832 XSETFASTINT (end, Z); | 5056 XSETFASTINT (end, Z); |
5057 Fwiden (); | |
4833 } | 5058 } |
4834 | 5059 |
4835 record_unwind_protect (build_annotations_unwind, Fcurrent_buffer ()); | 5060 record_unwind_protect (build_annotations_unwind, Fcurrent_buffer ()); |
4836 count1 = SPECPDL_INDEX (); | 5061 count1 = SPECPDL_INDEX (); |
4837 | 5062 |
5074 #ifdef HAVE_FSYNC | 5299 #ifdef HAVE_FSYNC |
5075 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun). | 5300 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun). |
5076 Disk full in NFS may be reported here. */ | 5301 Disk full in NFS may be reported here. */ |
5077 /* mib says that closing the file will try to write as fast as NFS can do | 5302 /* mib says that closing the file will try to write as fast as NFS can do |
5078 it, and that means the fsync here is not crucial for autosave files. */ | 5303 it, and that means the fsync here is not crucial for autosave files. */ |
5079 if (!auto_saving && fsync (desc) < 0) | 5304 if (!auto_saving && !write_region_inhibit_fsync && fsync (desc) < 0) |
5080 { | 5305 { |
5081 /* If fsync fails with EINTR, don't treat that as serious. */ | 5306 /* If fsync fails with EINTR, don't treat that as serious. */ |
5082 if (errno != EINTR) | 5307 if (errno != EINTR) |
5083 failure = 1, save_errno = errno; | 5308 failure = 1, save_errno = errno; |
5084 } | 5309 } |
5146 XSETFASTINT (current_buffer->save_length, Z - BEG); | 5371 XSETFASTINT (current_buffer->save_length, Z - BEG); |
5147 current_buffer->filename = visit_file; | 5372 current_buffer->filename = visit_file; |
5148 update_mode_lines++; | 5373 update_mode_lines++; |
5149 } | 5374 } |
5150 else if (quietly) | 5375 else if (quietly) |
5151 return Qnil; | 5376 { |
5377 if (auto_saving | |
5378 && ! NILP (Fstring_equal (current_buffer->filename, | |
5379 current_buffer->auto_save_file_name))) | |
5380 SAVE_MODIFF = MODIFF; | |
5381 | |
5382 return Qnil; | |
5383 } | |
5152 | 5384 |
5153 if (!auto_saving) | 5385 if (!auto_saving) |
5154 message_with_string ("Wrote %s", visit_file, 1); | 5386 message_with_string ((INTEGERP (append) |
5387 ? "Updated %s" | |
5388 : ! NILP (append) | |
5389 ? "Added to %s" | |
5390 : "Wrote %s"), | |
5391 visit_file, 1); | |
5155 | 5392 |
5156 return Qnil; | 5393 return Qnil; |
5157 } | 5394 } |
5158 | 5395 |
5159 Lisp_Object merge (); | 5396 Lisp_Object merge (); |
5180 { | 5417 { |
5181 Lisp_Object annotations; | 5418 Lisp_Object annotations; |
5182 Lisp_Object p, res; | 5419 Lisp_Object p, res; |
5183 struct gcpro gcpro1, gcpro2; | 5420 struct gcpro gcpro1, gcpro2; |
5184 Lisp_Object original_buffer; | 5421 Lisp_Object original_buffer; |
5185 int i; | 5422 int i, used_global = 0; |
5186 | 5423 |
5187 XSETBUFFER (original_buffer, current_buffer); | 5424 XSETBUFFER (original_buffer, current_buffer); |
5188 | 5425 |
5189 annotations = Qnil; | 5426 annotations = Qnil; |
5190 p = Vwrite_region_annotate_functions; | 5427 p = Vwrite_region_annotate_functions; |
5191 GCPRO2 (annotations, p); | 5428 GCPRO2 (annotations, p); |
5192 while (CONSP (p)) | 5429 while (CONSP (p)) |
5193 { | 5430 { |
5194 struct buffer *given_buffer = current_buffer; | 5431 struct buffer *given_buffer = current_buffer; |
5432 if (EQ (Qt, XCAR (p)) && !used_global) | |
5433 { /* Use the global value of the hook. */ | |
5434 Lisp_Object arg[2]; | |
5435 used_global = 1; | |
5436 arg[0] = Fdefault_value (Qwrite_region_annotate_functions); | |
5437 arg[1] = XCDR (p); | |
5438 p = Fappend (2, arg); | |
5439 continue; | |
5440 } | |
5195 Vwrite_region_annotations_so_far = annotations; | 5441 Vwrite_region_annotations_so_far = annotations; |
5196 res = call2 (XCAR (p), start, end); | 5442 res = call2 (XCAR (p), start, end); |
5197 /* If the function makes a different buffer current, | 5443 /* If the function makes a different buffer current, |
5198 assume that means this buffer contains altered text to be output. | 5444 assume that means this buffer contains altered text to be output. |
5199 Reset START and END from the buffer bounds | 5445 Reset START and END from the buffer bounds |
5209 annotations = merge (annotations, res, Qcar_less_than_car); | 5455 annotations = merge (annotations, res, Qcar_less_than_car); |
5210 p = XCDR (p); | 5456 p = XCDR (p); |
5211 } | 5457 } |
5212 | 5458 |
5213 /* Now do the same for annotation functions implied by the file-format */ | 5459 /* Now do the same for annotation functions implied by the file-format */ |
5214 if (auto_saving && (!EQ (Vauto_save_file_format, Qt))) | 5460 if (auto_saving && (!EQ (current_buffer->auto_save_file_format, Qt))) |
5215 p = Vauto_save_file_format; | 5461 p = current_buffer->auto_save_file_format; |
5216 else | 5462 else |
5217 p = current_buffer->file_format; | 5463 p = current_buffer->file_format; |
5218 for (i = 0; CONSP (p); p = XCDR (p), ++i) | 5464 for (i = 0; CONSP (p); p = XCDR (p), ++i) |
5219 { | 5465 { |
5220 struct buffer *given_buffer = current_buffer; | 5466 struct buffer *given_buffer = current_buffer; |
5411 } | 5657 } |
5412 | 5658 |
5413 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, | 5659 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, |
5414 Sverify_visited_file_modtime, 1, 1, 0, | 5660 Sverify_visited_file_modtime, 1, 1, 0, |
5415 doc: /* Return t if last mod time of BUF's visited file matches what BUF records. | 5661 doc: /* Return t if last mod time of BUF's visited file matches what BUF records. |
5416 This means that the file has not been changed since it was visited or saved. */) | 5662 This means that the file has not been changed since it was visited or saved. |
5663 See Info node `(elisp)Modification Time' for more details. */) | |
5417 (buf) | 5664 (buf) |
5418 Lisp_Object buf; | 5665 Lisp_Object buf; |
5419 { | 5666 { |
5420 struct buffer *b; | 5667 struct buffer *b; |
5421 struct stat st; | 5668 struct stat st; |
5466 } | 5713 } |
5467 | 5714 |
5468 DEFUN ("visited-file-modtime", Fvisited_file_modtime, | 5715 DEFUN ("visited-file-modtime", Fvisited_file_modtime, |
5469 Svisited_file_modtime, 0, 0, 0, | 5716 Svisited_file_modtime, 0, 0, 0, |
5470 doc: /* Return the current buffer's recorded visited file modification time. | 5717 doc: /* Return the current buffer's recorded visited file modification time. |
5471 The value is a list of the form (HIGH . LOW), like the time values | 5718 The value is a list of the form (HIGH LOW), like the time values |
5472 that `file-attributes' returns. */) | 5719 that `file-attributes' returns. If the current buffer has no recorded |
5720 file modification time, this function returns 0. | |
5721 See Info node `(elisp)Modification Time' for more details. */) | |
5473 () | 5722 () |
5474 { | 5723 { |
5475 return long_to_cons ((unsigned long) current_buffer->modtime); | 5724 Lisp_Object tcons; |
5725 tcons = long_to_cons ((unsigned long) current_buffer->modtime); | |
5726 if (CONSP (tcons)) | |
5727 return list2 (XCAR (tcons), XCDR (tcons)); | |
5728 return tcons; | |
5476 } | 5729 } |
5477 | 5730 |
5478 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime, | 5731 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime, |
5479 Sset_visited_file_modtime, 0, 1, 0, | 5732 Sset_visited_file_modtime, 0, 1, 0, |
5480 doc: /* Update buffer's recorded modification time from the visited file's time. | 5733 doc: /* Update buffer's recorded modification time from the visited file's time. |
5517 Lisp_Object error; | 5770 Lisp_Object error; |
5518 { | 5771 { |
5519 Lisp_Object args[3], msg; | 5772 Lisp_Object args[3], msg; |
5520 int i, nbytes; | 5773 int i, nbytes; |
5521 struct gcpro gcpro1; | 5774 struct gcpro gcpro1; |
5775 char *msgbuf; | |
5776 USE_SAFE_ALLOCA; | |
5522 | 5777 |
5523 ring_bell (); | 5778 ring_bell (); |
5524 | 5779 |
5525 args[0] = build_string ("Auto-saving %s: %s"); | 5780 args[0] = build_string ("Auto-saving %s: %s"); |
5526 args[1] = current_buffer->name; | 5781 args[1] = current_buffer->name; |
5527 args[2] = Ferror_message_string (error); | 5782 args[2] = Ferror_message_string (error); |
5528 msg = Fformat (3, args); | 5783 msg = Fformat (3, args); |
5529 GCPRO1 (msg); | 5784 GCPRO1 (msg); |
5530 nbytes = SBYTES (msg); | 5785 nbytes = SBYTES (msg); |
5786 SAFE_ALLOCA (msgbuf, char *, nbytes); | |
5787 bcopy (SDATA (msg), msgbuf, nbytes); | |
5531 | 5788 |
5532 for (i = 0; i < 3; ++i) | 5789 for (i = 0; i < 3; ++i) |
5533 { | 5790 { |
5534 if (i == 0) | 5791 if (i == 0) |
5535 message2 (SDATA (msg), nbytes, STRING_MULTIBYTE (msg)); | 5792 message2 (msgbuf, nbytes, STRING_MULTIBYTE (msg)); |
5536 else | 5793 else |
5537 message2_nolog (SDATA (msg), nbytes, STRING_MULTIBYTE (msg)); | 5794 message2_nolog (msgbuf, nbytes, STRING_MULTIBYTE (msg)); |
5538 Fsleep_for (make_number (1), Qnil); | 5795 Fsleep_for (make_number (1), Qnil); |
5539 } | 5796 } |
5540 | 5797 |
5798 SAFE_FREE (); | |
5541 UNGCPRO; | 5799 UNGCPRO; |
5542 return Qnil; | 5800 return Qnil; |
5543 } | 5801 } |
5544 | 5802 |
5545 Lisp_Object | 5803 Lisp_Object |
5546 auto_save_1 () | 5804 auto_save_1 () |
5547 { | 5805 { |
5548 struct stat st; | 5806 struct stat st; |
5807 Lisp_Object modes; | |
5808 | |
5809 auto_save_mode_bits = 0666; | |
5549 | 5810 |
5550 /* Get visited file's mode to become the auto save file's mode. */ | 5811 /* Get visited file's mode to become the auto save file's mode. */ |
5551 if (! NILP (current_buffer->filename) | 5812 if (! NILP (current_buffer->filename)) |
5552 && stat (SDATA (current_buffer->filename), &st) >= 0) | 5813 { |
5553 /* But make sure we can overwrite it later! */ | 5814 if (stat (SDATA (current_buffer->filename), &st) >= 0) |
5554 auto_save_mode_bits = st.st_mode | 0600; | 5815 /* But make sure we can overwrite it later! */ |
5555 else | 5816 auto_save_mode_bits = st.st_mode | 0600; |
5556 auto_save_mode_bits = 0666; | 5817 else if ((modes = Ffile_modes (current_buffer->filename), |
5818 INTEGERP (modes))) | |
5819 /* Remote files don't cooperate with stat. */ | |
5820 auto_save_mode_bits = XINT (modes) | 0600; | |
5821 } | |
5557 | 5822 |
5558 return | 5823 return |
5559 Fwrite_region (Qnil, Qnil, | 5824 Fwrite_region (Qnil, Qnil, |
5560 current_buffer->auto_save_file_name, | 5825 current_buffer->auto_save_file_name, |
5561 Qnil, Qlambda, Qnil, Qnil); | 5826 Qnil, Qlambda, Qnil, Qnil); |
5562 } | 5827 } |
5563 | 5828 |
5564 static Lisp_Object | 5829 static Lisp_Object |
5565 do_auto_save_unwind (stream) /* used as unwind-protect function */ | 5830 do_auto_save_unwind (arg) /* used as unwind-protect function */ |
5566 Lisp_Object stream; | 5831 Lisp_Object arg; |
5567 { | 5832 { |
5833 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer; | |
5568 auto_saving = 0; | 5834 auto_saving = 0; |
5569 if (!NILP (stream)) | 5835 if (stream != NULL) |
5570 fclose ((FILE *) (XFASTINT (XCAR (stream)) << 16 | 5836 fclose (stream); |
5571 | XFASTINT (XCDR (stream)))); | |
5572 return Qnil; | 5837 return Qnil; |
5573 } | 5838 } |
5574 | 5839 |
5575 static Lisp_Object | 5840 static Lisp_Object |
5576 do_auto_save_unwind_1 (value) /* used as unwind-protect function */ | 5841 do_auto_save_unwind_1 (value) /* used as unwind-protect function */ |
5611 struct buffer *old = current_buffer, *b; | 5876 struct buffer *old = current_buffer, *b; |
5612 Lisp_Object tail, buf; | 5877 Lisp_Object tail, buf; |
5613 int auto_saved = 0; | 5878 int auto_saved = 0; |
5614 int do_handled_files; | 5879 int do_handled_files; |
5615 Lisp_Object oquit; | 5880 Lisp_Object oquit; |
5616 FILE *stream; | 5881 FILE *stream = NULL; |
5617 Lisp_Object lispstream; | |
5618 int count = SPECPDL_INDEX (); | 5882 int count = SPECPDL_INDEX (); |
5619 int orig_minibuffer_auto_raise = minibuffer_auto_raise; | 5883 int orig_minibuffer_auto_raise = minibuffer_auto_raise; |
5620 int old_message_p = 0; | 5884 int old_message_p = 0; |
5621 struct gcpro gcpro1, gcpro2; | 5885 struct gcpro gcpro1, gcpro2; |
5622 | 5886 |
5664 do_auto_save_eh); | 5928 do_auto_save_eh); |
5665 UNGCPRO; | 5929 UNGCPRO; |
5666 } | 5930 } |
5667 | 5931 |
5668 stream = fopen (SDATA (listfile), "w"); | 5932 stream = fopen (SDATA (listfile), "w"); |
5669 if (stream != NULL) | 5933 } |
5670 { | 5934 |
5671 /* Arrange to close that file whether or not we get an error. | 5935 record_unwind_protect (do_auto_save_unwind, |
5672 Also reset auto_saving to 0. */ | 5936 make_save_value (stream, 0)); |
5673 lispstream = Fcons (Qnil, Qnil); | |
5674 XSETCARFASTINT (lispstream, (EMACS_UINT)stream >> 16); | |
5675 XSETCDRFASTINT (lispstream, (EMACS_UINT)stream & 0xffff); | |
5676 } | |
5677 else | |
5678 lispstream = Qnil; | |
5679 } | |
5680 else | |
5681 { | |
5682 stream = NULL; | |
5683 lispstream = Qnil; | |
5684 } | |
5685 | |
5686 record_unwind_protect (do_auto_save_unwind, lispstream); | |
5687 record_unwind_protect (do_auto_save_unwind_1, | 5937 record_unwind_protect (do_auto_save_unwind_1, |
5688 make_number (minibuffer_auto_raise)); | 5938 make_number (minibuffer_auto_raise)); |
5689 minibuffer_auto_raise = 0; | 5939 minibuffer_auto_raise = 0; |
5690 auto_saving = 1; | 5940 auto_saving = 1; |
5691 | 5941 |
5692 /* First, save all files which don't have handlers. If Emacs is | 5942 /* On first pass, save all files that don't have handlers. |
5693 crashing, the handlers may tweak what is causing Emacs to crash | 5943 On second pass, save all files that do have handlers. |
5694 in the first place, and it would be a shame if Emacs failed to | 5944 |
5695 autosave perfectly ordinary files because it couldn't handle some | 5945 If Emacs is crashing, the handlers may tweak what is causing |
5696 ange-ftp'd file. */ | 5946 Emacs to crash in the first place, and it would be a shame if |
5947 Emacs failed to autosave perfectly ordinary files because it | |
5948 couldn't handle some ange-ftp'd file. */ | |
5949 | |
5697 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++) | 5950 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++) |
5698 for (tail = Vbuffer_alist; GC_CONSP (tail); tail = XCDR (tail)) | 5951 for (tail = Vbuffer_alist; GC_CONSP (tail); tail = XCDR (tail)) |
5699 { | 5952 { |
5700 buf = XCDR (XCAR (tail)); | 5953 buf = XCDR (XCAR (tail)); |
5701 b = XBUFFER (buf); | 5954 b = XBUFFER (buf); |
5831 return Qnil; | 6084 return Qnil; |
5832 } | 6085 } |
5833 | 6086 |
5834 DEFUN ("recent-auto-save-p", Frecent_auto_save_p, Srecent_auto_save_p, | 6087 DEFUN ("recent-auto-save-p", Frecent_auto_save_p, Srecent_auto_save_p, |
5835 0, 0, 0, | 6088 0, 0, 0, |
5836 doc: /* Return t if buffer has been auto-saved since last read in or saved. */) | 6089 doc: /* Return t if current buffer has been auto-saved recently. |
6090 More precisely, if it has been auto-saved since last read from or saved | |
6091 in the visited file. If the buffer has no visited file, | |
6092 then any auto-save counts as "recent". */) | |
5837 () | 6093 () |
5838 { | 6094 { |
5839 return (SAVE_MODIFF < current_buffer->auto_save_modified) ? Qt : Qnil; | 6095 return (SAVE_MODIFF < current_buffer->auto_save_modified) ? Qt : Qnil; |
5840 } | 6096 } |
5841 | 6097 |
5974 } | 6230 } |
5975 else | 6231 else |
5976 #endif | 6232 #endif |
5977 { | 6233 { |
5978 /* Must do it the hard (and slow) way. */ | 6234 /* Must do it the hard (and slow) way. */ |
6235 Lisp_Object tem; | |
5979 GCPRO3 (all, comp, specdir); | 6236 GCPRO3 (all, comp, specdir); |
5980 count = SPECPDL_INDEX (); | 6237 count = SPECPDL_INDEX (); |
5981 record_unwind_protect (read_file_name_cleanup, current_buffer->directory); | 6238 record_unwind_protect (read_file_name_cleanup, current_buffer->directory); |
5982 current_buffer->directory = realdir; | 6239 current_buffer->directory = realdir; |
5983 for (comp = Qnil; CONSP (all); all = XCDR (all)) | 6240 for (comp = Qnil; CONSP (all); all = XCDR (all)) |
5984 if (!NILP (call1 (Vread_file_name_predicate, XCAR (all)))) | 6241 { |
5985 comp = Fcons (XCAR (all), comp); | 6242 tem = call1 (Vread_file_name_predicate, XCAR (all)); |
6243 if (!NILP (tem)) | |
6244 comp = Fcons (XCAR (all), comp); | |
6245 } | |
5986 unbind_to (count, Qnil); | 6246 unbind_to (count, Qnil); |
5987 UNGCPRO; | 6247 UNGCPRO; |
5988 } | 6248 } |
5989 return Fnreverse (comp); | 6249 return Fnreverse (comp); |
5990 } | 6250 } |
5994 /* Supposedly this helps commands such as `cd' that read directory names, | 6254 /* Supposedly this helps commands such as `cd' that read directory names, |
5995 but can someone explain how it helps them? -- RMS */ | 6255 but can someone explain how it helps them? -- RMS */ |
5996 if (SCHARS (name) == 0) | 6256 if (SCHARS (name) == 0) |
5997 return Qt; | 6257 return Qt; |
5998 #endif /* VMS */ | 6258 #endif /* VMS */ |
6259 string = Fexpand_file_name (string, dir); | |
5999 if (!NILP (Vread_file_name_predicate)) | 6260 if (!NILP (Vread_file_name_predicate)) |
6000 return call1 (Vread_file_name_predicate, string); | 6261 return call1 (Vread_file_name_predicate, string); |
6001 return Ffile_exists_p (string); | 6262 return Ffile_exists_p (string); |
6002 } | 6263 } |
6003 | 6264 |
6265 DEFUN ("next-read-file-uses-dialog-p", Fnext_read_file_uses_dialog_p, | |
6266 Snext_read_file_uses_dialog_p, 0, 0, 0, | |
6267 doc: /* Return t if a call to `read-file-name' will use a dialog. | |
6268 The return value is only relevant for a call to `read-file-name' that happens | |
6269 before any other event (mouse or keypress) is handeled. */) | |
6270 () | |
6271 { | |
6272 #if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) || defined (HAVE_CARBON) | |
6273 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) | |
6274 && use_dialog_box | |
6275 && use_file_dialog | |
6276 && have_menus_p ()) | |
6277 return Qt; | |
6278 #endif | |
6279 return Qnil; | |
6280 } | |
6281 | |
6004 DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 6, 0, | 6282 DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 6, 0, |
6005 doc: /* Read file name, prompting with PROMPT and completing in directory DIR. | 6283 doc: /* Read file name, prompting with PROMPT and completing in directory DIR. |
6006 Value is not expanded---you must call `expand-file-name' yourself. | 6284 Value is not expanded---you must call `expand-file-name' yourself. |
6007 Default name to DEFAULT-FILENAME if user enters a null string. | 6285 Default name to DEFAULT-FILENAME if user exits the minibuffer with |
6286 the same non-empty string that was inserted by this function. | |
6008 (If DEFAULT-FILENAME is omitted, the visited file name is used, | 6287 (If DEFAULT-FILENAME is omitted, the visited file name is used, |
6009 except that if INITIAL is specified, that combined with DIR is used.) | 6288 except that if INITIAL is specified, that combined with DIR is used.) |
6289 If the user exits with an empty minibuffer, this function returns | |
6290 an empty string. (This can only happen if the user erased the | |
6291 pre-inserted contents or if `insert-default-directory' is nil.) | |
6010 Fourth arg MUSTMATCH non-nil means require existing file's name. | 6292 Fourth arg MUSTMATCH non-nil means require existing file's name. |
6011 Non-nil and non-t means also require confirmation after completion. | 6293 Non-nil and non-t means also require confirmation after completion. |
6012 Fifth arg INITIAL specifies text to start with. | 6294 Fifth arg INITIAL specifies text to start with. |
6013 If optional sixth arg PREDICATE is non-nil, possible completions and the | 6295 If optional sixth arg PREDICATE is non-nil, possible completions and |
6014 resulting file name must satisfy (funcall PREDICATE NAME). | 6296 the resulting file name must satisfy (funcall PREDICATE NAME). |
6015 DIR defaults to current buffer's directory default. | 6297 DIR should be an absolute directory name. It defaults to the value of |
6298 `default-directory'. | |
6016 | 6299 |
6017 If this command was invoked with the mouse, use a file dialog box if | 6300 If this command was invoked with the mouse, use a file dialog box if |
6018 `use-dialog-box' is non-nil, and the window system or X toolkit in use | 6301 `use-dialog-box' is non-nil, and the window system or X toolkit in use |
6019 provides a file dialog box. */) | 6302 provides a file dialog box. |
6303 | |
6304 See also `read-file-name-completion-ignore-case' | |
6305 and `read-file-name-function'. */) | |
6020 (prompt, dir, default_filename, mustmatch, initial, predicate) | 6306 (prompt, dir, default_filename, mustmatch, initial, predicate) |
6021 Lisp_Object prompt, dir, default_filename, mustmatch, initial, predicate; | 6307 Lisp_Object prompt, dir, default_filename, mustmatch, initial, predicate; |
6022 { | 6308 { |
6023 Lisp_Object val, insdef, tem; | 6309 Lisp_Object val, insdef, tem; |
6024 struct gcpro gcpro1, gcpro2; | 6310 struct gcpro gcpro1, gcpro2; |
6025 register char *homedir; | 6311 register char *homedir; |
6312 Lisp_Object decoded_homedir; | |
6026 int replace_in_history = 0; | 6313 int replace_in_history = 0; |
6027 int add_to_history = 0; | 6314 int add_to_history = 0; |
6028 int count; | 6315 int count; |
6029 | 6316 |
6030 if (NILP (dir)) | 6317 if (NILP (dir)) |
6031 dir = current_buffer->directory; | 6318 dir = current_buffer->directory; |
6319 if (NILP (Ffile_name_absolute_p (dir))) | |
6320 dir = Fexpand_file_name (dir, Qnil); | |
6032 if (NILP (default_filename)) | 6321 if (NILP (default_filename)) |
6033 default_filename = !NILP (initial) | 6322 default_filename |
6034 ? Fexpand_file_name (initial, dir) | 6323 = (!NILP (initial) |
6035 : current_buffer->filename; | 6324 ? Fexpand_file_name (initial, dir) |
6325 : current_buffer->filename); | |
6036 | 6326 |
6037 /* If dir starts with user's homedir, change that to ~. */ | 6327 /* If dir starts with user's homedir, change that to ~. */ |
6038 homedir = (char *) egetenv ("HOME"); | 6328 homedir = (char *) egetenv ("HOME"); |
6039 #ifdef DOS_NT | 6329 #ifdef DOS_NT |
6040 /* homedir can be NULL in temacs, since Vprocess_environment is not | 6330 /* homedir can be NULL in temacs, since Vprocess_environment is not |
6043 { | 6333 { |
6044 homedir = strcpy (alloca (strlen (homedir) + 1), homedir); | 6334 homedir = strcpy (alloca (strlen (homedir) + 1), homedir); |
6045 CORRECT_DIR_SEPS (homedir); | 6335 CORRECT_DIR_SEPS (homedir); |
6046 } | 6336 } |
6047 #endif | 6337 #endif |
6338 if (homedir != 0) | |
6339 decoded_homedir | |
6340 = DECODE_FILE (make_unibyte_string (homedir, strlen (homedir))); | |
6048 if (homedir != 0 | 6341 if (homedir != 0 |
6049 && STRINGP (dir) | 6342 && STRINGP (dir) |
6050 && !strncmp (homedir, SDATA (dir), strlen (homedir)) | 6343 && !strncmp (SDATA (decoded_homedir), SDATA (dir), |
6051 && IS_DIRECTORY_SEP (SREF (dir, strlen (homedir)))) | 6344 SBYTES (decoded_homedir)) |
6052 { | 6345 && IS_DIRECTORY_SEP (SREF (dir, SBYTES (decoded_homedir)))) |
6053 dir = make_string (SDATA (dir) + strlen (homedir) - 1, | 6346 { |
6054 SBYTES (dir) - strlen (homedir) + 1); | 6347 dir = Fsubstring (dir, make_number (SCHARS (decoded_homedir)), Qnil); |
6055 SSET (dir, 0, '~'); | 6348 dir = concat2 (build_string ("~"), dir); |
6056 } | 6349 } |
6057 /* Likewise for default_filename. */ | 6350 /* Likewise for default_filename. */ |
6058 if (homedir != 0 | 6351 if (homedir != 0 |
6059 && STRINGP (default_filename) | 6352 && STRINGP (default_filename) |
6060 && !strncmp (homedir, SDATA (default_filename), strlen (homedir)) | 6353 && !strncmp (SDATA (decoded_homedir), SDATA (default_filename), |
6061 && IS_DIRECTORY_SEP (SREF (default_filename, strlen (homedir)))) | 6354 SBYTES (decoded_homedir)) |
6355 && IS_DIRECTORY_SEP (SREF (default_filename, SBYTES (decoded_homedir)))) | |
6062 { | 6356 { |
6063 default_filename | 6357 default_filename |
6064 = make_string (SDATA (default_filename) + strlen (homedir) - 1, | 6358 = Fsubstring (default_filename, |
6065 SBYTES (default_filename) - strlen (homedir) + 1); | 6359 make_number (SCHARS (decoded_homedir)), Qnil); |
6066 SSET (default_filename, 0, '~'); | 6360 default_filename = concat2 (build_string ("~"), default_filename); |
6067 } | 6361 } |
6068 if (!NILP (default_filename)) | 6362 if (!NILP (default_filename)) |
6069 { | 6363 { |
6070 CHECK_STRING (default_filename); | 6364 CHECK_STRING (default_filename); |
6071 default_filename = double_dollars (default_filename); | 6365 default_filename = double_dollars (default_filename); |
6106 args[6] = predicate; | 6400 args[6] = predicate; |
6107 RETURN_UNGCPRO (Ffuncall (7, args)); | 6401 RETURN_UNGCPRO (Ffuncall (7, args)); |
6108 } | 6402 } |
6109 | 6403 |
6110 count = SPECPDL_INDEX (); | 6404 count = SPECPDL_INDEX (); |
6111 #ifdef VMS | 6405 specbind (intern ("completion-ignore-case"), |
6112 specbind (intern ("completion-ignore-case"), Qt); | 6406 read_file_name_completion_ignore_case ? Qt : Qnil); |
6113 #endif | |
6114 | |
6115 specbind (intern ("minibuffer-completing-file-name"), Qt); | 6407 specbind (intern ("minibuffer-completing-file-name"), Qt); |
6116 specbind (intern ("read-file-name-predicate"), | 6408 specbind (intern ("read-file-name-predicate"), |
6117 (NILP (predicate) ? Qfile_exists_p : predicate)); | 6409 (NILP (predicate) ? Qfile_exists_p : predicate)); |
6118 | 6410 |
6119 GCPRO2 (insdef, default_filename); | 6411 GCPRO2 (insdef, default_filename); |
6120 | 6412 |
6121 #if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) | 6413 #if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) || defined (HAVE_CARBON) |
6122 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) | 6414 if (! NILP (Fnext_read_file_uses_dialog_p ())) |
6123 && use_dialog_box | |
6124 && have_menus_p ()) | |
6125 { | 6415 { |
6126 /* If DIR contains a file name, split it. */ | 6416 /* If DIR contains a file name, split it. */ |
6127 Lisp_Object file; | 6417 Lisp_Object file; |
6128 file = Ffile_name_nondirectory (dir); | 6418 file = Ffile_name_nondirectory (dir); |
6129 if (SCHARS (file) && NILP (default_filename)) | 6419 if (SCHARS (file) && NILP (default_filename)) |
6131 default_filename = file; | 6421 default_filename = file; |
6132 dir = Ffile_name_directory (dir); | 6422 dir = Ffile_name_directory (dir); |
6133 } | 6423 } |
6134 if (!NILP(default_filename)) | 6424 if (!NILP(default_filename)) |
6135 default_filename = Fexpand_file_name (default_filename, dir); | 6425 default_filename = Fexpand_file_name (default_filename, dir); |
6136 val = Fx_file_dialog (prompt, dir, default_filename, mustmatch); | 6426 val = Fx_file_dialog (prompt, dir, default_filename, mustmatch, |
6427 EQ (predicate, Qfile_directory_p) ? Qt : Qnil); | |
6137 add_to_history = 1; | 6428 add_to_history = 1; |
6138 } | 6429 } |
6139 else | 6430 else |
6140 #endif | 6431 #endif |
6141 val = Fcompleting_read (prompt, intern ("read-file-name-internal"), | 6432 val = Fcompleting_read (prompt, intern ("read-file-name-internal"), |
6168 | 6459 |
6169 tem = Fstring_equal (val, CONSP (insdef) ? XCAR (insdef) : insdef); | 6460 tem = Fstring_equal (val, CONSP (insdef) ? XCAR (insdef) : insdef); |
6170 | 6461 |
6171 if (!NILP (tem) && !NILP (default_filename)) | 6462 if (!NILP (tem) && !NILP (default_filename)) |
6172 val = default_filename; | 6463 val = default_filename; |
6173 else if (SCHARS (val) == 0 && NILP (insdef)) | |
6174 { | |
6175 if (!NILP (default_filename)) | |
6176 val = default_filename; | |
6177 else | |
6178 error ("No default file name"); | |
6179 } | |
6180 val = Fsubstitute_in_file_name (val); | 6464 val = Fsubstitute_in_file_name (val); |
6181 | 6465 |
6182 if (replace_in_history) | 6466 if (replace_in_history) |
6183 /* Replace what Fcompleting_read added to the history | 6467 /* Replace what Fcompleting_read added to the history |
6184 with what we will actually return. */ | 6468 with what we will actually return. */ |
6185 XSETCAR (Fsymbol_value (Qfile_name_history), double_dollars (val)); | 6469 { |
6470 Lisp_Object val1 = double_dollars (val); | |
6471 tem = Fsymbol_value (Qfile_name_history); | |
6472 if (history_delete_duplicates) | |
6473 XSETCDR (tem, Fdelete (val1, XCDR(tem))); | |
6474 XSETCAR (tem, val1); | |
6475 } | |
6186 else if (add_to_history) | 6476 else if (add_to_history) |
6187 { | 6477 { |
6188 /* Add the value to the history--but not if it matches | 6478 /* Add the value to the history--but not if it matches |
6189 the last value already there. */ | 6479 the last value already there. */ |
6190 Lisp_Object val1 = double_dollars (val); | 6480 Lisp_Object val1 = double_dollars (val); |
6191 tem = Fsymbol_value (Qfile_name_history); | 6481 tem = Fsymbol_value (Qfile_name_history); |
6192 if (! CONSP (tem) || NILP (Fequal (XCAR (tem), val1))) | 6482 if (! CONSP (tem) || NILP (Fequal (XCAR (tem), val1))) |
6193 Fset (Qfile_name_history, | 6483 { |
6194 Fcons (val1, tem)); | 6484 if (history_delete_duplicates) tem = Fdelete (val1, tem); |
6485 Fset (Qfile_name_history, Fcons (val1, tem)); | |
6486 } | |
6195 } | 6487 } |
6196 | 6488 |
6197 return val; | 6489 return val; |
6198 } | 6490 } |
6199 | 6491 |
6207 | 6499 |
6208 | 6500 |
6209 void | 6501 void |
6210 syms_of_fileio () | 6502 syms_of_fileio () |
6211 { | 6503 { |
6504 Qoperations = intern ("operations"); | |
6212 Qexpand_file_name = intern ("expand-file-name"); | 6505 Qexpand_file_name = intern ("expand-file-name"); |
6213 Qsubstitute_in_file_name = intern ("substitute-in-file-name"); | 6506 Qsubstitute_in_file_name = intern ("substitute-in-file-name"); |
6214 Qdirectory_file_name = intern ("directory-file-name"); | 6507 Qdirectory_file_name = intern ("directory-file-name"); |
6215 Qfile_name_directory = intern ("file-name-directory"); | 6508 Qfile_name_directory = intern ("file-name-directory"); |
6216 Qfile_name_nondirectory = intern ("file-name-nondirectory"); | 6509 Qfile_name_nondirectory = intern ("file-name-nondirectory"); |
6233 Qfile_directory_p = intern ("file-directory-p"); | 6526 Qfile_directory_p = intern ("file-directory-p"); |
6234 Qfile_regular_p = intern ("file-regular-p"); | 6527 Qfile_regular_p = intern ("file-regular-p"); |
6235 Qfile_accessible_directory_p = intern ("file-accessible-directory-p"); | 6528 Qfile_accessible_directory_p = intern ("file-accessible-directory-p"); |
6236 Qfile_modes = intern ("file-modes"); | 6529 Qfile_modes = intern ("file-modes"); |
6237 Qset_file_modes = intern ("set-file-modes"); | 6530 Qset_file_modes = intern ("set-file-modes"); |
6531 Qset_file_times = intern ("set-file-times"); | |
6238 Qfile_newer_than_file_p = intern ("file-newer-than-file-p"); | 6532 Qfile_newer_than_file_p = intern ("file-newer-than-file-p"); |
6239 Qinsert_file_contents = intern ("insert-file-contents"); | 6533 Qinsert_file_contents = intern ("insert-file-contents"); |
6240 Qwrite_region = intern ("write-region"); | 6534 Qwrite_region = intern ("write-region"); |
6241 Qverify_visited_file_modtime = intern ("verify-visited-file-modtime"); | 6535 Qverify_visited_file_modtime = intern ("verify-visited-file-modtime"); |
6242 Qset_visited_file_modtime = intern ("set-visited-file-modtime"); | 6536 Qset_visited_file_modtime = intern ("set-visited-file-modtime"); |
6243 | 6537 Qauto_save_coding = intern ("auto-save-coding"); |
6538 | |
6539 staticpro (&Qoperations); | |
6244 staticpro (&Qexpand_file_name); | 6540 staticpro (&Qexpand_file_name); |
6245 staticpro (&Qsubstitute_in_file_name); | 6541 staticpro (&Qsubstitute_in_file_name); |
6246 staticpro (&Qdirectory_file_name); | 6542 staticpro (&Qdirectory_file_name); |
6247 staticpro (&Qfile_name_directory); | 6543 staticpro (&Qfile_name_directory); |
6248 staticpro (&Qfile_name_nondirectory); | 6544 staticpro (&Qfile_name_nondirectory); |
6265 staticpro (&Qfile_directory_p); | 6561 staticpro (&Qfile_directory_p); |
6266 staticpro (&Qfile_regular_p); | 6562 staticpro (&Qfile_regular_p); |
6267 staticpro (&Qfile_accessible_directory_p); | 6563 staticpro (&Qfile_accessible_directory_p); |
6268 staticpro (&Qfile_modes); | 6564 staticpro (&Qfile_modes); |
6269 staticpro (&Qset_file_modes); | 6565 staticpro (&Qset_file_modes); |
6566 staticpro (&Qset_file_times); | |
6270 staticpro (&Qfile_newer_than_file_p); | 6567 staticpro (&Qfile_newer_than_file_p); |
6271 staticpro (&Qinsert_file_contents); | 6568 staticpro (&Qinsert_file_contents); |
6272 staticpro (&Qwrite_region); | 6569 staticpro (&Qwrite_region); |
6273 staticpro (&Qverify_visited_file_modtime); | 6570 staticpro (&Qverify_visited_file_modtime); |
6274 staticpro (&Qset_visited_file_modtime); | 6571 staticpro (&Qset_visited_file_modtime); |
6572 staticpro (&Qauto_save_coding); | |
6275 | 6573 |
6276 Qfile_name_history = intern ("file-name-history"); | 6574 Qfile_name_history = intern ("file-name-history"); |
6277 Fset (Qfile_name_history, Qnil); | 6575 Fset (Qfile_name_history, Qnil); |
6278 staticpro (&Qfile_name_history); | 6576 staticpro (&Qfile_name_history); |
6279 | 6577 |
6305 User should not set this variable manually, | 6603 User should not set this variable manually, |
6306 instead use `file-name-coding-system' to get a constant encoding | 6604 instead use `file-name-coding-system' to get a constant encoding |
6307 of file names regardless of the current language environment. */); | 6605 of file names regardless of the current language environment. */); |
6308 Vdefault_file_name_coding_system = Qnil; | 6606 Vdefault_file_name_coding_system = Qnil; |
6309 | 6607 |
6310 DEFVAR_LISP ("auto-save-file-format", &Vauto_save_file_format, | |
6311 doc: /* *Format in which to write auto-save files. | |
6312 Should be a list of symbols naming formats that are defined in `format-alist'. | |
6313 If it is t, which is the default, auto-save files are written in the | |
6314 same format as a regular save would use. */); | |
6315 Vauto_save_file_format = Qt; | |
6316 | |
6317 Qformat_decode = intern ("format-decode"); | 6608 Qformat_decode = intern ("format-decode"); |
6318 staticpro (&Qformat_decode); | 6609 staticpro (&Qformat_decode); |
6319 Qformat_annotate_function = intern ("format-annotate-function"); | 6610 Qformat_annotate_function = intern ("format-annotate-function"); |
6320 staticpro (&Qformat_annotate_function); | 6611 staticpro (&Qformat_annotate_function); |
6612 Qafter_insert_file_set_coding = intern ("after-insert-file-set-coding"); | |
6613 staticpro (&Qafter_insert_file_set_coding); | |
6321 | 6614 |
6322 Qcar_less_than_car = intern ("car-less-than-car"); | 6615 Qcar_less_than_car = intern ("car-less-than-car"); |
6323 staticpro (&Qcar_less_than_car); | 6616 staticpro (&Qcar_less_than_car); |
6324 | 6617 |
6325 Fput (Qfile_error, Qerror_conditions, | 6618 Fput (Qfile_error, Qerror_conditions, |
6345 | 6638 |
6346 DEFVAR_LISP ("read-file-name-predicate", &Vread_file_name_predicate, | 6639 DEFVAR_LISP ("read-file-name-predicate", &Vread_file_name_predicate, |
6347 doc: /* Current predicate used by `read-file-name-internal'. */); | 6640 doc: /* Current predicate used by `read-file-name-internal'. */); |
6348 Vread_file_name_predicate = Qnil; | 6641 Vread_file_name_predicate = Qnil; |
6349 | 6642 |
6643 DEFVAR_BOOL ("read-file-name-completion-ignore-case", &read_file_name_completion_ignore_case, | |
6644 doc: /* *Non-nil means when reading a file name completion ignores case. */); | |
6645 #if defined VMS || defined DOS_NT || defined MAC_OS | |
6646 read_file_name_completion_ignore_case = 1; | |
6647 #else | |
6648 read_file_name_completion_ignore_case = 0; | |
6649 #endif | |
6650 | |
6350 DEFVAR_BOOL ("insert-default-directory", &insert_default_directory, | 6651 DEFVAR_BOOL ("insert-default-directory", &insert_default_directory, |
6351 doc: /* *Non-nil means when reading a filename start with default dir in minibuffer. */); | 6652 doc: /* *Non-nil means when reading a filename start with default dir in minibuffer. |
6653 If the initial minibuffer contents are non-empty, you can usually | |
6654 request a default filename by typing RETURN without editing. For some | |
6655 commands, exiting with an empty minibuffer has a special meaning, | |
6656 such as making the current buffer visit no file in the case of | |
6657 `set-visited-file-name'. | |
6658 If this variable is non-nil, the minibuffer contents are always | |
6659 initially non-empty and typing RETURN without editing will fetch the | |
6660 default name, if one is provided. Note however that this default name | |
6661 is not necessarily the name originally inserted in the minibuffer, if | |
6662 that is just the default directory. | |
6663 If this variable is nil, the minibuffer often starts out empty. In | |
6664 that case you may have to explicitly fetch the next history element to | |
6665 request the default name. */); | |
6352 insert_default_directory = 1; | 6666 insert_default_directory = 1; |
6353 | 6667 |
6354 DEFVAR_BOOL ("vms-stmlf-recfm", &vms_stmlf_recfm, | 6668 DEFVAR_BOOL ("vms-stmlf-recfm", &vms_stmlf_recfm, |
6355 doc: /* *Non-nil means write new files with record format `stmlf'. | 6669 doc: /* *Non-nil means write new files with record format `stmlf'. |
6356 nil means use format `var'. This variable is meaningful only on VMS. */); | 6670 nil means use format `var'. This variable is meaningful only on VMS. */); |
6388 or local variable spec of the tailing lines with `coding:' tag. */); | 6702 or local variable spec of the tailing lines with `coding:' tag. */); |
6389 Vset_auto_coding_function = Qnil; | 6703 Vset_auto_coding_function = Qnil; |
6390 | 6704 |
6391 DEFVAR_LISP ("after-insert-file-functions", &Vafter_insert_file_functions, | 6705 DEFVAR_LISP ("after-insert-file-functions", &Vafter_insert_file_functions, |
6392 doc: /* A list of functions to be called at the end of `insert-file-contents'. | 6706 doc: /* A list of functions to be called at the end of `insert-file-contents'. |
6393 Each is passed one argument, the number of bytes inserted. It should return | 6707 Each is passed one argument, the number of characters inserted. |
6394 the new byte count, and leave point the same. If `insert-file-contents' is | 6708 It should return the new character count, and leave point the same. |
6395 intercepted by a handler from `file-name-handler-alist', that handler is | 6709 If `insert-file-contents' is intercepted by a handler from |
6396 responsible for calling the after-insert-file-functions if appropriate. */); | 6710 `file-name-handler-alist', that handler is responsible for calling the |
6711 functions in `after-insert-file-functions' if appropriate. */); | |
6397 Vafter_insert_file_functions = Qnil; | 6712 Vafter_insert_file_functions = Qnil; |
6398 | 6713 |
6399 DEFVAR_LISP ("write-region-annotate-functions", &Vwrite_region_annotate_functions, | 6714 DEFVAR_LISP ("write-region-annotate-functions", &Vwrite_region_annotate_functions, |
6400 doc: /* A list of functions to be called at the start of `write-region'. | 6715 doc: /* A list of functions to be called at the start of `write-region'. |
6401 Each is passed two arguments, START and END as for `write-region'. | 6716 Each is passed two arguments, START and END as for `write-region'. |
6404 of the form (POSITION . STRING), consisting of strings to be effectively | 6719 of the form (POSITION . STRING), consisting of strings to be effectively |
6405 inserted at the specified positions of the file being written (1 means to | 6720 inserted at the specified positions of the file being written (1 means to |
6406 insert before the first byte written). The POSITIONs must be sorted into | 6721 insert before the first byte written). The POSITIONs must be sorted into |
6407 increasing order. If there are several functions in the list, the several | 6722 increasing order. If there are several functions in the list, the several |
6408 lists are merged destructively. Alternatively, the function can return | 6723 lists are merged destructively. Alternatively, the function can return |
6409 with a different buffer current and value nil.*/); | 6724 with a different buffer current; in that case it should pay attention |
6725 to the annotations returned by previous functions and listed in | |
6726 `write-region-annotations-so-far'.*/); | |
6410 Vwrite_region_annotate_functions = Qnil; | 6727 Vwrite_region_annotate_functions = Qnil; |
6728 staticpro (&Qwrite_region_annotate_functions); | |
6729 Qwrite_region_annotate_functions | |
6730 = intern ("write-region-annotate-functions"); | |
6411 | 6731 |
6412 DEFVAR_LISP ("write-region-annotations-so-far", | 6732 DEFVAR_LISP ("write-region-annotations-so-far", |
6413 &Vwrite_region_annotations_so_far, | 6733 &Vwrite_region_annotations_so_far, |
6414 doc: /* When an annotation function is called, this holds the previous annotations. | 6734 doc: /* When an annotation function is called, this holds the previous annotations. |
6415 These are the annotations made by other annotation functions | 6735 These are the annotations made by other annotation functions |
6429 doc: /* File name in which we write a list of all auto save file names. | 6749 doc: /* File name in which we write a list of all auto save file names. |
6430 This variable is initialized automatically from `auto-save-list-file-prefix' | 6750 This variable is initialized automatically from `auto-save-list-file-prefix' |
6431 shortly after Emacs reads your `.emacs' file, if you have not yet given it | 6751 shortly after Emacs reads your `.emacs' file, if you have not yet given it |
6432 a non-nil value. */); | 6752 a non-nil value. */); |
6433 Vauto_save_list_file_name = Qnil; | 6753 Vauto_save_list_file_name = Qnil; |
6754 | |
6755 #ifdef HAVE_FSYNC | |
6756 DEFVAR_BOOL ("write-region-inhibit-fsync", &write_region_inhibit_fsync, | |
6757 doc: /* *Non-nil means don't call fsync in `write-region'. | |
6758 This variable affects calls to `write-region' as well as save commands. | |
6759 A non-nil value may result in data loss! */); | |
6760 write_region_inhibit_fsync = 0; | |
6761 #endif | |
6434 | 6762 |
6435 defsubr (&Sfind_file_name_handler); | 6763 defsubr (&Sfind_file_name_handler); |
6436 defsubr (&Sfile_name_directory); | 6764 defsubr (&Sfile_name_directory); |
6437 defsubr (&Sfile_name_nondirectory); | 6765 defsubr (&Sfile_name_nondirectory); |
6438 defsubr (&Sunhandled_file_name_directory); | 6766 defsubr (&Sunhandled_file_name_directory); |
6466 defsubr (&Sfile_directory_p); | 6794 defsubr (&Sfile_directory_p); |
6467 defsubr (&Sfile_accessible_directory_p); | 6795 defsubr (&Sfile_accessible_directory_p); |
6468 defsubr (&Sfile_regular_p); | 6796 defsubr (&Sfile_regular_p); |
6469 defsubr (&Sfile_modes); | 6797 defsubr (&Sfile_modes); |
6470 defsubr (&Sset_file_modes); | 6798 defsubr (&Sset_file_modes); |
6799 defsubr (&Sset_file_times); | |
6471 defsubr (&Sset_default_file_modes); | 6800 defsubr (&Sset_default_file_modes); |
6472 defsubr (&Sdefault_file_modes); | 6801 defsubr (&Sdefault_file_modes); |
6473 defsubr (&Sfile_newer_than_file_p); | 6802 defsubr (&Sfile_newer_than_file_p); |
6474 defsubr (&Sinsert_file_contents); | 6803 defsubr (&Sinsert_file_contents); |
6475 defsubr (&Swrite_region); | 6804 defsubr (&Swrite_region); |
6483 defsubr (&Sclear_buffer_auto_save_failure); | 6812 defsubr (&Sclear_buffer_auto_save_failure); |
6484 defsubr (&Srecent_auto_save_p); | 6813 defsubr (&Srecent_auto_save_p); |
6485 | 6814 |
6486 defsubr (&Sread_file_name_internal); | 6815 defsubr (&Sread_file_name_internal); |
6487 defsubr (&Sread_file_name); | 6816 defsubr (&Sread_file_name); |
6817 defsubr (&Snext_read_file_uses_dialog_p); | |
6488 | 6818 |
6489 #ifdef unix | 6819 #ifdef unix |
6490 defsubr (&Sunix_sync); | 6820 defsubr (&Sunix_sync); |
6491 #endif | 6821 #endif |
6492 } | 6822 } |
6823 | |
6824 /* arch-tag: 64ba3fd7-f844-4fb2-ba4b-427eb928786c | |
6825 (do not change this comment) */ |