From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Human-readable file sorting Date: Sat, 20 Feb 2016 11:28:46 +0200 Message-ID: <83oabbpw6p.fsf@gnu.org> References: <87povs41xg.fsf@gnus.org> <87bn7c3yms.fsf@gnus.org> <87r3g7exb2.fsf@gnus.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1455960567 20470 80.91.229.3 (20 Feb 2016 09:29:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Feb 2016 09:29:27 +0000 (UTC) Cc: emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 20 10:29:26 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aX3qt-0004Vt-O3 for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 10:29:23 +0100 Original-Received: from localhost ([::1]:59496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX3qt-0005pz-2m for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 04:29:23 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX3qc-0005pd-W5 for emacs-devel@gnu.org; Sat, 20 Feb 2016 04:29:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aX3qY-0001tf-EJ for emacs-devel@gnu.org; Sat, 20 Feb 2016 04:29:06 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:57540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX3qY-0001ta-AJ; Sat, 20 Feb 2016 04:29:02 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1171 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1aX3qX-0007J7-M0; Sat, 20 Feb 2016 04:29:02 -0500 In-reply-to: <87r3g7exb2.fsf@gnus.org> (message from Lars Ingebrigtsen on Sat, 20 Feb 2016 17:00:01 +1100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:200291 Archived-At: > From: Lars Ingebrigtsen > Date: Sat, 20 Feb 2016 17:00:01 +1100 > > So I think the easiest way to get all this consistent throughout Emacs > isn't to allow `directory-files' to be customisable, but to instead > introduce a new function `file-string-lessp' (or a better name if you > have it) logical-string-lessp, alphanumeric-string-lessp, human-string-lessp. > (defun file-string-lessp (s1 s2) > (pcase file-sorting-method > (,unicode > (string-lessp s1 s2)) > (,human > (human-string-lessp s1 s2))) > ..) > > (Hey! Did I get the pcase syntax right? Bonus points!) Actually, pcase is not needed here, as you are comparing literal symbols. cond should be do the job. > (Perhaps it should be in the C layer for speed? Does it matter when > sorting files names? That's probably not the bottleneck...) Measure it before deciding. Btw, MS-Windows filesystems sort files internally in the order you want. E.g., here's what I get for a directory I set up for testing this: (directory-files "~/data/tsort") => ("." ".." "file1.png" "file10.png" "file11.png" "file2.png" "file3.png" "file31.png" "file4.png" "file5.png" "file6.png" "file8.png" "file9.png") Look, ma: no sorting required! > If the proposed method sounds fine, I can start implementing... It's certainly a good feature, thanks.