1

Most of the packages I currently use are major modes for various languages that are only included in the off-chance I load a file of that type.

Is there a way to postpone loading them at startup in my init file - until a filename with a particular file extension is loaded?


Note that I'm not familiar with exactly how emacs packages are already supposed to be using auto-load, but emacs without many packages starts nearly instantly, and with them - takes ~2seconds. I've profiled the startup and while some package a clearly worse offenders than others - this isn't one single package at fault. So I was interested to lazy load where possible.

  • autoload – Dan Aug 1 '17 at 21:03
  • 2
    If you mean package.el packages, then this should already be happening by default, and is arguably a bug in the package if it isn't. – npostavs Aug 2 '17 at 0:17
2

You can use autoload rather than require

example with yaml-mode

(autoload 'yaml-mode "yaml-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
1

An interesting and efficient method for your goal is the macro use-package, excerpt from author's readme:

"The use-package macro allows you to isolate package configuration in your .emacs file in a way that is both performance-oriented and, well, tidy. I created it because I have over 80 packages that I use in Emacs, and things were getting difficult to manage. Yet with this utility my total load time is around 2 seconds, with no loss of functionality!"

Some more explanations can be seen in this video. Many users also use this, for various packages configurations this is also a good reference.

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.