Re-sort init.el

This commit is contained in:
Case Duckworth 2021-09-15 23:32:16 -05:00
parent f3c9b7c3d9
commit 5380cfb762
2 changed files with 915 additions and 888 deletions

1782
init.el

File diff suppressed because it is too large Load Diff

View File

@ -265,10 +265,16 @@ With a prefix argument N, (un)comment that many sexps."
;; from https://github.com/alphapapa/unpackaged.el#sort-sexps
;; and https://github.com/alphapapa/unpackaged.el/issues/20
(defun sort-sexps (beg end &optional key)
(defun sort-sexps (beg end &optional key-fn sort-fn)
"Sort sexps between BEG and END.
Comments stay with the code below. KEY is a function to sort by,
e.g. (lambda (sexp) (symbol-name (car sexp)))"
Comments stay with the code below.
Optional argument KEY-FN will determine where in each sexp to
start sorting. e.g. (lambda (sexp) (symbol-name (car sexp)))
Optional argument SORT-FN will determine how to sort two sexps'
strings. It's passed to `sort'. By default, it sorts the sexps
with `string<' starting with the key determined by KEY-FN."
(interactive "r")
(cl-flet ((skip-whitespace () (while (looking-at (rx (1+ (or space "\n"))))
(goto-char (match-end 0))))
@ -298,8 +304,8 @@ e.g. (lambda (sexp) (symbol-name (car sexp)))"
(save-excursion
(goto-char (marker-position start))
(skip-both)
(if key
(funcall key sexp)
(if key-fn
(funcall key-fn sexp)
(buffer-substring
(point)
(marker-position end)))))
@ -307,8 +313,9 @@ e.g. (lambda (sexp) (symbol-name (car sexp)))"
collect (cons start end)
into markers
finally return (list sexps markers))
(setq sexps (sort sexps (lambda (a b)
(string< (cdr a) (cdr b)))))
(setq sexps (sort sexps (if sort-fn sort-fn
(lambda (a b)
(string< (cdr a) (cdr b))))))
(cl-loop for (real . sort) in sexps
for (start . end) in markers
do (progn