I have developed some private extensions to some major modes, and I would like to load those extensions only when the given major mode is actually used by the user. The extensions consists of a set of functions confined to a single file. For example, for emacs-lisp-mode
, I have developed a file "~/emacs/my-emacs-lisp-mode-hook.el
, here is a minimal example for illustration purposes:
(defun my-emacs-lisp-mode-hook ()
(my-hook-func))
(defun my-hook-func ()
(message-box "This is my hook function"))
And then, in my Emacs init file ~/.emacs
I have:
(autoload 'my-emacs-lisp-mode-hook "~/emacs/my-emacs-lisp-mode-hook.el" "My Emacs Lisp mode hook" nil nil)
(add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook)
Note that I do not have an autoload
call for the function my-hook-func
.
The question is: If it is sufficient to call autoload
only for the function my-emacs-lisp-mode-hook
, or if I have to call autoload
for each function in the file "~/emacs/my-emacs-lisp-mode-hook.el
? The idea is that, the other functions in the file will never be used unless a buffer switches to major mode emacs-lisp-mode
and the hook function my-emacs-lisp-mode-hook
has run.
Currently, this strategy seems to work (I get the message box created in my-hook-func
even if I have no explicit autoload
statement for that function). But I could not find a clear statement of this behavior in the manual. So is this a viable strategy? (It would certainly allow me to simplify my code, that is: not having to add autoload cookies for each function, and not call update-file-autoloads
and so on..)