From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.devel Subject: Re: empty-directory predicate, native implementation Date: Sun, 18 Oct 2020 13:52:26 +0200 Message-ID: <87k0vnoio5.fsf@gmx.de> 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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19482"; 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: Arthur Miller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Oct 18 13:56:27 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 1kU7IZ-0004z2-Oy for ged-emacs-devel@m.gmane-mx.org; Sun, 18 Oct 2020 13:56:27 +0200 Original-Received: from localhost ([::1]:45954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kU7IY-0005bL-L2 for ged-emacs-devel@m.gmane-mx.org; Sun, 18 Oct 2020 07:56:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kU7Er-0004gd-OV for emacs-devel@gnu.org; Sun, 18 Oct 2020 07:52:37 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:53285) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kU7Ep-0002Dd-AM; Sun, 18 Oct 2020 07:52:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1603021948; bh=0d+uv/Pmtw2J/gZVgHr83ZoQLWEde4gVRySE2mERiTk=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=CtYJ+kDaHusQ8JrMyFhJNdXZC/OXEhXSZCbqbgABKob/kJoGJjrZVw81ydUlWzq3p HsvMb7xmw6fGyoR0xkH25Na9O8qHCazfXH3qDWoyaoJLnN1iCN0RWUtnnP/lGnfOSc XDdmry3ri9tubskXy7d5a/BAkp/7idA0hYHCaFTc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([212.86.52.21]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MCKFu-1kdQtS0l5m-009QP6; Sun, 18 Oct 2020 13:52:28 +0200 In-Reply-To: (Arthur Miller's message of "Sat, 17 Oct 2020 21:03:24 +0200") X-Provags-ID: V03:K1:UeMup5O2uqcNWN3zZUALoTIY2DxTP32xf46XfSJ2nY5C7TCRgSz D5CRj4J/W5x/93cEpdvpxXa32nLFy+SxSVsfBAhaJKdHXUGOB2zobNIKuG+1ua1w4ih/wcA U9x1ZrtNayVDOlcVlltuqdRQ+DpSFvofg4ExMwNT8y1R3/TwE6C8s8LM48Gdbg4xrcvbw/X H1WgLbe+DlSYBuQTwlF5g== X-UI-Out-Filterresults: notjunk:1;V03:K0:xev5lmqayAQ=:4UTGsgUwZLvz9I4lgLI7bq 75bymw418HwUVRnpV9UbaU9BqivDPUckKuLQmGNjC7k+JVXTW3699UTe+qUkn5Ea8yGuP2kLP 59WMOAMw1W+Lu6SGU1mL8Zcsjs7qISLTC3jD5bS5n1gMYUZss/oX4jSd+UDGtPlUstdRR3veU 47mNb5UZlxtF7vLOlHsx5jwmo7dBc6dS6Dj1G+AeitrLiemWFL5bU6oXoppLGCL4WlgJQJiZX mbkvq8yzN2eG1h8d60RCLs3erVGZRgJYxQP5FZRhT3QRgVSuFL8SkD9n6JQ+fbWyqJUDZ0tNs WRgzvn9MfU4nTIQcgyfiP28K2Ms3DcEq5Iu4ouWLLY7xuV92wUoB86XkWgcP/g5N0AIr8zvmH NuuO9M/wqPpApuDB1AyuosOqdrdCz1/XyE8hqBK5j5vL3UahCKy478L35yLj+nL5RXMKVA6cJ Igpx4Dsv8wE1dl1CYhMYoZ1DxwTZfs2SHHNg9EEYWLPTs3X2/AO+iDteep4OoFzfWCA+kV+LY u2MlZruiCzwnZmj8Jqis/fl1PVkMEC9mqaBRbBiQp2ZnktrhuIG/QyG8S8IdR6oCH6k6C0g2o Chu7vdFGexSUDLaL9m3xF0UHHqbedYd1FS8h8NciGpRd8I+27F5LEkEyr6K43geHtpA44NQwa 6qAjCAlpZQECMMTX4ESC6K+qOsFBPOD3+XX8tZ/SPOZWnRFvU9frGAB4u8nDNpiF3PPzVYQTn i11mDBUXEIYYzKfDtSCUuHmboADB/XPSTsbBgDoBdbAOb6nJfUhaihueA4gMe37uRl89zPhi Received-SPF: pass client-ip=212.227.17.22; envelope-from=michael.albinus@gmx.de; helo=mout.gmx.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/18 07:52:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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:258019 Archived-At: Arthur Miller writes: Hi Arthur, > Please check that handlers stuff. I am not sure how to test it, and am > not sure I get those correct; especially tramp-crypt. See comments below. > I am using a regular expression from Dired+ by Drew in two places. I > have mention it the comment in ert tests, but don't know how to mention > it in the example in manual. Maybe remove example, or maybe it can stay > without creds? You don't need that regexp from Drew. We have the constant directory-files-no-dot-files-regexp for that purpose. > I also discovered that I wasn't covered with FIXNUM all the way; thought > it was unsigned int so -1 would be converted into ffffffff, which > would just yeild all results. Seems like fixnum is not what I thought so I > have added test for <=0 which return nil. What's wrong using FIXNATP and XFIXNAT everywhere? > Ert test are mostly foxused on new argument. I haven't found something > related to dired in test/src so I have created dired-tests.el. If it > shoudl be in some other place I can rename it. test/src/dired-tests.el is perfect. Maybe you add a comment, that just the tests for COUNT are added. > diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi > index 3b8b4fb3a9..2f15176e79 100644 > --- a/doc/lispref/files.texi > +++ b/doc/lispref/files.texi > > +If @var{count} is non-@code{nil}, the function will return first > +@var{count} number of files, or all files, whichever occurs > +first. @var{count} has to be a natural number (> 0). 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). In Emacs documentation, we use two spaces after an end-of-sentence period. Furthermore, pls say "file name" instead of "file"; this is what we return. > +@example > +@group > + (null (directory-files directory-name nil > + "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*" t 1)) Please format properly. It shall be (null (directory-files directory-name nil directory-files-no-dot-files-regexp t 1)) > diff --git a/etc/NEWS b/etc/NEWS > index 1838b6b38a..25c54d3dfe 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > +** 'diirectory-files' function can now take an additional count parameter Pls fix the spelling error. Finish the header line with a period. Use capital letters COUNT. > +This option makes directory-files return COUNT first files in It is not an option, but rather an optional parameter. Quote directory-files. Use two spaces. Use "file names". Fix "vill". > The option is useful for checking if > +directory is empty since it will check at most 3 files when COUNT = 1. As it stands it is not understandable, without mentioning the respective regexp. Better, you keep this sentence out. > diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el > index 0cb8d7cb83..335a07914c 100644 > --- a/lisp/net/ange-ftp.el > +++ b/lisp/net/ange-ftp.el > +(defun ange-ftp-directory-files (directory &optional full match nosort > + count) Could be in the same line. > @@ -3444,18 +3444,19 @@ ange-ftp-directory-files > (setq files > (cons (if full (concat directory f) f) files)))) > (nreverse files))) > - (apply 'ange-ftp-real-directory-files directory full match v19-args))) > + (apply 'ange-ftp-real-directory-files directory full match nosort count))) That is the fallback. But I don't see an implementation of COUNT. (Should be in the "while tail" loop). > (defun ange-ftp-directory-files-and-attributes > - (directory &optional full match nosort id-format) > + (directory &optional full match nosort attrs id-format count) What it attrs good for? > - (ange-ftp-directory-files directory full match nosort)) > + (ange-ftp-directory-files directory full match nosort attrs > + id_format count)) Remove attrs. Use id-format. > (ange-ftp-real-directory-files-and-attributes > - directory full match nosort id-format))) > + directory full match nosort attrs id-format count))) Remove attrs. > --- a/lisp/net/tramp-adb.el > +++ b/lisp/net/tramp-adb.el > @@ -312,7 +312,7 @@ tramp-adb-handle-directory-files-and-attributes > (copy-tree > (with-tramp-file-property > v localname (format "directory-files-and-attributes-%s-%s-%s-%s" > - full match id-format nosort) > + full match id-format nosort count) If you want to add count to the property name, you must adapt the format string. I miss the implementation of count. > diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el > index 3e96daa7b1..bda3735db4 100644 > --- a/lisp/net/tramp-crypt.el > +++ b/lisp/net/tramp-crypt.el > +;; This function does not seem to pass match and nosort into > +;; directory-files at all; is that intentional or bug? ATM: yes. Leave it as it is, we could change later on. Add FIXME in the comment. > diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el > index 3701bfc22c..787eead807 100644 > --- a/lisp/net/tramp-rclone.el > +++ b/lisp/net/tramp-rclone.el > +;; This function did not pass nosort arguemnt into directory-files > +;; not sure if intentional or bug You can remove the comment, because you did it right. > diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el > index 15eab0a4de..7a969979ac 100644 > +;; what about perl & sta -> need to fix list to count? That's correct. Mark the comment as FIXME. > diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el > index 1b6af2a2e3..62135f514d 100644 > --- a/lisp/net/tramp-smb.el > +++ b/lisp/net/tramp-smb.el > + (let ((result nil) > + (numres 0)) numres is not used. The rest I need to test later; I'm currently just dry reading. > diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el > index 6d44ad23ad..a99af70196 100644 > --- a/lisp/net/tramp.el > +++ b/lisp/net/tramp.el > +(defun tramp-handle-directory-files (directory &optional full match > + nosort count) This fits into one line (80 chars). I'm missiong an implementation for count. > diff --git a/src/dired.c b/src/dired.c > index 1584b6acf0..1fc8dd27fa 100644 > --- a/src/dired.c > +++ b/src/dired.c > @@ -17,7 +17,6 @@ > + if (FIXNUMP(return_count)) > + { > + last = XFIXNUM (return_count); > + if (last <= 0) > + return Qnil; > + } This is superfluous. Remove it. > +If COUNT is non-nil, the function will return max of COUNT and length > + files, where length is number of files in the directory. COUNT has to > + be a natural number > 0. */) So you haven't changed the docstring? > DEFUN ("directory-files-and-attributes", Fdirectory_files_and_attributes, > - Sdirectory_files_and_attributes, 1, 5, 0, > - doc: /* Return a list of names of files and their attributes in DIRECTORY. > + 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: > > - ((FILE1 . FILE1-ATTRS) (FILE2 . FILE2-ATTRS) ...) > +((FILE1 . FILE1-ATTRS) (FILE2 . FILE2-ATTRS) ...) ... Still the indentation doesn't fit with the original. > diff --git a/test/src/dired-tests.el b/test/src/dired-tests.el > new file mode 100644 > index 0000000000..3b739e59cc > --- /dev/null > +++ b/test/src/dired-tests.el > +;; Copyright (C) 2015-2020 Free Software Foundation, Inc. This shall be just 2020. > + ;; nodots expression from dired+ by Drew A. > + (nodots "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")) Not needed. Use directory-files-no-dot-files-regexp. > + (message name) That's OK for debugging purposes. Finally, the tests shall be silent. > + (make-directory name) Tests shall not kepp garbage. Please delete the directory at the end of the test, preferred as unwindorm of unwind-protect. > +(ert-deftest directory-files-and-attributes-tests () Same comments apply. > Best regards Best regards, Michael.