[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 17:00:01 +1100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
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)))
..)
(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
- Human-readable file sorting, Lars Ingebrigtsen, 2016/02/19
- Re: Human-readable file sorting, John Wiegley, 2016/02/19
- Re: Human-readable file sorting, Lars Ingebrigtsen, 2016/02/19
- Re: Human-readable file sorting, John Wiegley, 2016/02/19
- Re: Human-readable file sorting,
Lars Ingebrigtsen <=
- Re: Human-readable file sorting, Marcin Borkowski, 2016/02/20
- Re: Human-readable file sorting, Lars Ingebrigtsen, 2016/02/20
- Re: Human-readable file sorting, Marcin Borkowski, 2016/02/20
- Re: Human-readable file sorting, Nikolaus Rath, 2016/02/22
- Re: Human-readable file sorting, Marcin Borkowski, 2016/02/22
- Re: Human-readable file sorting, Yuri Khan, 2016/02/23
- Re: Human-readable file sorting, Andreas Schwab, 2016/02/23
- Re: Human-readable file sorting, Marcin Borkowski, 2016/02/24
- Re: Human-readable file sorting, John Wiegley, 2016/02/20
- Re: Human-readable file sorting, Lars Ingebrigtsen, 2016/02/20