summaryrefslogtreecommitdiff
path: root/lisp/dired.el
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-06-03 19:43:06 +0800
committerPo Lu <luangruo@yahoo.com>2022-06-03 19:46:25 +0800
commitca2e7409dcd694742704e424c3f6f5bc5f230f25 (patch)
treec966c37aacd1071d72faeea5256f04999b6e57f2 /lisp/dired.el
parent977f3f27c549db27a2d6fb33e0112b03f9b57371 (diff)
downloademacs-ca2e7409dcd694742704e424c3f6f5bc5f230f25.tar.gz
emacs-ca2e7409dcd694742704e424c3f6f5bc5f230f25.tar.bz2
emacs-ca2e7409dcd694742704e424c3f6f5bc5f230f25.zip
Allow dragging multiple files from a Dired buffer
* doc/lispref/frames.texi (Drag and Drop): Document new function `dnd-begin-drag-files'. * lisp/dired.el (dired-mouse-drag-files): Update doc string. (dired-map-over-marks): Accept a new value of ARG `marked', meaning to not fall back to the current file if no marks were found. (dired-mouse-drag): Handle marked files in an intuitive way. * lisp/dnd.el (dnd-last-dragged-remote-file): Allow list values as well. (dnd-remove-last-dragged-remote-file): Handle list values. (dnd-begin-file-drag): Fix file name expansion. (dnd-begin-drag-files): New function. * lisp/select.el (xselect-convert-to-filename): Handle mutiple files (a vector of file names):.
Diffstat (limited to 'lisp/dired.el')
-rw-r--r--lisp/dired.el49
1 files changed, 37 insertions, 12 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 94df2ddc4e9..1ab2c8c38b4 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -253,8 +253,9 @@ The target is used in the prompt for file copy, rename etc."
(defcustom dired-mouse-drag-files nil
"If non-nil, allow the mouse to drag files from inside a Dired buffer.
Dragging the mouse and then releasing it over the window of
-another program will result in that program opening the file, or
-creating a copy of it. This feature is supported only on X
+another program will result in that program opening or creating a
+copy of the file underneath the mouse pointer (or all marked
+files if it was marked). This feature is supported only on X
Windows, Haiku, and Nextstep (macOS or GNUstep).
If the value is `link', then a symbolic link will be created to
@@ -809,6 +810,9 @@ that commands on the next ARG (instead of the marked) files can
be chained easily.
For any other non-nil value of ARG, use the current file.
+If ARG is `marked', don't return the current file if nothing else
+is marked.
+
If optional third arg SHOW-PROGRESS evaluates to non-nil,
redisplay the dired buffer after each file is processed.
@@ -830,7 +834,7 @@ marked file, return (t FILENAME) instead of (FILENAME)."
;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
`(prog1
(let ((inhibit-read-only t) case-fold-search found results)
- (if ,arg
+ (if (and ,arg (not (eq ,arg 'marked)))
(if (integerp ,arg)
(progn ;; no save-excursion, want to move point.
(dired-repeat-over-lines
@@ -841,8 +845,8 @@ marked file, return (t FILENAME) instead of (FILENAME)."
(if (< ,arg 0)
(nreverse results)
results))
- ;; non-nil, non-integer ARG means use current file:
- (list ,body))
+ ;; non-nil, non-integer, non-marked ARG means use current file:
+ (list ,body))
(let ((regexp (dired-marker-regexp)) next-position)
(save-excursion
(goto-char (point-min))
@@ -867,7 +871,8 @@ marked file, return (t FILENAME) instead of (FILENAME)."
(setq results (cons t results)))
(if found
results
- (list ,body)))))
+ (unless (eq ,arg 'marked)
+ (list ,body))))))
;; save-excursion loses, again
(dired-move-to-filename)))
@@ -1706,7 +1711,9 @@ see `dired-use-ls-dired' for more details.")
(declare-function x-begin-drag "xfns.c")
(defun dired-mouse-drag (event)
- "Begin a drag-and-drop operation for the file at EVENT."
+ "Begin a drag-and-drop operation for the file at EVENT.
+If there are marked files and that file is marked, drag every
+other marked file as well. Otherwise, unmark all files."
(interactive "e")
(when mark-active
(deactivate-mark))
@@ -1736,12 +1743,30 @@ see `dired-use-ls-dired' for more details.")
(condition-case nil
(let ((filename (with-selected-window (posn-window
(event-end event))
- (dired-file-name-at-point))))
+ (let ((marked-files (dired-map-over-marks (dired-get-filename
+ nil 'no-error-if-not-filep)
+ 'marked))
+ (file-name (dired-get-filename nil 'no-error-if-not-filep)))
+ (if (and marked-files
+ (member file-name marked-files))
+ marked-files
+ (when marked-files
+ (dired-map-over-marks (dired-unmark nil)
+ 'marked))
+ file-name)))))
(when filename
- (dnd-begin-file-drag filename nil
- (if (eq 'dired-mouse-drag-files 'link)
- 'move 'copy)
- t)))
+ (if (and (consp filename)
+ (cdr filename))
+ (dnd-begin-drag-files filename nil
+ (if (eq 'dired-mouse-drag-files 'link)
+ 'move 'copy)
+ t)
+ (dnd-begin-file-drag (if (stringp filename)
+ filename
+ (car filename))
+ nil (if (eq 'dired-mouse-drag-files 'link)
+ 'move 'copy)
+ t))))
(error (when (eq (event-basic-type new-event) 'mouse-1)
(push new-event unread-command-events))))))))))