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: empty-directory predicate, native implementation Date: Sat, 17 Oct 2020 22:27:28 +0200 Message-ID: References: <83y2ka18t7.fsf@gnu.org> <87y2kaj799.fsf@gmx.de> <83blh60wgr.fsf@gnu.org> <87h7qxjh7g.fsf@gmx.de> <878sc8kgy8.fsf@gmx.de> <87imbcls71.fsf@gmx.de> <83eem0zt0b.fsf@gnu.org> <87k0vsrd6m.fsf@gmx.de> <83a6wozs7h.fsf@gnu.org> <87sgafq2e2.fsf@gmx.de> <87h7qvptm3.fsf@gmx.de> <871rhxp8we.fsf@gmx.de> <237bd21b-96c7-4433-a5bc-34b64a9f4250@default> 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="36722"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Eli Zaretskii , Michael Albinus , emacs-devel@gnu.org To: Drew Adams Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Oct 17 22:28:32 2020 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 1kTsoZ-0009RJ-RT for ged-emacs-devel@m.gmane-mx.org; Sat, 17 Oct 2020 22:28:31 +0200 Original-Received: from localhost ([::1]:39012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTsoY-0006ad-Tj for ged-emacs-devel@m.gmane-mx.org; Sat, 17 Oct 2020 16:28:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTsni-00069N-K3 for emacs-devel@gnu.org; Sat, 17 Oct 2020 16:27:38 -0400 Original-Received: from mail-am7eur06olkn2040.outbound.protection.outlook.com ([40.92.16.40]:33632 helo=EUR06-AM7-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 1kTsne-0003ZK-PH; Sat, 17 Oct 2020 16:27:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HX7BeYI5g4/m1ClWIHBnZoxATO/Q612H2c6gOAEZEk1VwJ/sZLRtPmFVGzEva6ie21ncit1B3IVU5tFK0S71XIOxp/YB3zkzMsfdlZEzbMhdGs2MHLUBy/lWeE6+VYppdksKx2oNK7U1w1eQvXnGFQrMSaUQeu24XVXEaegFG+ujr2WWt+06AB4Yq6otCGcv1LLiMObUzNj5iiw1ptu0mP2kF2HElUuhIzb6ido5yxbg0rMyl1AURQSrmqGCzaOcK2sVZfWWBuEN8P4c/+Km22HP+eIPFaIeBTeyR9J+Ud4h+5JJ6j2Y5lqifwxNofP2MPKOB9JQPomarDPc/cfnJw== 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=o3ARzTsu47AwT+e1oqMwAuJ0gSk/VH8a04Y5faiAmxg=; b=YH5ju3LQbtPHYMNILRLx76oy0fwo80sLiF8v19NJjBN/YuF96bo9CewZP37uty2AGdZfawQnxHmD5LEvXuRhZDGzLl/Q/LuhSLas+l2xPtPBKxDox7AoQMjU35zkuG665r6v+vqiZ6SabzKHbtaM6QeCvMKssRcNZmaaTyYcU3r1KqOsMpU7dW5E36Lp1sK+8NvFT067CccoSY1ChrGJPL3v0raUaY5L/Eu6hFWTlh2oRJz8xwtD+qnkoZ+bQayz1iSvBew0uQszVWXqLW0I1hc2IEtcmfd2OvkhQ0sNj8Aoy7BUAsNXbZrDmqvh5sS+dvQ+AQVTdi9o1rI2uF9aog== 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=o3ARzTsu47AwT+e1oqMwAuJ0gSk/VH8a04Y5faiAmxg=; b=X1ZFomLRK3yMGC4ZDn5/vaY+ed15TZ1hHvqIVNpuaUvoxGh0NlB9AtdHND2ZYsLZv50HswnkIXAD/bSjHUzB5cwaQEsyt+erH+I5yufcgH04jt37vVrwbw1YiCTC9R4HmS/Ya4lAc/uvRcYLfjKOr2Axkt/O4Bbi6DS5K/4lpLh1BJwM+cZp8JhHlm7CbGStG7Mo9/Wmbm0fRqETfLIjMvoSOcq2nWi6SQJyCkxuQxyb92yKf9qxr3kBX/+8Qa6JYQDlvx+2qlDNMruNWB5e/e7t5C3mMvw5y8Cpl1Ky5fEdoGyESW43octikLT/1vR73eNtd1EzGBiIZ2n2macO1Q== Original-Received: from AM7EUR06FT003.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::50) by AM7EUR06HT214.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::259) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21; Sat, 17 Oct 2020 20:27:30 +0000 Original-Received: from VI1PR06MB4526.eurprd06.prod.outlook.com (2a01:111:e400:fc36::50) by AM7EUR06FT003.mail.protection.outlook.com (2a01:111:e400:fc36::244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Sat, 17 Oct 2020 20:27:30 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:30A7DFB2FEF1360B591836042306CF0E6B0C1ED6D10F6D7878C340303C7560B7; UpperCasedChecksum:B10029E172C7CCF59894B4E825CB9E49F9F832E677139762D18F28C1A7A515F6; SizeAsReceived:8499; Count:46 Original-Received: from VI1PR06MB4526.eurprd06.prod.outlook.com ([fe80::187b:196a:cb2d:adf1]) by VI1PR06MB4526.eurprd06.prod.outlook.com ([fe80::187b:196a:cb2d:adf1%5]) with mapi id 15.20.3477.023; Sat, 17 Oct 2020 20:27:30 +0000 In-Reply-To: <237bd21b-96c7-4433-a5bc-34b64a9f4250@default> (Drew Adams's message of "Sat, 17 Oct 2020 13:03:35 -0700 (PDT)") X-TMN: [sB0Sldlfsb5pzp1ivZGOe/aAVZyA3fm2] X-ClientProxiedBy: AM5PR1001CA0033.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:2::46) To VI1PR06MB4526.eurprd06.prod.outlook.com (2603:10a6:803:ac::17) X-Microsoft-Original-Message-ID: <87zh4k61jj.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (90.230.29.56) by AM5PR1001CA0033.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:2::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Sat, 17 Oct 2020 20:27:29 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 1f62c7f4-5160-4f23-cd0b-08d872db11f0 X-MS-TrafficTypeDiagnostic: AM7EUR06HT214: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jtPQeDMOOfcl21Z61mnw74Q4NBkB1Hytp9A3EpTh1sv1UlRFtxY0VoCA9MEpS5ZpP1Y3E0p6eZE6F1AT1jNEcoUVzg93XUaLyh8Q0wdpXqtJeChBAmCnDwnmo6tFN13Hgy90uo9f4GlqRWQ1bandFOHasc4VZNq83TSYYJY89y1KhtG1GjbMFsVL38iVH2yMIwoVSZywgVLNvn0Hs2kE2Q== X-MS-Exchange-AntiSpam-MessageData: 1JGrpyA6RTf26e5/b31m/hwNToZGyfNYo9mc/LQUQ/oWNRHKWfSUdGkSAjzMUZM7hyHrNRSeDqNMx66C8dBDCp+v1nuh6F/usok6nEShHbMc8OgSCG+jsU7H0AMYgdZV9MA1peXUg4fktUNbMvLt5Q== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f62c7f4-5160-4f23-cd0b-08d872db11f0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2020 20:27:30.3589 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT003.eop-eur06.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: AM7EUR06HT214 Received-SPF: pass client-ip=40.92.16.40; envelope-from=arthur.miller@live.com; helo=EUR06-AM7-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/17 16:27:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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:257970 Archived-At: --=-=-= Content-Type: text/plain Drew Adams writes: > Sorry I'm coming to this late. It's a long thread, > and I've only checked your patch, not the messages. > > I don't understand why we would do this. Is the > real aim to be able to have an empty-directory > predicate, i.e., to be able to see if there are > no files in a directory? Yes. > If so, then why not do just that, witout > bothering (changing the signature of) > `directory-files'? Because it is not possible to that efficiently with current elisp; how would you do that directly? OS does not have such call, one have to iterate through directories. At least I am not aware of such call. If you know, please tell me, I would be happy to use it, at least for myself. Fastest I am aware of is to get a buffered list with SYS_getdents and then check for first non-dot file. That changes complexity from linear in number of files in directory to constant (3 files at max). It works only on Linux kernel, and I don't know if there is nt version of such call, or what there is on macs. I suggested such predicate, but to not re-iterate entire discussion, pls check my first mail and followed 2 or 3 I think. > Is there really some use case for getting only > the first N files in a directory? I can > understand wanting to test whether a dir is > empty. I can't see why someone would want the > first N files (however "first" might be defined). Probably not; it is just a result of having count parameter. > The doc string itself seems to suggest that the > (only?) use case is to test for emptiness: > > You can use this function to short circuit evaluation > in case you are just interested to find if a directory > is empty or not (request one file and tell it to > ignore dot-files). It does not say only, but it suggests it can be usd in that way. But yes, that was the driver behind. Check the attachment; maybe something you would like to have in Dired+? I don't know if it could become a part of Dired itself, I believe it is probably too niche and subjective. > That need is clear enough. But what else is > COUNT useful for? How about having the doc > string also tell us what we can use a COUNT > value > 1 for? That's the case that really > needs pointing out, not the empty-dir-p case. > > And what is the order that defines which file > is first, second, etc.? Without knowing that, > what use is getting the "first" N? OS. There is no hard guarantee by OS:s that you will get files in particular order. I had that sentence in docs, but it was a bit too verse. I am not very literal of me, if you can phrase it better and more concise, please go ahead, I would appreciate. Check all docs if you have time and feel for it, I always need help with the language. > If this has already been raised, discussed, > and dismissed, fine - apologies for the noise. > If not, what's the raison d'etre for adding > optional parameter COUNT? I hope you don't mind me snitching your regex for nodots. I was trying to get one fast myself, and gave up after half hour, would never thought it was so picky to get that one right. > Why not just add a predicate `directory-empty-p'? :-) Check my first mail. I implemented one with that name. Best regards /a --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=dired-mark-empty-dirs.el (require 'dired) (defvar nodots "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*") (defun dired-go-to-first () (interactive) (goto-char (point-min)) (dired-next-line 1) (skip-chars-forward " \n\t")) (defun directory-is-empty-p (directory-name) (null (directory-files directory-name nil nodots t 1))) (defun dired-mark-empty-dirs () (interactive) (when (equal major-mode 'dired-mode) (let ((curr-dir)) (save-excursion (dired-go-to-first) (while (not (eobp)) (setq curr-dir (dired-file-name-at-point)) (cond ((or (null curr-dir) (string= curr-dir ".") (string= curr-dir "..")) ;; do nothing here ) ((file-directory-p curr-dir) (when (directory-is-empty-p curr-dir) (dired-mark 1) (dired-previous-line 1)))) (dired-next-line 1)))))) --=-=-=--