Color your numbers in Emacs

numbers in emacs

I have dyscalculia and synesthesia. It’s helpful for music and language, but it makes math and numbers more difficult. I live in Emacs all day every day and had the idea to color my numbers there according to my own (synesthesia) numbers. Hence the code below.

Not sure if this would benefit anybody else, as the Venn diagram of Emacs users, synesthetes, and people with dyscalculia probably has a small overlap.

But.. it might, and/or it might inspire some other Emacs hacks.

To try this out, put this code in your Emacs config, which for me using Doom Emacs is located at ~/doom/config.el. Fair warning: I’m not really a coder, and adding random snippets to your config always has the potential to break stuff. You’ve been warned!

(add-hook 'org-mode-hook
       (lambda()
           ; settings here
  (font-lock-add-keywords
   nil
   '(
      ("\\(0\\)" 1 '( :foreground "#808080"))
      ("\\(1\\)" 1 '(:foreground "#ffffff"))
      ("\\(2\\)" 1 '(:foreground "#ffcc00"))
      ("\\(3\\)" 1 '(:foreground "#66ccff"))
      ("\\(4\\)" 1 '(:foreground "#0077b3"))
      ("\\(5\\)" 1 '(:foreground "#ffeb54"))
      ("\\(6\\)" 1 '(:foreground "#ff0066"))
      ("\\(7\\)" 1 '(:foreground "#39e600"))
      ("\\(8\\)" 1 '(:foreground "#993399"))
      ("\\(9\\)" 1 '(:foreground "#ff0000"))
     ;; punctuation and stuff
     ;; ("\\(\\?\\)" 1 '( :foreground "#ffff1a"))
     ;; ("\\(@\\)" 1 '(:foreground "#ffeb54"))
     ;; match dash if it happens between numbers
     ;;("\\([0-9]\\)-\\([0-9]\\)" 1 '(:background "#333333" :foreground "grey"))
     ;; ;; match H if it is followed by a number (eg H123)
     ("\\(h[0-9]\\)" 1 '(:background "#333333" :foreground "#47d147"))
     ))))

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.