From f1a5d776c4985b3ff1a2c6c17dd71dedf5d726e8 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Thu, 27 May 2010 19:30:11 -0400 Subject: 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. --- lisp/files.el | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'lisp/files.el') diff --git a/lisp/files.el b/lisp/files.el index d4c05bdc5d6..4ab583d018b 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4675,19 +4675,30 @@ this happens by default." "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*" "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 @@ If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well." (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 @@ If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well." ;; (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))) -- cgit v1.2.1