Installing and configuring Emacs development on Linux

Victor Nascimento
The Startup
Published in
5 min readJan 12, 2020

This is a walk through guide on how you can configure Emacs (the almighty text editor or OS depending on who you ask) for development source code.

Installing Emacs

On Linux, this was a somewhat difficult task a while ago. Nowadays is as easy as it can get. You can use, for instance, flatpak (a package system available to all linuxes) to install from flathub (a repository of flatpaks):

flatpak install flathub org.gnu.emacs

Done!

It is also very easy to install from source… you can clone it from git directly ( git://git.sv.gnu.org/emacs.git) and use make to install. A very good recipe is the emacs-git AUR package.

Languages and environments

Current best approach IMHO to install language runtimes/compilers is using asdf. It is a very simple tool that you can use to install erlang, elixir, nodejs, python and so on. After you go through its installation, just go and:

asdf install erlang 22.1
asdf global erlang 22.1
asdf install elixir 1.9.4-otp-22
asdf global elixir 1.9.4-otp-22

Done!

Begin fiddling with the configuration

All right. Up to now we have the environment set but Emacs is behaving as if it was just a text editor (don’t get fooled by this…).

The power of Emacs is that all of its aspects are programmable. It uses Elisp for tweaking any aspect of it. If you are completely new to Emacs you should first try and get used to its main concepts which I will not cover here. Things like buffers, frames, windows, yanking and so on should be on your agenda.

Emacs itself is self-documented and has a manual for using it and another one for configuring/programming it. There are also many guides on the web for getting started with it.

Word of advice: it is not an easy ride. Takes time and dedication to be “fluent” in Emacs. What I can tell you is that it pays off with time. It works on almost any operating system and many things are inspired by its design.

More advice: use Emacs to teach Emacs to yourself. That means you should start with the help functions. Like, what is the documentation of this function/variable, what this key bind does, what are all the key bindings available on this buffer and so on. Put that on a paper note glued to your computer and follow it through. Look for the shortcuts that start with C-h . That is: hold control and press the h key. Examples are:

  • C-h k : this will let you know which command is bound to a key sequence (it will prompt for the key sequence);
  • C-h f : looks for documentation of the function at “point” (where the cursor is);

Once you can move around with confidence, open files, kill buffers, etc. You SHOULD start tweaking Emacs to yourself. That is when you see A LOT of Elisp (emacs lisp). Don’t be afraid! It is strange at first. Will keep looking strange for a while but it actually is simple once you can grasp it.

Configuration

Let’s start configuring Emacs itself now. First thing you’ll notice is that it is not heavily graphical. Everything will be code. That is actually what makes it so powerful! Our configuration will need some external packages. So, the steps we will follow are:

  1. Configure basic sources for packages;
  2. Install a wonderful package configuration utility called use-package ;
  3. Install many packages for a better developer experience.

It all starts with creating a directory on your home with the name ~/.emacs.d/ . There we will need to create our first elisp file named init.el .

A word about Emacs configuration! Things are changing… There are multiple discussions about standards going on to help Emacs better behave. One of them is where it will look for its initialization script. Up to version 26 it was ~/.emacs.d/ but that clutters the user home directory and is not a XDG standard. So, on version 27 (yet to be released) it will first look for configuration on a new directory ~/.config/emacs/ which is itself standards compliant.

Also, there will be 2 initialization scripts on Emacs 27: early-init.el and init.el . If you are on bleeding edge, please read your Emacs documentation about it.

Configure basic sources for packages

The first thing we will add to our init.el is the package configuration. We will configure the sources where Emacs find new packages.

By default it only looks for on the ELPA (Emacs Lisp Package Archive). This is the default source curated by GNU maintainers themselves. This is a nice but limited repository as it has too few options. We need to add MELPA (Milkypostman’s Emacs Lisp Package Archive — read about Milkypostmans Emacs older repo). To do that, open up your init file and type:

With that we have already configured a new source (MELPA), installed if not yet installed the use-package diminish and bind-key packages and required them to be available to the rest of our configuration. Nice!

Develper packages

Now it’s time to go crazy! Let’s add a lot of functionality to Emacs!

My current choice of packages are:

  • treemacs : sidebar navigation
  • projectile : manages projects
  • magit : the best of the best GIT tool on the market
  • company : an auto-complete tool
  • lsp-mode : an LSP client for Emacs that makes it on par with heavy IDEs
  • docker : a very nice interactive interface for docker and docker-compose

There are many other packages that I use that I won’t get into too much detail. They are either language specific or UI specific that might come in another post. Let’s get down with these packages first!

Some dev packages

Here is the full configuration for the mentioned packages that I use:

With that, you have something like this on Emacs:

My Emacs setup

On the left you can see treemacs using magit and lsp-mode to show GIT status and Elixir module’s structure. On the right-top buffer you can see company with company-lsp connected with the elixir-ls server for suto-completion sources. On the right-bottom buffer there is a magit-status buffer tracking the empty repo.

There are other packages and tools available for refactoring, formatting and so on but I will leave that for the reader’s pleasure to find out more about Emacs.

It is quite a ride to dive deep into the emacs eco-system. I hope you enjoy it! Next I will post my Elixir development setup complete with the language server sources and so on.

--

--

Victor Nascimento
The Startup

Philosophy apprentice in the realms of technology. Android, Java and Elixir language rumblings and then some more.