My Minimal Emacs Setup- 11 mins
I begin by telling Emacs what my name and email address is. This is used by tools like git when creating commits.
Garbage collection in Emacs is quite simple. Every time memory crosses a certain threshold, it garbage collects. But the default value for this threshold is quite low by modern standards, just 800KB. Most extensions of Emacs use considerably more memory than that and this low threshold makes Emacs quite slow when using them. I set it something more reasonable like 50MB. Another low threshold is hit when opening files with sizes that are common nowadays and Emacs warns you about being wary of opening such a large file. I increase that limit too. I have RAM to spare.
Everything needs to be UTF-8. I have to be careful when opening files from sources other than my systems but in general, UTF-8 is preferred everywhere.
eli-zaretskii : If your system’s locale specifies UTF-8, these settings are redundant, as Emacs does that by default. And if your system’s locale is not UTF-8, you will get yourself in trouble, e.g., by assuming that your keyboard talks UTF-8.
Setup package manager and use-package
Emacs becomes truly useful with its package manager and thousands of freely available packages from its wonderful community. Use-package is a utility library that lets us declaratively setup the packages we will be using.
Visual defaults for Emacs have a menu bar, scroll bars on all buffers and a toolbar as well. But most functionality can and should be reached through just keyboard commands, which means most of this is just visual clutter. I like a clean Emacs look so I get rid of the menu bar, the tool bar, the blinking cursor and the scroll bar.
Next I enable a bunch of visual helpers like line numbers, current line highlighting, column number and file size in the mode line.
I never use the startup Emacs screen anymore so I disable that as well. This leads Emacs to load up with the scratch buffer open.
The model-line has the current file’s name but the path to the current file is still a few keystrokes away. The title bar can be used to show the full path of the current file, so lets set that up.
Default scrolling has some wierd quirks in Emacs, so I set margins that trigger scroll to zero and preserve screen position when jumping around.
I use the font “Hack” which you can find at this link and set that to be the frame font. I am still trying to figure out a way to setup font size that works on different screen resolutions but for now it is set to 12.
One of the things I liked about Visual Studio Code editor was the default theme. Fortunately there’s an Emacs package for it. Doom-one is my go to modern minimal theme. We also disable the default warning audio bell and replace it with a visual “bell” where only the mode-line flashes to warn you about something.
Smart mode line is a sexy mode line for Emacs. I also like the powerline theme for the mode line. The other option is Spaceline, the mode line from spacemacs, but I think it is more work to set that up.
Emacs likes to strew its backup and temporary files everywhere. Lets give them a home in the temporary file directory.
Ease of life
You can get fairly tired by typing a full “yes” or “no” to Emacs’ questions. So I replaced that with a simple “y” or “n”
If I edit a file outside of Emacs, the default setting is for Emacs to ask you to reload the file manually. I task Emacs to reload the file automatically.
Tabs are 4 spaces.
When I say kill a buffer (close a file), Emacs asks which one. I’d rather it kill the current buffer I am in.
Accidental whitespaces are annoying. And I let Emacs know it. So it cleans up behind me when I save a file.
Diminish lets you hide minor modes from showing in the mode line, keeping it minimal.
Smartparens is a minor-mode for dealing with paren pairs in Emacs. It inserts them in pairs, deletes them in pairs, highlights them and generally makes life easier when dealing with braces, quotes and the like.
Selecting a region becomes smarter with expand region which keeps selecting an increasing region based on dwim syntax.
Some useful defaults are provided by the crux package of Prelude fame. “C-k” now kills a line if nothing is selected. “C-a” now toggles between first letter on the line, or beginning of the line.
Given the thousands of commands at your disposal, its only reasonable to have a package help you figure out the next keystroke. which-key package opens a small buffer at the bottom with suggestions for next keystroke and possible commands that are available.
I can jump around in the current visual field using avy’s go to char.
Autocomplete and syntax checking
I use company mode to provide completion and flycheck to do syntax checking and enable them globally.
No project is begun without git and Emacs community’s integration with git through magit is unparalleled in its expanse and ease of use. Setting that up is just as easy. “C-M-g” now triggers a git status buffer for the current file’s repository.
Projectile is a project manager that lets you easily switch between files in a project and seamlessly between projects as well. I use it with helm which I set up below.
Helm requires its own heading. It is a dwim fuzzy completion framework for Emacs and makes navigating Emacs a much nicer experience overall. I like to setup Helm to be a comfortable 20 pts in height and bind the most frequent Emacs commands like “M-x” with the helm equivalents.
I combine it with projectile to show project files through a helm fuzzy find interface.
At the end I start the Emacs server so that any new frames that I open don’t have to load the configuration from scratch.
You can find my full Emacs configuration at my github repository.