Re-sort init.el
This commit is contained in:
parent
f3c9b7c3d9
commit
5380cfb762
21
lisp/acdw.el
21
lisp/acdw.el
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue