Sometimes I want to call unload-feature to unload a library… and it a library depends on it… and another library depends on that library…

How can I unload a library and all the libraries that depends on it, without walking through the dependency tree manually?

A common use case is to unload all the libraries of a package (e.g. when upgrading or uninstalling), so if there's a way to do that, it would be good enough.


There's no built-in way to do this--see Unloading in the Elisp manual.

unload-feature takes a force argument that allows forcibly unloading P even if other packages depend on P; is that sufficient for your needs?

If not, you can try to create a recursive version of unload-feature containing:

(let* ((file (feature-file feature))
       (dependents (delete file (copy-sequence (file-dependents file))))) 
  (when dependents
    (mapc #'unload-feature-recursive (mapcan #'file-provides dependents))))
  • Thanks, I fixed the error in the question. Writing a recursive version of unload-feature was the point of the question. Feb 27 '17 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.