11

有没有办法修改/告诉dired异步复制文件?如果您在 dired 中标记多个文件,然后使用“C”复制它们,emacs 会锁定,直到每个文件都被复制。相反,我希望启动此副本,并在后台继续编辑。有没有办法获得这种行为?

编辑:实际上,C 在 dired-aux 中调用'dired-do-copy',而不是在 dired 本身中。很抱歉有任何混淆。

4

3 回答 3

5

我认为emacs主要限于单个线程-因此这可能无法通过标准的dired命令(例如'C' copy)直接实现。

但是,有一个 dired 命令“ dired-do-shell-command ”,它调用 shell 在后台完成工作。如果您选择要复制的文件,然后使用键“!” (这运行 dired-do-shell-command)然后输入 'cp ? [destination]'(如果您在 Windows 上,可能可以使用 'copy')。我还没有对此进行测试 - 所以请参阅“dired-do-shell-command”的帮助以获取完整的详细信息。

于 2008-12-19T03:19:52.997 回答
2

另请参阅 Emacs 函数dired-do-async-shell-command

对于更通用的解决方案,请参阅https://github.com/jwiegley/emacs-async,您还可以通过调用单独的 Emacs 进程来评估任意 Emacs Lisp 代码(这当然会产生一些额外的延迟)。更具体地说,关于文件操作,请参阅此 repo 中的文件 dired-async.el。

另请注意,在 Emacs 中以工作名称 Concurrent Emacs 进行线程化的工作,但还没有。有关详细信息,请参阅http://www.emacswiki.org/emacs/ConcurrentEmacs

于 2014-01-16T09:34:24.237 回答
2

我发现这个答案很有帮助:https ://emacs.stackexchange.com/a/13802/10761 。阅读该答案表明您可以使用该方法而不是该方法dired进行复制(后者最初使用该方法对文件进行编码,并且可能会很慢)。该方法仅在文件大于时才会与程序一起复制(默认情况下)。将此方法与 结合使用非常好,因为它不仅可以快速复制 with ,而且还可以异步进行并且不碍事。scpsshgzipscpscptramp-copy-size-limit10240scpdired-async-modescp

另外,我认为这很有用:https ://oremacs.com/2016/02/24/dired-rsync/ 。它提供了这段代码用于rsync复制文件dired

;;;###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)
于 2017-04-26T19:17:47.177 回答