I am trying to figure out how to add autoload features to a private library. Let's say I have developed a private Lisp library "my-lib.el". It consist of a set of functions, some can be used from any mode, others are only used for a particular mode. According to the manual I could put a autoload cookie above each function definition, and then call update-file-autoloads. Is this correct? But when do I call update-file-autoloads? In the beginning of the Emacs init file?

For example, in my ~/.emacs init file, I could write:

(update-file-autoloads "my-lib.el")
(require 'my-lib)

Where in "my-lib.el"

(defun my-func()
  (message "Hello")) 

;;; more functions, omitted here...

(provide 'my-lib) 

But this gives error from update-file-autoloads if the file is not in the current directory. Or if "my-lib.el" is in the current directory, I get the error: Wrong type argument: stringp, nil.

My aim is to be able to type M-x my-func (as an example), and my-func should autoload at that point if this was the first time I called it.

2 Answers 2


That's not how I would do it. I would:

  1. update-file-autoloads for "my-lib.el" to "my-lib-autoloads.el".
  2. (require 'my-lib-autoloads) in "init.el".

That's it. Now, each time you add or remove an autoload cookie, you should update "my-lib-autoloads.el". Don't parse "my-lib.el" at startup: it's probably slower than just loading it.

  • Thanks @abo-abo. But why do I get error: Wrong type argument: stringp, nil from update-file-autoloads ? According to C-h f update-file-autoloads the syntax is: (update-file-autoloads FILE &optional SAVE-AFTER OUTFILE) .. and what is the purpose of the SAVE-AFTER argument? Feb 6, 2015 at 14:18
  • I did the thing interactively. The following code also works: (update-file-autoloads "lispy.el" t (expand-file-name "lispy-autoloads.el"))
    – abo-abo
    Feb 6, 2015 at 14:27
  • SAVE-AFTER will save the "-autoloads.el" file if it's already open, I guess.
    – abo-abo
    Feb 6, 2015 at 14:28
  • Ok, I see.. But now this produces a file "my-lib-autoloads.el" with only one statement "(provide 'my-lib-autoloads)".. Shouldn't there be some autoload statements in there too? Feb 6, 2015 at 14:35
  • Do you have ;;;###autoload in the file?
    – abo-abo
    Feb 6, 2015 at 16:28

If you are using package.el, after changing my-lib.el every time, use package-install-from-buffer to install your private library as a package. You don't need to issue (require 'my-lib) in your init file for invoking autoload commands because package.el has already generated "my-lib-autoloads.el" and loaded it for you.

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.