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: Sat, 24 Jul 2021 16:58:08 +0200 Message-ID: References: <8335se5v40.fsf@gnu.org> <83y2a64bla.fsf@gnu.org> <83czrh40hf.fsf@gnu.org> <83o8asynga.fsf@gnu.org> <83k0lgymsd.fsf@gnu.org> <83im0zzzhq.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="33292"; 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 Sat Jul 24 16:59:07 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 1m7J7K-0008V5-Vg for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Jul 2021 16:59:07 +0200 Original-Received: from localhost ([::1]:33236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m7J7J-0001vi-Vc for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Jul 2021 10:59:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m7J6V-0001CS-FN for emacs-devel@gnu.org; Sat, 24 Jul 2021 10:58:15 -0400 Original-Received: from mail-oln040092070092.outbound.protection.outlook.com ([40.92.70.92]:51269 helo=EUR03-AM5-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 1m7J6S-00054O-EL; Sat, 24 Jul 2021 10:58:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gALyODxGtuJ11J/bHNDKz7uRMlwq5UVzviIstiKJoj0dhTElP+w2vWB7QNg7D7z/biP/r4d9AmlQcL88ThCU/JZNX40KbKUiEzO0gneZQYTrg2gHD/u4gZp9iniwW9c65HLdyBcrrFdrrOPnDm/fHWKnJEdCHV+OUq8VUhHyZGykMb2oVAa0zK2WGwrJ9cQ5q+abXIpSH0AhDY4xzI4h19jOiT8Q722eGSWLru4AWZBWYZ/Tp1/tzNhwhr1ldlaC/FOz0cMCdELGIGaCTIvMdZSoYOeaTQgyNw8sz81xBOskjTTEoNgFbTmIbZehedfBkmE0rnE/l/hZCJKoNftQ1g== 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=yGHer6Uazp+DxKTM9gNemwsjtUqeyWBhZ6CPssjlhmA=; b=PpYBGpJFP/tzYgVjbOzCkWTVGHFbsHYA6c0ynXfm2MD+PbmQWaHDTnaygqs3f+PnRSRbFOYJZnzD/bDr83w7ywh5iQ0GMHBhos+1iYiuNYC1RvIPxmXUQSJwzq4eVF80g1JFwoIm8PBXDcBGiROikFi9JSRwKZqJ+kw60ci0q2ihcwnWD29wUozekQ5lZhqeVo8jxy6cwKGfg2FMvu+cdVkTEHAQJvpnjTbwk67eWY06GtqlP+iujUbw27z1SCxRKJB9ig6Wd0wAxzI0a2NWyAPRbbG6hn6Rir4Vjtxw5258p6vfEKf5LXIvVRibnP1j5+Smqt5hFy4Ke/zqe8m0cw== 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=yGHer6Uazp+DxKTM9gNemwsjtUqeyWBhZ6CPssjlhmA=; b=IDfvNQSCZdnNQL1AODcl39lgpegbf2+hBlOvJ+KTzA+BmqqVS+oZmhpa15ndSUSTJE9GKjMwnuvNo5J71nlH5jWHB/0xQCwTmg/tIDytyBaCZeaVCcMTDEf8ZnOcNWK2b8+QPg6PGPnKLPTsmkUZDUKOpuqpszHolRwmL2B30XBJOpbITGZg+SC//YA3s0VEFYVsxep3osryHacWIy7kf49jBUutgDbb5W7MZJkl8Rhrw4oiHyncz6Kfvp+wv/ibk/exw3DK6xPqK03IilPYcPr6Fli21ixKBdngpAWiFgP7+x1UE8OclonEOqPSv6/aV1+WUmVe/m3xyVV8SkeGvg== Original-Received: from DB5EUR03FT012.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e0a::45) by DB5EUR03HT066.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e0a::489) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.24; Sat, 24 Jul 2021 14:58:09 +0000 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:7e0a::42) by DB5EUR03FT012.mail.protection.outlook.com (2a01:111:e400:7e0a::161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.24 via Frontend Transport; Sat, 24 Jul 2021 14:58:09 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:050253AEBE29692807F1E1B12B8AB1A9BDF5EC317A3ACD37C785F0937E77C4D2; UpperCasedChecksum:05489C0F09C4EE034A6704282334C6FD421263FBA96A511936A6A34AC6D4C2E8; SizeAsReceived:7959; 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%7]) with mapi id 15.20.4352.029; Sat, 24 Jul 2021 14:58:09 +0000 In-Reply-To: <83im0zzzhq.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 24 Jul 2021 15:07:45 +0300") X-TMN: [i7zPuInuAy7MyZhGWc74mkjRM1h9wG8j] X-ClientProxiedBy: AM6PR10CA0056.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:80::33) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <87h7gjahdr.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (81.232.177.30) by AM6PR10CA0056.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:80::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.25 via Frontend Transport; Sat, 24 Jul 2021 14:58:09 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 7cb5f180-0e08-4849-0089-08d94eb3735b X-MS-TrafficTypeDiagnostic: DB5EUR03HT066: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fwCTsAlVAkpmxNcvfG5Ix+P1/9Ma93DXrDdQ4AbG0CA+jH1rvzGu7qn/o6AcTU+3eqrboWC9X1kaMKjM76VgAdKZ7BJMTG/CHos7mOFTNMv83QVnXvkKSw3bT500AAzjs+OZ0gMS+gbqxyFdoJopgaUYqjMU+1soApOYC8O9J/VUobdQZ+5qJEaHiqFgyo6Bm1CsJyMK+a+WNotZuYZDY45hl0g7GB5GP+9q3fR/rOJPwpNcqUWz7eKXdX9398G5RETw7kC5V4m/7KDf5FWcvc+kT/IKVf8zQ5AAEnoaLkh0dG04MBWvUylGlaClrn0MB/XBlxPLipXlq0UuTdvv0aIRnGt0HTspTWmc6h5lIfyNXXWlIvlSCnMjHsP6CauSoe8sAP4cD81tNn6EmP3sGBMaEUq4jp7BkH0G2B26W4TL3jaP1jjamUPRTTXpld9J X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fDI7EL5TMoJSscJ4Vx+1OiYLKYMBd5+vCBDWr10YUgHCIqW2exzgaN+odied8hPJ9Ci0/Bcj48kwPh7gjPr9q9FwJd9JZo8h97btI1EEzl0tPy2xy99ojr8Rn2N0yL4123XW9r7WpmmMmoIESk/u9Q== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7cb5f180-0e08-4849-0089-08d94eb3735b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2021 14:58:09.4377 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT012.eop-EUR03.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: DB5EUR03HT066 Received-SPF: pass client-ip=40.92.70.92; envelope-from=arthur.miller@live.com; helo=EUR03-AM5-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:271545 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Arthur Miller >> 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=ls-lisp.patch --- ../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 --=-=-=--