Emacs

This page is a collection of Emacs related notes. The From Scratch to Emacs, The Adventurous Configurator’s Handbook page contains a step-by-step guide to configure Emacs from scratch.

Notes on Emacs

My current flavour/distribution of Emacs is DOOM Emacs spacemacs1 DOOM Emacs2. Yes, DOOM Emacs is my preferred configuration framework at the moment. I have used Spacemacs for a long time, but the performance increase by switching to DOOM Emacs is simply to great to be ignored. Recently, I have also migrated to the Emacs 28 branch which includes Elisp native compilation. It is a thing of beauty in terms of speed.

This page refers to broad Emacs base configuration. For specific Emacs recipes check the Emacs cookbook.

Installation

macOS

Homebrew

Many people swear by emacs-mac as the gold standard for macOS Emacs distributions. To install it, using homebrew simply run

$ brew tap railwaycat/emacsmacport
$ brew install --cask emacs-mac-spacemacs-icon

Alternatively, you can choose whatever icon you want from here. A good alternative is for instance --with-emacs-big-sur-icon. On Linux you can use my con, if you wish.

However, emacs-mac is, at the time of writing, targeting Emacs 27. If you want to use Emacs 29 (and don’t want to build it from source) a good option is emacs-plus. To install it use:

$ brew install emacs-plus@28 \
	--with-native-comp \
	--with-modern-doom3-icon \
	--with-mailutils \
	--with-imagemagick

Another option is to use jimeh’s Emacs builds3. These include nightly builds of Emacs 28 with native compilation enabled. To install it, simply run

brew install --cask emacs-app

or, if want the latest nightly build from Emacs’ master branch:

brew install --cask emacs-app-nightly

MacPorts

Recently I’ve been using MacPorts4 more often than Homebrew. MacPorts also includes an Emacs5 recipe. I tend to use the simple Emacs 28 text-only one:

$ sudo port install emacs

Fedora

At the time of writing6, Fedora only supports, officially, Emacs 27. If you want to try Emacs 28 (and the native compilation feature) you need to install it using

$ sudo dnf copr enable deathwish/emacs-pgtk-nativecomp

and then (if Emacs is already present)

$ sudo dnf upgrade emacs

otherwise run

$ sudo dnf install emacs

Ubuntu

For Ubuntu (and other Linux distros, including Fedora) an option is to use the Snap store. The available Snap can install Emacs 28 with native compilation enabled. To use it, simply run

$ sudo snap install emacs --edge --classic

From source

In December 2021 the pgtk branch of Emacs was merged into master7. Among other features this adds full Wayland support and better font rendering for the Emacs GUI. This version can be compiled from source with just a few simple steps.

Dependencies

To build this version in Linux (I’m assuming Ubuntu and variants) you will need the following dependencies:

  • autoconf
  • build-essential, provides GCC, make, libc, etc.
  • libgtk-3-dev, Gnome dependencies
  • libgnutls28-dev, provides libgnutls28
  • libtiff5-dev, libgif-dev, libjpeg-dev, libpng-dev and libxpm-dev provide image support
  • libncurses-dev, provides terminal support
  • texinfo, for Info documentation
  • libxml2-dev for XML support

I also wanted to include Emacs’ native JSON support and Elisp native compilation, so will additionally need:

  • libjansson4, libjansson-dev, provides native JSON support
  • libgccjit0, libgccjit-11-dev, gcc-11 and g++-118

A one-liner to install all dependencies is:

$ sudo apt update
$ sudo apt install build-essential libgtk-3-dev libgnutls28-dev \
  libtiff5-dev libgif-dev libjpeg-dev libpng-dev libxpm-dev \
  libncurses-dev texinfo \
  libxml2-dev \
  jansson4 libjansson-dev \
  libgccjit0 libgccjit-11-dev gcc-11 g++-11

If building on Fedora, the dependency names will naturally be slightly different. In this case we would use

$ sudo dnf update
$ sudo dnf install @development-tools autoconf \
  gtk3-devel gnutls-devel \
  libtiff-devel giflib-devel libjpeg-devel libpng-devel libXpm-devel \
  ncurses-devel texinfo \
  libxml2-devel \
  jansson jansson-devel \
  libgccjit libgccjit-devel

Building

We can then clone the Emacs repo and run autogen. The steps from now on should be the same for most GNU/Linux distributions.

$ git clone git://git.sv.gnu.org/emacs.git
$ cd emacs
$ ./autogen.sh

To use native Elisp compilation we will use gcc-118 so before starting the build run:

 $ export CC=/usr/bin/gcc-11 CXX=/usr/bin/gcc-11

On Fedora, if are sure you have gcc 11, simply export

 $ export CC=/usr/bin/gcc CXX=/usr/bin/gcc

Emacs supports --with-xxx to enable support for feature xxx, which in our case will be:

  • --with-pgtk, native GTK support
  • --with-json, native JSON support
  • --with-native-compilation, native compilation support
  • --with-xml2, XML support
  • --with-modules, support for dynamic modules
  • --with-mailutils, support for mail-utils

So we can run the configure script with

$ ./configure \
    --with-native-compilation \
    --with-json \
    --with-pgtk \
    --with-xml2 \
    --with-modules \
    --with-mailutils

We can now start the build and installation (you can choose the approriate number for your machine for the parallel run, in this case 8):

$ make -j8
$ sudo make install

If everything completes successfully you should have Emacs 29 available in /usr/local/bin

$ emacs --version

GNU Emacs 29.0.50
Copyright (C) 2021 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Configuration

Completion

I recently move from helm9 to ivy. The main reason is that apparently helm development has stalled.

The important stuff?

Icon

I’ve also made a vaporwave Emacs icon which you can find in here.

Emacs.png

Cursor

A cursor should blink, in my opinion. For a history of the blinking cursor see The Forgotten History of the Blinking Cursor. You can instruct Emacs to blink it with the appropriate mode10.

(blink-cursor-mode 1)

Themes

An excellent resource for Emacs themes is Peach MELPA. Some selected theme are below.

Here is a list of good themes for Emacs:

The theme that I’m currently using is spacemacs-light. It works really well the new org-mode styling. A more detailed rundown of the specific theming can be found at DOOM Emacs.

Elisp

Command line

Running org files

Dynamic modules

Since Emacs 25.1, Emacs can use Dynamic Modules.