【问题标题】:emacs error 'ls does not support --dired'emacs 错误 'ls 不支持 --dired'
【发布时间】:2014-08-04 18:28:08
【问题描述】:

自从升级到emacs 24.x 后,每当我打开一个目录时,我都会看到这个错误。整个错误是:

ls does not support --dired; see `dired-use-ls-dired' for more details.

查看变量,发现:

dired-use-ls-dired is a variable defined in `dired.el'.
Its value is nil
Original value was unspecified

Documentation:
Non-nil means Dired should pass the "--dired" option to "ls".
The special value of `unspecified' means to check explicitly, and
save the result in this variable.  This is performed the first
time `dired-insert-directory' is called.

Note that if you set this option to nil, either through choice or
because your "ls" program does not support "--dired", Dired
will fail to parse some "unusual" file names, e.g. those with leading
spaces.  You might want to install ls from GNU Coreutils, which does
support this option.  Alternatively, you might want to use Emacs's
own emulation of "ls", by using:
  (setq ls-lisp-use-insert-directory-program nil)
  (require 'ls-lisp)
This is used by default on MS Windows, which does not have an "ls" program.
Note that `ls-lisp' does not support as many options as GNU ls, though.
For more details, see Info node `(emacs)ls in Lisp'.

You can customize this variable.

我在 FreeBSD 上运行;所以默认的ls 不是GNU'ish 并且不提供--dired 选项。我真的不想麻烦在我所有的服务器上安装 GNU coreutilities。

有人对上面提到的 lisp ls 替代方案有任何经验吗?

大概dired.el 在加载时将dired-use-ls-dired 设置为非零值,并且我在第一次查看目录时经常破坏它?在我的.emacs 中将dired-use-ls-dired 设置为nil 会使消息静音吗?

有没有人认为不急于工作可能代表安全问题?即由空格组成的文件名会保持不可见吗?

也许我应该测试一下上面的一些......

【问题讨论】:

  • emacs 依赖于 GNU 特定的 ls 实现,很有趣。我不熟悉 ls-lisp,但没有正确处理文件名中的空格可能会被利用。
  • “大概”——您不必假设任何事情,只需阅读您引用的文档即可。如果您想知道由空格组成的文件名会发生什么,只需尝试一个。而且这里不存在安全问题,当然与看起来与纯 ASCII 相同但实际上并非如此的 unicode 序列相比。
  • "emacs 依赖于 GNU 特定的 ls 实现,很有趣。" -- emacs 不“依赖”它,它只是在可用时使用它。它在那里说如果您的ls 不支持--dired,您可以使用ls-lispls-lisp 没有 GNU ls 的所有功能,但你不需要它们。并且 emacs 可以正确处理文件名中的空格; ls 并没有指明哪个空格是或不是文件名的一部分... 但您不必使用 ls ... 只需使用 ls-lisp 代替。 (emacs 在一些没有任何ls 命令的系统上运行。它不“依赖”它。)
  • P.S.如果您不希望空白文件名不可见,请在 dired-listing-switches 中设置 --quoting-style(参见 man ls)。

标签: emacs freebsd emacs24


【解决方案1】:

在 macOS 上,ls 不支持 --dired 选项,而在 Linux 上受支持。

(when (string= system-type "darwin")       
  (setq dired-use-ls-dired nil))

【讨论】:

    【解决方案2】:

    在这种情况下你也可以尝试使用gnu-ls,你可以安装这个工具看看这里how-to-replace-mac-os-x-utilities-with-gnu-core-utilities

    在我的情况下,我同时维护这两者,并且 gnu 核心实用程序都以“g”为前缀。

    如果您使用 gls,则启用 --dired 参数

    man gls
    

    名字 ls - 列出目录内容

    概要 ls [选项]...[文件]...

    描述 列出有关文件的信息(默认为当前目录)。如果 -cftuvSUX 和 --sort 都没有,则按字母顺序对条目进行排序 已指定。

       Mandatory arguments to long options are mandatory for short options too.
    
    
                                 .... 
       -d, --directory
              list directories themselves, not their contents
    
                                  ....
    
    which gls                                                                                                                                                                
    /usr/local/bin/gls
    

    然后我们也配置了emacs:

    (when (string= system-type "darwin")
      (setq dired-use-ls-dired t
            insert-directory-program "/usr/local/bin/gls"
            dired-listing-switches "-aBhl --group-directories-first"))
    

    那么你可以使用这个:

    【讨论】:

      【解决方案3】:

      大概 dired.el 在加载时将 dired-use-ls-dired 设置为非零值,并且我在第一次查看目录时经常破坏它?在我的 .emacs 中将 dired-use-ls-dired 设置为 nil 会使消息静音吗?

      我觉得你说的很对。将值自定义为nil。 (如果这没有帮助,您可以随时删除您的自定义。)

      【讨论】:

      • 我尝试在运行 24.5.1 的 OSX 机器上设置 dired-use-ls-diredto nil,它确实消除了该消息。 Dired 之后似乎也能正常工作。
      • @kevin 如果您将此选项设置为 nil ... Dired 将无法解析一些“不寻常”的文件名,例如那些有前导空格的人。除非你有这样的文件,否则当然 dired 会“正常工作”。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多