Skip to content

Commit

Permalink
sort-lines-by-length function, from stackoverflow
Browse files Browse the repository at this point in the history
  • Loading branch information
markhepburn committed Jul 11, 2016
1 parent a2563bc commit 432d753
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lisp/custom-functions.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ previous."
(next-line direction))))
(global-set-key (kbd "C-x M-;") 'mh/exchange-commenting-with-other-line)

;;; http://stackoverflow.com/a/30697761
(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)))))))))

;;; https://gist.github.com/tonini/31e349195f1a6d6d11e5
(defun mh/delete-process-at-point ()
(interactive)
Expand Down

0 comments on commit 432d753

Please sign in to comment.