emacs-devel
[Top][All Lists]
Advanced

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

Re: Human-readable file sorting


From: Eli Zaretskii
Subject: Re: Human-readable file sorting
Date: Sat, 20 Feb 2016 11:28:46 +0200

> From: Lars Ingebrigtsen <address@hidden>
> 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.



reply via email to

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