From 0920c1b361e50d99c943d30255fed95f7bc0da23 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 17 Oct 2022 23:28:38 -0500 Subject: meh --- lisp/yoke.el | 66 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 16 deletions(-) (limited to 'lisp/yoke.el') diff --git a/lisp/yoke.el b/lisp/yoke.el index 2673e5e..4f40869 100644 --- a/lisp/yoke.el +++ b/lisp/yoke.el @@ -32,7 +32,7 @@ directory created." (message "Downloading %S... done" repo)) dir)) -(defun yoke-lasso (pkg repo) +(defun yoke-lasso (pkg repo &optional load-path) "Add PKG to `load-path' so it can be used. If PKG is not installed, install it from REPO. Packages will be installed to `yoke-dir'." @@ -40,7 +40,8 @@ installed to `yoke-dir'." (yoke-git repo dir) (cond ((file-exists-p dir) - (add-to-list 'load-path dir) + (when (or load-path dir) + (add-to-list 'load-path (expand-file-name (or load-path dir)))) ;; This bit is stolen from `straight'. (eval-and-compile (require 'autoload)) (let ((generated-autoload-file @@ -91,6 +92,31 @@ Similar-ish to `plist-get', but works on non-proper plists." (setq list (cdr list))) (reverse r))) +(defun eval-after-init (fn) + "Evaluate FN after inititation, or now if Emacs is initialized. +FN is called with no arguments." + (if after-init-time + (funcall fn) + (add-hook 'after-init-hook fn))) + +(defmacro eval-after (features &rest body) + "Evaluate BODY, but only after loading FEATURES. +FEATURES can be an atom or a list; as an atom it works like +`with-eval-after-load'. The special feature `init' will evaluate +BODY after Emacs is finished initializing." + (declare (indent 1) + (debug (form def-body))) + (if (eq features 'init) + `(eval-after-init (lambda () ,@body)) + (unless (listp features) + (setq features (list features))) + (if (null features) + (macroexp-progn body) + (let* ((this (car features)) + (rest (cdr features))) + `(with-eval-after-load ',this + (eval-after ,rest ,@body)))))) + (defun yoke-pkg-name (pkg) (intern (format "yoke:%s" pkg))) @@ -98,28 +124,36 @@ Similar-ish to `plist-get', but works on non-proper plists." &optional repo &body body &key - requires ; :requires ((PKG REPO)...) - dest ; :dest DESTINATION + after ; :after (FEATURE...) + depends ; :depends ((PKG REPO)...) + load ; :load DIRECTORY (when t whenp) ; :when PREDICATE (unless nil unlessp) ; :unless PREDICATE &allow-other-keys) "Yoke a PKG into your Emacs session." (declare (indent defun)) - (let ((name (yoke-pkg-name pkg))) + (let ((name (yoke-pkg-name pkg)) + (body (delete2 body + :depends :when :unless :after :load))) `(cl-block ,name (condition-case e (let ((*yoke-name* ',name) (*yoke-repo* ,repo) (*yoke-dest* ,(when repo `(yoke-repo-dir ',pkg ,repo)))) - ,@(list (cond - ((and whenp unlessp) - `(when (or (not ,when) ,unless) - (cl-return-from ,name nil))) - (whenp `(unless ,when (cl-return-from ,name nil))) - (unlessp `(when ,unless (cl-return-from ,name nil))))) - ,@(cl-loop for (pkg repo) in requires - collect `(or (yoke-lasso ',pkg ,repo) + ,@(cond + ((and whenp unlessp) + `((when (or (not ,when) ,unless) + (cl-return-from ,name nil)))) + (whenp `((unless ,when (cl-return-from ,name nil)))) + (unlessp `((when ,unless (cl-return-from ,name nil))))) + ,@(cl-loop for (pkg* repo* load-path*) in depends + collect `(or (yoke-lasso ',pkg* ,repo* ,load-path*) (cl-return-from ,name nil))) - ,@(when repo `((yoke-lasso ',pkg ,repo))) - ,@(delete2 body :requires :when :unless)) - (t (message "%s: %S" ',name e)))))) + ,@(cond + (repo `((yoke-lasso ',pkg ,repo ,load))) + (load `((add-to-list 'load-path ,load)))) + ,@(if after + `((eval-after ,after ,@body)) + body)) + (:success ',pkg) + (t (message "%s: %s" ',name e)))))) -- cgit 1.4.1-21-gabe81