comparison lisp/files.el @ 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 a5969c855306
children b29291853540
comparison
equal deleted inserted replaced
108805:78199a49c4bf 108806:511da81b16c5
4673 4673
4674 (defconst directory-files-no-dot-files-regexp 4674 (defconst directory-files-no-dot-files-regexp
4675 "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*" 4675 "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"
4676 "Regexp of file names excluging \".\" an \"..\".") 4676 "Regexp of file names excluging \".\" an \"..\".")
4677 4677
4678 (defun delete-directory (directory &optional recursive) 4678 (defun delete-directory (directory &optional recursive trash)
4679 "Delete the directory named DIRECTORY. Does not follow symlinks. 4679 "Delete the directory named DIRECTORY. Does not follow symlinks.
4680 If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well." 4680 If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well.
4681 TRASH non-nil means to trash the directory instead, provided
4682 `delete-by-moving-to-trash' is non-nil.
4683
4684 When called interactively, TRASH is t if no prefix argument is
4685 given. With a prefix argument, TRASH is nil."
4681 (interactive 4686 (interactive
4682 (let ((dir (expand-file-name 4687 (let* ((trashing (and delete-by-moving-to-trash
4683 (read-file-name 4688 (null current-prefix-arg)))
4684 "Delete directory: " 4689 (dir (expand-file-name
4685 default-directory default-directory nil nil)))) 4690 (read-file-name
4691 (if trashing
4692 "Move directory to trash: "
4693 "Delete directory: ")
4694 default-directory default-directory nil nil))))
4686 (list dir 4695 (list dir
4687 (if (directory-files dir nil directory-files-no-dot-files-regexp) 4696 (if (directory-files dir nil directory-files-no-dot-files-regexp)
4688 (y-or-n-p 4697 (y-or-n-p
4689 (format "Directory `%s' is not empty, really delete? " dir)) 4698 (format "Directory `%s' is not empty, really %s? "
4690 nil)))) 4699 dir (if trashing "trash" "delete")))
4700 nil)
4701 (null current-prefix-arg))))
4691 ;; If default-directory is a remote directory, make sure we find its 4702 ;; If default-directory is a remote directory, make sure we find its
4692 ;; delete-directory handler. 4703 ;; delete-directory handler.
4693 (setq directory (directory-file-name (expand-file-name directory))) 4704 (setq directory (directory-file-name (expand-file-name directory)))
4694 (let ((handler (find-file-name-handler directory 'delete-directory))) 4705 (let ((handler (find-file-name-handler directory 'delete-directory)))
4695 (cond 4706 (cond
4696 (handler 4707 (handler
4697 (funcall handler 'delete-directory directory recursive)) 4708 (funcall handler 'delete-directory directory recursive))
4698 (delete-by-moving-to-trash 4709 ((and delete-by-moving-to-trash trash)
4699 ;; Only move non-empty dir to trash if recursive deletion was 4710 ;; Only move non-empty dir to trash if recursive deletion was
4700 ;; requested. This mimics the non-`delete-by-moving-to-trash' 4711 ;; requested. This mimics the non-`delete-by-moving-to-trash'
4701 ;; case, where the operation fails in delete-directory-internal. 4712 ;; case, where the operation fails in delete-directory-internal.
4702 ;; As `move-file-to-trash' trashes directories (empty or 4713 ;; As `move-file-to-trash' trashes directories (empty or
4703 ;; otherwise) as a unit, we do not need to recurse here. 4714 ;; otherwise) as a unit, we do not need to recurse here.
4713 (mapc (lambda (file) 4724 (mapc (lambda (file)
4714 ;; This test is equivalent to 4725 ;; This test is equivalent to
4715 ;; (and (file-directory-p fn) (not (file-symlink-p fn))) 4726 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
4716 ;; but more efficient 4727 ;; but more efficient
4717 (if (eq t (car (file-attributes file))) 4728 (if (eq t (car (file-attributes file)))
4718 (delete-directory file recursive) 4729 (delete-directory file recursive nil)
4719 (delete-file file))) 4730 (delete-file file nil)))
4720 ;; We do not want to delete "." and "..". 4731 ;; We do not want to delete "." and "..".
4721 (directory-files 4732 (directory-files
4722 directory 'full directory-files-no-dot-files-regexp))) 4733 directory 'full directory-files-no-dot-files-regexp)))
4723 (delete-directory-internal directory))))) 4734 (delete-directory-internal directory)))))
4724 4735