(x_set_alpha): Set alpha to -1 if nil given.
[bpt/emacs.git] / src / fileio.c
index 02c4124..cd68f4e 100644 (file)
@@ -201,6 +201,8 @@ int write_region_inhibit_fsync;
    Fdelete_directory.  */
 int delete_by_moving_to_trash;
 
+Lisp_Object Qdelete_by_moving_to_trash;
+
 /* Lisp function for moving files to trash.  */
 Lisp_Object Qmove_file_to_trash;
 
@@ -817,14 +819,19 @@ note that these simplifications are done without checking the resulting
 file names in the file system.
 An initial `~/' expands to your home directory.
 An initial `~USER/' expands to USER's home directory.
-See also the function `substitute-in-file-name'.  */)
+See also the function `substitute-in-file-name'.
+
+For technical reasons, this function can return correct but
+non-intuitive results for the root directory; for instance,
+\(expand-file-name ".." "/") returns "/..".  For this reason, use
+(directory-file-name (file-name-directory dirname)) to traverse a
+filesystem tree, not (expand-file-name ".."  dirname).  */)
      (name, default_directory)
      Lisp_Object name, default_directory;
 {
   /* These point to SDATA and need to be careful with string-relocation
      during GC (via DECODE_FILE).  */
   unsigned char *nm, *newdir;
-  int nm_in_name;
   /* This should only point to alloca'd data.  */
   unsigned char *target;
 
@@ -930,14 +937,11 @@ See also the function `substitute-in-file-name'.  */)
     }
 
   nm = SDATA (name);
-  nm_in_name = 1;
 
-#ifdef DOS_NT
-  /* We will force directory separators to be either all \ or /, so make
-     a local copy to modify, even if there ends up being no change. */
+  /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */
   nm = strcpy (alloca (strlen (nm) + 1), nm);
-  nm_in_name = 0;
 
+#ifdef DOS_NT
   /* Note if special escape prefix is present, but remove for now.  */
   if (nm[0] == '/' && nm[1] == ':')
     {
@@ -1038,7 +1042,7 @@ See also the function `substitute-in-file-name'.  */)
            }
          return name;
 #else /* not DOS_NT */
-         if (nm == SDATA (name))
+         if (strcmp (nm, SDATA (name)) == 0)
            return name;
          return make_specified_string (nm, -1, strlen (nm), multibyte);
 #endif /* not DOS_NT */
@@ -1078,13 +1082,8 @@ See also the function `substitute-in-file-name'.  */)
          tem = build_string (newdir);
          if (!STRING_MULTIBYTE (tem))
            {
-             /* FIXME: DECODE_FILE may GC, which may move SDATA(name),
-                after which `nm' won't point to the right place any more.  */
-             int offset = nm - SDATA (name);
              hdir = DECODE_FILE (tem);
              newdir = SDATA (hdir);
-             if (nm_in_name)
-             nm = SDATA (name) + offset;
            }
 #ifdef DOS_NT
          collapse_newdir = 0;
@@ -2240,6 +2239,7 @@ This is what happens in interactive use with M-x.  */)
     {
       if (errno == EXDEV)
        {
+          int count;
 #ifdef S_IFLNK
           symlink_target = Ffile_symlink_p (file);
           if (! NILP (symlink_target))
@@ -2253,7 +2253,10 @@ This is what happens in interactive use with M-x.  */)
                        NILP (ok_if_already_exists) ? Qnil : Qt,
                        Qt, Qt);
 
+         count = SPECPDL_INDEX ();
+         specbind (Qdelete_by_moving_to_trash, Qnil);
          Fdelete_file (file);
+         unbind_to (count, Qnil);
        }
       else
        report_file_error ("Renaming", list2 (file, newname));
@@ -2840,7 +2843,10 @@ DEFUN ("set-file-modes", Fset_file_modes, Sset_file_modes, 2, 2,
        "(let ((file (read-file-name \"File: \")))                      \
          (list file (read-file-modes nil file)))",
        doc: /* Set mode bits of file named FILENAME to MODE (an integer).
-Only the 12 low bits of MODE are used.  */)
+Only the 12 low bits of MODE are used.
+
+Interactively, mode bits are read by `read-file-modes', which accepts
+symbolic notation, like the `chmod' command from GNU Coreutils.  */)
   (filename, mode)
      Lisp_Object filename, mode;
 {
@@ -3682,7 +3688,6 @@ variable `last-coding-system-used' to the coding system actually used.  */)
 
       if (bufpos == inserted)
        {
-         specpdl_ptr--;
          /* Truncate the buffer to the size of the file.  */
          if (same_at_start == same_at_end)
            nochange = 1;
@@ -5675,6 +5680,7 @@ A non-nil value may result in data loss!  */);
 When non-nil, the function `move-file-to-trash' will be used by
 `delete-file' and `delete-directory'.  */);
   delete_by_moving_to_trash = 0;
+  Qdelete_by_moving_to_trash = intern ("delete-by-moving-to-trash");
   Qmove_file_to_trash = intern ("move-file-to-trash");
   staticpro (&Qmove_file_to_trash);