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.

2
  • autoload Commented Aug 1, 2017 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. Commented Aug 2, 2017 at 0:17

2 Answers 2

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.