changeset 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 dd83ec6103fe
children bf061c3ded67
files src/fileio.c
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c	Sat Oct 10 07:33:59 1992 +0000
+++ b/src/fileio.c	Sat Oct 10 08:34:51 1992 +0000
@@ -2386,6 +2386,9 @@
   and mark buffer not modified.\n\
 If VISIT is neither t nor nil, it means do not print\n\
   the \"Wrote file\" message.\n\
+If VISIT is a string, it is a second file name;\n\
+  the output goes to FILENAME, but the buffer is marked as visiting VISIT.\n\
+  VISIT is also the file name to lock and unlock for clash detection.\n\
 Kludgy feature: if START is a string, then that string is written\n\
 to the file, instead of any buffer contents, and END is ignored.")
   (start, end, filename, append, visit)
@@ -2402,7 +2405,8 @@
   unsigned char *fname = 0;	/* If non-0, original filename (must rename) */
 #endif /* VMS */
   Lisp_Object handler;
-  struct gcpro gcpro1, gcpro2;
+  Lisp_Object visit_file = XTYPE (visit) == Lisp_String ? visit : filename;
+  struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
 
   /* Special kludge to simplify auto-saving */
   if (NILP (start))
@@ -2413,7 +2417,7 @@
   else if (XTYPE (start) != Lisp_String)
     validate_region (&start, &end);
 
-  GCPRO2 (start, filename);
+  GCPRO4 (start, filename, visit, visit_file);
   filename = Fexpand_file_name (filename, Qnil);
 
   /* If the file name has special constructs in it,
@@ -2436,12 +2440,12 @@
       /* Do this before reporting IO error
 	 to avoid a "file has changed on disk" warning on
 	 next attempt to save.  */
-      if (EQ (visit, Qt))
+      if (EQ (visit, Qt) || XTYPE (visit) == Lisp_String)
 	{
 	  current_buffer->modtime = 0;
 	  current_buffer->save_modified = MODIFF;
 	  XFASTINT (current_buffer->save_length) = Z - BEG;
-	  current_buffer->filename = filename;
+	  current_buffer->filename = visit_file;
 	}
       UNGCPRO;
       return val;
@@ -2449,7 +2453,7 @@
 
 #ifdef CLASH_DETECTION
   if (!auto_saving)
-    lock_file (filename);
+    lock_file (visit_file);
 #endif /* CLASH_DETECTION */
 
   fn = XSTRING (filename)->data;
@@ -2513,7 +2517,7 @@
     {
 #ifdef CLASH_DETECTION
       save_errno = errno;
-      if (!auto_saving) unlock_file (filename);
+      if (!auto_saving) unlock_file (visit_file);
       errno = save_errno;
 #endif /* CLASH_DETECTION */
       report_file_error ("Opening output file", Fcons (filename, Qnil));
@@ -2525,7 +2529,7 @@
     if (lseek (desc, 0, 2) < 0)
       {
 #ifdef CLASH_DETECTION
-	if (!auto_saving) unlock_file (filename);
+	if (!auto_saving) unlock_file (visit_file);
 #endif /* CLASH_DETECTION */
 	report_file_error ("Lseek error", Fcons (filename, Qnil));
       }
@@ -2633,29 +2637,29 @@
 
 #ifdef CLASH_DETECTION
   if (!auto_saving)
-    unlock_file (filename);
+    unlock_file (visit_file);
 #endif /* CLASH_DETECTION */
 
   /* Do this before reporting IO error
      to avoid a "file has changed on disk" warning on
      next attempt to save.  */
-  if (EQ (visit, Qt))
+  if (EQ (visit, Qt) || XTYPE (visit) == Lisp_String)
     current_buffer->modtime = st.st_mtime;
 
   if (failure)
     error ("IO error writing %s: %s", fn, err_str (save_errno));
 
-  if (EQ (visit, Qt))
+  if (EQ (visit, Qt) || XTYPE (visit) == Lisp_String)
     {
       current_buffer->save_modified = MODIFF;
       XFASTINT (current_buffer->save_length) = Z - BEG;
-      current_buffer->filename = filename;
+      current_buffer->filename = visit_file;
     }
   else if (!NILP (visit))
     return Qnil;
 
   if (!auto_saving)
-    message ("Wrote %s", fn);
+    message ("Wrote %s", XSTRING (visit_file)->data);
 
   return Qnil;
 }