unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: Rasmus <rasmus@gmx.us>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Sorting buffer with string-collate-lessp
Date: Tue, 26 May 2015 19:57:01 +0200	[thread overview]
Message-ID: <87iobfql1u.fsf@gnu.org> (raw)
In-Reply-To: <87mw0rfkzy.fsf@gmx.us> (rasmus@gmx.us's message of "Tue, 26 May 2015 16:53:37 +0200")

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	other threads:[~2015-05-26 17:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-26 11:53 Sorting buffer with string-collate-lessp Rasmus
2015-05-26 14:49 ` Tassilo Horn
2015-05-26 14:53   ` Rasmus
2015-05-26 17:57     ` Tassilo Horn [this message]
2015-05-27 11:23       ` Michael Heerdegen
     [not found] <mailman.3682.1432641217.904.help-gnu-emacs@gnu.org>
2015-05-26 15:37 ` Emanuel Berg
2015-05-26 15:43   ` Rasmus
2015-05-26 15:52     ` Rasmus
     [not found]     ` <mailman.3702.1432655548.904.help-gnu-emacs@gnu.org>
2015-05-26 16:06       ` Emanuel Berg
2015-05-26 16:36         ` Rasmus
2015-05-26 16:40           ` Rasmus
2015-05-26 18:01         ` Tassilo Horn
     [not found]         ` <mailman.3706.1432658186.904.help-gnu-emacs@gnu.org>
2015-05-26 22:44           ` Emanuel Berg
2015-05-27  0:12             ` Rasmus
     [not found]             ` <mailman.3732.1432685593.904.help-gnu-emacs@gnu.org>
2015-05-27  0:25               ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87iobfql1u.fsf@gnu.org \
    --to=tsdh@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=rasmus@gmx.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).