Start Emacs In A Defun
This is a follow-up to my earlier article titled Speeding Up Emacs Startup from August 2017. Three years later, I once again spent time cleaning up and refactoring the results as described below. The end-result is to once again speed up Emacs startup, (about 25% faster on my laptop)while making the setup cleaner and easier to maintain than before.
2 Start Emacs In A Defun
This startup file is set up with the following goals:
- Speed up emacs startup — setting environment variable
TVR_TIME_EMSbefore starting emacs produces detailed timing information in the Messages buffer.
- Customize packages via Custom as far as possible.
- Keep the custom settings in a separate file, with a later goal of turning that into a theme.
- After converting to a theme, Move machine-specific custom settings into a separate host-specific custom file, thus making the earlier theme host-independent. Place host-specific non-customizable bits in default.el (not done yet).
- Define package-specific settings not available via Custom in a package-specific <package>-prepare.el file.
- Install everything from elpa/melpa as far as possible. (vm is an exception at present) — I have nearly 200 packages activated.
- The startup file is a collection of functions with entry-point tvr-emacs.
- The only top-level call is (tvr-emacs).
- Function tvr-emacs starts up Emacspeak, and sets up two hooks:
- after-init-hook to do the bulk of the work.
- emacs-startup-hook to set up initial window configuration.
- Function tvr-after-init-hook on after-init-hook does the following:
- Load package-specific prepare.el files.
- Load the custom settings file.
- Starts up things like the emacs server.
- Some of these tasks are done on a separate thread using make-thread.
- The work of loading files etc., is done within macro tvr-fastload
which sets up an efficient environment for loading files.
With this setup,
M-x emacs-init-time shows init-time as
on my laptop with an SSD. Setting
T is a
major win when running with a spinning-disk instead of an SSD. But the
biggest win is that I no longer have to go hunting to find out where
something in emacs got configured a given way — AKA, there are a
limited number of places I need to look.
- Remembering the name of a custom-setting you set up a while ago is still a challenge, You cant find it unless you remember its approximate name.
C-h C-shelps some in this regard but is a stop-gap solution.
- Custom themes are not easy to use.
- I keep my
custom-filechecked into a local Git repository and is the only part of my setup that I cannot publish — since that file tends to hoover up information that you shouldn't publish, e.g., aPI keys and other private/personal bits.
- Perhaps Emacs needs at least two custom-files, a public and a private custom-file.