Making deleted files go to the trash can

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:

( setq delete-by-moving-to-trash t )

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.