Create a gist now

Instantly share code, notes, and snippets.

@mordocai /init.el
Last active Mar 18, 2017

Fira code symbols in emacs. You need to grab the Fira Code Symbol font for this to work. https://github.com/tonsky/FiraCode/files/412440/FiraCode-Regular-Symbol.zip
;;; Fira code
;; This works when using emacs --daemon + emacsclient
(add-hook 'after-make-frame-functions (lambda (frame) (set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")))
;; This works when using emacs without server/client
(set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")
;; I haven't found one statement that makes both of the above situations work, so I use both for now
(defconst fira-code-font-lock-keywords-alist
(mapcar (lambda (regex-char-pair)
`(,(car regex-char-pair)
(0 (prog1 ()
(compose-region (match-beginning 1)
(match-end 1)
;; The first argument to concat is a string containing a literal tab
,(concat " " (list (decode-char 'ucs (cadr regex-char-pair)))))))))
'(("\\(www\\)" #Xe100)
("[^/]\\(\\*\\*\\)[^/]" #Xe101)
("\\(\\*\\*\\*\\)" #Xe102)
("\\(\\*\\*/\\)" #Xe103)
("\\(\\*>\\)" #Xe104)
("[^*]\\(\\*/\\)" #Xe105)
("\\(\\\\\\\\\\)" #Xe106)
("\\(\\\\\\\\\\\\\\)" #Xe107)
("\\({-\\)" #Xe108)
("\\(\\[\\]\\)" #Xe109)
("\\(::\\)" #Xe10a)
("\\(:::\\)" #Xe10b)
("[^=]\\(:=\\)" #Xe10c)
("\\(!!\\)" #Xe10d)
("\\(!=\\)" #Xe10e)
("\\(!==\\)" #Xe10f)
("\\(-}\\)" #Xe110)
("\\(--\\)" #Xe111)
("\\(---\\)" #Xe112)
("\\(-->\\)" #Xe113)
("[^-]\\(->\\)" #Xe114)
("\\(->>\\)" #Xe115)
("\\(-<\\)" #Xe116)
("\\(-<<\\)" #Xe117)
("\\(-~\\)" #Xe118)
("\\(#{\\)" #Xe119)
("\\(#\\[\\)" #Xe11a)
("\\(##\\)" #Xe11b)
("\\(###\\)" #Xe11c)
("\\(####\\)" #Xe11d)
("\\(#(\\)" #Xe11e)
("\\(#\\?\\)" #Xe11f)
("\\(#_\\)" #Xe120)
("\\(#_(\\)" #Xe121)
("\\(\\.-\\)" #Xe122)
("\\(\\.=\\)" #Xe123)
("\\(\\.\\.\\)" #Xe124)
("\\(\\.\\.<\\)" #Xe125)
("\\(\\.\\.\\.\\)" #Xe126)
("\\(\\?=\\)" #Xe127)
("\\(\\?\\?\\)" #Xe128)
("\\(;;\\)" #Xe129)
("\\(/\\*\\)" #Xe12a)
("\\(/\\*\\*\\)" #Xe12b)
("\\(/=\\)" #Xe12c)
("\\(/==\\)" #Xe12d)
("\\(/>\\)" #Xe12e)
("\\(//\\)" #Xe12f)
("\\(///\\)" #Xe130)
("\\(&&\\)" #Xe131)
("\\(||\\)" #Xe132)
("\\(||=\\)" #Xe133)
("[^|]\\(|=\\)" #Xe134)
("\\(|>\\)" #Xe135)
("\\(\\^=\\)" #Xe136)
("\\(\\$>\\)" #Xe137)
("\\(\\+\\+\\)" #Xe138)
("\\(\\+\\+\\+\\)" #Xe139)
("\\(\\+>\\)" #Xe13a)
("\\(=:=\\)" #Xe13b)
("[^!/]\\(==\\)[^>]" #Xe13c)
("\\(===\\)" #Xe13d)
("\\(==>\\)" #Xe13e)
("[^=]\\(=>\\)" #Xe13f)
("\\(=>>\\)" #Xe140)
("\\(<=\\)" #Xe141)
("\\(=<<\\)" #Xe142)
("\\(=/=\\)" #Xe143)
("\\(>-\\)" #Xe144)
("\\(>=\\)" #Xe145)
("\\(>=>\\)" #Xe146)
("[^-=]\\(>>\\)" #Xe147)
("\\(>>-\\)" #Xe148)
("\\(>>=\\)" #Xe149)
("\\(>>>\\)" #Xe14a)
("\\(<\\*\\)" #Xe14b)
("\\(<\\*>\\)" #Xe14c)
("\\(<|\\)" #Xe14d)
("\\(<|>\\)" #Xe14e)
("\\(<\\$\\)" #Xe14f)
("\\(<\\$>\\)" #Xe150)
("\\(<!--\\)" #Xe151)
("\\(<-\\)" #Xe152)
("\\(<--\\)" #Xe153)
("\\(<->\\)" #Xe154)
("\\(<\\+\\)" #Xe155)
("\\(<\\+>\\)" #Xe156)
("\\(<=\\)" #Xe157)
("\\(<==\\)" #Xe158)
("\\(<=>\\)" #Xe159)
("\\(<=<\\)" #Xe15a)
("\\(<>\\)" #Xe15b)
("[^-=]\\(<<\\)" #Xe15c)
("\\(<<-\\)" #Xe15d)
("\\(<<=\\)" #Xe15e)
("\\(<<<\\)" #Xe15f)
("\\(<~\\)" #Xe160)
("\\(<~~\\)" #Xe161)
("\\(</\\)" #Xe162)
("\\(</>\\)" #Xe163)
("\\(~@\\)" #Xe164)
("\\(~-\\)" #Xe165)
("\\(~=\\)" #Xe166)
("\\(~>\\)" #Xe167)
("[^<]\\(~~\\)" #Xe168)
("\\(~~>\\)" #Xe169)
("\\(%%\\)" #Xe16a)
;;("\\(x\\)" #Xe16b)
("[^:=]\\(:\\)[^:=]" #Xe16c)
("[^\\+<>]\\(\\+\\)[^\\+<>]" #Xe16d)
("[^\\*/<>]\\(\\*\\)[^\\*/<>]" #Xe16f))))
(defun add-fira-code-symbol-keywords ()
(font-lock-add-keywords nil fira-code-font-lock-keywords-alist))
(add-hook 'prog-mode-hook
#'add-fira-code-symbol-keywords)
@dagit
dagit commented Sep 24, 2016 edited

Thanks! This seems to be working for me on Emacs 25 + Windows.

Edit: Actually, I just discovered this interferes with some modes like Rust's racer mode (which offers smart completetions). Any idea how to fix that?

@voltecrus

This doesnt work for me on darwin and emacs 25.1. Characters overlap, rendering depends on the (point) position, etc.

@tomterl
tomterl commented Oct 17, 2016 edited

Doesn't work for me either, sadly, Ubuntu 16.04, emacs 25.1, same observations as @voltecrus
Doh - I forgot to install the symbol font... dealing with misaligned symbols now, but since you got that fixed, I'll try to follow :) thanks for the work that went into this!

Wow! Found my problem: The literal tabulator (first arg of the concat call) is lost during tangling of my emacs-config (an org-mode file); I have to find a way to protect it; but fixing it after tangling fixes the ligatures -- very nice indeed.

Edit: After updating org-mode, the tab stays a literal tab

@fbie
fbie commented Oct 27, 2016

Thanks, works great for me! I got really tired of Emacs freezing at seemingly random times. Did you consider putting the code on MELPA as a minor mode?

@thegeorgeous
thegeorgeous commented Nov 14, 2016 edited

Works on darwin, but certain symbols have alignment/positioning bugs. For example :: appears little too close to the character on the left while keeping a significant space on the right

@jappeace

For this to work on gentoo you need to enable the xft use flag. I also didn't get "Fira Code Symbol" to work so I replaced that with "Fira Code". And in spacemacs don't forget to update your spacemacs font setting.

@jilen
jilen commented Feb 4, 2017

Works perfectly

@dl1ely
dl1ely commented Feb 11, 2017

Works perfectly in Emacs 25.1 on Windows with spacemacs! Thank you very much!

@SavchenkoValeriy

In Emacs 25.1 on Ubuntu, I ended up with overlapping symbols.
fira-code-symbol

@pdawczak
pdawczak commented Mar 6, 2017 edited

UPDATE: The description below is no longer a case. What worked for me, was to install emacs-mac, and use (mac-auto-operator-composition-mode).

Hey!

I'm afraid I'm experiencing some problems as well - the special chars are displayed, but they seem misaligned:

2017-03-06_1200

On the screenshot there was "Fira Code Retina" used, but I've also tested that with "Regular" and the problem was the same.

I'm using spacemacs, with default font configured as:

   dotspacemacs-default-font '("Fira Code"
                               :size 13
                               :weight normal
                               :width normal
                               :powerline-scale 1.1)

It's Emacs Version 24.5 (9.0) with spacemacs on MacOS.

Do you have any suggestions what might be causing this issue?

Many thanks!

@deathmaz

Works great for me, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment