Commit d3415724 authored by Arthur Miller's avatar Arthur Miller Committed by Eli Zaretskii
Browse files

Support '--group-directories-first' in ls-lisp.el

* lisp/ls-lisp.el (ls-lisp--sanitize-switches): New function.
(ls-lisp--insert-directory): Support '--group-directories-first'.
Call 'ls-lisp--sanitize-switches' to convert long options to short
forms and remove unsupported long options.  Update the doc string.

Copyright-paperwork-exempt: yes
parent a6afa221
Pipeline #11586 failed with stages
in 15 seconds
......@@ -276,7 +276,9 @@ supports ordinary shell wildcards if `ls-lisp-support-shell-wildcards'
is non-nil; otherwise, it interprets wildcards as regular expressions
to match file names. It does not support all `ls' switches -- those
that work are: A a B C c F G g h i n R r S s t U u v X. The l switch
is assumed to be always present and cannot be turned off."
is assumed to be always present and cannot be turned off.
Long variants of the above switches, as documented for GNU `ls',
are also supported; unsupported long options are silently ignored."
(if ls-lisp-use-insert-directory-program
(funcall orig-fun
file switches wildcard full-directory-p)
......@@ -284,13 +286,21 @@ is assumed to be always present and cannot be turned off."
(let ((handler (find-file-name-handler (expand-file-name file)
'insert-directory))
(orig-file file)
wildcard-regexp)
wildcard-regexp
(ls-lisp-dirs-first
(or ls-lisp-dirs-first
(string-match "--group-directories-first" switches))))
(if handler
(funcall handler 'insert-directory file switches
wildcard full-directory-p)
;; Remove --dired switch
(if (string-match "--dired " switches)
(setq switches (replace-match "" nil nil switches)))
(when (string-match "--group-directories-first" switches)
;; if ls-lisp-dirs-first is nil, dirs are grouped but come out in
;; reverse order:
(setq ls-lisp-dirs-first t)
(setq switches (replace-match "" nil nil switches)))
;; Remove unrecognized long options, and convert the
;; recognized ones to their short variants.
(setq switches (ls-lisp--sanitize-switches switches))
;; Convert SWITCHES to a list of characters.
(setq switches (delete ?\ (delete ?- (append switches nil))))
;; Sometimes we get ".../foo*/" as FILE. While the shell and
......@@ -890,6 +900,60 @@ All ls time options, namely c, t and u, are handled."
;; Continue standard unloading.
nil)
(defun ls-lisp--sanitize-switches (switches)
"Convert long options of GNU 'ls' to their short form.
Conversion is done only for flags supported by ls-lisp.
Long options not supported by ls-lisp are removed.
Supported options are: A a B C c F G g h i n R r S s t U u v X.
The l switch is assumed to be always present and cannot be turned off."
(let ((lsflags '(("-a" . "--all")
("-A" . "--almost-all")
("-B" . "--ignore-backups")
("-C" . "--color")
("-F" . "--classify")
("-G" . "--no-group")
("-h" . "--human-readable")
("-H" . "--dereference-command-line")
("-i" . "--inode")
("-n" . "--numeric-uid-gid")
("-r" . "--reverse")
("-R" . "--recursive")
("-s" . "--size")
("-S" . "--sort.*[ \\\t]")
("" . "--group-directories-first")
("" . "--author")
("" . "--escape")
("" . "--directory")
("" . "--dired")
("" . "--file-type")
("" . "--format")
("" . "--full-time")
("" . "--si")
("" . "--dereference-command-line-symlink-to-dir")
("" . "--hide")
("" . "--hyperlink")
("" . "--ignore")
("" . "--kibibytes")
("" . "--dereference")
("" . "--literal")
("" . "--hide-control-chars")
("" . "--show-control-chars")
("" . "--quote-name")
("" . "--context")
("" . "--help")
;; ("" . "--indicator-style.*[ \\\t]")
;; ("" . "--quoting-style.*[ \t\\]")
;; ("" . "--time.*[ \\\t]")
;; ("" . "--time-style.*[ \\\t]")
;; ("" . "--tabsize.*[ \\\t]")
;; ("" . "--width.*[ \\\t]")
("" . "--.*=.*[ \\\t\n]?") ;; catch all with '=' sign in
("" . "--version"))))
(dolist (f lsflags)
(if (string-match (cdr f) switches)
(setq switches (replace-match (car f) nil nil switches))))
(string-trim switches)))
(provide 'ls-lisp)
;;; ls-lisp.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment