I'm changing up the API of my package pretty frequently, but company-mode
pulls every defined symbol (as it should) in its completions. I don't want to accidentally use an unbound name, so how can I unbind all variables and functions that start with, say, my-package-
? After this, I'll simply be able to load-file
again.

- 6,861
- 16
- 85
2 Answers
Call unload-feature
to undefine all symbols that were defined as part of loading an Elisp source or byte-compiled file. Make sure that your file ends by calling provide
at the end. This assumes that you loaded the file with one of the load
functions or via require
, it won't undefined symbols defined by C-M-x
(eval-defun
) or similar mechanisms.
If you really want to unbind symbols based on their name rather than based on the package that defined them, you can use mapatoms
to iterate over all symbols.
(mapatoms (lambda (symbol)
(if (string-prefix-p "foo-" (symbol-name symbol))
(unintern symbol))))

- 21,702
- 4
- 53
- 89
-
Useful, but I don't believe this will be effective with interactive development as I describe. I'm one level deeper than the `feature` system; I'm working only with functions and variables without any explicit grouping. I have not bothered evaluating `(provide 'my-package)`. – Sean Allred Oct 30 '14 at 00:50
-
2@SeanAllred I can't think of a good reason not to use `provide`. But anyway, if you really want to do things the dirty way, see my edit. – Gilles 'SO- stop being evil' Oct 30 '14 at 00:57
-
Oh, I love `provide`, I just don't think it would work in this case. Do functions remember what file they were defined in if they were evaluated interactively? – Sean Allred Oct 30 '14 at 00:59
-
2`unload-feature` has no effect if you evaluate code without loading it from a file (that has `provide`). – Drew Oct 30 '14 at 01:00
-
2@SeanAllred No, functions only remember where they were loaded from if they were loaded as part of loading a whole file. – Gilles 'SO- stop being evil' Oct 30 '14 at 01:10
Use
makunbound
to remove the use of a symbol as a dynamic variable (i.e., to void itssymbol-value
).Use
fmakunbound
to remove the use of a symbol as a function (i.e., to void itssymbol-function
).Use
mapatoms
to iterate over all symbols. Act on each whosesymbol-name
is matched by the particular prefix you are interested in: call bothmakunbound
andfmakunbound
on it.You do not need to
unintern
the symbol, unless you are also using completion against symbols themselves, and not just over their use as variables or functions. But if you do want to completely remove a symbol then useunintern
.

- 75,699
- 9
- 109
- 225