]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow controlling the Dired switches shown in the mode line
authorDrew Adams <drew.adams@oracle.com>
Wed, 30 Sep 2020 15:59:59 +0000 (17:59 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 30 Sep 2020 15:59:59 +0000 (17:59 +0200)
* doc/emacs/dired.texi (Dired Enter): Document it (bug#41250).

* lisp/dired.el (dired-switches-in-mode-line): New variable (bug#41250).
(dired-sort-set-mode-line): Use it.

doc/emacs/dired.texi
etc/NEWS
lisp/dired.el

index 24fd02aac1a6aab8cf417f21a0f18000906d4852..22fec134baf993d8f8c44db4634e1ba7ac4ba2ae 100644 (file)
@@ -129,6 +129,17 @@ options (that is, single characters) requiring no arguments, and long
 options (starting with @samp{--}) whose arguments are specified with
 @samp{=}.
 
+@vindex dired-switches-in-mode-line
+  Dired will display an indication of what the @command{ls} switches
+are in the mode line.  By default, Dired will try to determine whether
+the switches indicate sorting by name or date, and say so in the mode
+line.  If the @code{dired-switches-in-mode-line} variable is
+@code{as-is}, the switches will be shown verbatim.  If this variable
+in an integer, the switch display will be truncated to that length.
+This variable can also be a function, which will be passed
+@code{dired-actual-switches} as the only parameter and should return a
+string.
+
 @vindex dired-use-ls-dired
   If your @command{ls} program supports the @samp{--dired} option,
 Dired automatically passes it that option; this causes @command{ls} to
index 7be793e01a082413c359a89b1bb2d6a43fe5e78b..975207c877132b4c91105420bdc9dfd6d5095a6a 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -318,6 +318,12 @@ time zones will use a form like "+0100" instead of "CET".
 
 ** Dired
 
++++
+*** New user option 'dired-switches-in-mode-line'.
+This variable controls how "ls" switches is displayed, and allows
+truncating or showing them as they are, in addition to "by name" and
+"by date".
+
 ---
 *** Broken and circular links are shown with the 'dired-broken-symlink' face.
 
index b4b3368a5b789901e4177b3e8231834621246f00..08b19a022503ad4cbe6417dc129cf073baa273c4 100644 (file)
@@ -4227,22 +4227,50 @@ format, use `\\[universal-argument] \\[dired]'.")
   "Non-nil means the Dired sort command is disabled.
 The idea is to set this buffer-locally in special Dired buffers.")
 
+(defcustom dired-switches-in-mode-line nil
+  "How to indicate `dired-actual-switches' in mode-line.
+Possible values:
+ * `nil':    Indicate name-or-date sort order, if possible.
+             Else show full switches.
+ * `as-is':  Show full switches.
+ * Integer:  Show only the first N chars of full switches.
+ * Function: Pass `dired-actual-switches' as arg and show result."
+  :group 'Dired-Plus
+  :type '(choice
+          (const    :tag "Indicate by name or date, else full"   nil)
+          (const    :tag "Show full switches"                    as-is)
+          (integer  :tag "Show first N chars of switches" :value 10)
+          (function :tag "Format with function"           :value identity)))
+
 (defun dired-sort-set-mode-line ()
-  ;; 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.
+  "Set mode-line according to option `dired-switches-in-mode-line'."
   (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)))))
+         (let ((case-fold-search  nil))
+            (if dired-switches-in-mode-line
+                (concat
+                 "Dired"
+                 (cond ((integerp dired-switches-in-mode-line)
+                        (let* ((l1 (length dired-actual-switches))
+                               (xs (substring
+                                    dired-actual-switches
+                                    0 (min l1 dired-switches-in-mode-line)))
+                               (l2 (length xs)))
+                          (if (zerop l2)
+                              xs
+                            (concat " " xs (and (< l2  l1) "…")))))
+                       ((functionp dired-switches-in-mode-line)
+                        (format " %s" (funcall
+                                       dired-switches-in-mode-line
+                                       dired-actual-switches)))
+                       (t (concat " " dired-actual-switches))))
+              (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))))))
     (force-mode-line-update)))
 
 (define-obsolete-function-alias 'dired-sort-set-modeline