From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Arthur Miller Newsgroups: gmane.emacs.devel Subject: Re: Proposal: ls-lisp.el handle --group-directories-first flag Date: Mon, 19 Jul 2021 22:59:13 +0200 Message-ID: References: <8335se5v40.fsf@gnu.org> <83y2a64bla.fsf@gnu.org> <83czrh40hf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4542"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jul 19 23:01:37 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m5aOO-0000yp-Jd for ged-emacs-devel@m.gmane-mx.org; Mon, 19 Jul 2021 23:01:36 +0200 Original-Received: from localhost ([::1]:34956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5aOM-00021S-L8 for ged-emacs-devel@m.gmane-mx.org; Mon, 19 Jul 2021 17:01:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5aME-0008W8-NE for emacs-devel@gnu.org; Mon, 19 Jul 2021 16:59:22 -0400 Original-Received: from mail-db8eur05olkn2072.outbound.protection.outlook.com ([40.92.89.72]:30785 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5aM9-0001uD-N3; Mon, 19 Jul 2021 16:59:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nzm4efgriICnMDpVLORxWQ6I1uJy0cT+sfGQjuMB3UzSlGIpJiqRF5x0jdyGTC9FA8h5unJdxdb7mMFBGQcjHoWhSvbMhqmCwiEdIHzbHmdGjI7ZaqqLIeuE/yF7zc0f5cMQ3rp0mTjguWVKHwirO50NuKSw+sj4J6YLAQNd5ing0vA6lUaGgVEydWeBX3dsNTk0ey1ZQk2S/oKu6FhIannW3uAjRwwqNf+xNwLBpxUo0xJBWeHsRJnJCJBibxTnxaeScPRuoT5/7Ri20/CWGPMdu3llvptzRE+8qyGpWIqoOcPDrr/aiROu8e8v1CjeBl23ZEtJLL+N7gquNM658w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1gBAkwQhuAmF31tVCbrhDh6YYtWzNma7WKWNNVtdnAU=; b=Db0tmeXBJ5o+GDkmHuPWQneylpEjZ/6iy+aPp9LAmpUwY3/TNDbxt9gextRDo0KJDpxB5j+cosToCdku1SWJ+sS3cKKNDd4HQLs5aU4aS3+IYGB0Y5Q35AkY1XNG1sFMIkA2LPHsC82peWczbWf5TQGUWtN27y1M1G7ZO3ol5f3kLs7KVUMALHzWdf5rzubSZd2Tt74AkvxYx/SipwvjvO/F3p1H0N71UfCfBe49eO9XxyxgObzg65kQBCMMNAdtb/LtL69NTZZ7ly3fFlfG28vxXWt69ZHFvCSN1qPMjnA6L2tcOW8jKF4IEXYunyKsGYRHC0itsVWgKlloVUo6Og== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1gBAkwQhuAmF31tVCbrhDh6YYtWzNma7WKWNNVtdnAU=; b=fUA2wIG24HSEeKzBf/ykO3gHgjdvlDpdy/WCfO1FezzuICVR7IFL+yle4b2AKV+FiBv/NUB3s9wszuk5U9Pi0LXxnW0H2HfSgOPwlqSr9Erparp5bQ+k+c55gNLE4ESfAgF98rTGFk38bT+yYvi2K5yIdaFOqGaK/FWA1Pe2XrNQ3i1ACPBBwveUIzwJJA0nPCVxayb5ksV1L5+2N/B82rrHy3Jj3pDy/gOBx1zi1/Xwk6IbjZK3xyqe1IwPdF2ua0lBx25kJ8f3aZRhaoR6u2npgwP/VADjOS+swAhSl/rv4Lq3YxTB00+FymsVJqCL12RbvVvScd6M/bd3u5910Q== Original-Received: from AM6EUR05FT032.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc11::40) by AM6EUR05HT055.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc11::342) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Mon, 19 Jul 2021 20:59:14 +0000 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:fc11::45) by AM6EUR05FT032.mail.protection.outlook.com (2a01:111:e400:fc11::101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 20:59:14 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:FD98DB48E3C02E7CB835BD192D8523CD5243A17F35DB0024D206C5CCEDF79D5B; UpperCasedChecksum:A65CA19336F502E795B886D974CF657ABDEB9BE4D0B3EB240FD34B1637F02B7D; SizeAsReceived:7709; Count:46 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::e47b:760e:fa35:f28b]) by AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::e47b:760e:fa35:f28b%6]) with mapi id 15.20.4331.033; Mon, 19 Jul 2021 20:59:14 +0000 In-Reply-To: <83czrh40hf.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 17 Jul 2021 14:57:00 +0300") X-TMN: [gEfIeg/dv69uswo111P/yEyGx2Mio3pb] X-ClientProxiedBy: AM5PR0602CA0022.eurprd06.prod.outlook.com (2603:10a6:203:a3::32) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <87r1fut3z2.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (81.232.177.30) by AM5PR0602CA0022.eurprd06.prod.outlook.com (2603:10a6:203:a3::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 20:59:13 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 4598a05d-dd9b-458b-4218-08d94af8105c X-MS-TrafficTypeDiagnostic: AM6EUR05HT055: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yAuOAHPsMvAo6jQZ99hwChq+b/zd9qHVQpfQHw7QupEhBaD+hQhRG5g2LGFpKNDI2CbJtqbFXi5YXByX1yH57j5i5XStuc2nrJwK9GHAS0Kla2oWrZ7Ppu/QR28viNJn0WwDYzvLt7CpRW5IuihNqdNQEYkD2u3qdjis57Yfg/J3Ewndp5UAM4HGrUCaC3K/V3Y8wcQolTh7v6bqtB9EPP4/xI3U/U0P6dQPsGk5DxCG6avTPEC8rSbGB4N/q4jYxH5+vTP43xTBXOfP2bP+O3rgsax7c4A5KxqlQECoRu4VLOGIc/FeVLnwrr27WfLuUyvM9D+7AnnGqku2YnBHy/BULHGx8iXXVgm1uqINLfBS/YmWk1TZm5ECHt6UkVO8JJrOpikTYo1dzrNT2SQSa/pA41+Mop/CBxJm+1ipPp8Yky00OxpUAYzOl3uYG/VuHQzQmINzjkNwBbsXFmhzavUpxznkVtEjNadKEZEnu00= X-MS-Exchange-AntiSpam-MessageData: s7n12bTavYRapeVRL8R2hzRYBhtZAsJFE09JUlFfsVHPwBu8xMrskMT9Kalb3766LvKfssGXYdOb7lN2eraGFVrRo/4RaVaslbU7B9undy8Q7nlqss3dpMFN8V5XyvTDk9BDzVcx2guTStU4fE6BAQ== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4598a05d-dd9b-458b-4218-08d94af8105c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 20:59:13.9927 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM6EUR05FT032.eop-eur05.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6EUR05HT055 Received-SPF: pass client-ip=40.92.89.72; envelope-from=arthur.miller@live.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:271368 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Arthur Miller >> Cc: emacs-devel@gnu.org >> Date: Fri, 16 Jul 2021 16:58:16 +0200 >> >> Ok, I take my words back, it is actually not lost. I was to fast didn't >> reallize --group-directories-first was just converted with rest to a >> list of chars. >> >> Doesn't it mean that ls-lisp could potentialy recieve flags that user >> didn't ment to use? > > Yes, you need to remove that option before the options get converted. Yes, and possibly even other long options that an ignorant, unawary user like myself can pass in dired-listing-switches. The original code just removes "--dired" flag. Everything else is converted into character list, so if I pass something like --time-style=long-iso, everything but dashes makes it into list with switches. Manual says which switches are supported by ls-lisp, but now how it behaves when passed flags it does not support: https://www.gnu.org/software/emacs/manual/html_node/emacs/ls-in-Lisp.html Personally I expect it to just igonre those, now I have learned it does not. Bug or not, does not matter, I think it is more convenient to have one version of dired-listing-switches, then to keep two different, so I suggest to "sanitize switches" before they are processed. Check included ls-lisp-p2.patch and see if that is acceptable. >> Since --group-directories-first is still there, then let bind works fine >> :-). > > Great. I think this can be installed, as soon as you add the removal > of that option from the options' list. Yepp, included patch ls-lisp-p1.patch does it. A think to note is that -U will be ignored if --group-directories-first is passed (so does gls). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=ls-lisp-p1.patch --- ../emacs/lisp/ls-lisp.el 2021-06-06 23:11:38.317648694 +0200 +++ ./ls-lisp.el 2021-07-19 22:07:19.977128780 +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))) + (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)))) ;; Convert SWITCHES to a list of characters. (setq switches (delete ?\ (delete ?- (append switches nil)))) ;; Sometimes we get ".../foo*/" as FILE. While the shell and --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=ls-lisp-p2.patch --- ../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 --=-=-=--