Pretty fonts for R

2018/04/04

I’ve just stumbled upon this post by William Denton, and quickly wondered how I could have missed Emacs’s feature prettify-symbols-mode which had been released more than three years ago.

Some operators (%>%, <-, ->) in R wasn’t very eyepleasing, especially in Emacs, so I added this to my Emacs config:

(when (boundp 'global-prettify-symbols-mode)
  (add-hook 'ess-mode-hook
            (lambda ()
              (push '("%>%" . ?→) prettify-symbols-alist)
              ))
  (add-hook 'inferior-ess-mode-hook
            (lambda ()
              (push '("%>%" . ?→) prettify-symbols-alist)
              ))
  (global-prettify-symbols-mode +1))

Here’s the result, looking much neater.

For RStudio users, you might want to try out Fira Code or Hasklig - they are code fonts with monospaced ligatures.