UP | HOME

The Emacs Experience

Table of Contents

1. What Emacs?

Emacs is an extensible, customizable lisp interpreter, with multiple different uses.
Emacs is different things to different people.

It could be a:

  • Text Editor
  • Integrated Development Environment
  • E-Mail Client
  • Word Processor
  • IRC client
  • Whatever you want

Although, it is primarily used as a text editor, and some parts of this article will focus on that aspect.

2. Which Emacs?

I currently use emacs-git (v29.0.50 as of writing).

2.1. Compile it!

You can compile emacs yourself for a few features which were recently added to the git master.

  • Native Compilation: Implements gccjit in Emacs, which speeds up the loading of Elisp files.
  • Pure GTK: Removes X11 dependency and offers better integration with wayland compositors.

Alternatively, NixOS users can use emacs-overlay and Debian Sid users can use these binaries.

2.2. Premade Configurations

If you would rather not experience the pain joy of configuring emacs from scratch, here are a few premade configurations for you:

3. How Emacs?

3.1. The Basics of Emacs

3.1.1. Setting Variables

Official Documentation

To change the value of a variable in emacs-lisp:

(setq variable value)

Where variable is the name of the variable and value is the value you'd like to give the variable.

3.1.2. Binding keys

Official Documentation

Keys can be bound to commands either interactively or in your emacs configuration.

Global bindings can be set with global-set-key.
For example:

(global-set-key [f1] 'help-for-help)

This will bind the function help-for-help to the f1 key.


which-key is a package that displays available keybindings in popup.

3.1.3. Adding hooks

Emacs Documentation - Elisp Documentation

Hooks can be used to execute code on certain occasions

For example:

(add-hook 'text-mode-hook 'auto-fill-mode)

This calls auto-fill-mode when text-mode is active.

3.1.4. Using 'customize'

Official Documentation

Customize provides a more intuitive and interactive method to customize parts of Emacs.
To try it, type M-x customize.

3.1.5. Installing packages

https://github.com/jwiegley/use-package

The use-package macro allows you to isolate package configuration in your emacs config in a way that is both performance-oriented and tidy.

This is how I set up use-package in my config:

(require 'package)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

Now, we can install a package from MELPA like so:

(use-package evil)

use-package also provides a way to lazy-load packages. Read more about this in the User Manual.

3.2. Emacs Modes

Official Documentation

Emacs modes are different behaviors and features which you can turn on or off for use in different circumstances.

3.2.1. Major and Minor Modes

Major modes provide specialized facilities for working on a particular file type, such as a C source file, or a particular type of non-file buffer, such as a shell buffer. Major modes are mutually exclusive; each buffer has one and only one major mode at any time.

Minor modes are optional features which you can turn on or off, not necessarily specific to a type of file or buffer. For example, Auto Fill mode is a minor mode in which SPC breaks lines between words as you type. Minor modes are independent of one another, and of the selected major mode.

3.3. Builtins

Emacs comes with quite a few packages built-in.
We'll look into some of them here.

3.3.1. Dired

Official Documentation - Dired Reference Card

Dired is the emacs way to interact with your files. The name “Dired” stands for “directory editor”.
All the operations you expect from a typical file-manager application are available in Dired, plus some that are specific to Emacs.

all-the-icons-dired adds dired support to all-the-icons.

(use-package all-the-icons)
(use-package all-the-icons-dired :hook (dired-mode-hook . all-the-icons-dired-mode))

3.3.2. Ibuffer

Ibuffer is for buffers, what dired is for files. It provides a way of filtering and then grouping the list of buffers that you currently have open, and greatly improves Emacs’ usability.

unknown.png

You can define filter groups, and apply them, as such:

(setq ibuffer-saved-filter-groups
      '(("main"
         ("modified" (and
                      (modified . t)
                      (visiting-file . t)))
         ("blog" (filename . "/projects/site/"))
         ("code" (or (filename . "/projects/")
                     (filename . "/code/")))
         ("org" (mode . org-mode))
         ("dired" (mode . dired-mode))
         ("help" (or (name . "\*Help\*")
                     (name . "\*Apropos\*")
                     (name . "\*info\*")
                     (mode . help-mode)))
         ("internal" (name . "^\*.*$"))
         ("other" (name . "^.*$")))))

  (add-hook 'ibuffer-mode-hook
          (lambda ()
              (ibuffer-switch-to-saved-filter-groups "main")))

Additionally, ibuffer-auto-mode is a minor mode that automatically updates the buffer list.

(add-hook 'ibuffer-mode-hook
          '(lambda ()
             (ibuffer-auto-mode 1)
             (ibuffer-switch-to-saved-filter-groups "main")))

You'll probably also want to hide empty filter groups:

(setq ibuffer-show-empty-filter-groups nil)


all-the-icons-ibuffer is a package to display icons for all buffers in ibuffer.

(use-package all-the-icons-ibuffer
  :ensure t
  :init (all-the-icons-ibuffer-mode 1))

3.4. Yay, Evil!

https://github.com/emacs-evil/evil

Evil is an extensible vi layer for Emacs. It provides Vim features like Modal editing, Visual selection and text objects.

evil-collection adds evil keybindings to other parts of emacs and evil-org adds keybindings for org-mode.

My preferred settings for evil:

(setq evil-cross-lines t
      evil-move-beyond-eol t
      evil-symbol-word-search t
      evil-want-Y-yank-to-eol t
      evil-cross-lines t
      evil-want-integration t
      evil-want-keybinding nil)

3.5. Completion

3.5.1. Company

https://company-mode.github.io/

Company is a text completion framework for Emacs. The name stands for "complete anything".
It uses pluggable back-ends and front-ends to retrieve and display completion candidates.

Additional plugins:

  • company-box is a company frontend with icons.
  • company-statistics is a minor mode that keeps a log of completions chosen, and uses that to rank candidates the next time you choose.
  • company-quickhelp adds documentation popups when idling over a completion candidate.

Alternatively, corfu is a very minimal Emacs plugin that just works. By default, it's quite plain, but there's a sister plugin called cape that adds more functionality.

3.5.2. Vertico

https://github.com/minad/vertico

Vertico provides a performant and minimalistic vertical completion UI based on the default completion system.

3.5.3. Completion styles

orderless provides a completion style that divides the pattern into space-separated components, and matches candidates that match all of the components in any order

hotfuzz, on the other hand, is a fuzzy Emacs completion style similar to the built-in flex style, but with a better scoring algorithm. Specifically, it is non-greedy and ranks completions that match at word; path component; or camelCase boundaries higher.
I personally prefer using hotfuzz.

3.6. Org-mode

https://orgmode.org/

Org-mode is an Emacs major mode for keeping notes, authoring documents, computational notebooks, literate programming, maintaining to-do lists, planning projects, and more — in a fast and effective plain text system.

org-contrib has some neat packages that enhance org-mode.

3.6.1. Making Org-mode look pretty

org-hide-emphasis-markers automatically hides any inline emphasis markers which leads to a much cleaner look.
org-hide-leading-stars hides the leading stars in org headlines.
org-link-descriptive turns the markup of an org-mode link to show just the description

(setq org-hide-leading-stars t
      org-hide-emphasis-markers t
      org-link-descriptive t)


org-bullets shows org-mode bullets as UTF8 characters.
You can set the bullets that it uses like so:

(setq org-bullets-bullet-list '("◉" "○" "●" "○" "●" "○" "●"))

org-superstar is a descendant of org-bullets with some extra enhancements.

3.6.2. Writing notes with deft

https://github.com/jrblevin/deft

Deft is an Emacs mode for quickly browsing, filtering, and editing directories of plain text notes, inspired by Notational Velocity. It was designed for increased productivity when writing and taking notes by making it fast and simple to find the right file at the right time and by automating many of the usual tasks such as creating new files and saving files.

3.7. Help

Official Documentation

  • C-h f - Display documentation on a Lisp function.
  • C-h v - Display the documentation of a Lisp variable.
  • C-h k - Display the name and documentation of the command that a key runs

4. Ricing Emacs!

Because, why not?

4.1. Decluttering the Interface

In my opinion, the default emacs interface is quite cluttered. The various GUI elements may be useful to some people, but to me, they're just distractions. Let's fix that:

(setq inhibit-startup-echo-area-message t
      inhibit-startup-message t)

(tool-bar-mode -1)     ; Disable the toolbar
(tooltip-mode -1)      ; Disable tooltips
(menu-bar-mode -1)     ; Disable the menu bar
(scroll-bar-mode -1)   ; Disable the scrollbar


To add some padding around the frame:

(add-to-list 'default-frame-alist '(internal-border-width . 24))

4.2. Fonts

Official Documentation

The preferred way to set the font you want emacs to use is:

(add-to-list 'default-frame-alist '(font . "Cartograph CF 10"))

4.3. Theme

I use doom-themes to theme my emacs. It supports a wide range of plugins, comes with a few decent themes, and it is quite easy to make your own themes using its framework.

You can find the themes I made here.

4.3.1. Faces

Official Documentation

A face is a collection of graphical attributes for displaying text: font, foreground color, background color, optional underlining, etc.
Faces control how Emacs displays text in buffers, as well as other parts of the frame such as the mode line.

4.4. Modeline

Official Documentation

The mode line appears at the bottom of every Emacs window, and displays status information about the buffer displayed in the window.

Some resources to learn about mode line configuration:

You can also go the easy route and configure a premade modeline, like doom-modeline or mood-line.

5. More Resources