From: Arthur Miller <arthur.miller@live.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Proposal: ls-lisp.el handle --group-directories-first flag
Date: Sat, 24 Jul 2021 16:58:08 +0200 [thread overview]
Message-ID: <AM9PR09MB4977F3743DB64F4B794DD59E96E69@AM9PR09MB4977.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <83im0zzzhq.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 24 Jul 2021 15:07:45 +0300")
[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Arthur Miller <arthur.miller@live.com>
>> Cc: emacs-devel@gnu.org
>> Date: Sat, 24 Jul 2021 13:54:49 +0200
>>
>> > Btw, in my testing, with ls-lisp-dirs-first bound non-nil, the
>> > directories are shown in their correct alphabetically sorted order.
>> > So I'm unsure what problems you saw and in which scenario. Can you
>> > tell more about this issue?
When I was testing, if ls-lisp-dirs-first is nil, and
--group-directories-first is specified, dirs come out in reverse order
in new buffer. Just reverting the buffer didn't show this. I don't know
why it is so. I just tested with emacs built last night from the
master (though only on Arch Linux). Either kill the dired buffer and
open again, or just navigate to another dir.
>> Ok, I'll test more.
>
> Thanks.
I remember now what was going on: when --group-directories-first is
specified, the -U option does not have effect according to gnu ls
manual. Anyway, since we let-bind the ls-lisp-dirs-first, I can just set
that one to 't and get same effect.
>> Have you seen the other patch, where flags are sanitized, that would
>> make ls-lisp accept all the flags as gnu ls, but ignore those it does
>> not undrstand.
>
> Yes, it looks OK to me.
If you are OK with the patch2, then here is one without -U on top of
that one.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ls-lisp.patch --]
[-- Type: text/x-patch, Size: 3947 bytes --]
--- ../emacs/lisp/ls-lisp.el 2021-06-06 23:11:38.317648694 +0200
+++ ./ls-lisp.el 2021-07-24 16:51:38.433573800 +0200
@@ -284,13 +284,19 @@
(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 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 +896,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
next prev parent reply other threads:[~2021-07-24 14:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-15 9:19 Proposal: ls-lisp.el handle --group-directories-first flag Arthur Miller
2021-07-16 11:57 ` Eli Zaretskii
2021-07-16 13:20 ` Arthur Miller
2021-07-16 13:44 ` Eli Zaretskii
2021-07-16 14:58 ` Arthur Miller
2021-07-17 11:57 ` Eli Zaretskii
2021-07-19 20:59 ` Arthur Miller
2021-07-24 11:13 ` Eli Zaretskii
2021-07-24 11:27 ` Eli Zaretskii
2021-07-24 11:54 ` Arthur Miller
2021-07-24 12:07 ` Eli Zaretskii
2021-07-24 14:58 ` Arthur Miller [this message]
2021-07-24 15:43 ` Eli Zaretskii
2021-07-24 19:02 ` Arthur Miller
2021-07-25 7:46 ` Eli Zaretskii
2021-07-25 8:29 ` Arthur Miller
2021-07-25 9:11 ` Eli Zaretskii
2021-07-25 9:31 ` Arthur Miller
2021-07-25 12:44 ` Michael Albinus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM9PR09MB4977F3743DB64F4B794DD59E96E69@AM9PR09MB4977.eurprd09.prod.outlook.com \
--to=arthur.miller@live.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).