]> code.delx.au - gnu-emacs/blobdiff - src/fileio.c
(redisplay_window): Clear force_start field
[gnu-emacs] / src / fileio.c
index cd2e9bbfe0f83394f1f35e05bec3ea5bfde555d9..33e887cb4c8fd735bd7e262042d7bb4c82d30157 100644 (file)
@@ -1788,11 +1788,20 @@ expand_and_dir_to_file (filename, defdir)
   return abspath;
 }
 \f
+/* Signal an error if the file ABSNAME already exists.
+   If INTERACTIVE is nonzero, ask the user whether to proceed,
+   and bypass the error if the user says to go ahead.
+   QUERYSTRING is a name for the action that is being considered
+   to alter the file.
+   *STATPTR is used to store the stat information if the file exists.
+   If the file does not exist, STATPTR->st_mode is set to 0.  */
+
 void
-barf_or_query_if_file_exists (absname, querystring, interactive)
+barf_or_query_if_file_exists (absname, querystring, interactive, statptr)
      Lisp_Object absname;
      unsigned char *querystring;
      int interactive;
+     struct stat *statptr;
 {
   register Lisp_Object tem;
   struct stat statbuf;
@@ -1814,6 +1823,13 @@ barf_or_query_if_file_exists (absname, querystring, interactive)
        Fsignal (Qfile_already_exists,
                 Fcons (build_string ("File already exists"),
                        Fcons (absname, Qnil)));
+      if (statptr)
+       *statptr = statbuf;
+    }
+  else
+    {
+      if (statptr)
+       statptr->st_mode = 0;
     }
   return;
 }
@@ -1833,7 +1849,7 @@ A prefix arg makes KEEP-TIME non-nil.")
 {
   int ifd, ofd, n;
   char buf[16 * 1024];
-  struct stat st;
+  struct stat st, out_st;
   Lisp_Object handler;
   struct gcpro gcpro1, gcpro2;
   int count = specpdl_ptr - specpdl;
@@ -1858,7 +1874,9 @@ A prefix arg makes KEEP-TIME non-nil.")
   if (NILP (ok_if_already_exists)
       || INTEGERP (ok_if_already_exists))
     barf_or_query_if_file_exists (newname, "copy to it",
-                                 INTEGERP (ok_if_already_exists));
+                                 INTEGERP (ok_if_already_exists), &out_st);
+  else if (stat (XSTRING (newname)->data, &out_st) < 0)
+    out_st.st_mode = 0;
 
   ifd = open (XSTRING (filename)->data, O_RDONLY);
   if (ifd < 0)
@@ -1870,6 +1888,16 @@ A prefix arg makes KEEP-TIME non-nil.")
      copyable by us. */
   input_file_statable_p = (fstat (ifd, &st) >= 0);
 
+#ifndef DOS_NT
+  if (out_st.st_mode != 0
+      && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino)
+    {
+      errno = 0;
+      report_file_error ("Input and output files are the same",
+                        Fcons (filename, Fcons (newname, Qnil)));
+    }
+#endif
+
 #if defined (S_ISREG) && defined (S_ISLNK)
   if (input_file_statable_p)
     {
@@ -1879,7 +1907,7 @@ A prefix arg makes KEEP-TIME non-nil.")
          /* Get a better looking error message. */
          errno = EISDIR;
 #endif /* EISDIR */
-       report_file_error ("Non-regular file", Fcons (filename, Qnil));
+         report_file_error ("Non-regular file", Fcons (filename, Qnil));
        }
     }
 #endif /* S_ISREG && S_ISLNK */
@@ -1896,7 +1924,7 @@ A prefix arg makes KEEP-TIME non-nil.")
 #endif /* not MSDOS */
 #endif /* VMS */
   if (ofd < 0)
-      report_file_error ("Opening output file", Fcons (newname, Qnil));
+    report_file_error ("Opening output file", Fcons (newname, Qnil));
 
   record_unwind_protect (close_file_unwind, make_number (ofd));
 
@@ -1904,7 +1932,7 @@ A prefix arg makes KEEP-TIME non-nil.")
   QUIT;
   while ((n = read (ifd, buf, sizeof buf)) > 0)
     if (write (ofd, buf, n) != n)
-       report_file_error ("I/O error", Fcons (newname, Qnil));
+      report_file_error ("I/O error", Fcons (newname, Qnil));
   immediate_quit = 0;
 
   /* Closing the output clobbers the file times on some systems.  */
@@ -1921,7 +1949,18 @@ A prefix arg makes KEEP-TIME non-nil.")
          if (set_file_times (XSTRING (newname)->data, atime, mtime))
            report_file_error ("I/O error", Fcons (newname, Qnil));
        }
+#ifndef MSDOS
+      chmod (XSTRING (newname)->data, st.st_mode & 07777);
+#else /* MSDOS */
+#if defined (__DJGPP__) && __DJGPP__ > 1
+      /* In DJGPP v2.0 and later, fstat usually returns true file mode bits,
+         and if it can't, it tells so.  Otherwise, under MSDOS we usually
+         get only the READ bit, which will make the copied file read-only,
+         so it's better not to chmod at all.  */
+      if ((_djstat_flags & _STFAIL_WRITEBIT) == 0)
        chmod (XSTRING (newname)->data, st.st_mode & 07777);
+#endif /* DJGPP version 2 or newer */
+#endif /* MSDOS */
     }
 
   close (ifd);
@@ -2054,7 +2093,7 @@ This is what happens in interactive use with M-x.")
   if (NILP (ok_if_already_exists)
       || INTEGERP (ok_if_already_exists))
     barf_or_query_if_file_exists (newname, "rename to it",
-                                 INTEGERP (ok_if_already_exists));
+                                 INTEGERP (ok_if_already_exists), 0);
 #ifndef BSD4_1
   if (0 > rename (XSTRING (filename)->data, XSTRING (newname)->data))
 #else
@@ -2134,7 +2173,7 @@ This is what happens in interactive use with M-x.")
   if (NILP (ok_if_already_exists)
       || INTEGERP (ok_if_already_exists))
     barf_or_query_if_file_exists (newname, "make it a new name",
-                                 INTEGERP (ok_if_already_exists));
+                                 INTEGERP (ok_if_already_exists), 0);
 #ifdef WINDOWSNT
   /* Windows does not support this operation.  */
   report_file_error ("Adding new name", Flist (2, &filename));
@@ -2201,7 +2240,7 @@ This happens for interactive use with M-x.")
   if (NILP (ok_if_already_exists)
       || INTEGERP (ok_if_already_exists))
     barf_or_query_if_file_exists (linkname, "make it a link",
-                                 INTEGERP (ok_if_already_exists));
+                                 INTEGERP (ok_if_already_exists), 0);
   if (0 > symlink (XSTRING (filename)->data, XSTRING (linkname)->data))
     {
       /* If we didn't complain already, silently delete existing file.  */
@@ -2319,7 +2358,8 @@ check_executable (filename)
          && len >= 5
          && (stricmp ((suffix = filename + len-4), ".com") == 0
              || stricmp (suffix, ".exe") == 0
-             || stricmp (suffix, ".bat") == 0));
+             || stricmp (suffix, ".bat") == 0)
+         || (st.st_mode & S_IFMT) == S_IFDIR);
 #else /* not DOS_NT */
 #ifdef HAVE_EACCESS
   return (eaccess (filename, 1) >= 0);
@@ -2943,6 +2983,10 @@ and (2) it puts less data in the undo list.")
             Otherwise loop around and scan the preceding bufferfull.  */
          if (bufpos != 0)
            break;
+         /* If display current starts at beginning of line,
+            keep it that way.  */
+         if (XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer)
+           XWINDOW (selected_window)->start_at_line_beg = Fbolp ();
        }
       immediate_quit = 0;
 
@@ -3395,13 +3439,12 @@ to the file, instead of any buffer contents, and END is ignored.")
          nwritten += XINT (end) - tem;
          save_errno = errno;
        }
-
-      if (nwritten == 0)
-       {
-         /* If file was empty, still need to write the annotations */
-         failure = 0 > a_write (desc, "", 0, XINT (start), &annotations);
-         save_errno = errno;
-       }
+    }
+  else
+    {
+      /* If file was empty, still need to write the annotations */
+      failure = 0 > a_write (desc, "", 0, XINT (start), &annotations);
+      save_errno = errno;
     }
 
   immediate_quit = 0;
@@ -4405,7 +4448,10 @@ This applies only to the operation `inhibit-file-name-operation'.");
   Vinhibit_file_name_operation = Qnil;
 
   DEFVAR_LISP ("auto-save-list-file-name", &Vauto_save_list_file_name,
-    "File name in which we write a list of all auto save file names.");
+    "File name in which we write a list of all auto save file names.\n\
+This variable is initialized automatically from `auto-save-list-file-prefix'\n\
+shortly after Emacs reads your `.emacs' file, if you have not yet given it\n\
+a non-nil value.");
   Vauto_save_list_file_name = Qnil;
 
   defsubr (&Sfind_file_name_handler);