Created
October 22, 2010 10:34
-
-
Save nibrahim/640311 to your computer and use it in GitHub Desktop.
Sort lines by length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun sort-lines-by-length (b e) | |
(interactive "r") | |
(save-excursion | |
(save-restriction | |
(narrow-to-region b e) | |
(let ((items (sort | |
(split-string | |
(buffer-substring (point-min) (point-max)) "[\n]") | |
(lambda(x y) (< (length x) (length y))))) | |
) | |
(delete-region (point-min) (point-max)) | |
(save-excursion | |
(point-min) | |
(insert (apply 'concat (map 'list (lambda (x) (format "%s\n" x)) items)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment