lunes, 23 de abril de 2012

elisp of the day: undefine a defun

Elisp is a pretty archaic lisp. I'm not refering to the problems everyone talk about (dynamic scope, One namespace to rule them all,...) but the aspect of being very rudimentary in its construction.

That's why there have been several attempts to substitute elisp for something else (let's rewrite emacs in erlang!). For me, it's doing pretty well, and now that we have lexical scope there, I think I can live with prefixed-and-very-long-method-names.

A positive thing of elisp being archaic is that the system is wide open to users, and most things are just obvious (once you were given the proper explanation, heh).

One place that doesn't work like that is when redefining a defun to defmethod. setfing the symbol-function to nil does not work. (It makes the old defun inaccessible, but doesn't free the symbol)

That's why fmakunbound exists. fmakunbound 'symbol,  and after that you'll be able to defmethod on that symbol.

For now, I haven't found any other real use case for that, but I can imagine unloading a package by removing all methods it previously defined.  That's not much in the culture of emacs though (never seen any plugin that does that)