Automate a package's group and version number12 Jan 2015, by Artur Malabarba.
One month ago, I officially announced Names, a package that writes your elisp
namespaces for you. Today, I go into other ways in which Names can help. Think of
these as delicious Easter eggs hidden inside the shabby wood cabin that is the
define-namespace macro (which is built on top of an underground Machiavellic
engine of infinite cogs and spikes, but that's beyond the point).
Names is about turning your code into an actual cohesive package, as opposed to
a collection of functions with a common goal. Since it knows everything about
your namespace, it can use that information to simplify your code. These
features are all implemented as keywords you can pass to the macro, and are
documented inside the
As a practical example, take this simple snippet from camcorder.el.
The first two lines should be no surprise to you if you've read my introduction to Names, but next three might. Those three tiny keywords are expressive and easy to read, and save you a lot of code. The macro above expands to the following.
This just defines the name of the package, which is also the name of the group.
If you don't provide it, Names will calculate it by taking the namespace (here,
camcorder-) and removing the last character.
Most packages have a customization group. Names can define the group for you,
all you need to do is give it the
:group keyword and tell it which group is
the parent of your package's
The code above is specifying that Names should create a group for this package,
whose parent is the
It is considered good practice by many for a package to define its version number as both a constant and an interactive command. If you don't believe me, see for yourself:
- hit M-x,
- hit TAB.
By using the
:version keyword, which is pretty self explanatory, you get a
constant and a command defined —both named
PACKAGE-version— which return
the version you specify.
This concludes the most useful current keywords. The purpose of these facilitators is not to write less code, writing is easy to automate. The objective here is the same overarching goal behind Names itself, making the source code shorter to read and nicer to look at.
To make use of the described features, make sure you require
"20150000") in your package. Also in the works are
I'll let you know when these come out.