summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-09-04 10:38:06 -0500
committerCase Duckworth2021-09-04 10:38:06 -0500
commit06770985d7539afe97747ae4fff7211e6abea94e (patch)
tree2d68a7146598dea0d2c7b95c11f2dd7ed7b1513c /lisp
parentFix bug (diff)
downloademacs-06770985d7539afe97747ae4fff7211e6abea94e.tar.gz
emacs-06770985d7539afe97747ae4fff7211e6abea94e.zip
Sort init.el by package
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw.el19
1 files changed, 14 insertions, 5 deletions
diff --git a/lisp/acdw.el b/lisp/acdw.el index 8db7fea..cf8914f 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -19,7 +19,9 @@
19;; functions for me, acdw. 19;; functions for me, acdw.
20 20
21;;; Code: 21;;; Code:
22 22
23(require 'cl-lib)
24
23;;; Variables 25;;; Variables
24 26
25(defconst acdw/system 27(defconst acdw/system
@@ -242,10 +244,12 @@ With a prefix argument N, (un)comment that many sexps."
242 244
243;;; Sort sexps 245;;; Sort sexps
244;; from https://github.com/alphapapa/unpackaged.el#sort-sexps 246;; from https://github.com/alphapapa/unpackaged.el#sort-sexps
247;; and https://github.com/alphapapa/unpackaged.el/issues/20
245 248
246(defun sort-sexps (beg end) 249(defun sort-sexps (beg end &optional key)
247 "Sort sexps in region. 250 "Sort sexps in region.
248Comments stay with the code below." 251Comments stay with the code below. KEY is a function to sort by,
252e.g. (lambda (sexp) (symbol-name (car sexp)))"
249 (interactive "r") 253 (interactive "r")
250 (cl-flet ((skip-whitespace () (while (looking-at (rx (1+ (or space "\n")))) 254 (cl-flet ((skip-whitespace () (while (looking-at (rx (1+ (or space "\n"))))
251 (goto-char (match-end 0)))) 255 (goto-char (match-end 0))))
@@ -270,11 +274,16 @@ Comments stay with the code below."
270 for end = (point-marker) 274 for end = (point-marker)
271 while sexp 275 while sexp
272 ;; Collect the real string, then one used for sorting. 276 ;; Collect the real string, then one used for sorting.
273 collect (cons (buffer-substring (marker-position start) (marker-position end)) 277 collect (cons (buffer-substring (marker-position start)
278 (marker-position end))
274 (save-excursion 279 (save-excursion
275 (goto-char (marker-position start)) 280 (goto-char (marker-position start))
276 (skip-both) 281 (skip-both)
277 (buffer-substring (point) (marker-position end)))) 282 (if key
283 (funcall key sexp)
284 (buffer-substring
285 (point)
286 (marker-position end)))))
278 into sexps 287 into sexps
279 collect (cons start end) 288 collect (cons start end)
280 into markers 289 into markers