Skip to content

Making deleted files go to the trash can

by mickey on December 30th, 2010

In Emacs 23.1 support for your operating system’s trash can (or recycle bin, or whatever) was added. File deletions in Emacs now uses your system’s trash can and the deleted files will be put there instead. The feature must be enabled manually by adding this to your .emacs:

The delete to trash functionality will obviously behave differently depending on your operating system. On Windows the special function system-move-file-to-trash is defined because Windows exposes its own API for handling files sent to the recycle bin. On other operating systems that function will be nil, and the default behavior provided by move-file-to-trash is used instead.

In Emacs 23.2 new functionality was added to ensure Emacs conforms to the freedesktop.org specification used by all major, free desktop environments. The new variable is trash-directory and determines where Emacs will put the deleted files. If the variable is nil the freedesktop.org trash can default is used, otherwise the variable must contain a path string to where the files are to be put.

6 Comments
  1. Interesting! This is something I wondered about dired & deleting. The time to update my emacs in my Mac is coming, I use Carbon Emacs and it is just version 22.3.1… And no update available…

    Cheers,

    Ruben
    Latest in my blog: Emacs 30 Day Challenge: Get the latest version of gnus to improve speed

    • mickey permalink

      Why not give a vanilla macosx build a shot? I’m not sure what CarbonEmacs adds that makes it worthwhile (not a mac user as you can tell..) but Emacs 23 adds a lot of useful goodies, so it’d probably be worthwhile.

    • Try Aquamacs nightly builds based on 24. They’re so fast :)

  2. It breaks my Emacs daemon… if someone know how fix it let me know! :-)

  3. M. Grégoire permalink

    I use Gnus to read my e-mail. When I had this feature turned on, all my expired (i.e., deleted) messages ended up in the Trash on my server. Eventually I realised that the /home partition was filling up, and that the problem was 130000 files in the Trash.

    I strongly recommend that all people installing this feature check their Trash cans to be sure they’re not accidentally holding on to files that ought to disappear.

    • mickey permalink

      Indeed. The problem with the feature is the same one afflicting flymake. Because flymake, et al. use the same API they end up sending files to trash. I think developers could get away with let-binding the variable when they do their deleting to avoid the problem.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS