From 7c4fea3b60cd9ba05459049e777c3b6658f0ff56 Mon Sep 17 00:00:00 2001 From: kj Date: Fri, 29 Aug 2025 18:09:21 -0300 Subject: [PATCH] Add function to sort lines by length. --- configs/init-functions.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/configs/init-functions.el b/configs/init-functions.el index ce398f0..eccee26 100644 --- a/configs/init-functions.el +++ b/configs/init-functions.el @@ -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.