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

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

Re: [SOLVED] Re: Need help with sort function for tabulated-list-format


From: Jean Louis
Subject: Re: [SOLVED] Re: Need help with sort function for tabulated-list-format
Date: Sat, 27 Aug 2022 06:39:46 +0300
User-agent: Mutt/+ () (2022-06-11)

* Emanuel Berg <incal@dataswamp.org> [2022-08-27 06:31]:
> Jean Louis wrote:
> 
> > I guess I solved it by looking into the package package
> 
> Sort the numeric `sort-numeric-fields' fields.

That function is for sorting lines in region numerically.

While I had to find a function to sort a column within the tabulated
list mode.

Sample value of `tabulated-list-entries':

Value:
((1
  ["1" ""])
 (2
  ["2" "ACTION"])
 (3
  ["3" "COMPLETED"])
 (4
  ["4" "PENDING"])
 (5
  ["5" "UPDATE PENDING"])
 (6
  ["6" "DECISION REVERSED"]))

That means that this first column with "1", "2", that one has to be
used for sorting. By sorting it as strings, then it goes like "1" "10"

 1          
 2          ACTION
 3          COMPLETED
 4          PENDING
 5          UPDATE PENDING
 6          DECISION REVERSED

 6          DECISION REVERSED
 5          UPDATE PENDING
 4          PENDING
 3          COMPLETED
 2          ACTION
 1          

Sorting as strings:

(sort '("100" "9" "10" "1") 'string<) ⇒ ("1" "10" "100" "9")

That would be incorrect for numbers, rightß

Tabulated list mode by default sorts columns by its strings.

So I had to make a function that converts strings to numbers, so that
we get something like this:

(sort '(100 9 10 1) '<) ⇒ (1 9 10 100)

Which then makes sense.



-- 
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]