Add function to sort lines by length.

This commit is contained in:
kj
2025-08-29 18:09:21 -03:00
parent b7168fd349
commit 7c4fea3b60

View File

@ -137,5 +137,19 @@ If PROJECT is not specified, assume current project root."
(interactive)
(insert (file-name-nondirectory (buffer-file-name))))
(defun sort-lines-by-length (reverse beg end)
"Sort lines by length."
(interactive "P\nr")
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
(let ;; To make `end-of-line' and etc. to ignore fields.
((inhibit-field-text-motion t))
(sort-subr reverse 'forward-line 'end-of-line nil nil
(lambda (l1 l2)
(apply #'< (mapcar (lambda (range) (- (cdr range) (car range)))
(list l1 l2)))))))))
(provide 'init-functions)
;;; init-functions.el ends here.