A Deep Dive On Registers

Arialdo Martini is back with a very informative post about using registers to store buffer locations and other data. He starts with positing the need to store buffer locations by name rather than storing them in a ring buffer as he discussed in his post on the mark ring and then gives two possible implementations.

Of course, that’s not necessary because Emacs already has functions to do this. I generally use registers to store other information such as window configurations and text I need to insert repeatedly into a document but storing buffer locations can be useful.

It turns out that the Emacs implementation is much more robust than you might imagine. For example, if you close a buffer that is stored in a register and is displaying a file, Emacs will update the register to a file-query that will reload the buffer if you jump to the register containing the reference.

But it gets better. Martini shows how you can make registers persist across Emacs sessions. All of this is builtin to Emacs and available simply by invoking the requisite functions.

The only thing that Martini doesn’t mention is that the register keys aren’t stored as a single character but as a symbol reference.That means that you can name a register as a symbol (in Elisp), which makes it easy to store, say, window configurations without risking having it overwritten interactively. I use this all the time to run certain functions in full screen and then restore the previous window configuration when I’m done.

The thing about registers, as Martini says, is that they’re implemented using normal Elisp data structures that are available to end users to use in any way they see fit. It’s another example of how configurable Emacs is.

This entry was posted in General and tagged . Bookmark the permalink.