【已解决】在 macOS 上无法使用 Dired

macOS 版本 12.4,Emacs 版本 28.1。

启动 Dired 时,总是出现提示: Listing directory failed but ‘access-file’ worked

我试过论坛里所有提过的方法,包括不限于把 ruby 放进安全&隐私设置里,以及删除 Emacs.app 包里的某些文件。但不知道是不是因为 ARM 版的关系,删除包里的相关文件会导致 Emacs 打开报错。

跟 ARM 没关系,我使用的 ARM 版的Mac,dired 使用的很好。

请把「所有」方法列出来。

这个问题我好像遇到过。试试这个? :grinning:

  1. Install coreutils: brew install coreutils
  2. Update the path:
# Make all GNU flavor commands available, may override same-name BSD flavor commands
# For x86 Mac
export PATH="/usr/local/opt/coreutils/libexec/gnubin:${PATH}"
export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:${MANPATH}"

# For M1 Mac
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:${PATH}"
export MANPATH="/opt/homebrew/opt/coreutils/libexec/gnuman:${MANPATH}"
  1. add the settings:
;; add when is-a-mac
  (setq insert-directory-program "gls" dired-use-ls-dired t)
  (setq dired-listing-switches "-al --group-directories-first")

注:权限问题要先解决好。

这个设定是在哪个文件里修改?

我已经列了…在安全&隐私性设置添加 ruby,和清理 Emacs.app 里的相关文件都不行…

试过给Emacs fulldisk 权限没有?

这个是在终端下,对路径进行添加。

有的,已经把 Emacs 拉进完全磁盘访问权限的清单里

用gls应该是可以的,我也用的mac,没有问题

你可能需要安装这个包

这是我的设置:

(use-package exec-path-from-shell
  :when (or (memq window-system '(mac ns x))
            (unless (memq system-type '(ms-dos windows-nt))
              (daemonp)))
  :custom (exec-path-from-shell-arguments '("-l"))
  :config
  (dolist (var '("GPG_AGENT_INFO" "LANG" "LC_CTYPE"))
    (add-to-list 'exec-path-from-shell-variables var))
  (exec-path-from-shell-initialize))

你进 eshell 看看当前找到的是那个 ls 命令

1 个赞

我再试试看,谢谢

向大家汇报,我找到解决办法了。

首先,该解决办法是针对我安装的 emacs-plus 版本。其次,之前论坛里帖子里提到的,将 usr/bin/ruby 添加到「完全磁盘访问权限」的做法,是针对 EmacsforMacOSX 的。

我现在的解决方法如下,可以在 emacs-plus 的 issue 列表里找到

其实和 3 楼 EthanLin 的方法是一样的,但没有 update the path 那一步(主要是我不懂 update the path 是什么操作)。

楼上 aqua0210 建议安装的 exec-path-from-shell,我安装了,同时也写入了配置,但不成功。

正解在这里:

Turned out this line in my config broke it, due to macos built in ls doesn’t support --group-directories-first flag

(setq dired-listing-switches "-al --group-directories-first")

Solution:

brew install coreutils

Then in your init.el, add

(setq insert-directory-program "gls" dired-use-ls-dired t)
(setq dired-listing-switches "-al --group-directories-first")

你这不就是四楼的方法吗?

2 个赞

当时没意识到是同样的方法,因为4楼首先 update the path,我也说明了,我不懂什么是 update the path,所以没有意识到,下面的配置是可以单独使用的。直到我查到了这个方法,测试有效了之后,才发现和4楼基本一样,但不用 update the path。