emacs/dired: drop non-standard switches on Windows

On Windows (or systems that don't support ls),
ls-lisp-use-insert-directory-program will be nil. In these cases, strip
out non-standard switches so they don't throw an error and make dired unusuable.

Fixes #3939
This commit is contained in:
Henrik Lissner 2021-04-14 17:40:57 -04:00
parent 0683861f3f
commit 33af1f98b4

View file

@ -36,12 +36,14 @@
(setq dired-listing-switches (string-join args " "))
(add-hook! 'dired-mode-hook
(defun +dired-disable-gnu-ls-flags-in-tramp-buffers-h ()
"Fix #1703: dired over TRAMP displays a blank screen.
(defun +dired-disable-gnu-ls-flags-maybe-h ()
"Remove extraneous switches from `dired-actual-switches' when it's
uncertain that they are supported (e.g. over TRAMP or on Windows).
This is because there's no guarantee the remote system has GNU ls, which is the
only variant that supports --group-directories-first."
(when (file-remote-p default-directory)
Fixes #1703: dired over TRAMP displays a blank screen.
Fixes #3939: unsortable dired entries on Windows."
(when (or (file-remote-p default-directory)
(not (bound-and-true-p ls-lisp-use-insert-directory-program)))
(setq-local dired-actual-switches (car args))))))
;; Don't complain about this command being disabled when we use it