diff options
Diffstat (limited to 'lisp/+setup.el')
-rw-r--r-- | lisp/+setup.el | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/lisp/+setup.el b/lisp/+setup.el new file mode 100644 index 0000000..dce5d7b --- /dev/null +++ b/lisp/+setup.el | |||
@@ -0,0 +1,105 @@ | |||
1 | ;;; +setup.el -- my `setup' commands -*- lexical-binding: t -*- | ||
2 | |||
3 | ;; Author: Case Duckworth <acdw@acdw.net> | ||
4 | |||
5 | ;; This file is NOT part of GNU Emacs. | ||
6 | |||
7 | ;;; License: | ||
8 | ;; Everyone is permitted to do whatever with this software, without | ||
9 | ;; limitation. This software comes without any warranty whatsoever, | ||
10 | ;; but with two pieces of advice: | ||
11 | ;; - Don't hurt yourself. | ||
12 | ;; - Make good choices. | ||
13 | |||
14 | ;;; Commentary: | ||
15 | |||
16 | ;; `setup', by Philip Kaludercic, is a wonderful package that works | ||
17 | ;; sort of like `use-package', but to my mind it's cleaner and easier | ||
18 | ;; to extend. These are my additions to the local macros provided by | ||
19 | ;; the package. | ||
20 | |||
21 | ;;; Code: | ||
22 | |||
23 | (require 'el-patch) | ||
24 | (require 'setup) | ||
25 | (require 'straight) | ||
26 | |||
27 | ;; I don't like the "magic" `setup' performs to ensure a symbol is a | ||
28 | ;; function in `:global', `:bind', `:hook', `:hook-into', and others. | ||
29 | ;; So here, I'll just make it return the symbol unmodified. | ||
30 | (el-patch-feature setup) | ||
31 | (with-eval-after-load 'setup | ||
32 | (el-patch-defvar | ||
33 | (el-patch-add setup-ensure-function-inhibit nil | ||
34 | "Whether to inhibit `setup-ensure-function'.")) | ||
35 | (el-patch-defun setup-ensure-function (sexp) | ||
36 | (el-patch-concat | ||
37 | "Attempt to return SEXP as a quoted function name." | ||
38 | (el-patch-add | ||
39 | "\nIf `setup-ensure-function-inhibit' is non-nil, just return SEXP.")) | ||
40 | (el-patch-wrap 3 0 | ||
41 | (if (and setup-ensure-function-inhibit | ||
42 | (not (eq sexp (setup-get 'mode)))) | ||
43 | sexp | ||
44 | (cond ((eq (car-safe sexp) 'function) | ||
45 | sexp) | ||
46 | ((eq (car-safe sexp) 'quote) | ||
47 | `#',(cadr sexp)) | ||
48 | ((symbolp sexp) | ||
49 | `#',sexp) | ||
50 | (sexp)))))) | ||
51 | |||
52 | (setup-define :face | ||
53 | (lambda (face spec) | ||
54 | `(custom-set-faces '(,face ,spec 'now "Customized by `setup'."))) | ||
55 | :documentation "Customize FACE with SPEC using `custom-set-faces'." | ||
56 | :repeatable t) | ||
57 | |||
58 | (setup-define :load-after | ||
59 | (lambda (&rest features) | ||
60 | (let ((body `(require ',(setup-get 'feature)))) | ||
61 | (dolist (feature (nreverse features)) | ||
62 | (setq body `(with-eval-after-load ',feature ,body))) | ||
63 | body)) | ||
64 | :documentation "Load the current feature after FEATURES.") | ||
65 | |||
66 | (setup-define :also-straight | ||
67 | (lambda (recipe) `(setup (:straight ,recipe))) | ||
68 | :documentation | ||
69 | "Install RECIPE with `straight-use-package', after loading FEATURE." | ||
70 | :repeatable t | ||
71 | :after-loaded t) | ||
72 | |||
73 | (setup-define :straight | ||
74 | (lambda (recipe) | ||
75 | `(unless (straight-use-package ',recipe) | ||
76 | ,(setup-quit))) | ||
77 | :documentation | ||
78 | "Install RECIPE with `straight-use-package'. | ||
79 | This macro can be used as HEAD, and will replace itself with the | ||
80 | first RECIPE's package." | ||
81 | :repeatable t | ||
82 | :shorthand (lambda (sexp) | ||
83 | (let ((recipe (cadr sexp))) | ||
84 | (if (consp recipe) | ||
85 | (car recipe) | ||
86 | recipe)))) | ||
87 | |||
88 | (setup-define :straight-when | ||
89 | (lambda (recipe condition) | ||
90 | `(unless (and ,condition | ||
91 | (straight-use-package ',recipe)) | ||
92 | ,(setup-quit))) | ||
93 | :documentation | ||
94 | "Install RECIPE with `straight-use-package' when CONDITION is met. | ||
95 | If CONDITION is false, or if `straight-use-package' fails, stop | ||
96 | evaluating the body. This macro can be used as HEAD, and will | ||
97 | replace itself with the RECIPE's package." | ||
98 | :repeatable 2 | ||
99 | :indent 1 | ||
100 | :shorthand (lambda (sexp) | ||
101 | (let ((recipe (cadr sexp))) | ||
102 | (if (consp recipe) (car recipe) recipe)))) | ||
103 | |||
104 | (provide '+setup) | ||
105 | ;;; +setup.el ends here | ||