mac 上面使用 magit 删除一个untracked folder非常慢

在一个git 项目下面新建一个文件夹,里面放几个文件,然后在magit里面按“x”键删除这个文件夹,我设置的是把文件移动到trash中,这个操作非常慢。。会导致emacs ui卡住

这里有两个问题:

1。 为什么move to trash这么慢?是同步的原因吗?

  1. 有没有办法异步化?

找到真凶了。

Spacemacs 使用了 osx-trash 这个package,这个package里面会查找本地的一个trash命令行,如果没有就使用applescript,这个非常慢。。。

(defun osx-trash-move-file-to-trash (file-name)
  "Move FILE-NAME to trash.

Try to call the `trash' utility first, because it's faster, and
fall back to AppleScript if `trash' wasn't found."
  (let ((file-name (expand-file-name file-name)))
    (with-temp-buffer
      (let ((retcode (condition-case nil
                         (call-process "trash" nil t nil file-name)
                       (file-error
                        (call-process "osascript" nil t nil
                                      osx-trash-script-file file-name)))))
        (unless (equal retcode 0)
          (error "Failed to trash %S: %S" file-name (buffer-string)))))))

同时,在spacemacs里面,如果是emacs-mac-port的话,是不会使用调用这个函数的:

(defun osx/init-osx-trash ()
  (use-package osx-trash
    :if (and (spacemacs/system-is-mac)
             (not (boundp 'mac-system-move-file-to-trash-use-finder)))
    :init (osx-trash-setup)))
(when (spacemacs/system-is-mac)
  ;; Enable built-in trash support via finder API if available (only on Emacs
  ;; Mac Port)
  (when (boundp 'mac-system-move-file-to-trash-use-finder)
    (setq mac-system-move-file-to-trash-use-finder t)))

因为我没有使用 emacs-mac-port :joy:

看来是时候使用 emacs-mac-port了 (如果不使用 emacs-mac-port, 还可以通过 brew install trash来解决magit里面删除untracked文件夹慢的问题)

2 个赞