Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 69185bc

Browse files
authoredJan 18, 2023
Merge pull request Fuco1#197 from aagon/master
Use asynchronous copy and move provided by dired-async
2 parents 41d3eb4 + aebd9a4 commit 69185bc

File tree

1 file changed

+16
-52
lines changed

1 file changed

+16
-52
lines changed
 

‎dired-ranger.el

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;; Maintainer: Matúš Goljer <matus.goljer@gmail.com>
77
;; Version: 0.0.1
88
;; Created: 17th June 2014
9-
;; Package-Requires: ((dash "2.7.0") (dired-hacks-utils "0.0.1"))
9+
;; Package-Requires: ((dash "2.7.0"))
1010
;; Keywords: files
1111

1212
;; This program is free software; you can redistribute it and/or
@@ -61,6 +61,9 @@
6161
;; cleared, so you can repeat the copy operation in another dired
6262
;; buffer.
6363

64+
;; The copy or move operation is asynchronous if `dired-async-mode'
65+
;; is activated.
66+
6467
;; Bookmarks
6568
;; ---------
6669

@@ -83,9 +86,9 @@
8386

8487
;;; Code:
8588

86-
(require 'dired-hacks-utils)
8789
(require 'dash)
8890
(require 'ring)
91+
(require 'dired-aux)
8992

9093
(defgroup dired-ranger ()
9194
"Implementation of useful ranger features for dired."
@@ -132,22 +135,9 @@ buffers for a single paste."
132135
(length marked)
133136
(if (> (length marked) 1) "s" "")))))))
134137

135-
(defun dired-ranger--revert-target (char target-directory files)
136-
"Revert the target buffer and mark the new files.
137-
138-
CHAR is the temporary value for `dired-marker-char'.
139-
140-
TARGET-DIRECTORY is the current dired directory.
141-
142-
FILES is the list of files (from the `dired-ranger-copy-ring') we
143-
operated on."
144-
(let ((current-file (dired-utils-get-filename)))
145-
(revert-buffer)
146-
(let ((dired-marker-char char))
147-
(--each (-map 'file-name-nondirectory files)
148-
(dired-utils-goto-line (concat target-directory it))
149-
(dired-mark 1)))
150-
(dired-utils-goto-line current-file)))
138+
(defun dired-ranger--name-constructor (oldname)
139+
"Return the new file name corresponding to OLDNAME."
140+
(concat (dired-current-directory) (file-name-nondirectory oldname)))
151141

152142
;;;###autoload
153143
(defun dired-ranger-paste (arg)
@@ -161,22 +151,10 @@ copy ring."
161151
(interactive "P")
162152
(let* ((index (if (numberp arg) arg 0))
163153
(data (ring-ref dired-ranger-copy-ring index))
164-
(files (cdr data))
165-
(target-directory (dired-current-directory))
166-
(copied-files 0))
167-
(--each files (when (file-exists-p it)
168-
(if (file-directory-p it)
169-
(copy-directory it target-directory)
170-
(condition-case err
171-
(copy-file it target-directory 0)
172-
(file-already-exists nil)))
173-
(cl-incf copied-files)))
174-
(dired-ranger--revert-target ?P target-directory files)
175-
(unless arg (ring-remove dired-ranger-copy-ring 0))
176-
(message (format "Pasted %d/%d item%s from copy ring."
177-
copied-files
178-
(length files)
179-
(if (> (length files) 1) "s" "")))))
154+
(files (cdr data)))
155+
(dired-create-files #'dired-copy-file "Copy" files
156+
#'dired-ranger--name-constructor ?C)
157+
(unless arg (ring-remove dired-ranger-copy-ring 0))))
180158

181159
;;;###autoload
182160
(defun dired-ranger-move (arg)
@@ -187,24 +165,10 @@ instead of copying them."
187165
(interactive "P")
188166
(let* ((index (if (numberp arg) arg 0))
189167
(data (ring-ref dired-ranger-copy-ring index))
190-
(buffers (car data))
191-
(files (cdr data))
192-
(target-directory (dired-current-directory))
193-
(copied-files 0))
194-
(--each files (when (file-exists-p it)
195-
(condition-case err
196-
(rename-file it target-directory 0)
197-
(file-already-exists nil))
198-
(cl-incf copied-files)))
199-
(dired-ranger--revert-target ?M target-directory files)
200-
(--each buffers
201-
(when (buffer-live-p it)
202-
(with-current-buffer it (revert-buffer))))
203-
(unless arg (ring-remove dired-ranger-copy-ring 0))
204-
(message (format "Moved %d/%d item%s from copy ring."
205-
copied-files
206-
(length files)
207-
(if (> (length files) 1) "s" "")))))
168+
(files (cdr data)))
169+
(dired-create-files #'rename-file "Rename" files
170+
#'dired-ranger--name-constructor ?M)
171+
(unless arg (ring-remove dired-ranger-copy-ring 0))))
208172

209173

210174
;; bookmarks

0 commit comments

Comments
 (0)
Failed to load comments.