Stop using the ensure-library macro

There are simpler ways to achieve the same thing.
This commit is contained in:
Tom Willemse 2016-10-10 13:48:00 +02:00
parent bea7b141b7
commit cfdefc4a8b

View file

@ -30,6 +30,15 @@ To start off, first I need to enable lexical binding.
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))) (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/")))
#+END_SRC #+END_SRC
Add all my vendored packages to the load path.
#+BEGIN_SRC emacs-lisp
(eval-and-compile
(mapc (lambda (d) (add-to-list 'load-path d))
(directory-files
(locate-user-emacs-file "vendor-lisp/") t "^[^.]")))
#+END_SRC
Initialize package.el so that packages can be loaded and used. This Initialize package.el so that packages can be loaded and used. This
also needs to be done at both run-time and compile-time so packages also needs to be done at both run-time and compile-time so packages
can be installed at compile-time. can be installed at compile-time.
@ -75,48 +84,17 @@ To start off, first I need to enable lexical binding.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(eval-when-compile (eval-when-compile
(silently "Refresh packages" (let* ((not-installed (seq-remove 'package-installed-p
(package-refresh-contents))) package-selected-packages))
#+END_SRC (available (seq-filter (lambda (p)
(assq p package-archive-contents))
This macro is inspired by use-package, but I want to maintain some not-installed))
control of the syntax I use to configure my settings. (difference (- (length not-installed) (length available))))
(when (> difference 0)
#+BEGIN_SRC emacs-lisp (silently "Refresh packages"
(defmacro ensure-library (library &rest args) (package-refresh-contents)))
"Make sure LIBRARY is installed. (when available
(mapc (lambda (p) (package-install p t)) available))))
ARGS should be a plist which may contain one of the following options:
- :package
Specify which package should actually be installed to ensure
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))
(package-symbol (cl-gensym))
(path-symbol (cl-gensym))
(package (or (plist-get args :package) library))
(path (plist-get args :path)))
`(progn
(eval-and-compile
(let ((,path-symbol ,path))
(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)))))))
#+END_SRC #+END_SRC
* Site lisp * Site lisp
@ -258,8 +236,6 @@ To start off, first I need to enable lexical binding.
with people who don't pay attention to it, it has worked flawlessly. with people who don't pay attention to it, it has worked flawlessly.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library destroy-trailing-whitespace
:path "vendor-lisp/destroy-trailing-whitespace")
(require 'destroy-trailing-whitespace) (require 'destroy-trailing-whitespace)
(global-destroy-trailing-whitespace-mode) (global-destroy-trailing-whitespace-mode)
#+END_SRC #+END_SRC
@ -285,8 +261,6 @@ To start off, first I need to enable lexical binding.
* Theme * Theme
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library yoshi-theme
:path "vendor-lisp/yoshi-theme")
(add-to-list 'custom-theme-load-path (add-to-list 'custom-theme-load-path
(concat user-emacs-directory "vendor-lisp/yoshi-theme")) (concat user-emacs-directory "vendor-lisp/yoshi-theme"))
(load-theme 'yoshi :no-confirm) (load-theme 'yoshi :no-confirm)
@ -297,7 +271,6 @@ To start off, first I need to enable lexical binding.
I really don't need to see some of the minor modes. I really don't need to see some of the minor modes.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library diminish)
(require 'diminish) (require 'diminish)
#+END_SRC #+END_SRC
@ -307,16 +280,6 @@ To start off, first I need to enable lexical binding.
vertically. I'm surprised how much I like it. I've tried Swiper vertically. I'm surprised how much I like it. I've tried Swiper
before and I didn't like that so much. before and I didn't like that so much.
#+BEGIN_SRC emacs-lisp
(ensure-library ivy)
#+END_SRC
Also install the =flx= package to allow ivy to use fuzzy matching.
#+BEGIN_SRC emacs-lisp
(ensure-library flx)
#+END_SRC
Since I immediately use and enable Ivy, there's no need to autoload Since I immediately use and enable Ivy, there's no need to autoload
it, so require it to keep the byte-compiler quiet. it, so require it to keep the byte-compiler quiet.
@ -350,10 +313,6 @@ To start off, first I need to enable lexical binding.
Counsel is a group of functions that use Ivy to specialize on Counsel is a group of functions that use Ivy to specialize on
certain built-in commands, such as M-x. certain built-in commands, such as M-x.
#+BEGIN_SRC emacs-lisp
(ensure-library counsel)
#+END_SRC
Since I enable Counsel mode immediately, there's no point in leaving Since I enable Counsel mode immediately, there's no point in leaving
it to be autoloaded. Requiring it keeps the byte-compiler happy. it to be autoloaded. Requiring it keeps the byte-compiler happy.
@ -510,10 +469,6 @@ To start off, first I need to enable lexical binding.
first, but once you get the hang of using it, you won't want to first, but once you get the hang of using it, you won't want to
live without it. live without it.
#+BEGIN_SRC emacs-lisp
(ensure-library paredit)
#+END_SRC
Don't show that paredit is enabled, it should be obvious from the Don't show that paredit is enabled, it should be obvious from the
effects it has. This will save some precious real-estate on my mode effects it has. This will save some precious real-estate on my mode
line. line.
@ -555,15 +510,10 @@ To start off, first I need to enable lexical binding.
Flycheck lets me see (compiler) errors, warnings and info messages Flycheck lets me see (compiler) errors, warnings and info messages
while writing code. while writing code.
#+BEGIN_SRC emacs-lisp
(ensure-library flycheck)
#+END_SRC
When developing packages with Cask, some special care needs to be When developing packages with Cask, some special care needs to be
taken to ensure the checkers work correctly. taken to ensure the checkers work correctly.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library flycheck-cask)
(add-hook 'flycheck-mode-hook 'flycheck-cask-setup) (add-hook 'flycheck-mode-hook 'flycheck-cask-setup)
#+END_SRC #+END_SRC
@ -588,8 +538,6 @@ To start off, first I need to enable lexical binding.
Show the error message at point in a tooltip. Show the error message at point in a tooltip.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library flycheck-pos-tip)
(with-eval-after-load 'flycheck (with-eval-after-load 'flycheck
(require 'flycheck-pos-tip) (require 'flycheck-pos-tip)
(flycheck-pos-tip-mode)) (flycheck-pos-tip-mode))
@ -623,7 +571,6 @@ To start off, first I need to enable lexical binding.
commit. commit.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library diff-hl)
(require 'diff-hl) (require 'diff-hl)
(global-diff-hl-mode) (global-diff-hl-mode)
#+END_SRC #+END_SRC
@ -633,10 +580,6 @@ To start off, first I need to enable lexical binding.
Hydra is an interesting way of managing keybindings, I want to Hydra is an interesting way of managing keybindings, I want to
experiment. experiment.
#+BEGIN_SRC emacs-lisp
(ensure-library hydra)
#+END_SRC
Add a hydra for org. Add a hydra for org.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
@ -664,7 +607,6 @@ To start off, first I need to enable lexical binding.
Projectile is, thus far, the best project module for Emacs. Projectile is, thus far, the best project module for Emacs.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library projectile)
(require 'projectile) (require 'projectile)
#+END_SRC #+END_SRC
@ -755,11 +697,6 @@ To start off, first I need to enable lexical binding.
might release it as a package, but for now I keep it with the rest might release it as a package, but for now I keep it with the rest
of my configuration. of my configuration.
#+BEGIN_SRC emacs-lisp
(ensure-library mbsync-conf-mode
:path "vendor-lisp/mbsync-conf-mode")
#+END_SRC
Since it isn't installed by package.el, I need to specify the Since it isn't installed by package.el, I need to specify the
autoload myself. autoload myself.
@ -782,11 +719,6 @@ To start off, first I need to enable lexical binding.
release it as a package, but for now I keep it with the rest of my release it as a package, but for now I keep it with the rest of my
configuration. configuration.
#+BEGIN_SRC emacs-lisp
(ensure-library msmtprc-mode
:path "vendor-lisp/msmtprc-mode")
#+END_SRC
Since it isn't installed by package.el, I need to specify the Since it isn't installed by package.el, I need to specify the
autoload myself. autoload myself.
@ -831,10 +763,6 @@ To start off, first I need to enable lexical binding.
Web mode is a good general-purpose web template mode. It works well Web mode is a good general-purpose web template mode. It works well
with many template languages and PHP as well. with many template languages and PHP as well.
#+BEGIN_SRC emacs-lisp
(ensure-library web-mode)
#+END_SRC
Enable a specialized whitespace mode for web mode that shows tabs Enable a specialized whitespace mode for web mode that shows tabs
at the beginning of a line. at the beginning of a line.
@ -868,15 +796,9 @@ To start off, first I need to enable lexical binding.
** Clojure mode ** Clojure mode
#+BEGIN_SRC emacs-lisp
(ensure-library clojure-mode)
#+END_SRC
Install extra font-locking for clojure. Install extra font-locking for clojure.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library clojure-mode-extra-font-locking)
(with-eval-after-load 'clojure-mode (with-eval-after-load 'clojure-mode
(require 'clojure-mode-extra-font-locking)) (require 'clojure-mode-extra-font-locking))
#+END_SRC #+END_SRC
@ -909,10 +831,6 @@ To start off, first I need to enable lexical binding.
Cider is like Slime for Common Lisp. This configuration is copied Cider is like Slime for Common Lisp. This configuration is copied
from the one provided by Clojure for the Brave and True. from the one provided by Clojure for the Brave and True.
#+BEGIN_SRC emacs-lisp
(ensure-library cider)
#+END_SRC
Provides minibuffer documentation for the code you're typing into Provides minibuffer documentation for the code you're typing into
the repl. the repl.
@ -961,10 +879,6 @@ To start off, first I need to enable lexical binding.
do just about anything with Git without leaving the comfort of your do just about anything with Git without leaving the comfort of your
Emacs session. Emacs session.
#+BEGIN_SRC emacs-lisp
(ensure-library magit)
#+END_SRC
Show refined diffs in magit. This makes it much easier to see Show refined diffs in magit. This makes it much easier to see
/what/ has changed on a line. /what/ has changed on a line.
@ -1179,10 +1093,6 @@ To start off, first I need to enable lexical binding.
I switched to Circe from ERC because I couldn't make the I switched to Circe from ERC because I couldn't make the
customizations I wanted to, Circe seems much better at this. customizations I wanted to, Circe seems much better at this.
#+BEGIN_SRC emacs-lisp
(ensure-library circe)
#+END_SRC
Make sure that Emacs knows these function exist when the file is Make sure that Emacs knows these function exist when the file is
being compiled. being compiled.
@ -1233,9 +1143,6 @@ To start off, first I need to enable lexical binding.
Align all nicks. Align all nicks.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library sermon
:path "vendor-lisp/sermon")
(with-eval-after-load 'circe (with-eval-after-load 'circe
(require 'sermon) (require 'sermon)
(enable-sermon)) (enable-sermon))
@ -1264,7 +1171,6 @@ To start off, first I need to enable lexical binding.
this. this.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(ensure-library jabber)
(eval-when-compile (require 'jabber)) (eval-when-compile (require 'jabber))
#+END_SRC #+END_SRC