Improve ensure-package macro
- Rename to “ensure-library”, since I’m really trying to make sure a certain library is installed and calling something like the following is just silly: (ensure-package geiser-impl :package geiser) - Rename the “:from” keyword parameter to “:package” since it is ambiguous when a “:path” keyword parameter is added, which could also be considered to determine from where a library is loaded. - Add the “:path” keyword parameter, some libraries aren’t managed by package.el but by me. This parameter adds its value to the load path before attempting to check if it has been installed. - Instead of checking if the package is installed and can be located, just try requiring it. This is easier for libraries not managed by package.el, since they will technically not be installed.
This commit is contained in:
parent
289d0f4d9d
commit
85a3512b05
1 changed files with 28 additions and 12 deletions
|
@ -50,24 +50,40 @@
|
||||||
|
|
||||||
;; This macro is inspired by use-package, but I want to maintain some
|
;; This macro is inspired by use-package, but I want to maintain some
|
||||||
;; control of the syntax I use to configure my settings.
|
;; control of the syntax I use to configure my settings.
|
||||||
(defmacro ensure-package (package &rest args)
|
(defmacro ensure-library (library &rest args)
|
||||||
"Make sure PACKAGE is installed.
|
"Make sure LIBRARY is installed.
|
||||||
|
|
||||||
ARGS should be a plist which may contain one of the following options:
|
ARGS should be a plist which may contain one of the following options:
|
||||||
|
|
||||||
- :from
|
- :package
|
||||||
|
|
||||||
Specify which package should actually be installed to ensure
|
Specify which package should actually be installed to ensure
|
||||||
the library named in PACKAGE exists."
|
the library named in LIBRARY exists.
|
||||||
|
|
||||||
|
- :path
|
||||||
|
|
||||||
|
Specify a path to add to the load path to be able to load this
|
||||||
|
package."
|
||||||
|
(declare (indent 1))
|
||||||
(let ((library-symbol (cl-gensym))
|
(let ((library-symbol (cl-gensym))
|
||||||
(package-symbol (cl-gensym)))
|
(package-symbol (cl-gensym))
|
||||||
`(eval-when-compile
|
(path-symbol (cl-gensym))
|
||||||
(let ((,library-symbol ',package)
|
(package (or (plist-get args :package) library))
|
||||||
(,package-symbol ',(or (plist-get args :from) package)))
|
(path (plist-get args :path)))
|
||||||
(unless (and (package-installed-p ,package-symbol)
|
`(progn
|
||||||
(locate-library (symbol-name ,library-symbol)))
|
(eval-and-compile
|
||||||
(package-install ,package-symbol))
|
(let ((,path-symbol ,path))
|
||||||
(require ,library-symbol)))))
|
(if ,path-symbol
|
||||||
|
(add-to-list 'load-path
|
||||||
|
(if (file-name-absolute-p ,path-symbol)
|
||||||
|
,path-symbol
|
||||||
|
(concat user-emacs-directory ,path-symbol))))))
|
||||||
|
(eval-when-compile
|
||||||
|
(let ((,library-symbol ',library)
|
||||||
|
(,package-symbol ',package))
|
||||||
|
(unless (require ,library-symbol nil :noerror)
|
||||||
|
(package-install ,package-symbol)
|
||||||
|
(require ,library-symbol)))))))
|
||||||
|
|
||||||
;;;; Helper functions:
|
;;;; Helper functions:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue