diff options
author | Po Lu <luangruo@yahoo.com> | 2022-03-30 16:36:10 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-03-30 16:36:10 +0800 |
commit | 34ff19a8820334f92802be13e9d88f1264e493ab (patch) | |
tree | e6739e209eed9d87c13d99908b8481924f5822cf /lisp/dired.el | |
parent | ea86ba8966c80256e05c45aead130aff462f9ad8 (diff) | |
download | emacs-34ff19a8820334f92802be13e9d88f1264e493ab.tar.gz emacs-34ff19a8820334f92802be13e9d88f1264e493ab.tar.bz2 emacs-34ff19a8820334f92802be13e9d88f1264e493ab.zip |
Remove local copies of remote files created for drag-and-drop
* lisp/dired.el (dired-mouse-drag): Remove last dragged remote
file and save a record of any local copy created.
(dired-remove-last-dragged-local-file): New function.
Diffstat (limited to 'lisp/dired.el')
-rw-r--r-- | lisp/dired.el | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index 41313f5eb9f..0b5f2cab417 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1699,13 +1699,29 @@ see `dired-use-ls-dired' for more details.") beg)) beg)))) -(declare-function x-begin-drag "xfns.cx") +(defvar dired-last-dragged-remote-file nil + "If non-nil, the name of a local copy of the last remote file that was dragged. +It can't be removed immediately after the drag-and-drop operation +completes, since there is no way to determine when the drop +target has finished opening it. So instead, this file is removed +when Emacs exits or the user drags another file.") + +(declare-function x-begin-drag "xfns.c") + +(defun dired-remove-last-dragged-local-file () + "Remove the local copy of the last remote file to be dragged." + (when dired-last-dragged-remote-file + (unwind-protect + (delete-file dired-last-dragged-remote-file) + (setq dired-last-dragged-remote-file nil))) + (remove-hook 'kill-emacs-hook #'dired-remove-last-dragged-local-file)) (defun dired-mouse-drag (event) "Begin a drag-and-drop operation for the file at EVENT." (interactive "e") (when mark-active (deactivate-mark)) + (dired-remove-last-dragged-local-file) (save-excursion (with-selected-window (posn-window (event-end event)) (goto-char (posn-point (event-end event)))) @@ -1728,7 +1744,10 @@ see `dired-use-ls-dired' for more details.") ;; actually implements file DND according to the ;; spec. (when (file-remote-p filename) - (setq filename (file-local-copy filename))) + (setq filename (file-local-copy filename)) + (setq dired-last-dragged-remote-file filename) + (add-hook 'kill-emacs-hook + #'dired-remove-last-dragged-local-file)) (gui-backend-set-selection 'XdndSelection filename) (x-begin-drag '("text/uri-list" "text/x-dnd-username") |