From 50d7ff8077f61bf1d91be9927dbd9117337a1b85 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 7 Feb 2022 13:16:04 -0600 Subject: Add :load-from --- lisp/+setup.el | 93 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 37 deletions(-) (limited to 'lisp/+setup.el') diff --git a/lisp/+setup.el b/lisp/+setup.el index d8e9bb8..c77cb36 100644 --- a/lisp/+setup.el +++ b/lisp/+setup.el @@ -42,57 +42,76 @@ body)) :documentation "Load the current feature after FEATURES.") -(setup-define :also-straight +(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 (lambda (recipe) `(setup (:straight ,recipe))) - :documentation - "Install RECIPE with `straight-use-package', after loading FEATURE." - :repeatable t - :after-loaded t) + :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))) + (defun +setup-straight-shorthand (sexp) + "Shorthand for `:straight' and other local macros." + (let ((recipe (cadr sexp))) + (or (car-safe recipe) recipe))) -(setup-define :straight + (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'. + :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. + :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. + :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) + :repeatable 2 + :indent 1 + :shorthand #'+setup-straight-shorthand)) ;;; Redefines of `setup' forms -- cgit 1.4.1-21-gabe81