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: Tassilo Horn
Subject: Re: Sorting buffer with string-collate-lessp
Date: Tue, 26 May 2015 19:57:01 +0200
User-agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux)

Rasmus <rasmus@gmx.us> writes:

>> So either my `cl-letf' usage is wrong or `sort-lines' doesn't really use
>> `string<'.  (Actually, `string<' is an alias to `string-lessp', so I
>> also tried changing that accordingly, but still no effect...)
>
> I though sort-lines used compare-buffer-substrings, but this is just based
> on the docstring.

Ah, that's the reason it had no effect. :-)

> It seems the nesting of parentheses is wrong in your example, but I
> guess it just the example.  I did not try to letf to temporarily
> rename string<.

No, indeed you have to replace `compare-buffer-substrings'.  This seems
to do the trick although my replacement lambda doesn't really satisfy
the contract of the return value of `compare-buffer-substrings' but it
seems to be good enough for usage in `sort-lines'.

--8<---------------cut here---------------start------------->8---
(cl-letf (((symbol-function 'compare-buffer-substrings)
           (lambda (b1 s1 e1 b2 s2 e2)
             (if (string-collate-lessp (buffer-substring s1 e1)
                                       (buffer-substring s2 e2))
                 -1
               1))))
  (sort-lines nil (point-min) 191))
--8<---------------cut here---------------end--------------->8---

The (point-min) and 191 when performed in *scratch* sort the initial
scratch message comment lines.

Bye,
Tassilo



reply via email to

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