异步复制Dired文件夹

12

有没有办法修改/告诉dired异步地复制文件? 如果您在dired中标记多个文件,然后使用“ C”将它们复制,emacs会锁定直到每个文件都被复制。我希望这个复制过程在后台启动,并且我可以继续编辑。 有没有办法实现这种行为?

编辑:实际上,“C”在dired-aux中调用“dired-do-copy”,而不是在dired本身中调用。对此造成的任何困惑表示抱歉。

3个回答

5

我认为 Emacs 大多数情况下仅限于一个单线程,因此直接通过标准的 dired 命令(例如 'C' 复制)可能不可行。

但是,有一个名为 "dired-do-shell-command" 的 dired 命令,它会调用 shell 在后台进行操作。如果你选择要复制的文件,然后使用键盘上的 '!' (这将运行 dired-do-shell-command),然后输入 'cp ? [目标]'(如果你使用的是 Windows,则可能可以使用 'copy')。我没有测试过这个命令,所以请查看 "dired-do-shell-command" 帮助文档以获取完整细节。


2
另请参见Emacs函数。
对于更通用的解决方案,请参见https://github.com/jwiegley/emacs-async,您还可以通过调用单独的Emacs进程来评估任意的Emacs Lisp代码(当然会产生一些额外的延迟)。关于文件操作,请参阅此存储库中的文件dired-async.el。
还要注意,在Emacs中有关于线程的工作,名为Concurrent Emacs,但它还没有完成。有关详细信息,请参见http://www.emacswiki.org/emacs/ConcurrentEmacs

2
我发现这个答案非常有用:https://emacs.stackexchange.com/a/13802/10761。阅读该答案可知,您可以使dired使用scp方法而不是ssh方法进行复制(后者最初使用gzip对文件进行编码,这可能会相当缓慢)。只有当文件大小超过tramp-copy-size-limit(默认为10240)时,scp方法才会使用scp程序进行复制。与dired-async-mode结合使用这个scp方法非常好,因为它不仅可以快速地使用scp进行复制,而且还可以异步地完成,不会影响您的操作。
此外,我认为这很有用:https://oremacs.com/2016/02/24/dired-rsync/。它提供了这段代码来在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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接