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

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

Re: Sorting on compound keys?


From: Tim Landscheidt
Subject: Re: Sorting on compound keys?
Date: Thu, 26 May 2011 22:49:04 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:

>>>> sometimes I want to sort unified diffs of CSV files (sepa-
>>>> rated by tabs (here: \t)):

>>>> | +A 1\t1\tx
>>>> | +A 1\t2\ty
>>>> | +B 2\t3\tz
>>>> | -A 1\t1\tx
>>>> | -B 2\t2\ty
>>>> | -B 2\t3\tz

>>>> by the second column, then the first column, then "+" vs.
>>>> "-". Unfortunately, it seems that sort-regexp-fields doesn't
>>>> allow more than one match field as a key. sort-fields
>>>> doesn't work either as it requires the fields to be sur-
>>>> rounded by white space (no "+" vs. "-") and doesn't allow
>>>> white space inside the fields.

>>>>     Is there any function in vanilla Emacs (23.1.1) that I
>>>> missed? I looked at pimping sort-regexp-fields, but it seems
>>>> to me that sort-subr would have to be rewritten from scratch
>>>> to achieve sorting on compound keys.

>>> last time I looked into that feature was missing indeed.
>>> However, didn't look for a need of re-write from the
>>> scratch, just to extend to existing routine - ie. introduce
>>> one or more levels of sorting.

>> I remember our discussion in de.comp.editoren :-), but as I
>> read sort-subr it is hard-coded that the sort key is one
>> literal, continuous part of the buffer as sort-lists is a
>> list of buffer positions.

> sort-subr takes functions to determine the fields to sort.

No, it accepts functions to determine the *boundaries* of
the fields that have to be part of the buffer as I have
written above.

> As for the functions as arguments, maybe have a look at
> `ar-th-sort' in thingatpt-utils-base.el

> https://code.launchpad.net/s-x-emacs-werkstatt/

How is this useful in this case?

Tim




reply via email to

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