diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/+setup.el | 133 |
1 files changed, 85 insertions, 48 deletions
diff --git a/lisp/+setup.el b/lisp/+setup.el index 7c658b6..975bcde 100644 --- a/lisp/+setup.el +++ b/lisp/+setup.el | |||
@@ -23,6 +23,7 @@ | |||
23 | (require 'el-patch) | 23 | (require 'el-patch) |
24 | (require 'setup) | 24 | (require 'setup) |
25 | (require 'straight) | 25 | (require 'straight) |
26 | (require 'cl-lib) | ||
26 | 27 | ||
27 | (defun +setup-warn (message &rest args) | 28 | (defun +setup-warn (message &rest args) |
28 | "Warn the user that something bad happened in `setup'." | 29 | "Warn the user that something bad happened in `setup'." |
@@ -66,57 +67,93 @@ If PATH does not exist, abort the evaluation." | |||
66 | ;;; Straight.el | 67 | ;;; Straight.el |
67 | 68 | ||
68 | (with-eval-after-load 'straight | 69 | (with-eval-after-load 'straight |
69 | (setup-define :also-straight | 70 | (defun setup--straight-handle-arg (arg var) |
70 | (lambda (recipe) `(setup (:straight ,recipe))) | 71 | (cond |
71 | :documentation | 72 | ((and (boundp var) (symbol-value var)) t) |
72 | "Install RECIPE with `straight-use-package', after loading FEATURE." | 73 | ((keywordp arg) (set var t)) |
73 | :repeatable t | 74 | ((functionp arg) (set var nil) (funcall arg)) |
74 | :after-loaded t) | 75 | ((listp arg) (set var nil) (eval arg :lexical)))) |
75 | |||
76 | (defun +setup-straight-shorthand (sexp) | ||
77 | "Shorthand for `:straight' and other local macros." | ||
78 | (let ((recipe (cadr sexp))) | ||
79 | (or (car-safe recipe) recipe))) | ||
80 | 76 | ||
81 | (setup-define :straight | 77 | (setup-define :straight |
82 | (lambda (recipe) | 78 | (lambda (recipe &rest predicates) |
83 | `(unless (ignore-errors (straight-use-package ',recipe) t) | 79 | (let* ((skp (make-symbol "straight-keyword-p")) |
84 | (+setup-warn ":straight error: %S" ',recipe) | 80 | (straight-use-p |
85 | ,(setup-quit))) | 81 | (cl-every (lambda (f) (setup--straight-handle-arg f skp)) |
86 | :documentation | 82 | predicates)) |
87 | "Install RECIPE with `straight-use-package'. | 83 | (form `(unless (and ,straight-use-p |
88 | This macro can be used as HEAD, and will replace itself with the | 84 | (condition-case e |
89 | first RECIPE's package." | 85 | (straight-use-package ',recipe) |
90 | :repeatable t | 86 | (error |
91 | :shorthand #'+setup-straight-shorthand) | 87 | (+setup-warn ":straight error: %S" |
92 | 88 | ',recipe) | |
93 | (setup-define :straight-after | 89 | ,(setup-quit)) |
94 | (lambda (recipe feature) | 90 | (:success t))) |
95 | `(with-eval-after-load ,feature | 91 | (defun setup--straight-handle-arg (arg var) |
96 | (setup (:straight ,recipe)))) | 92 | (cond |
97 | :indent 1 | 93 | ((and (boundp var) (symbol-value var)) t) |
98 | :documentation | 94 | ((keywordp arg) (set var t)) |
99 | "Install RECIPE with `straight-use-package', after FEATURE. | 95 | ((functionp arg) (set var nil) (funcall arg)) |
100 | This macro can be used as HEAD, and will replace itself with the | 96 | ((listp arg) (set var nil) (eval arg :lexical)))) |
101 | first RECIPE's package." | 97 | |
102 | :shorthand #'+setup-straight-shorthand) | 98 | (setup-define :straight |
103 | 99 | (lambda (recipe &rest predicates) | |
104 | (setup-define :straight-when | 100 | (let* ((skp (make-symbol "straight-keyword-p")) |
105 | (lambda (recipe condition) | 101 | (straight-use-p |
106 | `(if ,condition | 102 | (cl-every (lambda (f) (setup--straight-handle-arg f skp)) |
107 | (unless (ignore-errors (straight-use-package ',recipe) t) | 103 | predicates)) |
108 | (+setup-warn ":straight error: %S" ',recipe) | 104 | (form `(unless (and ,straight-use-p |
109 | ,(setup-quit)) | 105 | (condition-case e |
110 | (message "Setup: :straight-when returned nil %S" ',recipe) | 106 | (straight-use-package ',recipe) |
111 | ,(setup-quit))) | 107 | (error |
112 | :documentation | 108 | (+setup-warn ":straight error: %S" |
113 | "Install RECIPE with `straight-use-package' when CONDITION is met. | 109 | ',recipe) |
114 | If CONDITION is false, or if `straight-use-package' fails, stop | 110 | ,(setup-quit)) |
115 | evaluating the body. This macro can be used as HEAD, and will | 111 | (:success t))) |
116 | replace itself with the RECIPE's package." | 112 | ,(setup-quit)))) |
117 | :repeatable 2 | 113 | ;; Keyword arguments --- :quit is special and should short-circuit |
114 | (if (memq :quit predicates) | ||
115 | (setq form `,(setup-quit)) | ||
116 | ;; Otherwise, handle the rest of them ... | ||
117 | (when-let ((after (cadr (memq :after predicates)))) | ||
118 | (setq form `(with-eval-after-load ,(if (eq after t) | ||
119 | (setup-get 'feature) | ||
120 | after) | ||
121 | ,form)))) | ||
122 | ;; Finally ... | ||
123 | form)) | ||
124 | :documentation "Install RECIPE with `straight-use-package'. | ||
125 | If PREDICATES are given, only install RECIPE if all of them return non-nil. | ||
126 | The following keyword arguments are also recognized: | ||
127 | - :quit --- immediately stop evaluating. Good for commenting. | ||
128 | - :after FEATURE --- only install RECIPE after FEATURE is loaded. | ||
129 | If FEATURE is t, install RECIPE after the current feature." | ||
130 | :repeatable nil | ||
131 | :indent 1 | ||
132 | :shorthand (lambda (sexp) | ||
133 | (let ((recipe (cadr sexp))) | ||
134 | (or (car-safe recipe) recipe)))) ,(setup-quit)))) | ||
135 | ;; Keyword arguments --- :quit is special and should short-circuit | ||
136 | (if (memq :quit predicates) | ||
137 | (setq form `,(setup-quit)) | ||
138 | ;; Otherwise, handle the rest of them ... | ||
139 | (when-let ((after (cadr (memq :after predicates)))) | ||
140 | (setq form `(with-eval-after-load ,(if (eq after t) | ||
141 | (setup-get 'feature) | ||
142 | after) | ||
143 | ,form)))) | ||
144 | ;; Finally ... | ||
145 | form)) | ||
146 | :documentation "Install RECIPE with `straight-use-package'. | ||
147 | If PREDICATES are given, only install RECIPE if all of them return non-nil. | ||
148 | The following keyword arguments are also recognized: | ||
149 | - :quit --- immediately stop evaluating. Good for commenting. | ||
150 | - :after FEATURE --- only install RECIPE after FEATURE is loaded. | ||
151 | If FEATURE is t, install RECIPE after the current feature." | ||
152 | :repeatable nil | ||
118 | :indent 1 | 153 | :indent 1 |
119 | :shorthand #'+setup-straight-shorthand)) | 154 | :shorthand (lambda (sexp) |
155 | (let ((recipe (cadr sexp))) | ||
156 | (or (car-safe recipe) recipe))))) | ||
120 | 157 | ||
121 | 158 | ||
122 | ;;; Redefines of `setup' forms | 159 | ;;; Redefines of `setup' forms |