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

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

Need help with sort function for tabulated-list-format


From: Jean Louis
Subject: Need help with sort function for tabulated-list-format
Date: Fri, 26 Aug 2022 20:28:48 +0300

In my extensive tabulated list work, usually I use the ID number as
the first column. The ID number, while number in reality, it is
string.

That would mean that I would need to make a function that converts
strings to numbers before sorting such.

And here below there is explanation that SORT shall represent
predicate to `sort' function.

 -- Variable: tabulated-list-format
     This buffer-local variable specifies the format of the Tabulated
     List data.  Its value should be a vector.  Each element of the
     vector represents a data column, and should be a list ‘(NAME WIDTH
     SORT)’, where

        • NAME is the column’s name (a string).

        • WIDTH is the width to reserve for the column (an integer).
          This is meaningless for the last column, which runs to the end
          of each line.

        • SORT specifies how to sort entries by the column.  If ‘nil’,
          the column cannot be used for sorting.  If ‘t’, the column is
          sorted by comparing string values.  Otherwise, this should be
          a predicate function for ‘sort’ (*note Rearrangement::), which
          accepts two arguments with the same form as the elements of
          ‘tabulated-list-entries’ (see below).


Here is my tabulated-list-format:

(defvar cf-people-tabulated-format-with-account [("ID" 8 t) ("Name" 40 t) 
("Account" 40 t)])

I would like to provide the mentioned predicate here, something like:

(defvar cf-people-tabulated-format-with-account [("ID" 8 
string-as-number-is-smaller-than) ("Name" 40 t) ("Account" 40 t)])

Purpose is to sort the first column by its number represented as string.

 320193   Qg
 328635   Sgh
 334546   Tbrich
 338532   jnet
 347050   ygmail.com
 347886   Tsimmons
 360982   mail.com
 361677   D

Does anybody have sample predicate function for `sort' which accepts
two arguments as the elements of `tabulated-list-entries'?



Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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