2

I read from some posts (require vs. package-initialize?, and here) that Emacs can autoload packages installed via ELPA/MELPA, which avoids using require on packages and speeds up loading during initialization. And quoting this answer:

Note that for 99% of the packages require should not be needed (the autoloads should cause the package to be loaded as soon as you try to make use of it).

I do have quite a few usages of (require ...) in my init.el that significantly slow down emacs initialization. By turning things on and off, some culprits seems to be

(require 'help-fns+)   ; about 0.2 to 0.3 s
(require 'org)
(require 'ob-octave)   ; not sure, but up to 1 s

I tried to just comment out these require statements (since I use emacs 27.1 under Ubuntu). But help-fns+.el does not seem to work anymore. Functions defined there (e.g. describe-buffer) can no longer be found.

My questions are:

Is it the right way to take advantage of autoloads by just removing the require call? Or is it because help-fns+.el doesn't have the autoload capability from ELPA?

If the latter case, (how) can I autoload help-fns+.el and avoid a hard require in init.el?

1
  • 1
    Do C-h i g (elisp)Autoload - ELPA packages may be using it, but it has nothing to do with ELPA per se.
    – NickD
    Jun 12 at 15:21
2

There are some alternatives. Do any of them after putting the library in a directory that's in your load-path.

  1. Unconditionally load the library.

    (require 'help-fns+)
    
  2. Autoload the library for individual commands (or other functions, but typically commands), by putting a sexp like this in your init file:

    (autoload 'describe-command "help-fns+" "Help commands." t)
    

    Then, whenever you invoke that command, the file will automatically be loaded.

  3. But library help-fns+.el also provides ;;;###autoload cookies, so you can alternatively generate a file of autoloads for it, using command update-file-autoloads.

As @NickD wrote in a comment, see the Elisp manual, node Autoload.

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.