2021-11-22 05:57:41 +00:00
|
|
|
|
;;; +setup.el -- my `setup' commands -*- lexical-binding: t -*-
|
|
|
|
|
|
|
|
|
|
;; Author: Case Duckworth <acdw@acdw.net>
|
|
|
|
|
|
|
|
|
|
;; This file is NOT part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;;; License:
|
|
|
|
|
;; Everyone is permitted to do whatever with this software, without
|
|
|
|
|
;; limitation. This software comes without any warranty whatsoever,
|
|
|
|
|
;; but with two pieces of advice:
|
|
|
|
|
;; - Don't hurt yourself.
|
|
|
|
|
;; - Make good choices.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; `setup', by Philip Kaludercic, is a wonderful package that works
|
|
|
|
|
;; sort of like `use-package', but to my mind it's cleaner and easier
|
|
|
|
|
;; to extend. These are my additions to the local macros provided by
|
|
|
|
|
;; the package.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'el-patch)
|
|
|
|
|
(require 'setup)
|
|
|
|
|
(require 'straight)
|
|
|
|
|
|
2022-01-06 00:41:41 +00:00
|
|
|
|
(defun +setup-warn (message &rest args)
|
|
|
|
|
"Warn the user that something bad happened in `setup'."
|
|
|
|
|
(display-warning 'setup (format message args)))
|
|
|
|
|
|
2022-02-19 00:20:38 +00:00
|
|
|
|
(setup-define :quit
|
|
|
|
|
'setup-quit
|
|
|
|
|
:documentation "Quit the current `setup' form.
|
|
|
|
|
Good for commenting.")
|
|
|
|
|
|
2021-11-22 05:57:41 +00:00
|
|
|
|
(setup-define :face
|
|
|
|
|
(lambda (face spec)
|
|
|
|
|
`(custom-set-faces '(,face ,spec 'now "Customized by `setup'.")))
|
|
|
|
|
:documentation "Customize FACE with SPEC using `custom-set-faces'."
|
|
|
|
|
:repeatable t)
|
|
|
|
|
|
|
|
|
|
(setup-define :load-after
|
|
|
|
|
(lambda (&rest features)
|
|
|
|
|
(let ((body `(require ',(setup-get 'feature))))
|
2022-01-06 00:19:47 +00:00
|
|
|
|
(dolist (feature (nreverse features))
|
|
|
|
|
(setq body `(with-eval-after-load ',feature ,body)))
|
|
|
|
|
body))
|
2021-11-22 05:57:41 +00:00
|
|
|
|
:documentation "Load the current feature after FEATURES.")
|
|
|
|
|
|
2022-02-07 19:16:04 +00:00
|
|
|
|
(setup-define :load-from
|
|
|
|
|
(lambda (path)
|
|
|
|
|
`(let ((path* (expand-file-name ,path)))
|
|
|
|
|
(if (file-exists-p path*)
|
|
|
|
|
(add-to-list 'load-path path*)
|
|
|
|
|
,(setup-quit))))
|
|
|
|
|
:documentation "Add PATH to load path.
|
|
|
|
|
This macro can be used as NAME, and it will replace itself with
|
|
|
|
|
the nondirectory part of PATH.
|
|
|
|
|
If PATH does not exist, abort the evaluation."
|
|
|
|
|
:shorthand (lambda (args)
|
|
|
|
|
(intern
|
|
|
|
|
(file-name-nondirectory
|
|
|
|
|
(directory-file-name (cadr args))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Straight.el
|
|
|
|
|
|
|
|
|
|
(with-eval-after-load 'straight
|
|
|
|
|
(setup-define :also-straight
|
2021-11-22 05:57:41 +00:00
|
|
|
|
(lambda (recipe) `(setup (:straight ,recipe)))
|
2022-02-07 19:16:04 +00:00
|
|
|
|
:documentation
|
|
|
|
|
"Install RECIPE with `straight-use-package', after loading FEATURE."
|
|
|
|
|
:repeatable t
|
|
|
|
|
:after-loaded t)
|
2021-11-22 05:57:41 +00:00
|
|
|
|
|
2022-02-07 19:16:04 +00:00
|
|
|
|
(defun +setup-straight-shorthand (sexp)
|
|
|
|
|
"Shorthand for `:straight' and other local macros."
|
|
|
|
|
(let ((recipe (cadr sexp)))
|
|
|
|
|
(or (car-safe recipe) recipe)))
|
2022-01-17 05:13:11 +00:00
|
|
|
|
|
2022-02-07 19:16:04 +00:00
|
|
|
|
(setup-define :straight
|
2021-11-22 05:57:41 +00:00
|
|
|
|
(lambda (recipe)
|
2022-01-06 00:19:47 +00:00
|
|
|
|
`(unless (ignore-errors (straight-use-package ',recipe) t)
|
2022-01-06 00:41:41 +00:00
|
|
|
|
(+setup-warn ":straight error: %S" ',recipe)
|
2022-01-06 00:19:47 +00:00
|
|
|
|
,(setup-quit)))
|
2022-02-07 19:16:04 +00:00
|
|
|
|
:documentation
|
|
|
|
|
"Install RECIPE with `straight-use-package'.
|
2021-11-22 05:57:41 +00:00
|
|
|
|
This macro can be used as HEAD, and will replace itself with the
|
|
|
|
|
first RECIPE's package."
|
2022-02-07 19:16:04 +00:00
|
|
|
|
:repeatable t
|
|
|
|
|
:shorthand #'+setup-straight-shorthand)
|
|
|
|
|
|
|
|
|
|
(setup-define :straight-after
|
|
|
|
|
(lambda (recipe feature)
|
|
|
|
|
`(with-eval-after-load ,feature
|
|
|
|
|
(setup (:straight ,recipe))))
|
|
|
|
|
:indent 1
|
|
|
|
|
:documentation
|
|
|
|
|
"Install RECIPE with `straight-use-package', after FEATURE.
|
2022-01-17 05:13:11 +00:00
|
|
|
|
This macro can be used as HEAD, and will replace itself with the
|
|
|
|
|
first RECIPE's package."
|
2022-02-07 19:16:04 +00:00
|
|
|
|
:shorthand #'+setup-straight-shorthand)
|
|
|
|
|
|
|
|
|
|
(setup-define :straight-when
|
|
|
|
|
(lambda (recipe condition)
|
|
|
|
|
`(if ,condition
|
|
|
|
|
(unless (ignore-errors (straight-use-package ',recipe) t)
|
|
|
|
|
(+setup-warn ":straight error: %S" ',recipe)
|
|
|
|
|
,(setup-quit))
|
|
|
|
|
(message "Setup: :straight-when returned nil %S" ',recipe)
|
|
|
|
|
,(setup-quit)))
|
|
|
|
|
:documentation
|
|
|
|
|
"Install RECIPE with `straight-use-package' when CONDITION is met.
|
2021-11-22 05:57:41 +00:00
|
|
|
|
If CONDITION is false, or if `straight-use-package' fails, stop
|
|
|
|
|
evaluating the body. This macro can be used as HEAD, and will
|
|
|
|
|
replace itself with the RECIPE's package."
|
2022-02-07 19:16:04 +00:00
|
|
|
|
:repeatable 2
|
|
|
|
|
:indent 1
|
|
|
|
|
:shorthand #'+setup-straight-shorthand))
|
2021-11-22 05:57:41 +00:00
|
|
|
|
|
2022-01-31 06:54:53 +00:00
|
|
|
|
|
|
|
|
|
;;; Redefines of `setup' forms
|
|
|
|
|
|
|
|
|
|
(setup-define :bind-into
|
|
|
|
|
(lambda (feature-or-map &rest rest)
|
|
|
|
|
(cl-loop for f/m in (ensure-list feature-or-map)
|
|
|
|
|
collect (if (string-match-p "-map\\'" (symbol-name f/m))
|
|
|
|
|
`(:with-map ,f/m (:bind ,@rest))
|
|
|
|
|
`(:with-feature ,f/m (:bind ,@rest)))
|
|
|
|
|
into forms
|
|
|
|
|
finally return `(progn ,@forms)))
|
|
|
|
|
:documentation "Bind into keys into the map(s) of FEATURE-OR-MAP.
|
|
|
|
|
FEATURE-OR-MAP can be a feature or map name or a list of them.
|
|
|
|
|
The arguments REST are handled as by `:bind'."
|
|
|
|
|
:debug '(sexp &rest form sexp)
|
|
|
|
|
:indent 1)
|
|
|
|
|
|
2022-02-19 00:20:45 +00:00
|
|
|
|
(setup-define :require
|
|
|
|
|
(lambda (&rest features)
|
|
|
|
|
(require 'cl-lib)
|
|
|
|
|
(if features
|
|
|
|
|
`(progn ,@(cl-loop for feature in features collect
|
|
|
|
|
`(unless (require ',feature nil t)
|
|
|
|
|
,(setup-quit))))
|
|
|
|
|
`(unless (require ',(setup-get 'feature) nil t)
|
|
|
|
|
,(setup-quit))))
|
|
|
|
|
:documentation "Try to require FEATURE, or stop evaluating body.
|
|
|
|
|
This macro can be used as NAME, and it will replace itself with
|
|
|
|
|
the first FEATURE."
|
|
|
|
|
:repeatable nil
|
|
|
|
|
:shorthand #'cadr)
|
|
|
|
|
|
2021-11-22 05:57:41 +00:00
|
|
|
|
(provide '+setup)
|
|
|
|
|
;;; +setup.el ends here
|