Group directories first in Emacs Dired

By default on *nix systems, Emacs uses `ls’ program to get directory listings.

How a listing will appear in a Dired buffer depends of course on flags passed to ls as well as of capabilities of the `ls’ program. Probably the most used `ls’ is Gnu ls which takes flag `–group-directories-first’ and will do what you think it will do with that flag.

However, back to an old Windows laptop after a long time and I see that my Dired setup does not work properly. Directories are not listed first. Also, dired-subtree does not toggle directories either.

Some investigation revealed that Emacs on Windows by default uses internal ls written in Lisp, instead of Gnu ls program installed by MSYS. Why this internal utility does not understand the same flag, is a bit of mystery, since it has its own flag for this, `ls-lisp-dirs-first’. A mapping between flags could be easily done. Anyway, in order to spare me of future surprises, we can also tell the internal ls program to use an external ls program:

(setq ls-lisp-use-insert-directory-program "gls")

With that flag Dired seem to work as on my Arch Linux box too.