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: Wed, 14 Oct 2020 16:49:02 +0200 Message-ID: References: <83y2ka18t7.fsf@gnu.org> <87y2kaj799.fsf@gmx.de> <83blh60wgr.fsf@gnu.org> <87h7qxjh7g.fsf@gmx.de> 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="25014"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Eli Zaretskii , emacs-devel@gnu.org To: Michael Albinus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Oct 14 17:08:47 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 1kSiOT-0006Pr-EW for ged-emacs-devel@m.gmane-mx.org; Wed, 14 Oct 2020 17:08:45 +0200 Original-Received: from localhost ([::1]:35474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kSiOS-0004Xb-DG for ged-emacs-devel@m.gmane-mx.org; Wed, 14 Oct 2020 11:08:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kSi5X-0001CF-I9 for emacs-devel@gnu.org; Wed, 14 Oct 2020 10:49:11 -0400 Original-Received: from mail-vi1eur06olkn2051.outbound.protection.outlook.com ([40.92.17.51]:3168 helo=EUR06-VI1-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 1kSi5T-00083i-F4; Wed, 14 Oct 2020 10:49:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iXt/OzgyqWzFcRAFv5qNpdkAqtbdI7iqreXX/b3i4jbCP6wePxbR/Cz1SON5Hdh8iFbDc/0lINzqtJZ3oIaD6am6TCnaOmSnUGqg15mBOlaH+HphsUwBBlT/kv6tgNml1H80YqgwzISz5yeNz6vttptnDrabdKsWdH/4B+OWjJ7vwo2bKyx3GYxqF/hz6QScjbQA+hiauDclckG+cjWITz7iFihSMMU4O9XYIsvlPczQL8rWw27hSwS4/XqkyErToxpW5OI1g2d537OL5AuQ66mezoa2f+WtDqRBdQ/Dr/g/3Lt718bvuontzpenRbUnEYq2s1r/cqpyy4WbY9U+RQ== 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=DvqYLHutBgYPuPzigZ3Z6kvg0ZiYbE1KMDcsmVwjuUM=; b=KuvvIOJR3qgwZxEH/ZzBGHkwwKhq7j2tk3L7d7NJYWohjLXb38HR2lvK/rUYEKAVNonTho+Hp+/33Wo30ZfBiRfE/UXMapD9GpYlecxLvrYrVNjqeODY+tbwtZeoQ2MACaan0iLceTcvqh7aVKVOjKIM1bqflTIYydKcjkJhvuPpEcHTeeniAL3X63+4M3vw75zDJNQ3coe6J46XiaZ7j5clm9egD+5qKMbdFt9EZD6KyP33IS2pZnBQtL4vMN/Ov4Il1FGL5FyyA/jw85YPTxrUalPE3Pn6GQdyGZCMzE+NybTJvPLBZyk2505aOv0CCI0ps6lJLQzf5NDkUNOHkg== 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=DvqYLHutBgYPuPzigZ3Z6kvg0ZiYbE1KMDcsmVwjuUM=; b=SUJWfI7fDqIKGfIXLxu8C2wHPKUdUTsus0O9AIFOfOYfcI3PZUgExph0pTr3KKkjGTLkSpDIbPJm6UeXz0Rsc36bMtRRqSCEQsFdhx+sMqfnTiuP6ga5tVLsBwvZdoWcsX7QPwgPImF2dMmsYHglqsDCNc17M5XijkLefvXUl+xNkLA/E61CtItYMBOFTgzxJwL4zBqQrOqvrcsi/xmqKA+KATYl2YaAcFe8O4PxIAZ+Q4Nj1LmCcE2+fB7QolV2im+76QKO8n2AeiAF00/0dLjHNo2hyBTSjGr39e+dIEqwpYprBa6FyfKG7TS12ySP7B68j6xnnQv3GEd00t/f9Q== Original-Received: from AM7EUR06FT058.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::47) by AM7EUR06HT013.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21; Wed, 14 Oct 2020 14:49:04 +0000 Original-Received: from VI1PR06MB4526.eurprd06.prod.outlook.com (2a01:111:e400:fc36::4c) by AM7EUR06FT058.mail.protection.outlook.com (2a01:111:e400:fc36::161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Wed, 14 Oct 2020 14:49:04 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:BF7955A50C1C003A4C417AA244403B116B6DD5270C663575F771599BFABCAF7C; UpperCasedChecksum:CBB013A5AFEE1FBB0394E14E83A22DF42064862FA616970DF3E0E1542CB3D27D; SizeAsReceived:7821; Count:46 Original-Received: from VI1PR06MB4526.eurprd06.prod.outlook.com ([fe80::b547:51cd:16c5:4487]) by VI1PR06MB4526.eurprd06.prod.outlook.com ([fe80::b547:51cd:16c5:4487%7]) with mapi id 15.20.3455.031; Wed, 14 Oct 2020 14:49:04 +0000 In-Reply-To: (Arthur Miller's message of "Wed, 14 Oct 2020 15:56:36 +0200") X-TMN: [t04ilzWcq/q+87beGZMM2ZmNAn4Zg1b3] X-ClientProxiedBy: AM6PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::42) To VI1PR06MB4526.eurprd06.prod.outlook.com (2603:10a6:803:ac::17) X-Microsoft-Original-Message-ID: <87imbcyiap.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (90.230.29.56) by AM6PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.21 via Frontend Transport; Wed, 14 Oct 2020 14:49:03 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 888e80a9-245c-4d64-0d80-08d870504b57 X-MS-TrafficTypeDiagnostic: AM7EUR06HT013: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BBeLsm3u6rPsbdaXNmfwfiCFtciU8ff3aV85XvlDjoEWgz2gZzykVdsN/foX11hZ2gM3oCgshvySjSAcze74NRKG7z0v+Vr0WdoFkNfxA0xMPeFDZGhXC0dWa4hoV8kWFV3iHjiYCQZoi0PHwuq1sQStjjFvuSYoTyEWt9jJ5A4VUvk5wBDR0K+Kg0ah2skLPvqb/DMBMWoi1ptYvuXeLA== X-MS-Exchange-AntiSpam-MessageData: gY9CqHRXDrNL5gQM+pvwV3H9HYLlbraGN9gHMtB9rmroh5OxfK1N6bF72oDuTCk6HN0EKzY06PxM9CLywTFrlVoIAHQ/6lc8BV3quI9fs1QiEi0k1QgkBfetE+ypvG63Xof9ZJe8ELWsPmSuGxxi0w== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: 888e80a9-245c-4d64-0d80-08d870504b57 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2020 14:49:04.0274 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT058.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: AM7EUR06HT013 Received-SPF: pass client-ip=40.92.17.51; envelope-from=arthur.miller@live.com; helo=EUR06-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/14 10:49:04 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:257644 Archived-At: --=-=-= Content-Type: text/plain Arthur Miller writes: > Michael Albinus writes: > >> Arthur Miller writes: >> >> Hi Arthur, >> >>> The only thing I am not sure about is how to deal with 0 count; I >>> mean if user explicitly ask for 0 count; the case when count is not >>> NILP. >> >>>I have chosen not to deal with it all, I check for zer set >>> explicit limit for count to be [1,COUNT]. I am not sure if that is best >>> thing to do; maybe just to return Qnil? I am probably doing something >>> else wrong, advice apprecaiated. >> >> Returning Qnil seems to be OK, when count is 0. >> >> Best regards, Michael. > What about return the length, number of the files in that case? > > In order to get number of the files currently we would get list of files > and get length of the list afterwards; if we asked to get 0 files, it > could return the length; I thought of it afterwards. Ok; just a very-very fast hack; I am in very rush today, so this was my coffee pause :-) I have tested with those previous tests, seems to work, but I don't have time to test on windows. I am also not sure if I can circut that early, please see just as an idea. If cunt 0 is asked, then directory-files will return number of files in directory. If also "match" is provided it *should* give only number of files that match the given regex and sort will have no effect (no sorting). I don't have time to test with match or to write docs; but can do probably tomorrow or on friday. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=dired.c.patch Content-Description: dired.c.patch --- /home/arthur/dired.c 2020-10-13 13:06:07.517648492 +0200 +++ src/dired.c 2020-10-14 16:18:03.750214680 +0200 @@ -20,6 +20,7 @@ #include +#include #include #ifdef HAVE_PWD_H @@ -165,7 +166,7 @@ Lisp_Object directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object match, Lisp_Object nosort, bool attrs, - Lisp_Object id_format) + Lisp_Object id_format, Lisp_Object count_to_return) { if (!NILP (match)) CHECK_STRING (match); @@ -224,6 +225,18 @@ case_table = BVAR (&buffer_defaults, case_canon_table); #endif + bool only_length = false; + ptrdiff_t ind = 0, last = 0; + if(!NILP(count_to_return) && FIXNATP(count_to_return)) + { + last = XFIXNAT(count_to_return); + + if(!last){ + last = 1; + only_length = true; + } + } + /* Read directory entries and accumulate them into LIST. */ Lisp_Object list = Qnil; for (struct dirent *dp; (dp = read_dirent (d, directory)); ) @@ -267,7 +280,22 @@ else finalname = name; - list = Fcons (attrs ? Fcons (finalname, fileattrs) : finalname, list); + if (only_length) + { + ind++; + } + else + { + if (!NILP(count_to_return) && FIXNATP(count_to_return)) + { + if (ind == last) + break; + ind ++; + } + + list = Fcons (attrs ? Fcons (finalname, fileattrs) : + finalname, list); + } } closedir (d); @@ -279,16 +307,19 @@ /* Discard the unwind protect. */ specpdl_ptr = specpdl + count; + if (only_length) + return make_fixnum(ind); + if (NILP (nosort)) list = Fsort (Fnreverse (list), attrs ? Qfile_attributes_lessp : Qstring_lessp); - + (void) directory_volatile; return list; } -DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 4, 0, +DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 5, 0, doc: /* Return a list of names of files in DIRECTORY. There are three optional arguments: If FULL is non-nil, return absolute file names. Otherwise return names @@ -296,9 +327,14 @@ If MATCH is non-nil, mention only file names that match the regexp MATCH. If NOSORT is non-nil, the list is not sorted--its order is unpredictable. Otherwise, the list returned is sorted with `string-lessp'. - NOSORT is useful if you plan to sort the result yourself. */) + NOSORT is useful if you plan to sort the result yourself. +If COUNT is non-nil, the function will return max (COUNT,length) + files, where length means number of files in directory. Order + in which files are returned is not guaranteed and is file system and + OS dependent. COUNT has to be an integral number in interval + [1,COUNT]. */) (Lisp_Object directory, Lisp_Object full, Lisp_Object match, - Lisp_Object nosort) + Lisp_Object nosort, Lisp_Object count) { directory = Fexpand_file_name (directory, Qnil); @@ -306,14 +342,15 @@ call the corresponding file name handler. */ Lisp_Object handler = Ffind_file_name_handler (directory, Qdirectory_files); if (!NILP (handler)) - return call5 (handler, Qdirectory_files, directory, - full, match, nosort); + return call6 (handler, Qdirectory_files, directory, + full, match, nosort, count); - return directory_files_internal (directory, full, match, nosort, false, Qnil); + return directory_files_internal (directory, full, match, nosort, + false, Qnil, count); } DEFUN ("directory-files-and-attributes", Fdirectory_files_and_attributes, - Sdirectory_files_and_attributes, 1, 5, 0, + Sdirectory_files_and_attributes, 1, 6, 0, doc: /* Return a list of names of files and their attributes in DIRECTORY. Value is a list of the form: @@ -331,9 +368,14 @@ ID-FORMAT specifies the preferred format of attributes uid and gid, see `file-attributes' for further documentation. On MS-Windows, performance depends on `w32-get-true-file-attributes', -which see. */) - (Lisp_Object directory, Lisp_Object full, Lisp_Object match, - Lisp_Object nosort, Lisp_Object id_format) +which see. +If COUNT is non-nil, the function will return max (COUNT,length) + files, where length means number of files in directory. Order + in which files are returned is not guaranteed and is file system and + OS dependent. COUNT has to be an integral number in interval + [1,COUNT]. */) +(Lisp_Object directory, Lisp_Object full, Lisp_Object match, + Lisp_Object nosort, Lisp_Object id_format, Lisp_Object count) { directory = Fexpand_file_name (directory, Qnil); @@ -342,11 +384,11 @@ Lisp_Object handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes); if (!NILP (handler)) - return call6 (handler, Qdirectory_files_and_attributes, - directory, full, match, nosort, id_format); + return call7 (handler, Qdirectory_files_and_attributes, + directory, full, match, nosort, id_format, count); return directory_files_internal (directory, full, match, nosort, - true, id_format); + true, id_format, count); } @@ -929,7 +971,7 @@ struct stat s; /* An array to hold the mode string generated by filemodestring, - including its terminating space and null byte. */ + including its terminating space and NUL byte. */ char modes[sizeof "-rwxr-xr-x "]; char *uname = NULL, *gname = NULL; --=-=-=--