One month ago, I officially announcedNames, 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 names--keyword-list variable.
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.
Package name
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.
Group definition
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 defgroup.
The code above is specifying that Names should create a group for this package,
whose parent is the emacs group.
Version numbers
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,
type -version,
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 (names
"20150000") in your package. Also in the works are :require and :use, but
I'll let you know when these come out.
Automate a package's group and version number
12 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
names--keyword-list
variable.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.
Package name
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.Group definition
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'sdefgroup
.The code above is specifying that Names should create a group for this package, whose parent is the
emacs
group.Version numbers
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:
-version
,By using the
:version
keyword, which is pretty self explanatory, you get a constant and a command defined —both namedPACKAGE-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
(names "20150000")
in your package. Also in the works are:require
and:use
, but I'll let you know when these come out.Tags: package, names, emacs,
Be a 4clojure hero with Emacs »
« What's a defconst and why you should use it
Related Posts
It’s Magit! And you’re the magician! in package
validate.el: Schema validation for Emacs-Lisp in package
Beacon — Never lose your cursor again in package
Content © 2019, All rights reserved. Icons under CC3.0.