help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Sorting buffer with string-collate-lessp


From: Emanuel Berg
Subject: Re: Sorting buffer with string-collate-lessp
Date: Wed, 27 May 2015 00:44:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Rasmus <rasmus@gmx.us> writes:

>> Anyhow, that function name ends with a "p" so it is
>> a unary function which returns a boolean, I take
>> it. So why doesn't it work to do just as you
>> suggested with `sort-subr' with that as the third
>> optional argument, namely PREDICATE?
>
> Yeah, but you get bufferf pointers.  As I hinted in my first post you can
> write a boilerplate around it,
>
>     (with-temp-buffer
>       (save-excursion (insert (mapconcat 'symbol-name '(c b a .) "\n")))
>       (sort-subr nil 'forward-line 'end-of-line nil nil
>                  (lambda (a b) (funcall
>                            (if (fboundp 'string-collate-lessp)
>                                'string-collate-lessp
>                              'string-lessp)
>                            (buffer-substring (car a) (cdr a))
>                            (buffer-substring (car b) (cdr b)))))
>       (buffer-string))
>
> But this seems like a lot of trouble just to get
> locale-aware sorting...

"Locale aware" stuff is always trouble which is why
I don't care for it but eat, sleep and dream an
assimilated Anglo-American when it comes to computing,
and with no shame or blame attached - that said,
I don't think ten lines of Elisp is "a lot of
trouble".

That code looks a bit complicated - perhaps some
things can be extracted, and in particular the
predicate?

But I don't see anything reoccurring so if it works
why not just put it in some init file and move on?

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

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