emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master cc3e369: Allow controlling the Dired switches shown in the mode l


From: Lars Ingebrigtsen
Subject: master cc3e369: Allow controlling the Dired switches shown in the mode line
Date: Wed, 30 Sep 2020 12:03:56 -0400 (EDT)

branch: master
commit cc3e369ab00524b63aa407018be91a2a1a0cc052
Author: Drew Adams <drew.adams@oracle.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Allow controlling the Dired switches shown in the mode line
    
    * 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 | 11 +++++++++++
 etc/NEWS             |  6 ++++++
 lisp/dired.el        | 54 +++++++++++++++++++++++++++++++++++++++-------------
 3 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 24fd02a..22fec13 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index 7be793e..975207c 100644
--- 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.
 
diff --git a/lisp/dired.el b/lisp/dired.el
index b4b3368..08b19a0 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]