--- ../emacs/lisp/ls-lisp.el 2021-06-06 23:11:38.317648694 +0200 +++ ./ls-lisp.el 2021-07-19 22:34:46.464966628 +0200 @@ -284,13 +284,18 @@ (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))) + (if (string-match "--group-directories-first" switches) + ;; if ls-lisp-dirs-first is nil, dirs are grouped but come out in + ;; reverse order, so add -U flag to fix that + (setq switches (concat "-U " (replace-match "" nil nil switches)))) + ;; Remove unrecognized ls long flags, and convert recognized to short + (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 +895,60 @@ ;; Continue standard unloading. nil) +(defun ls-lisp--sanitize-switches (switches) + "Convert long opt flags to short. 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. --As listed in docs for +ls-lisp--insert-directory function." + (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