emacs-devel
[Top][All Lists]
Advanced

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

Re: Human-readable file sorting


From: Lars Ingebrigtsen
Subject: Re: Human-readable file sorting
Date: Sat, 20 Feb 2016 22:45:31 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

>> > Please don't call that function `file-string-lessp', or anything that
>> > has "file" in it.  This sorting order has nothing to do with files.
>> 
>> Well, this is the function that's supposed to sort file names in the
>> order requested by the user
>
> I think it's supposed to sort strings while treating numeric parts of
> them specially.  Its usage domain is wider than just file names.

No no.  This is the function that all Emacs things that want to sort
file names should use.  

The definition of that function will be just

(if some-user-setting
    (string-lessp ...)
  (logical-string-lessp ...))

>> Hm, interesting...
>> 
>> (sort '("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp)
>>   => ("11" "1 1" "1.1" "12" "1 2" "1.2")
>
> You will see that 'ls' in a UTF-8 locale does the same.

Huh, I never noticed:

address@hidden:/tmp/zot$ echo $LANG
en_US.UTF-8
address@hidden:/tmp/zot$ ls 1*
10  11  1.1  12

But:

address@hidden:/tmp/zot$ ls foo*
foo12.txt   foo1.txt  foo2.txt

Sorting is hard!

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



reply via email to

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