Endless Parentheses

Concise ramblings on Emacs productivity.

Automate a package's group and version number

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.

(define-namespace camcorder-
:package camcorder
:group emacs
:version "0.1"

;; ...

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.

(defgroup camcorder nil
  "Customization group for camcorder."
  :prefix "camcorder-"
  :group 'emacs)

(defconst camcorder-version "0.1"
  "Version of the camcorder package.")
(defun camcorder-version ()
  "Version of the camcorder package."
  (message "camcorder version: 0.1")

;; ...

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:

  1. hit M-x,
  2. type -version,
  3. 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.

Tags: package, names, emacs

Say thanks on Gratipay
comments powered by Disqus