GNU bug report logs - #45361
28.0.50; tabulated-list-mode: should be sorting by specified sort function

Previous Next

Package: emacs;

Reported by: Jean Louis <bugs <at> gnu.support>

Date: Tue, 22 Dec 2020 07:15:02 UTC

Severity: normal

Tags: notabug

Found in version 28.0.50

Done: Jean Louis <bugs <at> gnu.support>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jean Louis <bugs <at> gnu.support>
To: Stephen Berman <stephen.berman <at> gmx.net>
Cc: 45361-done <at> debbugs.gnu.org, 45361 <at> debbugs.gnu.org
Subject: bug#45361: 28.0.50; tabulated-list-mode: should be sorting by specified sort function
Date: Tue, 22 Dec 2020 12:43:55 +0300
* Stephen Berman <stephen.berman <at> gmx.net> [2020-12-22 12:32]:
> On Tue, 22 Dec 2020 08:13:50 +0100 Jean Louis <bugs <at> gnu.support> wrote:
> 
> > PROBLEM:
> >
> > The variable `tabulated-list-format' provides for programmer
> > option to sort columns and I would like to sort number as
> > strings "12" as numbers, not as strings. I do not know how to
> > properly provide the sorting function to `tabulated-list-format' so
> > that it works when actually sorting.
> [...]
> > Then I would like to use the function `string-collate-lessp' as that
> > seem to understand how numbers should be compared.
> >
> > For example this is giving me correct result:
> >
> > (sort '("121" "117" "1") 'string-collate-lessp) => ("1" "117" "121")
> 
> But:
> 
> (sort '("21" "117" "1") 'string-collate-lessp) => ("1" "117" "21")
> 
> So string-collate-lessp doesn't do what it seems you want.

Oh, I missed to see that. That is the problem.

> Actually, tabulated-list-print does call my-sort via
> tabulated-list--get-sorter.  Anyway, buffer-menu.el has the function
> `tabulated-list-entry-size->', which with a small adjustment does what
> you seem to want.  Try this:
> 
> (defun my-tabulated-list-entry-size-> (entry1 entry2)
>   (> (string-to-number (aref (cadr entry1) 0))
>      (string-to-number (aref (cadr entry2) 0))))

That is what I missed to see, thank you for references and your
help. Now it works well. 

Jean

P.S. Closing it as it is not a bug.







This bug report was last modified 4 years and 150 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.