changeset 108806:511da81b16c5

Change delete-by-moving-to-trash so Lisp calls explicitly request trashing. * src/fileio.c (Fdelete_file): Change meaning of optional arg to mean whether to trash. (internal_delete_file, Frename_file): Callers changed. (delete_by_moving_to_trash): Doc fix. (Fdelete_directory_internal): Don't move to trash. * src/callproc.c (delete_temp_file): * src/buffer.c (Fkill_buffer): Callers changed. * src/lisp.h: Update prototype. * lisp/diff.el (diff-sentinel): * lisp/epg.el (epg--make-temp-file, epg-decrypt-string) (epg-verify-string, epg-sign-string, epg-encrypt-string): * lisp/jka-compr.el (jka-compr-partial-uncompress) (jka-compr-call-process, jka-compr-write-region): * lisp/server.el (server-sentinel): Remove optional arg from delete-file, reverting 2010-05-03 change. * lisp/dired.el (dired-delete-file): New arg TRASH. (dired-internal-do-deletions): New arg TRASH. Use progress reporter. (dired-do-flagged-delete, dired-do-delete): Use trash. * lisp/files.el (delete-directory): New arg TRASH. * lisp/speedbar.el (speedbar-item-delete): Allow trashing. * lisp/net/ange-ftp.el (ange-ftp-del-tmp-name, ange-ftp-delete-file) (ange-ftp-rename-remote-to-remote) (ange-ftp-rename-local-to-remote) (ange-ftp-rename-remote-to-local, ange-ftp-load) (ange-ftp-compress, ange-ftp-uncompress): Remove optional arg from `delete-file'. (ange-ftp-delete-directory): Add optional arg to `delete-file', to allow trashing. * lisp/net/tramp-compat.el (tramp-compat-delete-file): Rewrite to handle new TRASH arg of `delete-file'. * lisp/net/tramp-fish.el (tramp-fish-handle-delete-directory) (tramp-fish-handle-delete-file) (tramp-fish-handle-make-symbolic-link) (tramp-fish-handle-process-file): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-ftp.el (tramp-ftp-file-name-handler): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-delete-file): Rename arg. (tramp-gvfs-handle-write-region): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-imap.el (tramp-imap-handle-delete-file): Rename arg. (tramp-imap-do-copy-or-rename-file): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-smb.el (tramp-smb-handle-copy-file) (tramp-smb-handle-file-local-copy, tramp-smb-handle-rename-file) (tramp-smb-handle-write-region): Use null TRASH arg in tramp-compat-delete-file call. (tramp-smb-handle-delete-directory): Use tramp-compat-delete-file. (tramp-smb-handle-delete-file): Rename arg. * lisp/net/tramp.el (tramp-handle-delete-file): Change FORCE arg to TRASH. (tramp-handle-make-symbolic-link, tramp-handle-load) (tramp-do-copy-or-rename-file-via-buffer) (tramp-do-copy-or-rename-file-directly) (tramp-do-copy-or-rename-file-out-of-band) (tramp-handle-process-file, tramp-handle-call-process-region) (tramp-handle-shell-command, tramp-handle-file-local-copy) (tramp-handle-insert-file-contents, tramp-handle-write-region) (tramp-delete-temp-file-function): Use null TRASH arg in tramp-compat-delete-file call.
author Chong Yidong <cyd@stupidchicken.com>
date Thu, 27 May 2010 19:30:11 -0400
parents 78199a49c4bf
children 2fde4b52f1ed cb093dac3d58
files etc/NEWS lisp/ChangeLog lisp/diff.el lisp/dired.el lisp/epg.el lisp/files.el lisp/jka-compr.el lisp/net/ange-ftp.el lisp/net/tramp-compat.el lisp/net/tramp-fish.el lisp/net/tramp-ftp.el lisp/net/tramp-gvfs.el lisp/net/tramp-imap.el lisp/net/tramp-smb.el lisp/net/tramp.el lisp/server.el lisp/speedbar.el src/ChangeLog src/buffer.c src/callproc.c src/fileio.c src/lisp.h
diffstat 22 files changed, 238 insertions(+), 136 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS	Thu May 27 11:49:01 2010 -0400
+++ b/etc/NEWS	Thu May 27 19:30:11 2010 -0400
@@ -109,16 +109,20 @@
 ** New property `scroll-command' should be set on a command's symbol to
 define it as a scroll command affected by `scroll-preserve-screen-position.
 
+** Trash changes
+
+*** `delete-by-moving-to-trash' now only affects commands that specify
+trashing.  This avoids inadvertently trashing temporary files.
+
+*** Calling `delete-file' or `delete-directory' with a prefix argument
+now forces true deletion, regardless of `delete-by-moving-to-trash'.
+
 
 * Editing Changes in Emacs 24.1
 
 ** completion-at-point is now an alias for complete-symbol.
 
 ** mouse-region-delete-keys has been deleted.
-
-** If delete-file is called with a prefix argument, it really deletes,
-regardless of the value of `delete-by-moving-to-trash'.
-
 
 * Changes in Specialized Modes and Packages in Emacs 24.1
 
@@ -237,8 +241,10 @@
 ** prog-mode is a new major-mode meant to be the parent of programming mode.
 ** define-minor-mode accepts a new keyword :variable.
 
-** delete-file now accepts an optional second arg, FORCE, which says
-to always delete and ignore the value of delete-by-moving-to-trash.
+** `delete-file' and `delete-directory now accept optional arg TRASH.
+Trashing is performed if TRASH and `delete-by-moving-to-trash' are
+both non-nil.  Interactively, TRASH defaults to t, unless a prefix
+argument is supplied (see Trash changes, above).
 
 ** buffer-substring-filters is obsoleted by filter-buffer-substring-functions.
 
--- a/lisp/ChangeLog	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/ChangeLog	Thu May 27 19:30:11 2010 -0400
@@ -1,3 +1,70 @@
+2010-05-27  Chong Yidong  <cyd@stupidchicken.com>
+
+	* dired.el (dired-delete-file): New arg TRASH.
+	(dired-internal-do-deletions): New arg TRASH.  Use progress
+	reporter.
+	(dired-do-flagged-delete, dired-do-delete): Use trash.
+
+	* speedbar.el (speedbar-item-delete): Allow trashing.
+
+	* files.el (delete-directory): New arg TRASH.
+
+	* net/ange-ftp.el (ange-ftp-del-tmp-name, ange-ftp-delete-file)
+	(ange-ftp-rename-remote-to-remote)
+	(ange-ftp-rename-local-to-remote)
+	(ange-ftp-rename-remote-to-local, ange-ftp-load)
+	(ange-ftp-compress, ange-ftp-uncompress): Remove optional arg from
+	`delete-file'.
+	(ange-ftp-delete-directory): Add optional arg to `delete-file', to
+	allow trashing.
+
+	* net/tramp-compat.el (tramp-compat-delete-file): Rewrite to
+	handle new TRASH arg of `delete-file'.
+
+	* net/tramp.el (tramp-handle-delete-file): Change FORCE arg to
+	TRASH.
+	(tramp-handle-make-symbolic-link, tramp-handle-load)
+	(tramp-do-copy-or-rename-file-via-buffer)
+	(tramp-do-copy-or-rename-file-directly)
+	(tramp-do-copy-or-rename-file-out-of-band)
+	(tramp-handle-process-file, tramp-handle-call-process-region)
+	(tramp-handle-shell-command, tramp-handle-file-local-copy)
+	(tramp-handle-insert-file-contents, tramp-handle-write-region)
+	(tramp-delete-temp-file-function): Use null TRASH arg in
+	tramp-compat-delete-file call.
+
+	* net/tramp-fish.el (tramp-fish-handle-delete-directory)
+	(tramp-fish-handle-delete-file)
+	(tramp-fish-handle-make-symbolic-link)
+	(tramp-fish-handle-process-file): Use null TRASH arg in
+	`tramp-compat-delete-file' call.
+
+	* net/tramp-ftp.el (tramp-ftp-file-name-handler): Use null TRASH
+	arg in `tramp-compat-delete-file' call.
+
+	* net/tramp-gvfs.el (tramp-gvfs-handle-delete-file): Rename arg.
+	(tramp-gvfs-handle-write-region): Use null TRASH arg in
+	`tramp-compat-delete-file' call.
+
+	* net/tramp-imap.el (tramp-imap-handle-delete-file): Rename arg.
+	(tramp-imap-do-copy-or-rename-file): Use null TRASH arg in
+	`tramp-compat-delete-file' call.
+
+	* net/tramp-smb.el (tramp-smb-handle-copy-file)
+	(tramp-smb-handle-file-local-copy, tramp-smb-handle-rename-file)
+	(tramp-smb-handle-write-region): Use null TRASH arg in
+	tramp-compat-delete-file call.
+	(tramp-smb-handle-delete-directory): Use tramp-compat-delete-file.
+	(tramp-smb-handle-delete-file): Rename arg.
+
+	* diff.el (diff-sentinel):
+	* epg.el (epg--make-temp-file, epg-decrypt-string)
+	(epg-verify-string, epg-sign-string, epg-encrypt-string):
+	* jka-compr.el (jka-compr-partial-uncompress)
+	(jka-compr-call-process, jka-compr-write-region):
+	* server.el (server-sentinel): Remove optional arg from
+	delete-file, reverting 2010-05-03 change.
+
 2010-05-27  Chong Yidong  <cyd@stupidchicken.com>
 
 	* progmodes/verilog-mode.el (verilog-type-font-keywords): Use
--- a/lisp/diff.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/diff.el	Thu May 27 19:30:11 2010 -0400
@@ -64,8 +64,8 @@
   "Code run when the diff process exits.
 CODE is the exit code of the process.  It should be 0 only if no diffs
 were found."
-  (if diff-old-temp-file (delete-file diff-old-temp-file t))
-  (if diff-new-temp-file (delete-file diff-new-temp-file t))
+  (if diff-old-temp-file (delete-file diff-old-temp-file))
+  (if diff-new-temp-file (delete-file diff-new-temp-file))
   (save-excursion
     (goto-char (point-max))
     (let ((inhibit-read-only t))
--- a/lisp/dired.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/dired.el	Thu May 27 19:30:11 2010 -0400
@@ -2579,7 +2579,7 @@
 ;; Delete file, possibly delete a directory and all its files.
 ;; This function is usefull outside of dired.  One could change it's name
 ;; to e.g. recursive-delete-file and put it somewhere else.
-(defun dired-delete-file (file &optional recursive) "\
+(defun dired-delete-file (file &optional recursive trash) "\
 Delete FILE or directory (possibly recursively if optional RECURSIVE is true.)
 RECURSIVE determines what to do with a non-empty directory.  If RECURSIVE is:
 nil, do not delete.
@@ -2590,15 +2590,19 @@
   ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
   ;; but more efficient
   (if (not (eq t (car (file-attributes file))))
-      (delete-file file)
+      (delete-file file trash)
     (if (and recursive
 	     (directory-files file t dired-re-no-dot) ; Not empty.
 	     (or (eq recursive 'always)
-		 (yes-or-no-p (format "Recursive delete of %s? "
+		 (yes-or-no-p (format "Recursively %s %s? "
+				      (if (and trash
+					       delete-by-moving-to-trash)
+					  "trash"
+					"delete")
 				      (dired-make-relative file)))))
 	(if (eq recursive 'top) (setq recursive 'always)) ; Don't ask again.
       (setq recursive nil))
-    (delete-directory file recursive)))
+    (delete-directory file recursive trash)))
 
 (defun dired-do-flagged-delete (&optional nomessage)
   "In Dired, delete the files flagged for deletion.
@@ -2616,7 +2620,7 @@
 	 ;; this can't move point since ARG is nil
 	 (dired-map-over-marks (cons (dired-get-filename) (point))
 			       nil)
-	 nil)
+	 nil t)
       (or nomessage
 	  (message "(No deletions requested)")))))
 
@@ -2631,11 +2635,11 @@
    ;; this may move point if ARG is an integer
    (dired-map-over-marks (cons (dired-get-filename) (point))
 			 arg)
-   arg))
+   arg t))
 
 (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
 
-(defun dired-internal-do-deletions (l arg)
+(defun dired-internal-do-deletions (l arg &optional trash)
   ;; L is an alist of files to delete, with their buffer positions.
   ;; ARG is the prefix arg.
   ;; Filenames are absolute.
@@ -2644,14 +2648,21 @@
   ;; lines still to be changed, so the (point) values in L stay valid.
   ;; Also, for subdirs in natural order, a subdir's files are deleted
   ;; before the subdir itself - the other way around would not work.
-  (let ((files (mapcar (function car) l))
-	(count (length l))
-	(succ 0))
+  (let* ((files (mapcar (function car) l))
+	 (count (length l))
+	 (succ 0)
+	 (trashing (and trash delete-by-moving-to-trash))
+	 (progress-reporter
+	  (make-progress-reporter
+	   (if trashing "Trashing..." "Deleting...")
+	   succ count)))
     ;; canonicalize file list for pop up
     (setq files (nreverse (mapcar (function dired-make-relative) files)))
     (if (dired-mark-pop-up
 	 " *Deletions*" 'delete files dired-deletion-confirmer
-	 (format "Delete %s " (dired-mark-prompt arg files)))
+	 (format "%s %s "
+		 (if trashing "Trash" "Delete")
+		 (dired-mark-prompt arg files)))
 	(save-excursion
 	  (let (failures);; files better be in reverse order for this loop!
 	    (while l
@@ -2659,10 +2670,10 @@
 	      (let ((inhibit-read-only t))
 		(condition-case err
 		    (let ((fn (car (car l))))
-		      (dired-delete-file fn dired-recursive-deletes)
+		      (dired-delete-file fn dired-recursive-deletes trash)
 		      ;; if we get here, removing worked
 		      (setq succ (1+ succ))
-		      (message "%s of %s deletions" succ count)
+		      (progress-reporter-update progress-reporter succ)
 		      (dired-fun-in-all-buffers
 		       (file-name-directory fn) (file-name-nondirectory fn)
 		       (function dired-delete-entry) fn))
@@ -2671,7 +2682,7 @@
 		   (setq failures (cons (car (car l)) failures)))))
 	      (setq l (cdr l)))
 	    (if (not failures)
-		(message "%d deletion%s done" count (dired-plural-s count))
+		(progress-reporter-done progress-reporter)
 	      (dired-log-summary
 	       (format "%d of %d deletion%s failed"
 		       (length failures) count
--- a/lisp/epg.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/epg.el	Thu May 27 19:30:11 2010 -0400
@@ -1899,7 +1899,7 @@
 	  ;; Cleanup the tempfile.
 	  (and tempfile
 	       (file-exists-p tempfile)
-	       (delete-file tempfile t))
+	       (delete-file tempfile))
 	  ;; Cleanup the tempdir.
 	  (and tempdir
 	       (file-directory-p tempdir)
@@ -1999,7 +1999,7 @@
 	  (epg-read-output context))
       (epg-delete-output-file context)
       (if (file-exists-p input-file)
-	  (delete-file input-file t))
+	  (delete-file input-file))
       (epg-reset context))))
 
 (defun epg-start-verify (context signature &optional signed-text)
@@ -2203,7 +2203,7 @@
 	  (epg-read-output context))
       (epg-delete-output-file context)
       (if input-file
-	  (delete-file input-file t))
+	  (delete-file input-file))
       (epg-reset context))))
 
 (defun epg-start-encrypt (context plain recipients
@@ -2323,7 +2323,7 @@
 	  (epg-read-output context))
       (epg-delete-output-file context)
       (if input-file
-	  (delete-file input-file t))
+	  (delete-file input-file))
       (epg-reset context))))
 
 (defun epg-start-export-keys (context keys)
--- a/lisp/files.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/files.el	Thu May 27 19:30:11 2010 -0400
@@ -4675,19 +4675,30 @@
   "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"
   "Regexp of file names excluging \".\" an \"..\".")
 
-(defun delete-directory (directory &optional recursive)
+(defun delete-directory (directory &optional recursive trash)
   "Delete the directory named DIRECTORY.  Does not follow symlinks.
-If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well."
+If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well.
+TRASH non-nil means to trash the directory instead, provided
+`delete-by-moving-to-trash' is non-nil.
+
+When called interactively, TRASH is t if no prefix argument is
+given.  With a prefix argument, TRASH is nil."
   (interactive
-   (let ((dir (expand-file-name
-	       (read-file-name
-		"Delete directory: "
-		default-directory default-directory nil nil))))
+   (let* ((trashing (and delete-by-moving-to-trash
+			 (null current-prefix-arg)))
+	  (dir (expand-file-name
+		(read-file-name
+		 (if trashing
+		     "Move directory to trash: "
+		   "Delete directory: ")
+		 default-directory default-directory nil nil))))
      (list dir
 	   (if (directory-files	dir nil directory-files-no-dot-files-regexp)
 	       (y-or-n-p
-		(format "Directory `%s' is not empty, really delete? " dir))
-	     nil))))
+		(format "Directory `%s' is not empty, really %s? "
+			dir (if trashing "trash" "delete")))
+	     nil)
+	   (null current-prefix-arg))))
   ;; If default-directory is a remote directory, make sure we find its
   ;; delete-directory handler.
   (setq directory (directory-file-name (expand-file-name directory)))
@@ -4695,7 +4706,7 @@
     (cond
      (handler
       (funcall handler 'delete-directory directory recursive))
-     (delete-by-moving-to-trash
+     ((and delete-by-moving-to-trash trash)
       ;; Only move non-empty dir to trash if recursive deletion was
       ;; requested.  This mimics the non-`delete-by-moving-to-trash'
       ;; case, where the operation fails in delete-directory-internal.
@@ -4715,8 +4726,8 @@
 		  ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
 		  ;; but more efficient
 		  (if (eq t (car (file-attributes file)))
-		      (delete-directory file recursive)
-		    (delete-file file)))
+		      (delete-directory file recursive nil)
+		    (delete-file file nil)))
 		;; We do not want to delete "." and "..".
 		(directory-files
 		 directory 'full directory-files-no-dot-files-regexp)))
--- a/lisp/jka-compr.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/jka-compr.el	Thu May 27 19:30:11 2010 -0400
@@ -181,7 +181,7 @@
 			  null-device))
 			jka-compr-acceptable-retval-list)
 		  (jka-compr-error prog args infile message err-file))
-	    (delete-file err-file t)))
+	    (delete-file err-file)))
 
       ;; Run the uncompression program directly.
       ;; We get the whole file and must delete what we don't want.
@@ -223,7 +223,7 @@
 					   "")))
 		   jka-compr-acceptable-retval-list)
 		  (jka-compr-error prog args infile message err-file))
-	    (delete-file err-file t)))
+	    (delete-file err-file)))
       (or (eq 0
 	      (apply 'call-process
 		     prog infile (if (stringp output) temp output)
@@ -335,7 +335,7 @@
 						(and append can-append) 'dont))
 	      (erase-buffer)) )
 
-	  (delete-file temp-file t)
+	  (delete-file temp-file)
 
 	  (and
 	   compress-message
--- a/lisp/net/ange-ftp.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/net/ange-ftp.el	Thu May 27 19:30:11 2010 -0400
@@ -1736,7 +1736,7 @@
 
 (defun ange-ftp-del-tmp-name (filename)
   "Force to delete temporary file."
-  (delete-file filename 'force))
+  (delete-file filename))
 
 
 ;;;; ------------------------------------------------------------
@@ -3507,8 +3507,9 @@
 	(file-exists-p file)
       (ange-ftp-real-file-executable-p file))))
 
-(defun ange-ftp-delete-file (file &optional force)
-  (interactive "fDelete file: ")
+(defun ange-ftp-delete-file (file &optional trash)
+  (interactive (list (read-file-name "Delete file: " nil default-directory)
+		     (null current-prefix-arg)))
   (setq file (expand-file-name file))
   (let ((parsed (ange-ftp-ftp-name file)))
     (if parsed
@@ -3526,7 +3527,7 @@
 		       (format "FTP Error: \"%s\"" (cdr result))
 		       file)))
 	  (ange-ftp-delete-file-entry file))
-      (ange-ftp-real-delete-file file force))))
+      (ange-ftp-real-delete-file file trash))))
 
 (defun ange-ftp-file-modtime (file)
   "Return the modification time of remote file FILE.
@@ -3897,7 +3898,7 @@
 	  (ange-ftp-add-file-entry newname)
 	  (ange-ftp-delete-file-entry filename))
       (ange-ftp-copy-file-internal filename newname t nil)
-      (delete-file filename 'force))))
+      (delete-file filename))))
 
 (defun ange-ftp-rename-local-to-remote (filename newname)
   "Rename local file FILENAME to remote file NEWNAME."
@@ -3906,7 +3907,7 @@
 	 (msg (format "Renaming %s to %s" fabbr nabbr)))
     (ange-ftp-copy-file-internal filename newname t nil msg)
     (let (ange-ftp-process-verbose)
-      (delete-file filename 'force))))
+      (delete-file filename))))
 
 (defun ange-ftp-rename-remote-to-local (filename newname)
   "Rename remote file FILENAME to local file NEWNAME."
@@ -3915,7 +3916,7 @@
 	 (msg (format "Renaming %s to %s" fabbr nabbr)))
     (ange-ftp-copy-file-internal filename newname t nil msg)
     (let (ange-ftp-process-verbose)
-      (delete-file filename 'force))))
+      (delete-file filename))))
 
 (defun ange-ftp-rename-file (filename newname &optional ok-if-already-exists)
   (interactive "fRename file: \nFRename %s to file: \np")
@@ -4196,7 +4197,7 @@
 	(if copy
 	    (unwind-protect
 		(funcall 'load copy noerror nomessage nosuffix)
-	      (delete-file copy 'force))
+	      (delete-file copy))
 	  (or noerror
 	      (signal 'file-error (list "Cannot open load file" file)))
 	  nil))
@@ -4267,7 +4268,7 @@
 	  (if (zerop (buffer-size))
 	      (progn
 		(let (ange-ftp-process-verbose)
-		  (delete-file file 'force))
+		  (delete-file file))
 		(ange-ftp-copy-file-internal tmp2 nfile t nil msg2))))
       (ange-ftp-del-tmp-name tmp1)
       (ange-ftp-del-tmp-name tmp2))))
@@ -4303,7 +4304,7 @@
 	  (if (zerop (buffer-size))
 	      (progn
 		(let (ange-ftp-process-verbose)
-		  (delete-file file 'force))
+		  (delete-file file))
 		(ange-ftp-copy-file-internal tmp2 nfile t nil msg2))))
       (ange-ftp-del-tmp-name tmp1)
       (ange-ftp-del-tmp-name tmp2))))
--- a/lisp/net/tramp-compat.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/net/tramp-compat.el	Thu May 27 19:30:11 2010 -0400
@@ -334,23 +334,18 @@
 	(if keep-time
 	    (set-file-times newname (nth 5 (file-attributes directory))))))))
 
-;; FORCE has been introduced with Emacs 24.1.
-(defun tramp-compat-delete-file (filename &optional force)
+;; TRASH has been introduced with Emacs 24.1.
+(defun tramp-compat-delete-file (filename &optional trash)
   "Like `delete-file' for Tramp files (compat function)."
-  (if (null force)
-      (delete-file filename)
-    (condition-case nil
-	(tramp-compat-funcall 'delete-file filename force)
-      ;; This Emacs version does not support the FORCE flag.  Setting
-      ;; `delete-by-moving-to-trash' shall give us the same effect.
-      (wrong-number-of-arguments
-       (let ((delete-by-moving-to-trash
-	      (cond
-	       ((null force) t)
-	       ((boundp 'delete-by-moving-to-trash)
-		(symbol-value 'delete-by-moving-to-trash))
-	       (t nil))))
-	 (delete-file filename))))))
+  (condition-case nil
+      (tramp-compat-funcall 'delete-file filename trash)
+    ;; This Emacs version does not support the TRASH flag.
+    (wrong-number-of-arguments
+     (let ((delete-by-moving-to-trash
+	    (and (boundp 'delete-by-moving-to-trash)
+		 delete-by-moving-to-trash
+		 trash)))
+       (delete-file filename)))))
 
 ;; RECURSIVE has been introduced with Emacs 23.2.
 (defun tramp-compat-delete-directory (directory &optional recursive)
--- a/lisp/net/tramp-fish.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/net/tramp-fish.el	Thu May 27 19:30:11 2010 -0400
@@ -326,16 +326,16 @@
 	 (lambda (file)
 	   (if (file-directory-p file)
 	       (tramp-compat-delete-directory file recursive)
-	     (delete-file file)))
+	     (tramp-compat-delete-file file)))
 	 ;; We do not want to delete "." and "..".
 	 (directory-files
 	  directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
-     (with-parsed-tramp-file-name
-	(directory-file-name (expand-file-name directory)) nil
-      (tramp-flush-directory-property v localname)
-      (tramp-fish-send-command-and-check v (format "#RMD %s" localname)))))
+    (with-parsed-tramp-file-name
+     (directory-file-name (expand-file-name directory)) nil
+     (tramp-flush-directory-property v localname)
+     (tramp-fish-send-command-and-check v (format "#RMD %s" localname)))))
 
-(defun tramp-fish-handle-delete-file (filename &optional force)
+(defun tramp-fish-handle-delete-file (filename &optional trash)
   "Like `delete-file' for Tramp files."
   (when (file-exists-p filename)
     (with-parsed-tramp-file-name (expand-file-name filename) nil
@@ -660,7 +660,7 @@
 			  localname)))))
 	  (tramp-error
 	   v 'file-already-exists "File %s already exists" localname)
-	(tramp-compat-delete-file linkname 'force)))
+	(tramp-compat-delete-file linkname)))
 
     ;; If FILENAME is a Tramp name, use just the localname component.
     (when (tramp-tramp-file-p filename)
@@ -839,8 +839,8 @@
       ;; Provide error file.
       (when tmpstderr (rename-file tmpstderr (cadr destination) t))
       ;; Cleanup.
-      (when tmpinput (tramp-compat-delete-file tmpinput 'force))
-      (when tmpoutput (tramp-compat-delete-file tmpoutput 'force))
+      (when tmpinput (tramp-compat-delete-file tmpinput))
+      (when tmpoutput (tramp-compat-delete-file tmpoutput))
       ;; Return exit status.
       ret)))
 
--- a/lisp/net/tramp-ftp.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/net/tramp-ftp.el	Thu May 27 19:30:11 2010 -0400
@@ -182,7 +182,7 @@
 	  (unwind-protect
 	      (rename-file tmpfile newname (car args))
 	    ;; Cleanup.
-	    (ignore-errors (tramp-compat-delete-file tmpfile 'force)))))
+	    (ignore-errors (tramp-compat-delete-file tmpfile)))))
 
        ;; Normally, the handlers must be discarded.
        ;; `inhibit-file-name-handlers' isn't sufficient, because the
--- a/lisp/net/tramp-gvfs.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/net/tramp-gvfs.el	Thu May 27 19:30:11 2010 -0400
@@ -533,9 +533,9 @@
   (tramp-compat-delete-directory
    (tramp-gvfs-fuse-file-name directory) recursive))
 
-(defun tramp-gvfs-handle-delete-file (filename &optional force)
+(defun tramp-gvfs-handle-delete-file (filename &optional tramp)
   "Like `delete-file' for Tramp files."
-  (tramp-compat-delete-file (tramp-gvfs-fuse-file-name filename) force))
+  (tramp-compat-delete-file (tramp-gvfs-fuse-file-name filename) tramp))
 
 (defun tramp-gvfs-handle-directory-files
   (directory &optional full match nosort)
@@ -742,7 +742,7 @@
 		   "gvfs-save" tmpfile (tramp-get-buffer v) nil
 		   (tramp-gvfs-url-file-name filename)))
 	       (signal (car err) (cdr err)))
-	   (tramp-compat-delete-file tmpfile 'force)))))
+	   (tramp-compat-delete-file tmpfile)))))
 
     ;; Set file modification time.
     (when (or (eq visit t) (stringp visit))
--- a/lisp/net/tramp-imap.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/net/tramp-imap.el	Thu May 27 19:30:11 2010 -0400
@@ -268,7 +268,7 @@
 	    (write-region (point-min) (point-max) newname)))))
 
     (when (eq op 'rename)
-      (tramp-compat-delete-file filename 'force))))
+      (tramp-compat-delete-file filename))))
 
 ;; TODO: revise this much
 (defun tramp-imap-handle-expand-file-name (name &optional dir)
@@ -552,7 +552,7 @@
   ;; (file-exists-p (file-name-directory filename)))
   (file-directory-p (file-name-directory filename)))
 
-(defun tramp-imap-handle-delete-file (filename &optional force)
+(defun tramp-imap-handle-delete-file (filename &optional trash)
   "Like `delete-file' for Tramp files."
   (cond
    ((not (file-exists-p filename)) nil)
--- a/lisp/net/tramp-smb.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/net/tramp-smb.el	Thu May 27 19:30:11 2010 -0400
@@ -345,7 +345,7 @@
 	  (condition-case err
 	      (rename-file tmpfile newname ok-if-already-exists)
 	    ((error quit)
-	     (tramp-compat-delete-file tmpfile 'force)
+	     (tramp-compat-delete-file tmpfile)
 	     (signal (car err) (cdr err))))
 
 	;; Remote newname.
@@ -382,7 +382,7 @@
 	 (lambda (file)
 	   (if (file-directory-p file)
 	       (tramp-compat-delete-directory file recursive)
-	     (delete-file file)))
+	     (tramp-compat-delete-file file t)))
 	 ;; We do not want to delete "." and "..".
 	 (directory-files
 	  directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
@@ -404,7 +404,7 @@
 	  (tramp-error
 	   v 'file-error "%s `%s'" (match-string 0) directory))))))
 
-(defun tramp-smb-handle-delete-file (filename &optional force)
+(defun tramp-smb-handle-delete-file (filename &optional trash)
   "Like `delete-file' for Tramp files."
   (setq filename (expand-file-name filename))
   (when (file-exists-p filename)
@@ -611,7 +611,7 @@
 		 v (format "get \"%s\" \"%s\""
 			   (tramp-smb-get-localname v) tmpfile))
 	  ;; Oops, an error.  We shall cleanup.
-	  (tramp-compat-delete-file tmpfile 'force)
+	  (tramp-compat-delete-file tmpfile)
 	  (tramp-error
 	   v 'file-error "Cannot make local copy of file `%s'" filename)))
       tmpfile)))
@@ -861,7 +861,7 @@
 	  (condition-case err
 	      (rename-file tmpfile newname ok-if-already-exists)
 	    ((error quit)
-	     (tramp-compat-delete-file tmpfile 'force)
+	     (tramp-compat-delete-file tmpfile)
 	     (signal (car err) (cdr err))))
 
 	;; Remote newname.
@@ -882,7 +882,7 @@
 			     filename (tramp-smb-get-localname v)))
 	    (tramp-error v 'file-error "Cannot rename `%s'" filename)))))
 
-    (tramp-compat-delete-file filename 'force)))
+    (tramp-compat-delete-file filename)))
 
 (defun tramp-smb-handle-set-file-modes (filename mode)
   "Like `set-file-modes' for Tramp files."
@@ -946,7 +946,7 @@
 		     v (format "put %s \"%s\""
 			       tmpfile (tramp-smb-get-localname v)))
 	      (tramp-error v 'file-error "Cannot write `%s'" filename))
-	  (tramp-compat-delete-file tmpfile 'force)))
+	  (tramp-compat-delete-file tmpfile)))
 
       (unless (equal curbuf (current-buffer))
 	(tramp-error
--- a/lisp/net/tramp.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/net/tramp.el	Thu May 27 19:30:11 2010 -0400
@@ -2544,7 +2544,7 @@
 			    l-localname)))))
 	    (tramp-error
 	     l 'file-already-exists "File %s already exists" l-localname)
-	  (tramp-compat-delete-file linkname 'force)))
+	  (tramp-compat-delete-file linkname)))
 
       ;; If FILENAME is a Tramp name, use just the localname component.
       (when (tramp-tramp-file-p filename)
@@ -2593,7 +2593,7 @@
 	    ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
 	    (unwind-protect
 		(load local-copy noerror t t)
-	      (tramp-compat-delete-file local-copy 'force)))))
+	      (tramp-compat-delete-file local-copy)))))
       t)))
 
 ;; Localname manipulation functions that grok Tramp localnames...
@@ -3769,7 +3769,7 @@
   ;; Set the mode.
   (set-file-modes newname (tramp-default-file-modes filename))
   ;; If the operation was `rename', delete the original file.
-  (unless (eq op 'copy) (tramp-compat-delete-file filename 'force)))
+  (unless (eq op 'copy) (tramp-compat-delete-file filename)))
 
 (defun tramp-do-copy-or-rename-file-directly
  (op filename newname ok-if-already-exists keep-date preserve-uid-gid)
@@ -3924,7 +3924,7 @@
 
 		;; Save exit.
 		(condition-case nil
-		    (tramp-compat-delete-file tmpfile 'force)
+		    (tramp-compat-delete-file tmpfile)
 		  (error)))))))))
 
       ;; Set the time and mode. Mask possible errors.
@@ -3964,7 +3964,7 @@
 		  (if dir-flag
 		      (tramp-compat-delete-directory
 		       (expand-file-name ".." tmpfile) 'recursive)
-		    (tramp-compat-delete-file tmpfile 'force))
+		    (tramp-compat-delete-file tmpfile))
 		(error))))
 
 	;; Expand hops.  Might be necessary for gateway methods.
@@ -4082,7 +4082,7 @@
       ;; If the operation was `rename', delete the original file.
       (unless (eq op 'copy)
 	(if (file-regular-p filename)
-	    (tramp-compat-delete-file filename 'force)
+	    (tramp-compat-delete-file filename)
 	  (tramp-compat-delete-directory filename 'recursive))))))
 
 (defun tramp-handle-make-directory (dir &optional parents)
@@ -4112,7 +4112,7 @@
 		     (tramp-shell-quote-argument localname))))
       (tramp-error v 'file-error "Couldn't delete %s" directory))))
 
-(defun tramp-handle-delete-file (filename &optional force)
+(defun tramp-handle-delete-file (filename &optional trash)
   "Like `delete-file' for Tramp files."
   (setq filename (expand-file-name filename))
   (with-parsed-tramp-file-name filename nil
@@ -4629,7 +4629,7 @@
 
       ;; Cleanup.  We remove all file cache values for the connection,
       ;; because the remote process could have changed them.
-      (when tmpinput (tramp-compat-delete-file tmpinput 'force))
+      (when tmpinput (tramp-compat-delete-file tmpinput))
 
       ;; `process-file-side-effects' has been introduced with GNU
       ;; Emacs 23.2.  If set to `nil', no remote file will be changed
@@ -4666,7 +4666,7 @@
     (when delete (delete-region start end))
     (unwind-protect
 	(apply 'call-process program tmpfile buffer display args)
-      (tramp-compat-delete-file tmpfile 'force))))
+      (tramp-compat-delete-file tmpfile))))
 
 (defun tramp-handle-shell-command
   (command &optional output-buffer error-buffer)
@@ -4731,7 +4731,7 @@
 	(when (listp buffer)
 	  (with-current-buffer error-buffer
 	    (insert-file-contents (cadr buffer)))
-	  (tramp-compat-delete-file (cadr buffer) 'force))
+	  (tramp-compat-delete-file (cadr buffer)))
 	(if current-buffer-p
 	    ;; This is like exchange-point-and-mark, but doesn't
 	    ;; activate the mark.  It is cleaner to avoid activation,
@@ -4813,7 +4813,7 @@
 		    (unwind-protect
 			(tramp-call-local-coding-command
 			 loc-dec tmpfile2 tmpfile)
-		      (tramp-compat-delete-file tmpfile2 'force)))))
+		      (tramp-compat-delete-file tmpfile2)))))
 
 	      ;; Set proper permissions.
 	      (set-file-modes tmpfile (tramp-default-file-modes filename))
@@ -4826,7 +4826,7 @@
 
 	;; Error handling.
 	((error quit)
-	 (tramp-compat-delete-file tmpfile 'force)
+	 (tramp-compat-delete-file tmpfile)
 	 (signal (car err) (cdr err))))
 
       (run-hooks 'tramp-handle-file-local-copy-hook)
@@ -4961,11 +4961,10 @@
 	    (set-buffer-modified-p nil))
 	  (when (and (stringp local-copy)
 		     (or remote-copy (null tramp-temp-buffer-file-name)))
-	    (tramp-compat-delete-file local-copy 'force))
+	    (tramp-compat-delete-file local-copy))
 	  (when (stringp remote-copy)
 	    (tramp-compat-delete-file
-	     (tramp-make-tramp-file-name method user host remote-copy)
-	     'force)))))
+	     (tramp-make-tramp-file-name method user host remote-copy))))))
 
     ;; Result.
     (list (expand-file-name filename)
@@ -5155,7 +5154,7 @@
 		 (list start end tmpfile append 'no-message lockname confirm))
 	      ((error quit)
 	       (setq tramp-temp-buffer-file-name nil)
-	       (tramp-compat-delete-file tmpfile 'force)
+	       (tramp-compat-delete-file tmpfile)
 	       (signal (car err) (cdr err))))
 
 	    ;; Now, `last-coding-system-used' has the right value.  Remember it.
@@ -5199,13 +5198,13 @@
 			(copy-file tmpfile filename t)
 		      ((error quit)
 		       (setq tramp-temp-buffer-file-name nil)
-		       (tramp-compat-delete-file tmpfile 'force)
+		       (tramp-compat-delete-file tmpfile)
 		       (signal (car err) (cdr err)))))
 		(setq tramp-temp-buffer-file-name nil)
 		;; Don't rename, in order to keep context in SELinux.
 		(unwind-protect
 		    (copy-file tmpfile filename t)
-		  (tramp-compat-delete-file tmpfile 'force))))
+		  (tramp-compat-delete-file tmpfile))))
 
 	     ;; Use inline file transfer.
 	     (rem-dec
@@ -5290,7 +5289,7 @@
 			  filename rem-dec)))))
 
 		;; Save exit.
-		(tramp-compat-delete-file tmpfile 'force)))
+		(tramp-compat-delete-file tmpfile)))
 
 	     ;; That's not expected.
 	     (t
@@ -6373,7 +6372,7 @@
   "Remove temporary files related to current buffer."
   (when (stringp tramp-temp-buffer-file-name)
     (condition-case nil
-	(tramp-compat-delete-file tramp-temp-buffer-file-name 'force)
+	(tramp-compat-delete-file tramp-temp-buffer-file-name)
       (error nil))))
 
 (add-hook 'kill-buffer-hook 'tramp-delete-temp-file-function)
--- a/lisp/server.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/server.el	Thu May 27 19:30:11 2010 -0400
@@ -345,7 +345,7 @@
   (and (process-contact proc :server)
        (eq (process-status proc) 'closed)
        (ignore-errors
-	(delete-file (process-get proc :server-file) t)))
+	(delete-file (process-get proc :server-file))))
   (server-log (format "Status changed to %s: %s" (process-status proc) msg) proc)
   (server-delete-client proc))
 
--- a/lisp/speedbar.el	Thu May 27 11:49:01 2010 -0400
+++ b/lisp/speedbar.el	Thu May 27 19:30:11 2010 -0400
@@ -1644,8 +1644,8 @@
     (if (speedbar-y-or-n-p (format "Delete %s? " f) t)
 	(progn
 	  (if (file-directory-p f)
-	      (delete-directory f)
-	    (delete-file f))
+	      (delete-directory f t t)
+	    (delete-file f t))
 	  (speedbar-message "Okie dokie.")
 	  (let ((p (point)))
 	    (speedbar-refresh)
--- a/src/ChangeLog	Thu May 27 11:49:01 2010 -0400
+++ b/src/ChangeLog	Thu May 27 19:30:11 2010 -0400
@@ -1,3 +1,16 @@
+2010-05-27  Chong Yidong  <cyd@stupidchicken.com>
+
+	* fileio.c (Fdelete_file): Change meaning of optional arg to mean
+	whether to trash.
+	(internal_delete_file, Frename_file): Callers changed.
+	(delete_by_moving_to_trash): Doc fix.
+	(Fdelete_directory_internal): Don't move to trash.
+
+	* callproc.c (delete_temp_file):
+	* buffer.c (Fkill_buffer): Callers changed.
+
+	* lisp.h: Update prototype.
+
 2010-05-27  Chong Yidong  <cyd@stupidchicken.com>
 
 	* xdisp.c (redisplay_window): After redisplay, check if point is
--- a/src/buffer.c	Thu May 27 11:49:01 2010 -0400
+++ b/src/buffer.c	Thu May 27 19:30:11 2010 -0400
@@ -1547,7 +1547,7 @@
       Lisp_Object tem;
       tem = Fsymbol_value (intern ("delete-auto-save-files"));
       if (! NILP (tem))
-	internal_delete_file (b->auto_save_file_name, Qt);
+	internal_delete_file (b->auto_save_file_name);
     }
 
   if (b->base_buffer)
--- a/src/callproc.c	Thu May 27 11:49:01 2010 -0400
+++ b/src/callproc.c	Thu May 27 19:30:11 2010 -0400
@@ -856,7 +856,7 @@
   /* Suppress jka-compr handling, etc.  */
   int count = SPECPDL_INDEX ();
   specbind (intern ("file-name-handler-alist"), Qnil);
-  internal_delete_file (name, Qt);
+  internal_delete_file (name);
   unbind_to (count, Qnil);
   return Qnil;
 }
--- a/src/fileio.c	Thu May 27 11:49:01 2010 -0400
+++ b/src/fileio.c	Thu May 27 19:30:11 2010 -0400
@@ -2180,12 +2180,7 @@
 
   CHECK_STRING (directory);
   directory = Fdirectory_file_name (Fexpand_file_name (directory, Qnil));
-
-  if (delete_by_moving_to_trash)
-    return call1 (Qmove_file_to_trash, directory);
-
   encoded_dir = ENCODE_FILE (directory);
-
   dir = SDATA (encoded_dir);
 
   if (rmdir (dir) != 0)
@@ -2195,19 +2190,21 @@
 }
 
 DEFUN ("delete-file", Fdelete_file, Sdelete_file, 1, 2,
-       "(list (read-file-name \"Delete file: \" nil default-directory \
-                (confirm-nonexistent-file-or-buffer))                 \
-              current-prefix-arg)",
+       "(list (read-file-name \
+                (if (and delete-by-moving-to-trash (null current-prefix-arg)) \
+                    \"Move file to trash: \" \"Delete file: \") \
+                nil default-directory (confirm-nonexistent-file-or-buffer)) \
+              (null current-prefix-arg))",
        doc: /* Delete file named FILENAME.  If it is a symlink, remove the symlink.
 If file has multiple names, it continues to exist with the other names.
-
-If optional arg FORCE is non-nil, really delete the file regardless of
-`delete-by-moving-to-trash'.  Otherwise, \"deleting\" actually moves
-it to the system's trash can if `delete-by-moving-to-trash' is non-nil.
-Interactively, FORCE is non-nil if called with a prefix arg.  */)
-     (filename, force)
+TRASH non-nil means to trash the file instead of deleting, provided
+`delete-by-moving-to-trash' is non-nil.
+
+When called interactively, TRASH is t if no prefix argument is given.
+With a prefix argument, TRASH is nil.  */)
+     (filename, trash)
      Lisp_Object filename;
-     Lisp_Object force;
+     Lisp_Object trash;
 {
   Lisp_Object handler;
   Lisp_Object encoded_file;
@@ -2226,7 +2223,7 @@
   if (!NILP (handler))
     return call2 (handler, Qdelete_file, filename);
 
-  if (delete_by_moving_to_trash && NILP (force))
+  if (delete_by_moving_to_trash && !NILP (trash))
     return call1 (Qmove_file_to_trash, filename);
 
   encoded_file = ENCODE_FILE (filename);
@@ -2244,14 +2241,14 @@
 }
 
 /* Delete file FILENAME, returning 1 if successful and 0 if failed.
-   FORCE means to ignore `delete-by-moving-to-trash'.  */
+   This ignores `delete-by-moving-to-trash'.  */
 
 int
-internal_delete_file (Lisp_Object filename, Lisp_Object force)
+internal_delete_file (Lisp_Object filename)
 {
   Lisp_Object tem;
 
-  tem = internal_condition_case_2 (Fdelete_file, filename, force,
+  tem = internal_condition_case_2 (Fdelete_file, filename, Qnil,
 				   Qt, internal_delete_file_1);
   return NILP (tem);
 }
@@ -2345,7 +2342,7 @@
 	      )
 	    call2 (Qdelete_directory, file, Qt);
 	  else
-	    Fdelete_file (file, Qt);
+	    Fdelete_file (file, Qnil);
 	  unbind_to (count, Qnil);
 	}
       else
@@ -5917,8 +5914,10 @@
 
   DEFVAR_BOOL ("delete-by-moving-to-trash", &delete_by_moving_to_trash,
                doc: /* Specifies whether to use the system's trash can.
-When non-nil, the function `move-file-to-trash' will be used by
-`delete-file' and `delete-directory'.  */);
+When non-nil, certain file deletion commands use the function
+`move-file-to-trash' instead of deleting files outright.
+This includes interactive calls to `delete-file' and
+`delete-directory' and the Dired deletion commands.  */);
   delete_by_moving_to_trash = 0;
   Qdelete_by_moving_to_trash = intern_c_string ("delete-by-moving-to-trash");
   Qmove_file_to_trash = intern_c_string ("move-file-to-trash");
--- a/src/lisp.h	Thu May 27 11:49:01 2010 -0400
+++ b/src/lisp.h	Thu May 27 19:30:11 2010 -0400
@@ -3060,7 +3060,7 @@
 extern Lisp_Object close_file_unwind P_ ((Lisp_Object));
 extern Lisp_Object restore_point_unwind P_ ((Lisp_Object));
 extern void report_file_error P_ ((const char *, Lisp_Object)) NO_RETURN;
-extern int internal_delete_file P_ ((Lisp_Object, Lisp_Object));
+extern int internal_delete_file P_ ((Lisp_Object));
 extern void syms_of_fileio P_ ((void));
 extern Lisp_Object make_temp_name P_ ((Lisp_Object, int));
 EXFUN (Fmake_symbolic_link, 3);