2

In a Cygwin Emacs on Windows, in Dired, if I try to sort by time (for example), I get the error:

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

In a Windows Emacs binary on Windows, I do not have any problem, but Emacs uses its own implementation of ls IIUC.

What I don't understand is that Cygwin ls DOES understand options such as --dired and -t (to sort by modification time).

My current config:

;; Switches passed to `ls' for Dired.
(setq dired-listing-switches
      (cond ((eq system-type 'windows-nt) ; Native Windows version of Emacs.
             "-a -F -l")
            (t                            ; Cygwin version of Emacs or ...
             "-a -F --group-directories-first -l --time-style=long-iso")))
user3341592
  • 1,419
  • 1
  • 17
  • 36
  • The underlying issue appears to be related to a thread entitled **error in dired sorting on OS X**: http://stackoverflow.com/q/4076360/2112489 I do not know whether Cygwin can be configured to use `coreutils`, which supports the `--group-directories-first` option. – lawlist Jun 10 '15 at 01:01

1 Answers1

1

Try setting dired-listing-switches to "-aFl" instead of "-a -F -l". Maybe that will make some difference (but it does not change anything for me).

What is your value of ls-lisp-use-insert-directory-program? If it is non-nil try setting it to nil, so that you use ls-lisp instead of Cygwin's ls. (At least do that as a trial, and maybe you will want to stick with that.)

what is your value of option ls-lisp-emulation? If it is something else, try customizing it to MS-Windows. (Be sure to read C-h v for this option - e.g., use Customize.)

In sum, I suggest that you first try getting Dired to work OK using ls-lisp and not Cygwin's ls. That will at least give you a solid Dired to work with. If you like, you can then still pursue tackling your problem as stated, i.e., to get it working with Cygwin Emacs.

Drew
  • 29,895
  • 7
  • 74
  • 104
  • The `"-a -F -l"`string is for the Windows Emacs case, and Dired sorting works OK in that version of Emacs. – user3341592 Jun 09 '15 at 07:53
  • Now, I tried to remove options from the second string, the one for all other versions of Emacs, and Dired sorting works OK when I remove `"--time-style=long-iso"`. But, then, I don't have the dates in the format I'm wishing... – user3341592 Jun 09 '15 at 07:54
  • The variable `ls-lisp-use-insert-directory-program` was undefined before explicitly requiring `ls-lisp`. After `(setq ls-lisp-use-insert-directory-program nil) (require 'ls-lisp)`, its value is now `t`. – user3341592 Jun 09 '15 at 07:59
  • Though, when using ls-lisp, I have weird extra columns at the beginning of the Dired buffer. See http://screencast.com/t/iZlDIKlzy8. – user3341592 Jun 09 '15 at 08:02
  • `"-aFl"` works fine in the Windows Emacs case, as does Dired sorting. No need to use `"-a -F -l"`. Dunno if using the latter is part of your problem, but there is no need for it. – Drew Jun 09 '15 at 14:25
  • If the Emacs or the `ls` you are using does not support a given switch, such as `"--time-style-long-iso"`, then it won't have any effect (and at worst it might cause problems). Nothing to be done about that. Don't use that switch when you use that Emacs or that `ls`. – Drew Jun 09 '15 at 14:26
  • Wrt your screencast: You don't say what switches you used. Try changing the switches slightly, to see what is adding those columns. I don't see such columns, e.g., with `-alF`. The second of the columns you show could be from switch `-s` - it is normal for `-s` to add the block size at that location. – Drew Jun 09 '15 at 14:29
  • Regarding `"-aFl"`vs `"-a -F -l"`, it simply that I've always written one-letter flags so. It's not done for a particular reason other than habit. Is your shorter version better in some cases? – user3341592 Jun 09 '15 at 21:23
  • Regarding the `--time-style=long-iso`option, it is supported by the Cygwin `ls`; it does work from the Cygwin terminal. That's what I do not understand... why doesn't it work when called from Dired (in Cygwin Emacs)? – user3341592 Jun 09 '15 at 21:25
  • Regarding the screenshot, it's when I used `ls-lisp`: when I do eval `(setq ls-lisp-use-insert-directory-program nil) (require 'ls-lisp)`. The value of `dired-listing-switches` at that moment is: Its value is `"-a -F --group-directories-first -l"`. – user3341592 Jun 09 '15 at 21:29
  • 1
    Try getting rid of `--group-directories-first`? When I add that switch I see what you see. Presumably ls-lisp does not support that switch. Should be no difference between `-alF` and `-a -l -F` (and I notice none), but who knows? – Drew Jun 09 '15 at 22:49
  • Using just `-alF` or `-a -l -F` with `ls-lisp` now works OK in Cygwin Emacs. So problem solved. However, I still don't get it why using the Cygwin `ls` command does not work from Cygwin Emacs... Thanks for your help. – user3341592 Jun 10 '15 at 08:10
  • Glad to hear it works. Dunno why Cygwin `ls` apparently doesn't work. Maybe someone will ultimately offer some help in that regard. – Drew Jun 10 '15 at 15:24
  • I'd like it to work. But, at the end, that's the result which imports me most. Thanks for your help on working around the problem. – user3341592 Jun 10 '15 at 18:21
  • BTW, in the same vein, `find-name-dired` is behaving differently between Windows Emacs and Cygwin Emacs: `find . \( -iname emacs\* \) -exec ls -ld \{\} \;` in the first case (for searching "emacs*") and `find . \( -iname emacs\* \) -ls` in the second one, leading to extra weird columns before the perms. Any idea? – user3341592 Jun 11 '15 at 20:38
  • @user3341592 Check the path that emacs is using to find ls ... it's probably not cygwin's /bin/ls. You can always explicitly set insert-directory-program to the path of the correct ls. – Jim Balter Nov 02 '18 at 03:01
  • @user3341592 Those "weird extra columns" are the inode number (ls -i) and block count (ls -s). Perhaps ls-lisp is interpreting --group-directories-first as a bunch of single-letter flags. – Jim Balter Nov 02 '18 at 03:08