Names

Yesterday, I wrote about name spaces in Emacs Lisp and mentioned Artur Malabarba’s names package. In a nice example of serendipity, Malabarba has just published a post that explains what the names package is all about1.

The basic idea is that you wrap your Elisp package in a define-namespace macro and write your code as if you were in a private name space. That is, you needn’t worry about adding the package name to every symbol that might be seen externally. This is pretty much what I was describing in footnote 3: internally all symbols are specified and accessed without worrying about the package name. Externally, the package name must be prepended to access those symbols.

The nice thing about the package is that it has no impact on existing code. Everything still works as before. When you’re writing new code you can choose to use define-namespace and dispense with worrying about adding the package name to all of your variables and functions. The define-namespace macro will take care of doing that for you.

You might think this could be risky—think about how you would write that macro—but Malabarba has already used it in two packages that he’s released to ELPA. When you read his post you will see that he’s considered the edge cases.

This package is really an accomplishment. Head on over and see if you don’t agree. It may even help put the eternal fretting about Emacs name spaces to rest.

Footnotes:

1

We don’t coordinate these things. Really.

This entry was posted in Programming and tagged , . Bookmark the permalink.