From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.devel Subject: Re: Human-readable file sorting Date: Sat, 20 Feb 2016 07:12:06 +0100 Message-ID: <87twl3vrk9.fsf@mbork.pl> References: <87povs41xg.fsf@gnus.org> <87bn7c3yms.fsf@gnus.org> <87r3g7exb2.fsf@gnus.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1455948763 19114 80.91.229.3 (20 Feb 2016 06:12:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Feb 2016 06:12:43 +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 07:12:35 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 1aX0mQ-0003MS-65 for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 07:12:34 +0100 Original-Received: from localhost ([::1]:58472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0mP-0002Gf-5Z for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 01:12:33 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0m8-0002Fw-Oq for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:12:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aX0m4-0006Od-OR for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:12:16 -0500 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:38264) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX0m4-0006OZ-HP for emacs-devel@gnu.org; Sat, 20 Feb 2016 01:12:12 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id C8EA59D2005; Sat, 20 Feb 2016 07:12:11 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mrfXiPUyvLMj; Sat, 20 Feb 2016 07:12:07 +0100 (CET) Original-Received: from localhost (unknown [109.232.24.28]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 333759D2004; Sat, 20 Feb 2016 07:12:07 +0100 (CET) User-agent: mu4e 0.9.13; emacs 25.1.50.2 In-reply-to: <87r3g7exb2.fsf@gnus.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2a01:5e00:2:52::8 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:200272 Archived-At: On 2016-02-20, at 07:00, Lars Ingebrigtsen wrote: > 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))) > ..) Wouldn't it be cleaner (and more flexible) to introduce a variable `file-string-lessp-function'? Then the user could also account for 1,000.23 and similar cases by themselves when needed. One could then even put a special value in .dir-locals.el for e.g. music files (which sometimes follow strange naming conventions). BTW, I like this idea. FWIW, exactly because of this issue I use trailing zeros when naming files, and do not expect file sorting to be too smart, but many people don't do this, and renaming files I get from them is a pain. Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University