;;; +setup.el -- my `setup' commands -*- lexical-binding: t -*- ;; Author: Case Duckworth ;; 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) (defun +setup-warn (message &rest args) "Warn the user that something bad happened in `setup'." (display-warning 'setup (format message args))) (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)))) (dolist (feature (nreverse features)) (setq body `(with-eval-after-load ',feature ,body))) body)) :documentation "Load the current feature after FEATURES.") (setup-define :also-straight (lambda (recipe) `(setup (:straight ,recipe))) :documentation "Install RECIPE with `straight-use-package', after loading FEATURE." :repeatable t :after-loaded t) (defun +setup-straight-shorthand (sexp) "Shorthand for `:straight' and other local macros." (let ((recipe (cadr sexp))) (or (car-safe recipe) recipe))) (setup-define :straight (lambda (recipe) `(unless (ignore-errors (straight-use-package ',recipe) t) (+setup-warn ":straight error: %S" ',recipe) ,(setup-quit))) :documentation "Install RECIPE with `straight-use-package'. This macro can be used as HEAD, and will replace itself with the first RECIPE's package." :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. This macro can be used as HEAD, and will replace itself with the first RECIPE's package." :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. 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." :repeatable 2 :indent 1 :shorthand #'+setup-straight-shorthand) (provide '+setup) ;;; +setup.el ends here