From 11f8a9e341be5779d568078813f3efa3ccb1e8e4 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 29 Sep 2021 17:18:21 -0500 Subject: Move sort-setups to acdw.el --- init.el | 36 +----------------------------------- lisp/acdw.el | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 48 deletions(-) diff --git a/init.el b/init.el index a1d0f14..f1419c1 100644 --- a/init.el +++ b/init.el @@ -85,41 +85,7 @@ (when-let ((default-directory (expand-file-name-exists-p "pkg/" user-emacs-directory))) - (normal-top-level-add-subdirs-to-load-path)) - - (defun acdw/sort-setups () - "Sort `setup' forms in the current buffer. -Actually sorts all forms, but based on the logic of `setup'. -In short, DO NOT USE THIS FUNCTION!!!" - (save-excursion - (sort-sexps - (point-min) (point-max) - ;; Key function - nil - ;; Sort function - (lambda (s1 s2) ; oh god, this is worse. - (let* ((s1 (cdr s1)) (s2 (cdr s2)) ; for the strings themselves - (require-regexp (rx bos (* nonl) ":require")) - (straight-regexp (rx bos (* nonl) ":straight")) - (s1-require (string-match require-regexp s1)) - (s2-require (string-match require-regexp s2)) - (s1-straight (string-match straight-regexp s1)) - (s2-straight (string-match straight-regexp s2))) - (cond - ;; Straight forms require some weirdness - ((and s1-straight s2-straight) - (let* ((r (rx ":straight" (? "-if") (* space) (? "("))) - (s1 (replace-regexp-in-string r "" s1)) - (s2 (replace-regexp-in-string r "" s2))) - (string< s1 s2))) - ;; requires should go first - ((and s1-require (not s2-require)) t) - ((and (not s1-require) s2-require) nil) - ;; straights should go last - ((and s1-straight (not s2-straight)) nil) - ((and (not s1-straight) s2-straight) t) - ;; else, just sort em. - (t (string< s1 s2))))))))) + (normal-top-level-add-subdirs-to-load-path))) (setup autorevert (:option global-auto-revert-non-file-buffers t diff --git a/lisp/acdw.el b/lisp/acdw.el index 4043134..6e66838 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -330,26 +330,23 @@ In short, DO NOT USE THIS FUNCTION!!!" (save-excursion (sort-sexps (point-min) (point-max) - (lambda (sexp) - (format "%S" (cadr sexp))) + ;; Key function + nil + ;; Sort function (lambda (s1 s2) ; oh god, this is worse. (let* ((s1 (cdr s1)) (s2 (cdr s2)) ; for the strings themselves - (s1-require (string-match ":require" s1)) - (s2-require (string-match ":require" s2)) - (s1-straight (string-match ":straight" s1)) - (s2-straight (string-match ":straight" s2)) - (s1-bare (not (or s1-require s1-straight))) - (s2-bare (not (or s2-require s2-straight)))) + (require-regexp (rx bos (* nonl) ":require")) + (straight-regexp (rx bos (* nonl) ":straight")) + (s1-require (string-match require-regexp s1)) + (s2-require (string-match require-regexp s2)) + (s1-straight (string-match straight-regexp s1)) + (s2-straight (string-match straight-regexp s2))) (cond - ;; if both are the same, sort regular style - ((or (and s1-require s2-require) - (and s1-bare s2-bare)) - (string< s1 s2)) + ;; Straight forms require some weirdness ((and s1-straight s2-straight) (let* ((r (rx ":straight" (? "-if") (* space) (? "("))) (s1 (replace-regexp-in-string r "" s1)) (s2 (replace-regexp-in-string r "" s2))) - (message "'%S' '%S'" s1 s2) (string< s1 s2))) ;; requires should go first ((and s1-require (not s2-require)) t) -- cgit 1.4.1-21-gabe81