mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 17:24:23 +00:00
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.
This commit is contained in:
parent
0bd221b29f
commit
cc3e369ab0
3 changed files with 58 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
6
etc/NEWS
6
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue