]> git.eshelyaron.com Git - emacs.git/commitdiff
Remove local copies of remote files created for drag-and-drop
authorPo Lu <luangruo@yahoo.com>
Wed, 30 Mar 2022 08:36:10 +0000 (16:36 +0800)
committerPo Lu <luangruo@yahoo.com>
Wed, 30 Mar 2022 08:36:10 +0000 (16:36 +0800)
* 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.

lisp/dired.el

index 41313f5eb9ffc3270fadb8834ba193ecf4c5aa0b..0b5f2cab417394443ced95c5805fd4f3429abdc2 100644 (file)
@@ -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")