I have some of my own Elisp code in my own directory. Like I have a file /tmp/foo/foo.el
with this in it:
;;; foo.el -- Foo
;;;###autoload
(defun foo-hello ()
(message "hello, world"))
(provide 'foo)
;;; foo.el ends here
I open Emacs and run M-x make-directory-autoloads RET /tmp/foo/foo-autoloads.el RET
.
Then I add this to my ~/.emacs.d/init.el
:
(add-to-list 'load-path "/tmp/foo/")
(foo-hello)
Then I start Emacs but I get this error:
eval-buffer: Symbol’s function definition is void: foo-hello
What did I miss? How do I make Emacs see my generate autoloads file and use it to automatically load the autoloads when I use them? Is there an extra step involved?
If there is an extra step involved, then how does Emacs automatically see the autoloads installed with package manager. Like I never did anything special to make Emacs recognize ~/.emacs.d/elpa/magit-20230402.1342/magit-autoloads.el
. How does Emacs see that file automatically but it does not see my autoloads file?
require
. But when I install a package from MELPA, I don't have to do anyrequire
for them. When I call any autoloaded function from those packages, the package gets "required" automatically. So I want to know how Emacs packages installed from MELPA get autoloaded without anyrequire
?require
(actually aload
, but that comes to the same thing) for you: it gathers up a list of packages under your~/.emacs.d/elpa
directory (or equivalent) and loops over them. For each one, itload
s the autoload file for the package, thereby making its autoloaded functions available to you. See the functionpackage-activate-1
and the line that reads(load (package--autoloads-file-name pkg-desc) nil t))
. Apart from the minorrequire
vsload
, it's exactly what the answer below and the duplicate question describe.emacs
after having installed some packages. When you install a package in a running Emacs session, thepackage-activate-1
function is called by the installation code explicitly, thereby adding that package's autoloads in the same way.