From 7a5f2b79e9d75e4fd67844bdb8325a32b011383d Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 30 Mar 2022 14:20:13 +0800 Subject: [PATCH] ; * lisp/dired.el (dired-mouse-drag): Create local copy if file is remote. --- lisp/dired.el | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lisp/dired.el b/lisp/dired.el index 409a312d0dd..41313f5eb9f 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1717,17 +1717,25 @@ see `dired-use-ls-dired' for more details.") ;; We can get an error if there's by some chance no file ;; name at point. (condition-case nil - (progn - (gui-backend-set-selection 'XdndSelection - (with-selected-window (posn-window - (event-end event)) - (dired-file-name-at-point))) - (x-begin-drag '("text/uri-list" - "text/x-dnd-username") - (if (eq 'dired-mouse-drag-files 'link) - 'XdndActionLink - 'XdndActionCopy) - nil nil t)) + (let ((filename (with-selected-window (posn-window + (event-end event)) + (dired-file-name-at-point)))) + (when filename + ;; In theory x-dnd-username combined with a proper + ;; file URI containing the hostname of the remote + ;; server could be used here instead of creating a + ;; local copy of the remote file, but no program + ;; actually implements file DND according to the + ;; spec. + (when (file-remote-p filename) + (setq filename (file-local-copy filename))) + (gui-backend-set-selection 'XdndSelection filename) + (x-begin-drag '("text/uri-list" + "text/x-dnd-username") + (if (eq 'dired-mouse-drag-files 'link) + 'XdndActionLink + 'XdndActionCopy) + nil nil t))) (error (when (eq (event-basic-type new-event) 'mouse-1) (push new-event unread-command-events))))))))) -- 2.39.2