Resetting a defvar Value

Apropos of yesterday’s post, I came across this query on Reddit and learned a new keystroke. One of the counterintuitive peculiarities of Elisp—and Lisps in general—is that a value defined by defvar or defcustom is immutable: once set it can’t be changed without restarting the process.

It turns out, though, that that’s not quite right. If you evaluate an expression such as

(defvar user "Jim")

with Ctrl+Meta+x instead of, say, Ctrl+x Ctrl+e you can change the value. I usually want to do this when I’m in the development phase an need to tweek a parameter. If you’re not an Elisp developer you won’t need to know this and even if you are, you probably won’t use it very often but it’s a really handy thing to know. And further proof that our Emacs education is never complete.

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