From the NEWS file for Emacs 23.2:
‘trash-directory’is now nil. This means that
‘move-file-to-trash’trashes files according to freedesktop.org specifications, the same method used by the Gnome, KDE, and XFCE desktops. (This change has no effect on Windows, which uses
‘delete-by-moving-to-trash’non-nil to use this. Deleted files and directories will then be sent to the Recycle Bin on Windows, and to
‘trash-directory’on other systems.
Using the Freedesktop.org trashcan is the default.
However, Emacs only uses the trash can in your home directory, and it will trash every file it deletes, including a great quantity of temp and backup files. If you want full Freedesktop trash support including per-mountpoint trashcans, as well as control over what gets sent to the trash and what doesn’t, see below, under Earlier Emacs.
The following code will configure Emacs to use the freedesktop.org trash specification, which is compatible with GNOME and KDE. This means that files deleted in Emacs will show up in the GNOME/KDE trash folder.
At the bottom of the file are two pieces of advice. They prevent some functions that normally delete directories recursively from also trashing them recursively.
Note that the following code requires the command `gvfs-trash,’ included with GNOME. If you do not use GNOME, you can install trash-cli and replace
‘gvfs-trash’ with `trash.’
After loading this code, use M-x customize-group trash to specify certain files that should skip the system trash. If you do not set this, emacs will fill your trash directory with countless backup files and other temp files. My trash-exclusion settings are as follows:
(setq system-trash-exclude-matches '("#[^/]+#$" ".*~$" "\\.emacs\\.desktop.*")) (setq system-trash-exclude-paths '("/tmp"))
This setting will prevent Emacs from trashing old desktop lock files (if you use DeskTop Mode) and backup files (with names like `#filename#’), as well as any files in /tmp (including the server file, which gets trashed on every emacs restart if you use server.el).
If you use Homebrew you can
brew install trash for a command-line program to trash files and directories using OSX conventions.
(setq delete-by-moving-to-trash t) (defun system-move-file-to-trash (file) "Use \"trash\" to move FILE to the system trash. When using Homebrew, install it using \"brew install trash\"." (call-process (executable-find "trash") nil 0 nil file))