Emacs
This page is a collection of Emacs related notes.
History
Emacs, originally named EMACS (an acronym for “Editor Macros”), was first developed in 1976 by David A. Moon and Guy L. Steele Jr. at MIT’s AI Lab as a set of macros for the TECO editor. The name Emacs was chosen because “E was not in use as an abbreviation on ITS at the time,” though there’s an apocryphal story linking it to a popular Boston ice cream store called Emack & Bolio’s.
The development of Emacs was driven by the need to unify the many divergent TECO command sets and key bindings at MIT. Richard Stallman, who would later found the GNU Project, played a crucial role in its evolution. He was inspired by the E editor at Stanford AI Lab, which featured intuitive WYSIWYG (What You See Is What You Get) behavior - a revolutionary concept at the time. Stallman reimplemented and improved upon the display-editing mode, adding macro capabilities that allowed users to redefine any keystroke to run a TECO program.
The most popular implementation today is GNU Emacs, created by Stallman for the GNU Project. It’s described as “the extensible, customizable, self-documenting, real-time display editor” and remains one of the oldest free and open source projects still under active development. Emacs has over 10,000 built-in commands and uses a dialect of Lisp for extensibility, allowing users to write new commands and applications. Its influence extends far beyond text editing, with extensions for file management, remote access, email, Git integration, and even games like Tetris and Snake. 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
, providesGCC
,make
,libc
, etc.libgtk-3-dev
, Gnome dependencieslibgnutls28-dev
, provideslibgnutls28
libtiff5-dev
,libgif-dev
,libjpeg-dev
,libpng-dev
andlibxpm-dev
provide image supportlibncurses-dev
, provides terminal supporttexinfo
, forInfo
documentationlibxml2-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 supportlibgccjit0
,libgccjit-11-dev
,gcc-11
andg++-11
8
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-11
9 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 formail-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 helm
10 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.
{{< figure src="/site/images/Emacs.png" alt="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 mode11.
1) (blink-cursor-mode
Themes
An excellent resource for Emacs themes is Peach MELPA. Some selected theme are below.
Here is a list of good themes for Emacs: - zenburn - ample - alect - cyberpunk - gruvbox
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
- The main page for Elisp
- You can check my solutions for the Euler project in Elisp: Project Euler in Elisp
Command line
Running org files
Dynamic modules
Since Emacs 25.1, Emacs can use Dynamic Modules.
Footnotes
https://www.spacemacs.org/↩︎
https://github.com/hlissner/doom-emacs↩︎
https://github.com/jimeh/emacs-builds↩︎
https://www.macports.org/↩︎
https://ports.macports.org/port/emacs/↩︎
Fedora 32/33.↩︎
https://mail.gnu.org/archive/html/emacs-devel/2021-12/msg01732.html↩︎
This also works with
gcc-10
.↩︎This also works with
gcc-10
.↩︎The main
Helm
maintainer is Thierry Volpiatto.↩︎https://www.emacswiki.org/emacs/NonBlinkingCursor↩︎