Mercurial > emacs
comparison src/fileio.c @ 1377:dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
use that as file name to visit, and print it in the message.
Use it for file locking too.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 10 Oct 1992 08:34:51 +0000 |
parents | aa32c275cbf9 |
children | b86ef0432100 |
comparison
equal
deleted
inserted
replaced
1376:dd83ec6103fe | 1377:dcec08a3bec4 |
---|---|
2384 Optional fifth argument VISIT if t means\n\ | 2384 Optional fifth argument VISIT if t means\n\ |
2385 set the last-save-file-modtime of buffer to this file's modtime\n\ | 2385 set the last-save-file-modtime of buffer to this file's modtime\n\ |
2386 and mark buffer not modified.\n\ | 2386 and mark buffer not modified.\n\ |
2387 If VISIT is neither t nor nil, it means do not print\n\ | 2387 If VISIT is neither t nor nil, it means do not print\n\ |
2388 the \"Wrote file\" message.\n\ | 2388 the \"Wrote file\" message.\n\ |
2389 If VISIT is a string, it is a second file name;\n\ | |
2390 the output goes to FILENAME, but the buffer is marked as visiting VISIT.\n\ | |
2391 VISIT is also the file name to lock and unlock for clash detection.\n\ | |
2389 Kludgy feature: if START is a string, then that string is written\n\ | 2392 Kludgy feature: if START is a string, then that string is written\n\ |
2390 to the file, instead of any buffer contents, and END is ignored.") | 2393 to the file, instead of any buffer contents, and END is ignored.") |
2391 (start, end, filename, append, visit) | 2394 (start, end, filename, append, visit) |
2392 Lisp_Object start, end, filename, append, visit; | 2395 Lisp_Object start, end, filename, append, visit; |
2393 { | 2396 { |
2400 int count = specpdl_ptr - specpdl; | 2403 int count = specpdl_ptr - specpdl; |
2401 #ifdef VMS | 2404 #ifdef VMS |
2402 unsigned char *fname = 0; /* If non-0, original filename (must rename) */ | 2405 unsigned char *fname = 0; /* If non-0, original filename (must rename) */ |
2403 #endif /* VMS */ | 2406 #endif /* VMS */ |
2404 Lisp_Object handler; | 2407 Lisp_Object handler; |
2405 struct gcpro gcpro1, gcpro2; | 2408 Lisp_Object visit_file = XTYPE (visit) == Lisp_String ? visit : filename; |
2409 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
2406 | 2410 |
2407 /* Special kludge to simplify auto-saving */ | 2411 /* Special kludge to simplify auto-saving */ |
2408 if (NILP (start)) | 2412 if (NILP (start)) |
2409 { | 2413 { |
2410 XFASTINT (start) = BEG; | 2414 XFASTINT (start) = BEG; |
2411 XFASTINT (end) = Z; | 2415 XFASTINT (end) = Z; |
2412 } | 2416 } |
2413 else if (XTYPE (start) != Lisp_String) | 2417 else if (XTYPE (start) != Lisp_String) |
2414 validate_region (&start, &end); | 2418 validate_region (&start, &end); |
2415 | 2419 |
2416 GCPRO2 (start, filename); | 2420 GCPRO4 (start, filename, visit, visit_file); |
2417 filename = Fexpand_file_name (filename, Qnil); | 2421 filename = Fexpand_file_name (filename, Qnil); |
2418 | 2422 |
2419 /* If the file name has special constructs in it, | 2423 /* If the file name has special constructs in it, |
2420 call the corresponding file handler. */ | 2424 call the corresponding file handler. */ |
2421 handler = find_file_handler (filename); | 2425 handler = find_file_handler (filename); |
2434 val = Ffuncall (7, args); | 2438 val = Ffuncall (7, args); |
2435 | 2439 |
2436 /* Do this before reporting IO error | 2440 /* Do this before reporting IO error |
2437 to avoid a "file has changed on disk" warning on | 2441 to avoid a "file has changed on disk" warning on |
2438 next attempt to save. */ | 2442 next attempt to save. */ |
2439 if (EQ (visit, Qt)) | 2443 if (EQ (visit, Qt) || XTYPE (visit) == Lisp_String) |
2440 { | 2444 { |
2441 current_buffer->modtime = 0; | 2445 current_buffer->modtime = 0; |
2442 current_buffer->save_modified = MODIFF; | 2446 current_buffer->save_modified = MODIFF; |
2443 XFASTINT (current_buffer->save_length) = Z - BEG; | 2447 XFASTINT (current_buffer->save_length) = Z - BEG; |
2444 current_buffer->filename = filename; | 2448 current_buffer->filename = visit_file; |
2445 } | 2449 } |
2446 UNGCPRO; | 2450 UNGCPRO; |
2447 return val; | 2451 return val; |
2448 } | 2452 } |
2449 | 2453 |
2450 #ifdef CLASH_DETECTION | 2454 #ifdef CLASH_DETECTION |
2451 if (!auto_saving) | 2455 if (!auto_saving) |
2452 lock_file (filename); | 2456 lock_file (visit_file); |
2453 #endif /* CLASH_DETECTION */ | 2457 #endif /* CLASH_DETECTION */ |
2454 | 2458 |
2455 fn = XSTRING (filename)->data; | 2459 fn = XSTRING (filename)->data; |
2456 desc = -1; | 2460 desc = -1; |
2457 if (!NILP (append)) | 2461 if (!NILP (append)) |
2511 | 2515 |
2512 if (desc < 0) | 2516 if (desc < 0) |
2513 { | 2517 { |
2514 #ifdef CLASH_DETECTION | 2518 #ifdef CLASH_DETECTION |
2515 save_errno = errno; | 2519 save_errno = errno; |
2516 if (!auto_saving) unlock_file (filename); | 2520 if (!auto_saving) unlock_file (visit_file); |
2517 errno = save_errno; | 2521 errno = save_errno; |
2518 #endif /* CLASH_DETECTION */ | 2522 #endif /* CLASH_DETECTION */ |
2519 report_file_error ("Opening output file", Fcons (filename, Qnil)); | 2523 report_file_error ("Opening output file", Fcons (filename, Qnil)); |
2520 } | 2524 } |
2521 | 2525 |
2523 | 2527 |
2524 if (!NILP (append)) | 2528 if (!NILP (append)) |
2525 if (lseek (desc, 0, 2) < 0) | 2529 if (lseek (desc, 0, 2) < 0) |
2526 { | 2530 { |
2527 #ifdef CLASH_DETECTION | 2531 #ifdef CLASH_DETECTION |
2528 if (!auto_saving) unlock_file (filename); | 2532 if (!auto_saving) unlock_file (visit_file); |
2529 #endif /* CLASH_DETECTION */ | 2533 #endif /* CLASH_DETECTION */ |
2530 report_file_error ("Lseek error", Fcons (filename, Qnil)); | 2534 report_file_error ("Lseek error", Fcons (filename, Qnil)); |
2531 } | 2535 } |
2532 | 2536 |
2533 #ifdef VMS | 2537 #ifdef VMS |
2631 /* Discard the unwind protect */ | 2635 /* Discard the unwind protect */ |
2632 specpdl_ptr = specpdl + count; | 2636 specpdl_ptr = specpdl + count; |
2633 | 2637 |
2634 #ifdef CLASH_DETECTION | 2638 #ifdef CLASH_DETECTION |
2635 if (!auto_saving) | 2639 if (!auto_saving) |
2636 unlock_file (filename); | 2640 unlock_file (visit_file); |
2637 #endif /* CLASH_DETECTION */ | 2641 #endif /* CLASH_DETECTION */ |
2638 | 2642 |
2639 /* Do this before reporting IO error | 2643 /* Do this before reporting IO error |
2640 to avoid a "file has changed on disk" warning on | 2644 to avoid a "file has changed on disk" warning on |
2641 next attempt to save. */ | 2645 next attempt to save. */ |
2642 if (EQ (visit, Qt)) | 2646 if (EQ (visit, Qt) || XTYPE (visit) == Lisp_String) |
2643 current_buffer->modtime = st.st_mtime; | 2647 current_buffer->modtime = st.st_mtime; |
2644 | 2648 |
2645 if (failure) | 2649 if (failure) |
2646 error ("IO error writing %s: %s", fn, err_str (save_errno)); | 2650 error ("IO error writing %s: %s", fn, err_str (save_errno)); |
2647 | 2651 |
2648 if (EQ (visit, Qt)) | 2652 if (EQ (visit, Qt) || XTYPE (visit) == Lisp_String) |
2649 { | 2653 { |
2650 current_buffer->save_modified = MODIFF; | 2654 current_buffer->save_modified = MODIFF; |
2651 XFASTINT (current_buffer->save_length) = Z - BEG; | 2655 XFASTINT (current_buffer->save_length) = Z - BEG; |
2652 current_buffer->filename = filename; | 2656 current_buffer->filename = visit_file; |
2653 } | 2657 } |
2654 else if (!NILP (visit)) | 2658 else if (!NILP (visit)) |
2655 return Qnil; | 2659 return Qnil; |
2656 | 2660 |
2657 if (!auto_saving) | 2661 if (!auto_saving) |
2658 message ("Wrote %s", fn); | 2662 message ("Wrote %s", XSTRING (visit_file)->data); |
2659 | 2663 |
2660 return Qnil; | 2664 return Qnil; |
2661 } | 2665 } |
2662 | 2666 |
2663 int | 2667 int |