General purpose Emacs tips

Published: November 21, 2020   |   Read time:


Emacs is a text editor that has a lot of history and a lot of functionality. Because of its history and the philosophy behind it, it can be hard to find the “right” way to do anything with it. In this post, I want to compile some information that I’ve found over time, and things that have worked for me.

This may be useful for others, but mainly I’m using this as a single location to find information for myself in the future. This post will be updated as I go.

Easily install Emacs on Windows

Use Scoop. Avoid the non-free software lecture from GNU and just get going with scoop install emacs.

Initializing an Emacs configuration

The default Emacs configuration file is ~/.emacs.d/init.el (on Windows, ~ is C:\Users\<username>\Appdata\Roaming\). It is read every time Emacs is started. The historical location is ~/.emacs, so if anything is there, it will be read first. Putting everything into ~/.emacs.d/ allows for easier version control and grouping of other files, such as installed packages.

Reducing startup time

To make Emacs snappier, follow these tips:

  1. Use the Emacs Startup Profiler to establish baseline startup times before making modifications to init.el.
  2. Lazy-load packages where possible. Only load small and essential packages in init.el, like evil and use-package.
  3. Run Emacs as a daemon process. More on this below.

Running Emacs as a daemon process

Use runemacs --bg-daemon to start a background Emacs server. When this is first run, it wil load init.el like normal. You can then connect to this daemon by running emacsclient -n -c -a "". This will connect to an existing Emacs server and create a new frame if none currently exists. You can then open and close frames as you want without having to load init.el every time, making Emacs overall much faster.

You can add runemacs --bg-daemon to your startup to have it enabled all the time. On Windows, the easiest way to do this is to create a shortcut in C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\. Then make a Start Menu shortcut to emacsclient for quick access.

In my experience, it takes 1-10 s for the daemon process to start, but < 1 s for the Emacs client to create a new frame.