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

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

Re: Sorting lines by length


From: Michael Heerdegen
Subject: Re: Sorting lines by length
Date: Tue, 16 Sep 2014 15:56:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

"Loris Bennett" <address@hidden> writes:

> Is there a canonical way of sorting lines by length, longest first?

`sort-subr' probably.  Use it like

  (sort-subr t #'forward-line #'end-of-line nil nil
             (lambda (l1 l2)
               (apply #'< (mapcar (lambda (range) (- (cdr range) (car range)))
                                  (list l1 l2)))))

You can even modify the lambda to do something more sophisticated like
counting words.

Michael.




reply via email to

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