Mercurial > hg > xemacs-beta
comparison src/fileio.c @ 444:576fb035e263 r21-2-37
Import from CVS: tag r21-2-37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:36:19 +0200 |
parents | abe6d1db359e |
children | 1ccc32a20af4 |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
91 this holds the annotations made by the previous functions. */ | 91 this holds the annotations made by the previous functions. */ |
92 Lisp_Object Vwrite_region_annotations_so_far; | 92 Lisp_Object Vwrite_region_annotations_so_far; |
93 | 93 |
94 /* File name in which we write a list of all our auto save files. */ | 94 /* File name in which we write a list of all our auto save files. */ |
95 Lisp_Object Vauto_save_list_file_name; | 95 Lisp_Object Vauto_save_list_file_name; |
96 | |
97 /* Prefix used to construct Vauto_save_list_file_name. */ | |
98 Lisp_Object Vauto_save_list_file_prefix; | |
99 | |
100 /* When non-nil, it prevents auto-save list file creation. */ | |
101 int inhibit_auto_save_session; | |
96 | 102 |
97 int disable_auto_save_when_buffer_shrinks; | 103 int disable_auto_save_when_buffer_shrinks; |
98 | 104 |
99 Lisp_Object Vdirectory_sep_char; | 105 Lisp_Object Vdirectory_sep_char; |
100 | 106 |
391 return result; | 397 return result; |
392 } | 398 } |
393 | 399 |
394 | 400 |
395 DEFUN ("file-name-directory", Ffile_name_directory, 1, 1, 0, /* | 401 DEFUN ("file-name-directory", Ffile_name_directory, 1, 1, 0, /* |
396 Return the directory component in file name NAME. | 402 Return the directory component in file name FILENAME. |
397 Return nil if NAME does not include a directory. | 403 Return nil if FILENAME does not include a directory. |
398 Otherwise return a directory spec. | 404 Otherwise return a directory spec. |
399 Given a Unix syntax file name, returns a string ending in slash. | 405 Given a Unix syntax file name, returns a string ending in slash. |
400 */ | 406 */ |
401 (file)) | 407 (filename)) |
402 { | 408 { |
403 /* This function can GC. GC checked 2000-07-28 ben */ | 409 /* This function can GC. GC checked 2000-07-28 ben */ |
404 Bufbyte *beg; | 410 Bufbyte *beg; |
405 Bufbyte *p; | 411 Bufbyte *p; |
406 Lisp_Object handler; | 412 Lisp_Object handler; |
407 | 413 |
408 CHECK_STRING (file); | 414 CHECK_STRING (filename); |
409 | 415 |
410 /* If the file name has special constructs in it, | 416 /* If the file name has special constructs in it, |
411 call the corresponding file handler. */ | 417 call the corresponding file handler. */ |
412 handler = Ffind_file_name_handler (file, Qfile_name_directory); | 418 handler = Ffind_file_name_handler (filename, Qfile_name_directory); |
413 if (!NILP (handler)) | 419 if (!NILP (handler)) |
414 return call2_check_string_or_nil (handler, Qfile_name_directory, file); | 420 return call2_check_string_or_nil (handler, Qfile_name_directory, filename); |
415 | 421 |
416 #ifdef FILE_SYSTEM_CASE | 422 #ifdef FILE_SYSTEM_CASE |
417 file = FILE_SYSTEM_CASE (file); | 423 filename = FILE_SYSTEM_CASE (filename); |
418 #endif | 424 #endif |
419 beg = XSTRING_DATA (file); | 425 beg = XSTRING_DATA (filename); |
420 p = beg + XSTRING_LENGTH (file); | 426 p = beg + XSTRING_LENGTH (filename); |
421 | 427 |
422 while (p != beg && !IS_ANY_SEP (p[-1]) | 428 while (p != beg && !IS_ANY_SEP (p[-1]) |
423 #ifdef WIN32_NATIVE | 429 #ifdef WIN32_NATIVE |
424 /* only recognize drive specifier at beginning */ | 430 /* only recognize drive specifier at beginning */ |
425 && !(p[-1] == ':' && p == beg + 2) | 431 && !(p[-1] == ':' && p == beg + 2) |
450 #endif /* WIN32_NATIVE */ | 456 #endif /* WIN32_NATIVE */ |
451 return make_string (beg, p - beg); | 457 return make_string (beg, p - beg); |
452 } | 458 } |
453 | 459 |
454 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, 1, 1, 0, /* | 460 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, 1, 1, 0, /* |
455 Return file name NAME sans its directory. | 461 Return file name FILENAME sans its directory. |
456 For example, in a Unix-syntax file name, | 462 For example, in a Unix-syntax file name, |
457 this is everything after the last slash, | 463 this is everything after the last slash, |
458 or the entire name if it contains no slash. | 464 or the entire name if it contains no slash. |
459 */ | 465 */ |
460 (file)) | 466 (filename)) |
461 { | 467 { |
462 /* This function can GC. GC checked 2000-07-28 ben */ | 468 /* This function can GC. GC checked 2000-07-28 ben */ |
463 Bufbyte *beg, *p, *end; | 469 Bufbyte *beg, *p, *end; |
464 Lisp_Object handler; | 470 Lisp_Object handler; |
465 | 471 |
466 CHECK_STRING (file); | 472 CHECK_STRING (filename); |
467 | 473 |
468 /* If the file name has special constructs in it, | 474 /* If the file name has special constructs in it, |
469 call the corresponding file handler. */ | 475 call the corresponding file handler. */ |
470 handler = Ffind_file_name_handler (file, Qfile_name_nondirectory); | 476 handler = Ffind_file_name_handler (filename, Qfile_name_nondirectory); |
471 if (!NILP (handler)) | 477 if (!NILP (handler)) |
472 return call2_check_string (handler, Qfile_name_nondirectory, file); | 478 return call2_check_string (handler, Qfile_name_nondirectory, filename); |
473 | 479 |
474 beg = XSTRING_DATA (file); | 480 beg = XSTRING_DATA (filename); |
475 end = p = beg + XSTRING_LENGTH (file); | 481 end = p = beg + XSTRING_LENGTH (filename); |
476 | 482 |
477 while (p != beg && !IS_ANY_SEP (p[-1]) | 483 while (p != beg && !IS_ANY_SEP (p[-1]) |
478 #ifdef WIN32_NATIVE | 484 #ifdef WIN32_NATIVE |
479 /* only recognize drive specifier at beginning */ | 485 /* only recognize drive specifier at beginning */ |
480 && !(p[-1] == ':' && p == beg + 2) | 486 && !(p[-1] == ':' && p == beg + 2) |
491 If FILENAME is a directly usable file itself, return | 497 If FILENAME is a directly usable file itself, return |
492 \(file-name-directory FILENAME). | 498 \(file-name-directory FILENAME). |
493 The `call-process' and `start-process' functions use this function to | 499 The `call-process' and `start-process' functions use this function to |
494 get a current directory to run processes in. | 500 get a current directory to run processes in. |
495 */ | 501 */ |
496 (filename)) | 502 (filename)) |
497 { | 503 { |
498 /* This function can GC. GC checked 2000-07-28 ben */ | 504 /* This function can GC. GC checked 2000-07-28 ben */ |
499 Lisp_Object handler; | 505 Lisp_Object handler; |
500 | 506 |
501 /* If the file name has special constructs in it, | 507 /* If the file name has special constructs in it, |
541 The result can be used as the value of `default-directory' | 547 The result can be used as the value of `default-directory' |
542 or passed as second argument to `expand-file-name'. | 548 or passed as second argument to `expand-file-name'. |
543 For a Unix-syntax file name, just appends a slash, | 549 For a Unix-syntax file name, just appends a slash, |
544 except for (file-name-as-directory \"\") => \"./\". | 550 except for (file-name-as-directory \"\") => \"./\". |
545 */ | 551 */ |
546 (file)) | 552 (filename)) |
547 { | 553 { |
548 /* This function can GC. GC checked 2000-07-28 ben */ | 554 /* This function can GC. GC checked 2000-07-28 ben */ |
549 char *buf; | 555 char *buf; |
550 Lisp_Object handler; | 556 Lisp_Object handler; |
551 | 557 |
552 CHECK_STRING (file); | 558 CHECK_STRING (filename); |
553 | 559 |
554 /* If the file name has special constructs in it, | 560 /* If the file name has special constructs in it, |
555 call the corresponding file handler. */ | 561 call the corresponding file handler. */ |
556 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); | 562 handler = Ffind_file_name_handler (filename, Qfile_name_as_directory); |
557 if (!NILP (handler)) | 563 if (!NILP (handler)) |
558 return call2_check_string (handler, Qfile_name_as_directory, file); | 564 return call2_check_string (handler, Qfile_name_as_directory, filename); |
559 | 565 |
560 buf = (char *) alloca (XSTRING_LENGTH (file) + 10); | 566 buf = (char *) alloca (XSTRING_LENGTH (filename) + 10); |
561 return build_string (file_name_as_directory | 567 return build_string (file_name_as_directory |
562 (buf, (char *) XSTRING_DATA (file))); | 568 (buf, (char *) XSTRING_DATA (filename))); |
563 } | 569 } |
564 | 570 |
565 /* | 571 /* |
566 * Convert from directory name to filename. | 572 * Convert from directory name to filename. |
567 * On UNIX, it's simple: just make sure there isn't a terminating / | 573 * On UNIX, it's simple: just make sure there isn't a terminating / |
586 dst[slen - 1] = 0; | 592 dst[slen - 1] = 0; |
587 return 1; | 593 return 1; |
588 } | 594 } |
589 | 595 |
590 DEFUN ("directory-file-name", Fdirectory_file_name, 1, 1, 0, /* | 596 DEFUN ("directory-file-name", Fdirectory_file_name, 1, 1, 0, /* |
591 Return the file name of the directory named DIR. | 597 Return the file name of the directory named DIRECTORY. |
592 This is the name of the file that holds the data for the directory DIR. | 598 This is the name of the file that holds the data for the directory. |
593 This operation exists because a directory is also a file, but its name as | 599 This operation exists because a directory is also a file, but its name as |
594 a directory is different from its name as a file. | 600 a directory is different from its name as a file. |
595 In Unix-syntax, this function just removes the final slash. | 601 In Unix-syntax, this function just removes the final slash. |
596 */ | 602 */ |
597 (directory)) | 603 (directory)) |
729 | 735 |
730 DEFUN ("expand-file-name", Fexpand_file_name, 1, 2, 0, /* | 736 DEFUN ("expand-file-name", Fexpand_file_name, 1, 2, 0, /* |
731 Convert filename NAME to absolute, and canonicalize it. | 737 Convert filename NAME to absolute, and canonicalize it. |
732 Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative | 738 Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative |
733 (does not start with slash); if DEFAULT-DIRECTORY is nil or missing, | 739 (does not start with slash); if DEFAULT-DIRECTORY is nil or missing, |
734 the current buffer's value of default-directory is used. | 740 the current buffer's value of `default-directory' is used. |
735 File name components that are `.' are removed, and | 741 File name components that are `.' are removed, and |
736 so are file name components followed by `..', along with the `..' itself; | 742 so are file name components followed by `..', along with the `..' itself; |
737 note that these simplifications are done without checking the resulting | 743 note that these simplifications are done without checking the resulting |
738 file names in the file system. | 744 file names in the file system. |
739 An initial `~/' expands to your home directory. | 745 An initial `~/' expands to your home directory. |
1245 | 1251 |
1246 RETURN_UNGCPRO (make_string (target, o - target)); | 1252 RETURN_UNGCPRO (make_string (target, o - target)); |
1247 } | 1253 } |
1248 | 1254 |
1249 DEFUN ("file-truename", Ffile_truename, 1, 2, 0, /* | 1255 DEFUN ("file-truename", Ffile_truename, 1, 2, 0, /* |
1250 Return the canonical name of the given FILE. | 1256 Return the canonical name of FILENAME. |
1251 Second arg DEFAULT is directory to start with if FILE is relative | 1257 Second arg DEFAULT is directory to start with if FILENAME is relative |
1252 (does not start with slash); if DEFAULT is nil or missing, | 1258 (does not start with slash); if DEFAULT is nil or missing, |
1253 the current buffer's value of default-directory is used. | 1259 the current buffer's value of `default-directory' is used. |
1254 No component of the resulting pathname will be a symbolic link, as | 1260 No component of the resulting pathname will be a symbolic link, as |
1255 in the realpath() function. | 1261 in the realpath() function. |
1256 */ | 1262 */ |
1257 (filename, default_)) | 1263 (filename, default_)) |
1258 { | 1264 { |
1387 | 1393 |
1388 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, 1, 1, 0, /* | 1394 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, 1, 1, 0, /* |
1389 Substitute environment variables referred to in FILENAME. | 1395 Substitute environment variables referred to in FILENAME. |
1390 `$FOO' where FOO is an environment variable name means to substitute | 1396 `$FOO' where FOO is an environment variable name means to substitute |
1391 the value of that variable. The variable name should be terminated | 1397 the value of that variable. The variable name should be terminated |
1392 with a character not a letter, digit or underscore; otherwise, enclose | 1398 with a character, not a letter, digit or underscore; otherwise, enclose |
1393 the entire variable name in braces. | 1399 the entire variable name in braces. |
1394 If `/~' appears, all of FILENAME through that `/' is discarded. | 1400 If `/~' appears, all of FILENAME through that `/' is discarded. |
1395 | 1401 */ |
1396 */ | 1402 (filename)) |
1397 (string)) | |
1398 { | 1403 { |
1399 /* This function can GC. GC checked 2000-07-28 ben. */ | 1404 /* This function can GC. GC checked 2000-07-28 ben. */ |
1400 Bufbyte *nm; | 1405 Bufbyte *nm; |
1401 | 1406 |
1402 Bufbyte *s, *p, *o, *x, *endp; | 1407 Bufbyte *s, *p, *o, *x, *endp; |
1404 int total = 0; | 1409 int total = 0; |
1405 int substituted = 0; | 1410 int substituted = 0; |
1406 Bufbyte *xnm; | 1411 Bufbyte *xnm; |
1407 Lisp_Object handler; | 1412 Lisp_Object handler; |
1408 | 1413 |
1409 CHECK_STRING (string); | 1414 CHECK_STRING (filename); |
1410 | 1415 |
1411 /* If the file name has special constructs in it, | 1416 /* If the file name has special constructs in it, |
1412 call the corresponding file handler. */ | 1417 call the corresponding file handler. */ |
1413 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name); | 1418 handler = Ffind_file_name_handler (filename, Qsubstitute_in_file_name); |
1414 if (!NILP (handler)) | 1419 if (!NILP (handler)) |
1415 return call2_check_string_or_nil (handler, Qsubstitute_in_file_name, | 1420 return call2_check_string_or_nil (handler, Qsubstitute_in_file_name, |
1416 string); | 1421 filename); |
1417 | 1422 |
1418 nm = XSTRING_DATA (string); | 1423 nm = XSTRING_DATA (filename); |
1419 endp = nm + XSTRING_LENGTH (string); | 1424 endp = nm + XSTRING_LENGTH (filename); |
1420 | 1425 |
1421 /* If /~ or // appears, discard everything through first slash. */ | 1426 /* If /~ or // appears, discard everything through first slash. */ |
1422 | 1427 |
1423 for (p = nm; p != endp; p++) | 1428 for (p = nm; p != endp; p++) |
1424 { | 1429 { |
1494 total += strlen ((char *) o); | 1499 total += strlen ((char *) o); |
1495 substituted = 1; | 1500 substituted = 1; |
1496 } | 1501 } |
1497 | 1502 |
1498 if (!substituted) | 1503 if (!substituted) |
1499 return string; | 1504 return filename; |
1500 | 1505 |
1501 /* If substitution required, recopy the string and do it */ | 1506 /* If substitution required, recopy the filename and do it */ |
1502 /* Make space in stack frame for the new copy */ | 1507 /* Make space in stack frame for the new copy */ |
1503 xnm = (Bufbyte *) alloca (XSTRING_LENGTH (string) + total + 1); | 1508 xnm = (Bufbyte *) alloca (XSTRING_LENGTH (filename) + total + 1); |
1504 x = xnm; | 1509 x = xnm; |
1505 | 1510 |
1506 /* Copy the rest of the name through, replacing $ constructs with values */ | 1511 /* Copy the rest of the name through, replacing $ constructs with values */ |
1507 for (p = nm; *p;) | 1512 for (p = nm; *p;) |
1508 if (*p != '$') | 1513 if (*p != '$') |
1570 #endif | 1575 #endif |
1571 | 1576 |
1572 return make_string (xnm, x - xnm); | 1577 return make_string (xnm, x - xnm); |
1573 | 1578 |
1574 badsubst: | 1579 badsubst: |
1575 syntax_error ("Bad format environment-variable substitution", string); | 1580 syntax_error ("Bad format environment-variable substitution", filename); |
1576 missingclose: | 1581 missingclose: |
1577 syntax_error ("Missing \"}\" in environment-variable substitution", | 1582 syntax_error ("Missing \"}\" in environment-variable substitution", |
1578 string); | 1583 filename); |
1579 badvar: | 1584 badvar: |
1580 syntax_error_2 ("Substituting nonexistent environment variable", | 1585 syntax_error_2 ("Substituting nonexistent environment variable", |
1581 string, build_string (target)); | 1586 filename, build_string ((char *) target)); |
1582 | 1587 |
1583 /* NOTREACHED */ | 1588 /* NOTREACHED */ |
1584 return Qnil; /* suppress compiler warning */ | 1589 return Qnil; /* suppress compiler warning */ |
1585 } | 1590 } |
1586 | 1591 |
1660 return; | 1665 return; |
1661 } | 1666 } |
1662 | 1667 |
1663 DEFUN ("copy-file", Fcopy_file, 2, 4, | 1668 DEFUN ("copy-file", Fcopy_file, 2, 4, |
1664 "fCopy file: \nFCopy %s to file: \np\nP", /* | 1669 "fCopy file: \nFCopy %s to file: \np\nP", /* |
1665 Copy FILE to NEWNAME. Both args must be strings. | 1670 Copy FILENAME to NEWNAME. Both args must be strings. |
1666 Signals a `file-already-exists' error if file NEWNAME already exists, | 1671 Signals a `file-already-exists' error if file NEWNAME already exists, |
1667 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil. | 1672 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil. |
1668 A number as third arg means request confirmation if NEWNAME already exists. | 1673 A number as third arg means request confirmation if NEWNAME already exists. |
1669 This is what happens in interactive use with M-x. | 1674 This is what happens in interactive use with M-x. |
1670 Fourth arg KEEP-TIME non-nil means give the new file the same | 1675 Fourth arg KEEP-TIME non-nil means give the new file the same |
1920 internal_delete_file_1, Qnil)); | 1925 internal_delete_file_1, Qnil)); |
1921 } | 1926 } |
1922 | 1927 |
1923 DEFUN ("rename-file", Frename_file, 2, 3, | 1928 DEFUN ("rename-file", Frename_file, 2, 3, |
1924 "fRename file: \nFRename %s to file: \np", /* | 1929 "fRename file: \nFRename %s to file: \np", /* |
1925 Rename FILE as NEWNAME. Both args strings. | 1930 Rename FILENAME as NEWNAME. Both args must be strings. |
1926 If file has names other than FILE, it continues to have those names. | 1931 If file has names other than FILENAME, it continues to have those names. |
1927 Signals a `file-already-exists' error if a file NEWNAME already exists | 1932 Signals a `file-already-exists' error if a file NEWNAME already exists |
1928 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | 1933 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. |
1929 A number as third arg means request confirmation if NEWNAME already exists. | 1934 A number as third arg means request confirmation if NEWNAME already exists. |
1930 This is what happens in interactive use with M-x. | 1935 This is what happens in interactive use with M-x. |
1931 */ | 1936 */ |
2004 return Qnil; | 2009 return Qnil; |
2005 } | 2010 } |
2006 | 2011 |
2007 DEFUN ("add-name-to-file", Fadd_name_to_file, 2, 3, | 2012 DEFUN ("add-name-to-file", Fadd_name_to_file, 2, 3, |
2008 "fAdd name to file: \nFName to add to %s: \np", /* | 2013 "fAdd name to file: \nFName to add to %s: \np", /* |
2009 Give FILE additional name NEWNAME. Both args strings. | 2014 Give FILENAME additional name NEWNAME. Both args must be strings. |
2010 Signals a `file-already-exists' error if a file NEWNAME already exists | 2015 Signals a `file-already-exists' error if a file NEWNAME already exists |
2011 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | 2016 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. |
2012 A number as third arg means request confirmation if NEWNAME already exists. | 2017 A number as third arg means request confirmation if NEWNAME already exists. |
2013 This is what happens in interactive use with M-x. | 2018 This is what happens in interactive use with M-x. |
2014 */ | 2019 */ |
2492 return Qnil; | 2497 return Qnil; |
2493 return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; | 2498 return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; |
2494 } | 2499 } |
2495 | 2500 |
2496 DEFUN ("file-modes", Ffile_modes, 1, 1, 0, /* | 2501 DEFUN ("file-modes", Ffile_modes, 1, 1, 0, /* |
2497 Return mode bits of FILE, as an integer. | 2502 Return mode bits of file named FILENAME, as an integer. |
2498 */ | 2503 */ |
2499 (filename)) | 2504 (filename)) |
2500 { | 2505 { |
2501 /* This function can GC. GC checked 1997.04.10. */ | 2506 /* This function can GC. GC checked 1997.04.10. */ |
2502 Lisp_Object abspath; | 2507 Lisp_Object abspath; |
2529 | 2534 |
2530 return make_int (st.st_mode & 07777); | 2535 return make_int (st.st_mode & 07777); |
2531 } | 2536 } |
2532 | 2537 |
2533 DEFUN ("set-file-modes", Fset_file_modes, 2, 2, 0, /* | 2538 DEFUN ("set-file-modes", Fset_file_modes, 2, 2, 0, /* |
2534 Set mode bits of FILE to MODE (an integer). | 2539 Set mode bits of file named FILENAME to MODE (an integer). |
2535 Only the 12 low bits of MODE are used. | 2540 Only the 12 low bits of MODE are used. |
2536 */ | 2541 */ |
2537 (filename, mode)) | 2542 (filename, mode)) |
2538 { | 2543 { |
2539 /* This function can GC. GC checked 1997.04.10. */ | 2544 /* This function can GC. GC checked 1997.04.10. */ |
2561 return Qnil; | 2566 return Qnil; |
2562 } | 2567 } |
2563 | 2568 |
2564 DEFUN ("set-default-file-modes", Fset_default_file_modes, 1, 1, 0, /* | 2569 DEFUN ("set-default-file-modes", Fset_default_file_modes, 1, 1, 0, /* |
2565 Set the file permission bits for newly created files. | 2570 Set the file permission bits for newly created files. |
2566 MASK should be an integer; if a permission's bit in MASK is 1, | 2571 The argument MODE should be an integer; if a bit in MODE is 1, |
2567 subsequently created files will not have that permission enabled. | 2572 subsequently created files will not have the permission corresponding |
2568 Only the low 9 bits are used. | 2573 to that bit enabled. Only the low 9 bits are used. |
2569 This setting is inherited by subprocesses. | 2574 This setting is inherited by subprocesses. |
2570 */ | 2575 */ |
2571 (mode)) | 2576 (mode)) |
2572 { | 2577 { |
2573 CHECK_INT (mode); | 2578 CHECK_INT (mode); |
2667 to CODESYS; if omitted, no conversion happens. If USED-CODESYS is non-nil, | 2672 to CODESYS; if omitted, no conversion happens. If USED-CODESYS is non-nil, |
2668 it should be a symbol, and the actual coding system that was used for the | 2673 it should be a symbol, and the actual coding system that was used for the |
2669 decoding is stored into it. It will in general be different from CODESYS | 2674 decoding is stored into it. It will in general be different from CODESYS |
2670 if CODESYS specifies automatic encoding detection or end-of-line detection. | 2675 if CODESYS specifies automatic encoding detection or end-of-line detection. |
2671 | 2676 |
2672 Currently BEG and END refer to byte positions (as opposed to character | 2677 Currently START and END refer to byte positions (as opposed to character |
2673 positions), even in Mule. (Fixing this is very difficult.) | 2678 positions), even in Mule. (Fixing this is very difficult.) |
2674 */ | 2679 */ |
2675 (filename, visit, beg, end, replace, codesys, used_codesys)) | 2680 (filename, visit, start, end, replace, codesys, used_codesys)) |
2676 { | 2681 { |
2677 /* This function can call lisp */ | 2682 /* This function can call lisp */ |
2678 /* #### dmoore - this function hasn't been checked for gc recently */ | |
2679 struct stat st; | 2683 struct stat st; |
2680 int fd; | 2684 int fd; |
2681 int saverrno = 0; | 2685 int saverrno = 0; |
2682 Charcount inserted = 0; | 2686 Charcount inserted = 0; |
2683 int speccount; | 2687 int speccount; |
2718 call the corresponding file handler. */ | 2722 call the corresponding file handler. */ |
2719 handler = Ffind_file_name_handler (filename, Qinsert_file_contents); | 2723 handler = Ffind_file_name_handler (filename, Qinsert_file_contents); |
2720 if (!NILP (handler)) | 2724 if (!NILP (handler)) |
2721 { | 2725 { |
2722 val = call6 (handler, Qinsert_file_contents, filename, | 2726 val = call6 (handler, Qinsert_file_contents, filename, |
2723 visit, beg, end, replace); | 2727 visit, start, end, replace); |
2724 goto handled; | 2728 goto handled; |
2725 } | 2729 } |
2726 | 2730 |
2727 #ifdef FILE_CODING | 2731 #ifdef FILE_CODING |
2728 if (!NILP (used_codesys)) | 2732 if (!NILP (used_codesys)) |
2729 CHECK_SYMBOL (used_codesys); | 2733 CHECK_SYMBOL (used_codesys); |
2730 #endif | 2734 #endif |
2731 | 2735 |
2732 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) | 2736 if ( (!NILP (start) || !NILP (end)) && !NILP (visit) ) |
2733 error ("Attempt to visit less than an entire file"); | 2737 error ("Attempt to visit less than an entire file"); |
2734 | 2738 |
2735 fd = -1; | 2739 fd = -1; |
2736 | 2740 |
2737 if (xemacs_stat ((char *) XSTRING_DATA (filename), &st) < 0) | 2741 if (xemacs_stat ((char *) XSTRING_DATA (filename), &st) < 0) |
2744 goto notfound; | 2748 goto notfound; |
2745 } | 2749 } |
2746 | 2750 |
2747 #ifdef S_IFREG | 2751 #ifdef S_IFREG |
2748 /* Signal an error if we are accessing a non-regular file, with | 2752 /* Signal an error if we are accessing a non-regular file, with |
2749 REPLACE, BEG or END being non-nil. */ | 2753 REPLACE, START or END being non-nil. */ |
2750 if (!S_ISREG (st.st_mode)) | 2754 if (!S_ISREG (st.st_mode)) |
2751 { | 2755 { |
2752 not_regular = 1; | 2756 not_regular = 1; |
2753 | 2757 |
2754 if (!NILP (visit)) | 2758 if (!NILP (visit)) |
2755 goto notfound; | 2759 goto notfound; |
2756 | 2760 |
2757 if (!NILP (replace) || !NILP (beg) || !NILP (end)) | 2761 if (!NILP (replace) || !NILP (start) || !NILP (end)) |
2758 { | 2762 { |
2759 end_multiple_change (buf, mc_count); | 2763 end_multiple_change (buf, mc_count); |
2760 | 2764 |
2761 return Fsignal (Qfile_error, | 2765 RETURN_UNGCPRO |
2762 list2 (build_translated_string("not a regular file"), | 2766 (Fsignal (Qfile_error, |
2763 filename)); | 2767 list2 (build_translated_string("not a regular file"), |
2768 filename))); | |
2764 } | 2769 } |
2765 } | 2770 } |
2766 #endif /* S_IFREG */ | 2771 #endif /* S_IFREG */ |
2767 | 2772 |
2768 if (!NILP (beg)) | 2773 if (!NILP (start)) |
2769 CHECK_INT (beg); | 2774 CHECK_INT (start); |
2770 else | 2775 else |
2771 beg = Qzero; | 2776 start = Qzero; |
2772 | 2777 |
2773 if (!NILP (end)) | 2778 if (!NILP (end)) |
2774 CHECK_INT (end); | 2779 CHECK_INT (end); |
2775 | 2780 |
2776 if (fd < 0) | 2781 if (fd < 0) |
2909 (same_at_end + st.st_size - BUF_ZV (buf)); | 2914 (same_at_end + st.st_size - BUF_ZV (buf)); |
2910 if (overlap > 0) | 2915 if (overlap > 0) |
2911 same_at_end += overlap; | 2916 same_at_end += overlap; |
2912 | 2917 |
2913 /* Arrange to read only the nonmatching middle part of the file. */ | 2918 /* Arrange to read only the nonmatching middle part of the file. */ |
2914 beg = make_int (same_at_start - BUF_BEGV (buf)); | 2919 start = make_int (same_at_start - BUF_BEGV (buf)); |
2915 end = make_int (st.st_size - (BUF_ZV (buf) - same_at_end)); | 2920 end = make_int (st.st_size - (BUF_ZV (buf) - same_at_end)); |
2916 | 2921 |
2917 buffer_delete_range (buf, same_at_start, same_at_end, | 2922 buffer_delete_range (buf, same_at_start, same_at_end, |
2918 !NILP (visit) ? INSDEL_NO_LOCKING : 0); | 2923 !NILP (visit) ? INSDEL_NO_LOCKING : 0); |
2919 /* Insert from the file at the proper position. */ | 2924 /* Insert from the file at the proper position. */ |
2921 } | 2926 } |
2922 #endif /* FSFMACS_SPEEDY_INSERT */ | 2927 #endif /* FSFMACS_SPEEDY_INSERT */ |
2923 | 2928 |
2924 if (!not_regular) | 2929 if (!not_regular) |
2925 { | 2930 { |
2926 total = XINT (end) - XINT (beg); | 2931 total = XINT (end) - XINT (start); |
2927 | 2932 |
2928 /* Make sure point-max won't overflow after this insertion. */ | 2933 /* Make sure point-max won't overflow after this insertion. */ |
2929 if (total != XINT (make_int (total))) | 2934 if (total != XINT (make_int (total))) |
2930 error ("Maximum buffer size exceeded"); | 2935 error ("Maximum buffer size exceeded"); |
2931 } | 2936 } |
2932 else | 2937 else |
2933 /* For a special file, all we can do is guess. The value of -1 | 2938 /* For a special file, all we can do is guess. The value of -1 |
2934 will make the stream functions read as much as possible. */ | 2939 will make the stream functions read as much as possible. */ |
2935 total = -1; | 2940 total = -1; |
2936 | 2941 |
2937 if (XINT (beg) != 0 | 2942 if (XINT (start) != 0 |
2938 #ifdef FSFMACS_SPEEDY_INSERT | 2943 #ifdef FSFMACS_SPEEDY_INSERT |
2939 /* why was this here? asked jwz. The reason is that the replace-mode | 2944 /* why was this here? asked jwz. The reason is that the replace-mode |
2940 connivings above will normally put the file pointer other than | 2945 connivings above will normally put the file pointer other than |
2941 where it should be. */ | 2946 where it should be. */ |
2942 || !NILP (replace) | 2947 || !NILP (replace) |
2943 #endif /* !FSFMACS_SPEEDY_INSERT */ | 2948 #endif /* !FSFMACS_SPEEDY_INSERT */ |
2944 ) | 2949 ) |
2945 { | 2950 { |
2946 if (lseek (fd, XINT (beg), 0) < 0) | 2951 if (lseek (fd, XINT (start), 0) < 0) |
2947 report_file_error ("Setting file position", list1 (filename)); | 2952 report_file_error ("Setting file position", list1 (filename)); |
2948 } | 2953 } |
2949 | 2954 |
2950 { | 2955 { |
2951 Bufpos cur_point = BUF_PT (buf); | 2956 Bufpos cur_point = BUF_PT (buf); |
3025 /* XEmacs addition: */ | 3030 /* XEmacs addition: */ |
3026 /* This function used to be in C, ostensibly so that | 3031 /* This function used to be in C, ostensibly so that |
3027 it could be called here. But that's just silly. | 3032 it could be called here. But that's just silly. |
3028 There's no reason C code can't call out to Lisp | 3033 There's no reason C code can't call out to Lisp |
3029 code, and it's a lot cleaner this way. */ | 3034 code, and it's a lot cleaner this way. */ |
3035 /* Note: compute-buffer-file-truename is called for | |
3036 side-effect! Its return value is intentionally | |
3037 ignored. */ | |
3030 if (!NILP (Ffboundp (Qcompute_buffer_file_truename))) | 3038 if (!NILP (Ffboundp (Qcompute_buffer_file_truename))) |
3031 call1 (Qcompute_buffer_file_truename, make_buffer (buf)); | 3039 call1 (Qcompute_buffer_file_truename, make_buffer (buf)); |
3032 } | 3040 } |
3033 BUF_SAVE_MODIFF (buf) = BUF_MODIFF (buf); | 3041 BUF_SAVE_MODIFF (buf) = BUF_MODIFF (buf); |
3034 buf->auto_save_modified = BUF_MODIFF (buf); | 3042 buf->auto_save_modified = BUF_MODIFF (buf); |
3645 } | 3653 } |
3646 #endif /* 0 */ | 3654 #endif /* 0 */ |
3647 | 3655 |
3648 | 3656 |
3649 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, 1, 1, 0, /* | 3657 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, 1, 1, 0, /* |
3650 Return t if last mod time of BUF's visited file matches what BUF records. | 3658 Return t if last mod time of BUFFER's visited file matches what BUFFER records. |
3651 This means that the file has not been changed since it was visited or saved. | 3659 This means that the file has not been changed since it was visited or saved. |
3652 */ | 3660 */ |
3653 (buf)) | 3661 (buffer)) |
3654 { | 3662 { |
3655 /* This function can call lisp; GC checked 2000-07-11 ben */ | 3663 /* This function can call lisp; GC checked 2000-07-11 ben */ |
3656 struct buffer *b; | 3664 struct buffer *b; |
3657 struct stat st; | 3665 struct stat st; |
3658 Lisp_Object handler; | 3666 Lisp_Object handler; |
3659 | 3667 |
3660 CHECK_BUFFER (buf); | 3668 CHECK_BUFFER (buffer); |
3661 b = XBUFFER (buf); | 3669 b = XBUFFER (buffer); |
3662 | 3670 |
3663 if (!STRINGP (b->filename)) return Qt; | 3671 if (!STRINGP (b->filename)) return Qt; |
3664 if (b->modtime == 0) return Qt; | 3672 if (b->modtime == 0) return Qt; |
3665 | 3673 |
3666 /* If the file name has special constructs in it, | 3674 /* If the file name has special constructs in it, |
3667 call the corresponding file handler. */ | 3675 call the corresponding file handler. */ |
3668 handler = Ffind_file_name_handler (b->filename, | 3676 handler = Ffind_file_name_handler (b->filename, |
3669 Qverify_visited_file_modtime); | 3677 Qverify_visited_file_modtime); |
3670 if (!NILP (handler)) | 3678 if (!NILP (handler)) |
3671 return call2 (handler, Qverify_visited_file_modtime, buf); | 3679 return call2 (handler, Qverify_visited_file_modtime, buffer); |
3672 | 3680 |
3673 if (xemacs_stat ((char *) XSTRING_DATA (b->filename), &st) < 0) | 3681 if (xemacs_stat ((char *) XSTRING_DATA (b->filename), &st) < 0) |
3674 { | 3682 { |
3675 /* If the file doesn't exist now and didn't exist before, | 3683 /* If the file doesn't exist now and didn't exist before, |
3676 we say that it isn't modified, provided the error is a tame one. */ | 3684 we say that it isn't modified, provided the error is a tame one. */ |
3980 } | 3988 } |
3981 | 3989 |
3982 /* Open the auto-save list file, if necessary. | 3990 /* Open the auto-save list file, if necessary. |
3983 We only do this now so that the file only exists | 3991 We only do this now so that the file only exists |
3984 if we actually auto-saved any files. */ | 3992 if we actually auto-saved any files. */ |
3985 if (!auto_saved && STRINGP (listfile) && listdesc < 0) | 3993 if (!auto_saved && !inhibit_auto_save_session |
3994 && !NILP (Vauto_save_list_file_prefix) | |
3995 && STRINGP (listfile) && listdesc < 0) | |
3986 { | 3996 { |
3987 listdesc = open ((char *) XSTRING_DATA (listfile), | 3997 listdesc = open ((char *) XSTRING_DATA (listfile), |
3988 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY, | 3998 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY, |
3989 CREAT_MODE); | 3999 CREAT_MODE); |
3990 | 4000 |
4296 DEFVAR_LISP ("auto-save-list-file-name", &Vauto_save_list_file_name /* | 4306 DEFVAR_LISP ("auto-save-list-file-name", &Vauto_save_list_file_name /* |
4297 File name in which we write a list of all auto save file names. | 4307 File name in which we write a list of all auto save file names. |
4298 */ ); | 4308 */ ); |
4299 Vauto_save_list_file_name = Qnil; | 4309 Vauto_save_list_file_name = Qnil; |
4300 | 4310 |
4311 DEFVAR_LISP ("auto-save-list-file-prefix", &Vauto_save_list_file_prefix /* | |
4312 Prefix for generating auto-save-list-file-name. | |
4313 Emacs's pid and the system name will be appended to | |
4314 this prefix to create a unique file name. | |
4315 */ ); | |
4316 Vauto_save_list_file_prefix = build_string ("~/.saves-"); | |
4317 | |
4318 DEFVAR_BOOL ("inhibit-auto-save-session", &inhibit_auto_save_session /* | |
4319 When non-nil, inhibit auto save list file creation. | |
4320 */ ); | |
4321 inhibit_auto_save_session = 0; | |
4322 | |
4301 DEFVAR_BOOL ("disable-auto-save-when-buffer-shrinks", | 4323 DEFVAR_BOOL ("disable-auto-save-when-buffer-shrinks", |
4302 &disable_auto_save_when_buffer_shrinks /* | 4324 &disable_auto_save_when_buffer_shrinks /* |
4303 If non-nil, auto-saving is disabled when a buffer shrinks too much. | 4325 If non-nil, auto-saving is disabled when a buffer shrinks too much. |
4304 This is to prevent you from losing your edits if you accidentally | 4326 This is to prevent you from losing your edits if you accidentally |
4305 delete a large chunk of the buffer and don't notice it until too late. | 4327 delete a large chunk of the buffer and don't notice it until too late. |