Emacs: fontaine version 2.0.0

Fontaine allows the user to define detailed font configurations and set them on demand. For example, one can have a regular-editing preset and another for presentation-mode (these are arbitrary, user-defined symbols): the former uses small fonts which are optimised for writing, while the latter applies typefaces that are pleasant to read at comfortable point sizes.


Control the fonts of more faces

This version brings a major expansion to the scope of the user option fontaine-presets. It can now control the font family and concomitant attributes of more Emacs faces. In particular, it covers the following additional faces:

  • mode-line-active and mode-line-inactive.
  • header-line.
  • line-number (from the display-line-numbers-mode or its global variant).
  • tab-bar (from the tab-bar-mode).
  • tab-line (from the tab-line-mode).

All the supported faces are stored as the value of the variable fontaine-faces. This is the complete list:

  • default
  • fixed-pitch
  • fixed-pitch-serif
  • variable-pitch
  • mode-line-active
  • mode-line-inactive
  • line-number
  • tab-bar
  • tab-line
  • bold
  • italic

Existing users do not need to update their configuration, as (i) the old values will still work and (ii) undefined values fall back to reliable known values.

This change empowers users to further configure their setup, such as:

  • Make the mode lines smaller than the main text.
  • Use a proportionately spaced font for the tabs, while retaining a monospaced font for editing.
  • Use a different font family for line numbers to differentiate them from the main body of text.

These are some possibilities. Then consider that different presets can change specify different configurations. For example, a coding preset can be all about small, monospaced fonts, while a reading preset may increase the font sizes and apply proportionately spaced fonts.

The doc string of fontaine-presets covers the technicalities, as does the official manual (shipped with the package or available on my website: https://protesilaos.com/emacs/fontaine).

Thanks to Ashlin Eldridge for suggesting the inclusion of mode line and line number faces. This was done in issue 4: https://github.com/protesilaos/fontaine/issues/4.

Use the fontaine-mode to persist presets

The new fontaine-mode provides a convenience toggle to do the following:

  1. Store the current Fontaine preset before closing Emacs.
  2. Store the latest preset after using the command fontaine-set-preset.
  3. Persist font configurations while changing themes.

The purpose of storing the latest preset is to restore it easily, such as when starting Emacs. In the manual, we mention this in the sample configuration:

;; Set the last preset or fall back to desired style from `fontaine-presets'
;; (the `regular' in this case).
(fontaine-set-preset (or (fontaine-restore-latest-preset) 'regular))

This takes effect while starting up Emacs. So if, say, the user had selected a reading preset with fontaine-set-preset and then closed Emacs while fontaine-mode was enabled, the reading preset will be restored on startup.

Thanks to Adam Porter (alphapapa) for suggesting this in issue 2: https://github.com/protesilaos/fontaine/issues/2.

We used to provide code in the sample configuration which was doing what fontaine-mode does, though this is easier to set up (plus it is a toggle).

Deprecated the command fontaine-set-face-font

This command was used to interactively set the attributes of a face. It was not consistent with the rest of Fontaine’s functionality, plus it was not faster than setting face attributes directly from Lisp (such as to test them, while experimenting in the *scratch* buffer).

The fontaine-set-preset-hook provides more options

The functions added to this hook are called after fontaine-set-preset. For example, users of my pulsar package can highlight the current line to not lose track of the cursor:

(add-hook 'fontaine-set-preset-hook #'pulsar-pulse-line)

I had thought about defining what Emacs terms “abnormal hooks”, which are hooks that pass arguments to their functions. This hook would pass the selected preset, but I ultimately opted for the normal hook that run their functions without arguments. If advanced users have a good reason for such a feature, they are welcome to discuss it with me.

Fontaine now works with Emacs 29+

Emacs 29 is the current stable version and has been out for almost a year now. I do not have the resources to test/support older versions, sorry!

Miscellaneous

  • Updated the manual in light of all the aforementioned.
  • Simplified large parts of the code base.