有没有办法修改/告诉dired异步地复制文件? 如果您在dired中标记多个文件,然后使用“ C”将它们复制,emacs会锁定直到每个文件都被复制。我希望这个复制过程在后台启动,并且我可以继续编辑。 有没有办法实现这种行为?
编辑:实际上,“C”在dired-aux中调用“dired-do-copy”,而不是在dired本身中调用。对此造成的任何困惑表示抱歉。
我认为 Emacs 大多数情况下仅限于一个单线程,因此直接通过标准的 dired 命令(例如 'C' 复制)可能不可行。
但是,有一个名为 "dired-do-shell-command" 的 dired 命令,它会调用 shell 在后台进行操作。如果你选择要复制的文件,然后使用键盘上的 '!' (这将运行 dired-do-shell-command),然后输入 'cp ? [目标]'(如果你使用的是 Windows,则可能可以使用 'copy')。我没有测试过这个命令,所以请查看 "dired-do-shell-command" 帮助文档以获取完整细节。
dired
使用scp
方法而不是ssh
方法进行复制(后者最初使用gzip
对文件进行编码,这可能会相当缓慢)。只有当文件大小超过tramp-copy-size-limit
(默认为10240
)时,scp
方法才会使用scp
程序进行复制。与dired-async-mode
结合使用这个scp
方法非常好,因为它不仅可以快速地使用scp
进行复制,而且还可以异步地完成,不会影响您的操作。dired
中使用rsync
复制文件:;;;###autoload
(defun ora-dired-rsync (dest)
(interactive
(list
(expand-file-name
(read-file-name
"Rsync to:"
(dired-dwim-target-directory)))))
;; store all selected files into "files" list
(let ((files (dired-get-marked-files
nil current-prefix-arg))
;; the rsync command
(tmtxt/rsync-command
"rsync -arvz --progress "))
;; add all selected file names as arguments
;; to the rsync command
(dolist (file files)
(setq tmtxt/rsync-command
(concat tmtxt/rsync-command
(shell-quote-argument file)
" ")))
;; append the destination
(setq tmtxt/rsync-command
(concat tmtxt/rsync-command
(shell-quote-argument dest)))
;; run the async shell command
(async-shell-command tmtxt/rsync-command "*rsync*")
;; finally, switch to that window
(other-window 1)))
(define-key dired-mode-map "Y" 'ora-dired-rsync)