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

From: Jean Louis <[email-masked]>
Date: Tue, 22 Dec 2020 12:43:55 +0300

* Stephen Berman <[email-masked]> [2020-12-22 12:32]:
> On Tue, 22 Dec 2020 08:13:50 +0100 Jean Louis <[email-masked]> 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.