1

I have an elisp file that contains the following:

(defun hello ()
 (interactive)
 (message "Hello World"))

(provide 'examples)

When I call unload-feature examples RET, the function hello is still defined, and I can still call it.

However, when I do C-h f hello, Emacs simply states:

hello is an interactive Lisp closure.

(hello)

Not documented.

In theory, according to the documentation unload-feature should undefine all the defuns.

How can I make it so that when I call unload-feature, Emacs will "forget" hello's definition?

Emacs Version: GNU Emacs 29.3

Note: I am loading the file using dir-locals like this:

((nil . ((eval . (load-file (concat (projectile-project-root) "hello.el"))))))

2 Answers 2

4

Most likely because you didn't evaluate the file as follows:

(load "/path/to/your-file.el")

(I've tested the above code and it does work.)


If you evaluate the defun form by typing C-x C-e (or similar commands), the evaluated function won't be considered the API provided by that file.

You can use

(feature-symbols 'examples)

to check whether a symbol belongs to the given library.

3
  • Hello @shynur, I updated my question. Thanks for your coment! Commented Jun 22 at 15:23
  • 3
    @PeterPetigru Each time you open a new buffer under the directory containing .dir-locals.el Emacs will evaluate the expression you specified. So that file will be loaded again and again.
    – shynur
    Commented Jun 22 at 15:31
  • 1
    It's working now. I was unloading the feature outside the directory. Maybe I did something differently. Regardless, thanks for the answer! Commented Jun 22 at 16:23
0

Like @shynur said; the file was being loaded again and again.

The solution was to simply add an if statement in the .dir-locals file to check if the feature had been loaded already, using featurep.

I did it like so:

 (nil . ((eval . (unless (featurep 'ejercicios-tda)
             (load-file (concat (projectile-project-root) "hello.el"))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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