Creating a Spacemacs Layer from an Existing Emacs Package

Chris Rinaldi
2 min readJul 22, 2018

--

“View from the bottom of a deep well on the blue sky above” by Aron Van de Pol on Unsplash

Spacemacs is an Emacs distribution that has a lot of awesome features. To achieve this, it relies on the concept of packages and layers. According to the documentation, an Emacs package is:

A set of Emacs Lisp files that, taken together, provide some feature. Packages may be available on a package repository, such as ELPA or MELPA or on a third-party service provider (such as github) or even locally on the disk.

A layer is a Spacemacs specific concept, which is described as:

A collected unit of configuration that can be enabled (or disabled) in Spacemacs. A layer typically brings together one or more packages, as well as the glue configuration code required to make them play well with each other and Spacemacs in general.

In Spacemacs, you always want to work with layers, but not all Emacs packages are available in this way. Thankfully, it is quite easy to convert an existing package into a layer.

As a concrete example, let’s take the case of making a Spacemacs layer for org-noter.

Step 1: Install the emacs package for org-noter.

M-x package-install org-noter

This installs the code associated with the org-noter package, but it isn’t yet available in Spacemacs. To do this, we need to create a layer that wraps the package.

Step 2: Create a new Spacemacs layer.

M-x configuration-layer/create-layer

This will then give you the option of where to place the layer, but you can just use the default of .emacs.d/private/ and then enter the name of the layer (e.g., org-noter-layer).

Step 3: Configure the layer.

After entering a name for the layer, you will be dropped into packages.el. It is simple enough to write some bare-bones Lisp to configure the layer:

(setq org-noter-layer-packages '(org-noter))(defun org-noter-layer/init-org-noter ()
(use-package org-noter
:defer t))

Step 4: Add your new layer to your .spacemacs

Open up .spacemacs (SPC f e d) and in dotspacemacs/layers() add the new name of your layer and refresh (SPC f e R). Voila!

--

--