summaryrefslogtreecommitdiff
path: root/lisp/dired.el
diff options
context:
space:
mode:
authorDrew Adams <drew.adams@oracle.com>2020-09-30 17:59:59 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-09-30 17:59:59 +0200
commitcc3e369ab00524b63aa407018be91a2a1a0cc052 (patch)
tree5721d7321f51c11921a378ea03f6a90c3988e21d /lisp/dired.el
parent0bd221b29fa29ebcd4b168d9abc67745ef5f85c2 (diff)
downloademacs-cc3e369ab00524b63aa407018be91a2a1a0cc052.tar.gz
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.
Diffstat (limited to 'lisp/dired.el')
-rw-r--r--lisp/dired.el54
1 files changed, 41 insertions, 13 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index b4b3368a5b7..08b19a02250 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