2

With (setq delete-by-moving-to-trash t), deleting a non-empty directory in a remote dired buffer fails with message file-error: Couldn’t delete /ssh:server:/home/user/Downloads/some_directory. I tried with toggle-debug-on-error on, but no stack trace was given.

Trashing a remote file is just OK.

When delete-by-moving-to-trash is nil, everything is just fine.

The remote Ubuntu server has trash-cli (0.12.9.14) install by sudo apt-get install trash-cli.

There's a related question here, but it does not seem to solve my problem.

My emacs version is: GNU Emacs 28.1 (build 1, x86_64-apple-darwin21.5.0, Carbon Version 165 AppKit 2113.5) of 2022-07-04.

How can I fix this?

1 Answer 1

3

According to the document of move-file-to-trash:

Move the file (or directory) named FILENAME to the trash.

When delete-by-moving-to-trash is non-nil, this function is
called by delete-file and delete-directory instead of
deleting files outright.

If the function system-move-file-to-trash is defined, call it
 with FILENAME as an argument.
Otherwise, if trash-directory is non-nil, move FILENAME to that
 directory.
Otherwise, trash FILENAME using the freedesktop.org conventions,
 like the GNOME, KDE and XFCE desktop environments.  Emacs moves
 files only to "home trash", ignoring per-volume trashcans.

I solve a similar problem by defining system-move-file-to-trash:

  (defun system-move-file-to-trash (filename)
    (process-file-shell-command
     (format "trash %S" (file-local-name filename))))
1
  • 1
    Works like a charm! Thank you! Jul 6 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.