emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Human-readable file sorting


From: Marcin Borkowski
Subject: Re: Human-readable file sorting
Date: Sat, 20 Feb 2016 07:12:06 +0100
User-agent: mu4e 0.9.13; emacs 25.1.50.2

On 2016-02-20, at 07:00, Lars Ingebrigtsen <address@hidden> wrote:

> John Wiegley <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]