summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2022-05-01 09:11:41 -0500
committerCase Duckworth2022-05-01 09:11:41 -0500
commit818cfc03800831db4bf734ee089ffb3c0a5e9e3c (patch)
tree9667872006c0763e95f5f501abbb072509a77fec /lisp
parentChange org-mode pretty symbols (diff)
downloademacs-818cfc03800831db4bf734ee089ffb3c0a5e9e3c.tar.gz
emacs-818cfc03800831db4bf734ee089ffb3c0a5e9e3c.zip
Return point to the same point relative of defun in +init-sort
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+init.el85
1 files changed, 48 insertions, 37 deletions
diff --git a/lisp/+init.el b/lisp/+init.el index a4c3b5a..8f999f9 100644 --- a/lisp/+init.el +++ b/lisp/+init.el
@@ -28,44 +28,55 @@ within that group, forms with a HEAD of `:require' are sorted
28first, and `:straight' HEADs are sorted last. All other forms 28first, and `:straight' HEADs are sorted last. All other forms
29are sorted lexigraphically." 29are sorted lexigraphically."
30 (interactive) 30 (interactive)
31 (save-excursion 31 ;; I have to make my own "version" of `save-excursion', since the mark and
32 (save-restriction 32 ;; point are lost (I think that's the problem) when sorting the buffer.
33 (widen) 33 (let* ((current-point (point))
34 (+lisp-sort-sexps 34 (current-defun (beginning-of-defun))
35 (point-min) (point-max) 35 (defun-point (- current-point (point)))
36 ;; Key function 36 (current-defun-re (buffer-substring-no-properties (line-beginning-position)
37 nil 37 (line-end-position))))
38 ;; Sort function 38 (widen) ; It makes no sense to `save-restriction'
39 (lambda (s1 s2) 39 (+lisp-sort-sexps
40 (let ((s1 (cdr s1)) (s2 (cdr s2))) 40 (point-min) (point-max)
41 (cond 41 ;; Key function
42 ;; Sort everything /not/ `setup' /before/ `setup' 42 nil
43 ((and (+init--sexp-setup-p s1) 43 ;; Sort function
44 (not (+init--sexp-setup-p s2))) 44 (lambda (s1 s2)
45 nil) 45 (let ((s1 (cdr s1)) (s2 (cdr s2)))
46 ((and (+init--sexp-setup-p s2)
47 (not (+init--sexp-setup-p s1)))
48 t)
49 ;; otherwise...
50 (t (let ((s1-straight (+init--sexp-setup-p s1 :straight))
51 (s2-straight (+init--sexp-setup-p s2 :straight))
52 (s1-require (+init--sexp-setup-p s1 :require))
53 (s2-require (+init--sexp-setup-p s2 :require)))
54 (cond 46 (cond
55 ;; `:straight' setups have extra processing 47 ;; Sort everything /not/ `setup' /before/ `setup'
56 ((and s1-straight s2-straight) 48 ((and (+init--sexp-setup-p s1)
57 (let* ((r (rx (: ":straight" (? "-when") (* space) (? "(")))) 49 (not (+init--sexp-setup-p s2)))
58 (s1 (replace-regexp-in-string r "" s1)) 50 nil)
59 (s2 (replace-regexp-in-string r "" s2))) 51 ((and (+init--sexp-setup-p s2)
60 (string< s1 s2))) 52 (not (+init--sexp-setup-p s1)))
61 ;; `:require' setups go first 53 t)
62 ((and s1-require (not s2-require)) t) 54 ;; otherwise...
63 ((and s2-require (not s1-require)) nil) 55 (t (let ((s1-straight (+init--sexp-setup-p s1 :straight))
64 ;; `:straight' setups go last 56 (s2-straight (+init--sexp-setup-p s2 :straight))
65 ((and s1-straight (not s2-straight)) nil) 57 (s1-require (+init--sexp-setup-p s1 :require))
66 ((and s2-straight (not s1-straight)) t) 58 (s2-require (+init--sexp-setup-p s2 :require)))
67 ;; otherwise, sort lexigraphically 59 (cond
68 (t (string< s1 s2)))))))))))) 60 ;; `:straight' setups have extra processing
61 ((and s1-straight s2-straight)
62 (let* ((r (rx (: ":straight" (? "-when") (* space) (? "("))))
63 (s1 (replace-regexp-in-string r "" s1))
64 (s2 (replace-regexp-in-string r "" s2)))
65 (string< s1 s2)))
66 ;; `:require' setups go first
67 ((and s1-require (not s2-require)) t)
68 ((and s2-require (not s1-require)) nil)
69 ;; `:straight' setups go last
70 ((and s1-straight (not s2-straight)) nil)
71 ((and s2-straight (not s1-straight)) t)
72 ;; otherwise, sort lexigraphically
73 (t (string< s1 s2)))))))))
74 ;; Return to original point relative to the defun we were in
75 (goto-char (point-min))
76 (re-search-forward current-defun-re)
77 (beginning-of-defun)
78 (goto-char (+ (point) defun-point))
79 ))
69 80
70(defun +init-sort-then-save () 81(defun +init-sort-then-save ()
71 "Sort init.el, then save it." 82 "Sort init.el, then save it."