Subject: bug#41250: 28.0.50; Dired displays unconditionally ls-switches on modeline

From: Arthur Miller <[email-masked]>
Date: Thu, 14 May 2020 03:42:32 +0200

There is no way to turn off displaying of ls-switches on modeline when
in dired-mode.

By default in certain configuration, dired display ls-switches on
modeline. In case those switches are a long list, for example:

"-lA --si --time-style long-iso --group-directories-first"

then everything else on modeline gets pushed far to the right which is
not very usable. In general I don't have much use of seing ls-switches
on modeline and would like to be able to turn them off. As of current it
does not seem possible since it is hard-coded in function
`dired-sort-set-mode-line' in dired.el.

I suggest, as small improvement, to introduce a user option to turn off
or on displaying of ls-switches on modeline. As a suggestion I have
attached small hack to dired.el as tested on my copy of Emacs, but you
might wish to rewrite it. Drew had some other suggestions.

--- dired.el	2020-05-14 03:06:34.046112281 +0200
+++ lisp/dired.el	2020-05-14 03:12:03.423097577 +0200
@@ -70,12 +70,20 @@
   :type 'string
   :group 'dired)
 
+(defcustom dired-display-listing-switches nil
+  "Display switches passed to `ls' for Dired on modeline.
+If value is `t', value of dired-listing-switches will be shown on
+modeline, when dired is not showing files `by name' or `by date'.
+Default value is nil."
+  :type 'boolean
+  :group 'dired)
+
 (defcustom dired-subdir-switches nil
   "If non-nil, switches passed to `ls' for inserting subdirectories.
 If nil, `dired-listing-switches' is used."
-   :group 'dired
-   :type '(choice (const :tag "Use dired-listing-switches" nil)
-                  (string :tag "Switches")))
+  :group 'dired
+  :type '(choice (const :tag "Use dired-listing-switches" nil)
+                 (string :tag "Switches")))
 
 (defcustom dired-chown-program
   (purecopy (cond ((executable-find "chown") "chown")
@@ -4118,22 +4126,25 @@
   ;; Set mode line display according to dired-actual-switches.
   ;; Mode line display of "by name" or "by date" guarantees the user a
   ;; match with the corresponding regexps.  Non-matching switches are
-  ;; shown literally.
+  ;; shown literally if user has not disabled displaying them by
+  ;; customizing dired-display-listing-switches variable.
   (when (eq major-mode 'dired-mode)
-    (setq mode-name
-	  (let (case-fold-search)
-	    (cond ((string-match-p
-		    dired-sort-by-name-regexp dired-actual-switches)
-		   "Dired by name")
-		  ((string-match-p
-		    dired-sort-by-date-regexp dired-actual-switches)
-		   "Dired by date")
-		  (t
-		   (concat "Dired " dired-actual-switches)))))
+    (setq mode-name 
+          (let (case-fold-search)
+            (cond ((string-match-p
+	            dired-sort-by-name-regexp dired-actual-switches)
+	           "Dired by name")
+	          ((string-match-p
+	            dired-sort-by-date-regexp dired-actual-switches)
+	           "Dired by date")
+	          ((eq dired-display-listing-switches t)
+	           (concat "Dired " dired-actual-switches))
+                  (t
+                   "Dired"))))
     (force-mode-line-update)))
 
-(define-obsolete-function-alias 'dired-sort-set-modeline
-  #'dired-sort-set-mode-line "24.3")
+  (define-obsolete-function-alias 'dired-sort-set-modeline
+    #'dired-sort-set-mode-line "24.3")
 
 (defun dired-sort-toggle-or-edit (&optional arg)
   "Toggle sorting by date, and refresh the Dired buffer.