aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1992-10-10 08:34:51 +0000
committerRichard M. Stallman1992-10-10 08:34:51 +0000
commit3b7792ed338db4e78efdd3d9280c863ca8d8bb8a (patch)
tree30fe8ea5eb8d28120e9200db34621cd6b914351d
parentae7a6b887ebbeedb2bab330727fa2f73ae12714b (diff)
downloademacs-3b7792ed338db4e78efdd3d9280c863ca8d8bb8a.tar.gz
emacs-3b7792ed338db4e78efdd3d9280c863ca8d8bb8a.zip
(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.
-rw-r--r--src/fileio.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 94261b8218e..23a0d8d27c6 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2386,6 +2386,9 @@ Optional fifth argument VISIT if t means\n\
2386 and mark buffer not modified.\n\ 2386 and mark buffer not modified.\n\
2387If VISIT is neither t nor nil, it means do not print\n\ 2387If VISIT is neither t nor nil, it means do not print\n\
2388 the \"Wrote file\" message.\n\ 2388 the \"Wrote file\" message.\n\
2389If 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\
2389Kludgy feature: if START is a string, then that string is written\n\ 2392Kludgy feature: if START is a string, then that string is written\n\
2390to the file, instead of any buffer contents, and END is ignored.") 2393to the file, instead of any buffer contents, and END is ignored.")
2391 (start, end, filename, append, visit) 2394 (start, end, filename, append, visit)
@@ -2402,7 +2405,8 @@ to the file, instead of any buffer contents, and END is ignored.")
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))
@@ -2413,7 +2417,7 @@ to the file, instead of any buffer contents, and END is ignored.")
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,
@@ -2436,12 +2440,12 @@ to the file, instead of any buffer contents, and END is ignored.")
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;
@@ -2449,7 +2453,7 @@ to the file, instead of any buffer contents, and END is ignored.")
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;
@@ -2513,7 +2517,7 @@ to the file, instead of any buffer contents, and END is ignored.")
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));
@@ -2525,7 +2529,7 @@ to the file, instead of any buffer contents, and END is ignored.")
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 }
@@ -2633,29 +2637,29 @@ to the file, instead of any buffer contents, and END is ignored.")
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}