【问题标题】:error in dired sorting on OS XOS X 上的直接排序错误
【发布时间】:2010-11-02 09:30:56
【问题描述】:

在 OS X 10.5 Emacs 23.2 上,在 dired 模式下,如果我尝试使用前缀参数 --sort=extension-Xdired-sort-toggle-or-edit 排序,我会得到:

insert-directory: Listing directory failed but `access-file' worked

并且dired缓冲区变空。我试过设置

(setq dired-use-ls-dired nil)

但这没有任何效果。 dired-sort-toggle-or-edit 和按扩展名排序似乎在我的 Ubuntu 机器上工作正常。有人知道发生了什么吗?

【问题讨论】:

  • 非常感谢您提出这样一个有用的问题,它产生了导致解决方案的答案和 cmets。
  • 嗯。我通过搜索我在 emacs 启动时开始遇到的错误发现了这个问题:ls does not support --dired; see dired-use-ls-dired' for more details`。所以,我看到/同意符号链接不是一个好主意。我已经安装了 coreutils(感谢 Homebrew,IIRC)(包括 gls)。所以,ls-lisp 解决方案很有趣,我认为命令@Marius lists alone 也应该有效。我很好奇@hatmatrix 的解决方案是否有优势。试一试……
  • 是的,Marius 的作品...让我们看看我是否喜欢这些开关...(是的,我打算尽快清理这些 cmets。)
  • 我没有。建议人们在 dired-listing-switches 的值中添加 B 对我来说似乎是一个糟糕的主意——如果你不先告诉他们它做了什么!而且由于这些文件已经是灰色的,所以隐藏它们似乎不是一个好主意。我选择了(setq dired-listing-switches "-al --human-readable --group-directories-first");
  • 由于 gls 运行良好,我将跳过 ls-lisp - 因为我猜 gls 的代码更好,并且 ls-lisp 旨在处理 ls 不可用的情况。 (如果有人想让我把这 3 个 cmets 清理成 1 个答案,请 ping 我。)

标签: macos emacs dired


【解决方案1】:

目前,我还找到了另一个使用ls-lisp的解决方案

(when (eq system-type 'darwin)
  (require 'ls-lisp)
  (setq ls-lisp-use-insert-directory-program nil))

【讨论】:

  • 你也可以使用eshell,它的内置ls理解-X。
  • 是否可以将insert-directory-program设置为eshell的ls
  • 感谢@crippledlambda 我结合了这个答案和杜马对前一个答案的评论,将我的插入目录程序设置为 gls,现在在 mac OSX 上一切正常
  • 这让我省了很多麻烦。我实际上在 Windows PowerShell 上,使用 cygwin emacs,但同样的问题。 ls 不会接受任何“长”参数。谢谢!!!
【解决方案2】:

安装在 OS X 上的 ls 不支持 -X 或任何像 --sort 这样的长参数。设置dired-use-ls-dired 不会有任何效果; dired 将始终使用 ls,但如果该变量不是 nil,它会将 --dired 传递给 ls。

如果你想要这种类型的排序,你可以使用 fink 之类的东西来安装 coreutils,它会提供一个更像你在 Ubuntu 中习惯的 ls。

【讨论】:

  • 啊,这就是问题所在... 奇怪的是 FreeBSD 没有这种类型的排序。我以为芬克死了,但实际上看起来很活跃……不知道为什么我会这么想。谢谢。
  • 我通过 Homebrew 安装了coreutils,它显然安装了/usr/local/bin/gls。我将 ln -s'd 发送到 /usr/local/bin/ls,然后我在 Emacs 中不再出现错误。
  • @duma:这在 Yosemite 10.10.3 下对我不起作用。然后,我在.emacs 中使用了(setq insert-directory-program "/usr/local/bin/gls"); use proper GNU ls,它起作用了
【解决方案3】:

以下是使用通过 macports 安装的 coreutils 在 Snow Leopard 10.6.8 上运行 Emacs 的步骤:

注意:我的 macports 安装与通用 (/opt/...) 不同——即,我使用 /macports 作为根。不需要更改根设置,这只是我的个人喜好。对于 vanilla macport 安装或替代设置,请相应地调整路径。

sudo /macports/bin/port install coreutils

这在.emacsinit.el 内:

;; sort directories first

(setq insert-directory-program "/macports/bin/gls")

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

注意:建议使用gls/ls 的符号链接,因为它会破坏 macports install 的功能,而且很可能还会破坏其他东西。


需要更多控制权的用户的替代安装:

下载:coreutils-8.21.tar.xz 来自:http://ftp.gnu.org/gnu/coreutils/

如果您没有解压缩*.xz 文件的实用程序,您可以使用TheUnarchiver3.9.1 等实用程序。

这里是制作coreutils 的快速参考——我将安装位置设置为我自己的个人喜好而不是默认位置:

./configure \
--prefix=/Users/HOME/.0.data/.0.emacs/elpa

make

sudo make install

将这些插入到您的.emacsinit.el 文件中——相应地调整路径:

;; sort directories first

(setq insert-directory-program "/Users/HOME/.0.data/.0.emacs/elpa/bin/ls")

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

【讨论】:

    【解决方案4】:

    2020 年仍在发生!如果像我一样,您使用 brew 作为您的开源包管理器,那么这是复制粘贴到您的 .emacs 文件或您保留启动自定义项的任何位置的正确解决方案:

    (when (equal system-type 'darwin)
      (setq insert-directory-program "/usr/local/opt/coreutils/libexec/gnubin/ls"))
    

    (我检查操作系统是因为我在多个系统上部署了我的 Emacs 配置)。

    奇怪的是,这突然发生在一个 Mojave 系统上,我一直在这个系统上经常使用 Emacs,而且我确信 dired 过去一直在这个系统上工作。我猜是更新破坏了一些东西,使得 dired 使用正确的二进制文件,而无需手动设置它。

    【讨论】:

    • 对于遵循此答案的任何人,您还需要安装 coreutils(通过 brew)才能使其正常工作。这可以通过命令brew install coreutils 来完成。
    【解决方案5】:

    这与 lawlist 的好答案没有太大区别,但信息略有不同,并且是为使用 Nix 包管理器的人量身定制的:

    (use-package dired
      :custom
      ;; See http://stackoverflow.com/questions/4115465/emacs-dired-too-much-information
      ;; NOTE: Just some information worth keeping in mind. More readable dired file
      ;; size output - consider adding F (make file type obvious), or p (p adds a
      ;; trailing slash to dirs, but makes moving dirs fail), and G (colorize) too.
      (dired-listing-switches "-alh --group-directories-first")
      :config
      ;; [[https://stackoverflow.com/questions/4076360/error-in-dired-sorting-on-os-x][macos - error in dired sorting on OS X - Stack Overflow]]
      ;; To fix the
      ;; (error "Listing directory failed but 'access-file' worked")
      ;; error. Emacs needs to use gnu's ls, which I get through nixpkgs' coreutils.
      ;; In my config, currently, Emacs is not picking up the path to my nix install
      ;; ls (todo: fix).
      ;;
      ;; Note that, unlike the info at the link provided above,
      ;; --group-directories-first is not needed to fix this error. I just like to
      ;; see the directories first in a dired buffer.
      (setq insert-directory-program (expand-file-name ".nix-profile/bin/ls"
                                                       (getenv "HOME"))))
    

    【讨论】:

      猜你喜欢
      • 2017-06-12
      • 1970-01-01
      • 2014-10-21
      • 2017-06-11
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 2014-10-14
      相关资源
      最近更新 更多