From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: Human-readable file sorting Date: Sat, 20 Feb 2016 17:00:01 +1100 Message-ID: <87r3g7exb2.fsf@gnus.org> References: <87povs41xg.fsf@gnus.org> <87bn7c3yms.fsf@gnus.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1455948052 9847 80.91.229.3 (20 Feb 2016 06:00:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Feb 2016 06:00:52 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 20 07:00:43 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 1aX0aw-00032b-JH for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 07:00:42 +0100 Original-Received: from localhost ([::1]:58401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0aw-0005uv-14 for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 01:00:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0aq-0005uQ-HI for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:00:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aX0an-0003XW-A7 for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:00:36 -0500 Original-Received: from hermes.netfonds.no ([80.91.224.195]:41287) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0am-0003Wi-UM for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:00:33 -0500 Original-Received: from cpe-60-225-211-161.nsw.bigpond.net.au ([60.225.211.161] helo=mouse) by hermes.netfonds.no with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aX0aL-0007Po-PT for emacs-devel@gnu.org; Sat, 20 Feb 2016 07:00:06 +0100 In-Reply-To: (John Wiegley's message of "Fri, 19 Feb 2016 18:33:26 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) X-MailScanner-ID: 1aX0aL-0007Po-PT MailScanner-NULL-Check: 1456552807.34572@6fqQgC9Grb6Y6lDA7hs1fQ X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.224.195 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:200271 Archived-At: John Wiegley writes: > If directory-files were made extensible, so a sorting method could be > provided... that sounds like a nice extension to me. So, having a > customization variable defaulting to `string-lessp', with an option to switch > to `string-human-lessp'. It currently calls `string-lessp' unconditionally, as do all the other functions that operate on files. This is a very typical example: (defun image-mode--images-in-directory (file) (let* ((dir (file-name-directory buffer-file-name)) (files (directory-files dir nil (image-file-name-regexp) t))) ;; Add the current file to the list of images if necessary, in ;; case it does not match `image-file-name-regexp'. (unless (member file files) (push file files)) (sort files 'string-lessp))) 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), which would basically look like: (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!) Then it's "only a matter" of changing these functions to call `file-string-lessp', and that would include `directory-files'. (Perhaps it should be in the C layer for speed? Does it matter when sorting files names? That's probably not the bottleneck...) > Whether the default should human-lessp is another matter, and something I'd > instinctively want to defer until feedback. Sure. > But having the extensibility does sound nice. If the proposed method sounds fine, I can start implementing... -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no