This article describes how to improve the Emacs user interface as part of the Emacs Writing Studio, a configuration for authors.

Improving the Emacs User Interface

Peter Prevos

Peter Prevos |

1880 words | 9 minutes

Share this content

A minimalist interface means that your Emacs becomes a place of rest and contemplation away from the cacophony of contemporary software, filled with buttons and functionality you don't need. Emacs is an ugly duckling that you can configure into a beautiful swan. This article further explains how to improve the Emacs user interface. These settings are obviously opinionated, so this article is, more than anything else, an example of how to configure Emacs to your personal preferences.

Emacs Writing Studio

Emacs Writing Studio

A comprehensive guide for writers seeking to streamline their workflow using Emacs. The book covers everything from organising ideas and writing distraction-free to publishing in multiple formats. It’s perfect for both beginners and experienced Emacs users, offering practical tips and a tailored configuration to enhance your writing process.

The source files of the book and EWS configuration are also freely available on GitHub.

Improving the Emacs user interface

The default Emacs user interface is a hybrid between keyboard and mouse-driven operations. While using the mouse might seem convenient, a keyboard-driven system is more efficient because you don't have to move your hand that much and switch contexts when finding icons.

Emacs Writing Studio is a keyboard-centric configuration and removed any distractions from the Emacs. The following code snippet modifies the Emacs interface to remove these distractions. The first line inhibits the splash or startup screen. If you want to see it again for nostalgia, use C-h C-a (about-emacs).

Emacs has the paternalistic habbit of asking for confirmation with either y / n or with yes / no, depending on the situation. The basic philosophy is that typing the whole word prevents accidentally killing unsaved buffers. While this functionality is a nice gesture, it can be annoying and confusing. The last line sets all yes / no confirmations to the one-letter abbreviation. The use-short-answers variable defines this behaviour.

The following three lines remove the tool, menu and scroll bars because we don't need these in a keyboard-driven system. These lines don't set a variable but disable the various minor modes that control these graphical elements.

This configuration also removes the menu bar. While the menus are a useful tool to discover functionality, there is no need to constantly keep it on the screen. You can access it by pressing F10 (menu-bar-open) and selecting menu options with the arrow keys and ENTER. You exit the menu with C-g (keyboard-quit). But after using Emacs for a while, you'll quickly build muscle memory and revert to keyboard shortcuts.

If you like to see the effect of each line of code, place your cursor at the end of each line and press C-x C-e to evaluate the expression (eval-last-sexp). If the cursor is inside the parenthesis, then use C-M-x (eval-defun). To evaluate all code in a buffer, run M-x eval-buffer.

  ;; LOOK AND FEEL

  ;; Keyboard-centric user interface
  (setq-default inhibit-startup-message t
                use-short-answers t)
  (tool-bar-mode -1)
  (menu-bar-mode -1)
  (scroll-bar-mode -1)

Themes

A theme is a set of instructions describing the colours of headings and other text parts. Colours in a text editor play a different role than in a word processor. Colours in Emacs are semantic, meaning they indicate the type of text, not how it looks when published. A heading might have a different colour than the text or metadata, which helps you find your way through the document.

Emacs does this through font-lock-mode. Font locking assigns faces to (or 'fontifies' in Emacs speak) various parts of your text using logical rules. Typing M-x font-lock-mode toggles between your buffer's themed and plain versions. Try this to see the effect of themes.

Two basic classes of themes exist for text editors: light and dark. Light backgrounds, common with most modern word processing software, can cause asthenopia (eye strain) after you stare at the screen for a while. Many text editor users, therefore, prefer dark themes. Light themes are, however, useful when you work in a brightly lit room.

The code snippet below installs and activates the most recent version of Prot's Modus themes. The Modus themes each have four versions. The modus-operandi theme is the primary light theme, while modus-vivendi is its dark counterpart.

The primary Modus themes maximise contrast between background and foreground following the Web Content Accessibility Guidelines (WCAG). The Modus themes comply with the triple-A standard of the WCAG, which specifies contrast ratio between background and foreground of 7:1. This high contrast ratio is legible for people with moderately low vision. Prot has also optimised versions for red-green and blue-yellow colour blindness (deuteranopia and tritanopia).

Emacs Writing Studio uses the tinted versions as default. These versions have a slightly lower contrast ratio than the default and are as such suitable for people with normal vision. The Modus themes do not prescribe any keyboard shortcuts, so I have defined some for EWS. The C-c w m shortcut toggles between the light and dark side (insert Star Wars pun here). Using C-c w M provides a selection menu of all Modus themes. Emacs Writing Studio uses C-c w as its default keybinding for its specific functionality, where the w is a mnemonic for writing and m/M for Modus themes.

  ;; Modus Themes
  (use-package modus-themes
    :custom
    (modus-themes-italic-constructs t)
    (modus-themes-bold-constructs t)
    (modus-themes-mixed-fonts t)
    (modus-themes-headings '((1 . (1.5))
                             (2 . (1.3))
                             (t . (1.1))))
    (modus-themes-to-toggle
     '(modus-operandi-tinted modus-vivendi-tinted))
    :bind
    (("C-c w m" . modus-themes-toggle)
     ("C-c w M" . modus-themes-select))
    :init
    (load-theme 'modus-operandi-tinted :no-confirm))

Let's unpack what this piece of code means. The use-package declaration has three sections.

The :custom section does the same as the setq-default function described previously. This configuration adds more variety to the theme, such as italic text, bold text, mixed fonts, and headings are rendered a bit larger than the normal text. This configuration uses the *-tinted versions of the Modus themes (medium contrast).

The :bind section binds the relevant keys to the function that toggles between light and dark Modus themes.

Lastly, the :init section defines the functions run when the package is loaded. In this case, we load the tinted version of the dark Modus theme without confirmation.

If you like your configuration to default to the high-contrast versions of the theme or one of the two colour blindness-safe versions, then customise the modus-themes-to-toggle variable to override this default and change the init version to the one you like Emacs to start with.

Other Themes

Several themes are part of Vanilla Emacs, which you can customise with the customize-themes function. When you click the Save Theme Settings function, the theme will be loaded next time you start Emacs. You will have to remove the Modus themes code to ensure that your other choice is loaded. When the theme is used for the first time, Emacs might ask you to confirm that it can run Elisp code.

Emacs users have developed a ragtag collection of themes. You can browse the Emacs Themes Gallery to pick your favourite. If the theme is available in the ELPA or MELPA package repositories, change the package and theme name in the code below to match the name of your favourite theme.

  (use-package dracula-theme
    :init
    (load-theme 'dracula))

Setting the fonts

The default font in Emacs is a fixed-pitch (mono-spaced) font designed for writing code. In a fixed-pitch font, all characters have the same width. An i or an m will use the same amount of space, just like the traditional typewriters. This type of letter is ideal when writing code because it helps to align the text. Mono-spaced fonts are also necessary to create fantastic ASCII art, such as the dinosaur shown in another article.

A variable-pitch font is easier on the eye when writing prose. Not all characters have the same width in a variable-pitch font, as is common in natural writing. Ideally, we want the best of both worlds and configure Emacs to use the best font category for the best situation. For example, Emacs can define a different font for certain parts of the text, for individual buffers, or for a major mode.

The configuration below uses Alex Branham's mixed-pitch package, which assigns fixed and variable pitch fonts to the relevant elements in the buffer. For example, tables in Org mode become fixed pitch so that all columns are the same size. The use-package call hooks the mixed-pitch mode to all text modes, including Org mode.

  ;; Set default, fixed and variable pitch fonts
  (use-package mixed-pitch
    :hook
    (text-mode . mixed-pitch-mode))

The Emacs Writing Studio configuration does not specify any particular fonts and use your system's defaults. You can configure your favourite fonts, provided they are available on your computer. You need to define three font variable:

  • default: The default face settings when nothing else is specified (a fixed-pitch font).
  • fixed-pitch: The font used for computer code .
  • variable-pitch: The settings for prose.

In Emacs, a 'face' is a collection of attributes for displaying text. It defines the font, foreground colour, background colour, optional underlining, etc. Various face attributes are available for configuration. The ones we use here are:

  • font: The name of the font
  • height: The font height as an integer in units of 1/10 point.

The settings of the last two categories override the default. The nil in the set-face-attribute function sets the parameters for all Emacs frames.

You can also use the customisation menu by evoking customize-face and select default, fixed-pich and variable-pitch and enter the font name in the Font Family box. Click Apply and Save for each font. This action saves the font settings to the custom.el file, which Emacs evaluates at the end of the startup sequence. See Configure Emacs for more information about the initialisation process.

Please note that anything you configure here will override the theme settings, so only customise font family and size.

To see which fonts are available, you can set the fonts in a graphical window, run menu-set-font. When you use the GUI to set the default font, the change is immediate but transient. Use menu-bar-options-save to save your default font and size to the custom.el file.

Alternatively, add the following three lines, with your fonts of choice to your init.el file.

  (set-face-attribute 'default nil :font "DejaVu Sans Mono" :height 130)
  (set-face-attribute 'fixed-pitch nil :font "DejaVu Sans Mono")
  (set-face-attribute 'variable-pitch nil :font "DejaVu Sans")

This video by Prot explains the principles of setting fonts in Emacs beautifully.

#+caption:Emacs: customize fonts (generic method and 'fontaine' package).

Emacs Writing Studio

If you like to support my work, then please purchase the Emacs Writing Studio book.

Emacs Writing Studio

Emacs Writing Studio

A comprehensive guide for writers seeking to streamline their workflow using Emacs. The book covers everything from organising ideas and writing distraction-free to publishing in multiple formats. It’s perfect for both beginners and experienced Emacs users, offering practical tips and a tailored configuration to enhance your writing process.

You can find the source files for the book and the latest configuration files on GitHub:

Emacs is a malleable system, so everybody will have their personal preferences. Any article on how to use Emacs is thus opinionated. If you have a different way of doing things, please complete the contact form to send me an email or contact me on social media.

The next article dives into enhancing the minibuffer completion system to make it easier to find files, buffers and other information.

Share this content

You might also enjoy reading these articles

Writing Prose with Emacs

Exploring Your Ideas With the Denote-Explore Package

Reading eBooks with Emacs