问题
On OS X 10.5 Emacs 23.2, in dired-mode, if I try to sort by dired-sort-toggle-or-edit
with prefix argument --sort=extension
or -X
, I get:
insert-directory: Listing directory failed but `access-file' worked
and the dired buffer becomes empty. I tried setting
(setq dired-use-ls-dired nil)
but this had no effect. dired-sort-toggle-or-edit
and sorting by extension seems to work okay on my Ubuntu box. Anyone have a clue what's going on?
回答1:
The ls
that's installed on OS X doesn't support -X
or any long arguments like --sort
. Setting dired-use-ls-dired
won't have any effect; dired will always use ls, but if that variable is non-nil, it will pass --dired
to ls.
If you want that type of sorting, you can probably use something like fink to install coreutils, which will provide an ls more like what you're used to in Ubuntu.
回答2:
For now, I've also found another solution using ls-lisp
(when (eq system-type 'darwin)
(require 'ls-lisp)
(setq ls-lisp-use-insert-directory-program nil))
回答3:
Here are the steps for Emacs running on Snow Leopard 10.6.8 using coreutils
installed through macports:
NOTE: My macports installation is different than the generic (/opt/...
) -- i.e., I use /macports
as the root. Altering the root setup is not required, it is just a personal preference of mine. For vanilla macport installations or alternative setups, adjust the path accordingly.
sudo /macports/bin/port install coreutils
This goes inside the .emacs
or init.el
:
;; sort directories first
(setq insert-directory-program "/macports/bin/gls")
(setq dired-listing-switches "-aBhl --group-directories-first")
NOTE: Using a symlink for gls
/ls
is not recommended because it breaks functionality with macports install and most likely other stuff too.
Alternative installation for users who want more control:
Download: coreutils-8.21.tar.xz
from: http://ftp.gnu.org/gnu/coreutils/
If you do not have a utility to unzip an *.xz
file, you can use a utility such as TheUnarchiver3.9.1
.
Here is a quick reference to make the coreutils
-- I set the installation location to my own personal preference instead of the default:
./configure \
--prefix=/Users/HOME/.0.data/.0.emacs/elpa
make
sudo make install
Insert these into your .emacs
or init.el
file -- adjust the path accordingly:
;; 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:
This is not much different than lawlist's nice answer, but has slightly different information and is tailored to those who use the Nix package manager:
(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"))))
来源:https://stackoverflow.com/questions/4076360/error-in-dired-sorting-on-os-x