Firacode: What would it take to get ligatures working in emacs?

Created on 21 Aug 2015  路  23Comments  路  Source: tonsky/FiraCode

I'm doing a lot of F# in emacs lately and find that I'd love to have this on my emacs like I do in Visual Studio.

I'm mostly looking for a starting point to work out what I would need to do to get the ball rolling myself.

Most helpful comment

So I haven't figured out the correct code points yet (is there a list somewhere? I didn't see it) but after you know them you just need to fill them in with the correct character sequences like this:

https://gist.github.com/mordocai/9fee3227d32c1945dccd8adb9ed03c55

If anyone can help me with the code points then I'll update the wiki once I confirm it works.

All 23 comments

AFAIK, Emacs does not support ligatures. There鈥檙e plugins to do substitution on presentation level though, so you can replace some sequences to unicode symbols

Not sure where the best place to report this is, but one of the lines in the Emacs workaround seems to cause Emacs to hang at 100% when connecting Cider, and produces the error:

error in process filter: Attempt to shape unibyte text

The offending line is:

(46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=]\\)")

Comment that out and everything works fine. The regexp looks pretty innocuous to me, but perhaps one of the buffers opened by Cider is causing an edge condition that makes it take a long time to match.

Should I open a new issue for this? This workaround isn't officially part of Fira Code, really, so I'm uncertain whether I should.

Edit: I believe this post addresses the bug directly.

I encountered the Attempt to shape unibyte text problem last week and found that the initial code from Yamamoto Mitsuharu on the mailing list was later fixed up into a nice elisp function and some changes to the C code to stop the error. The latest version of the mac port should be working and ligatures can be activated with mac-auto-operator-composition-mode. The commit is at https://github.com/railwaycat/mirror-emacs-mac/commit/e7a046987d66136da55ae10a9ef90728d1442cbb
Release email: https://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00882.html

Since I'm running emacs 25 pre-release and my config doesn't work with 24.5, I patched emacs HEAD with the relevant code from the above commit and recompiled (I pointed homebrew emacs at my github). https://github.com/minimal/emacs/commit/812dd5119645a09bc025a9dddedad9474d12ecb6

I pasted the elisp into my config so i can enable and disable the ligatures easily and it's been working great ever since. https://github.com/railwaycat/mirror-emacs-mac/commit/e7a046987d66136da55ae10a9ef90728d1442cbb#diff-3b589fe753801617f11a90443057ef7eR483

This is all mac centric, don't know what the story is on other platforms.

Ok, I鈥檓 not an emacs user, so I don鈥檛 really understand what鈥檚 going on. I put a link to this issue to the wiki page with Emacs setup instruction

What should I do to ligature ~> and <~, please?

The patch linked above doesn't apply cleanly to the emacs 24.5 distribution tarball. I've modified the patch slightly to accommodate the differences. I've built emacs with this patch on both linux and OS X and it seems to work fine and also fix the infinite loop issue.

unibyte.diff.txt

158 is a more specific bug for the hang, I think

While I can get fira code to work normally in my emacs on linux, I can't get ligatures to display (tried with firacode 1.200 OTF on emacs 25.0.95.1 and 24.5.1, using https://github.com/tonsky/FiraCode/wiki/Setting-up-Emacs). I read in this bugtracker that emacs on osx was patched to support ligatures so I wonder... Are the ligatures working only in emacs OSX, with no way to get it to work on linux short of patching and rebuilding emacs?
And if that is required, anybody knows where are the patches for emacs OSX, so I could apply them on linux too?

_EDIT_: I've built this emacs version from source: https://bitbucket.org/mituharu/emacs-mac (version 5.18) on linux, and even with that version and the "Setting up Emacs" setup, I still don't get ligatures.

I've googled some more and stumbled on that email thread:
http://emacs.1067599.n5.nabble.com/otf-ligature-rendering-support-td345082.html

"Actually the mac-ct font backend driver, which is used in the NS port as well as the Mac port, already supports ligatures. So I tried to activate the use of ligatures with the setting"

So for now I think the ligatures only work in the OSX version of emacs, when running on mac. Please correct me if I'm wrong.

@emmanueltouzery I didn't do as deep research as you did. But it is not working for me on emacs on linux even with the settings in the "Setting up emacs" wiki page.

@mordocai really? With ligatures? Which distribution is that? Or self-built emacs? No way i could get it to eork on linux. Glad if it's possible!

@emmanueltouzery

@mordocai said:

But it is not working for me

;(

Ah yes sorry, misread you

@emmanueltouzery I'm looking at trying https://www.reddit.com/r/emacs/comments/4sm6fa/how_to_enable_pragmatapro_ligatures/ for fira code. Specifically https://gist.github.com/DeLaGuardo/fe1f3d9397d6ef7468460d54d5601156 but I need to figure out what numbers I need to plug in.

Edit: This does look like it works fine but I haven't yet figured out what codepoints to map to.

So I haven't figured out the correct code points yet (is there a list somewhere? I didn't see it) but after you know them you just need to fill them in with the correct character sequences like this:

https://gist.github.com/mordocai/9fee3227d32c1945dccd8adb9ed03c55

If anyone can help me with the code points then I'll update the wiki once I confirm it works.

I got this working over here: https://github.com/tonsky/FiraCode/issues/211#issuecomment-239087391

Can someone who still has his snippet post it again? Unfortunately he deleted his account :(

I think you're referring to this @benbot?

(let ((alist '((33 . ".\\(?:\\(?:==\\|!!\\)\\|[!=]\\)")
               (35 . ".\\(?:###\\|##\\|_(\\|[#(?[_{]\\)")
               (36 . ".\\(?:>\\)")
               (37 . ".\\(?:\\(?:%%\\)\\|%\\)")
               (38 . ".\\(?:\\(?:&&\\)\\|&\\)")
               (42 . ".\\(?:\\(?:\\*\\*/\\)\\|\\(?:\\*[*/]\\)\\|[*/>]\\)")
               (43 . ".\\(?:\\(?:\\+\\+\\)\\|[+>]\\)")
               (45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)")
               (46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=-]\\)")
               (47 . ".\\(?:\\(?:\\*\\*\\|//\\|==\\)\\|[*/=>]\\)")
               (48 . ".\\(?:x[a-zA-Z]\\)")
               (58 . ".\\(?:::\\|[:=]\\)")
               (59 . ".\\(?:;;\\|;\\)")
               (60 . ".\\(?:\\(?:!--\\)\\|\\(?:~~\\|->\\|\\$>\\|\\*>\\|\\+>\\|--\\|<[<=-]\\|=[<=>]\\||>\\)\\|[*$+~/<=>|-]\\)")
               (61 . ".\\(?:\\(?:/=\\|:=\\|<<\\|=[=>]\\|>>\\)\\|[<=>~]\\)")
               (62 . ".\\(?:\\(?:=>\\|>[=>-]\\)\\|[=>-]\\)")
               (63 . ".\\(?:\\(\\?\\?\\)\\|[:=?]\\)")
               (91 . ".\\(?:]\\)")
               (92 . ".\\(?:\\(?:\\\\\\\\\\)\\|\\\\\\)")
               (94 . ".\\(?:=\\)")
               (119 . ".\\(?:ww\\)")
               (123 . ".\\(?:-\\)")
               (124 . ".\\(?:\\(?:|[=|]\\)\\|[=>|]\\)")
               (126 . ".\\(?:~>\\|~~\\|[>=@~-]\\)")
               )
             ))
 (dolist (char-regexp alist)
   (set-char-table-range composition-function-table (car char-regexp)
                         `([,(cdr char-regexp) 0 font-shape-gstring]))))

@benbot I've placed all info on the wiki. But please let me know if that's not working for you.

This bug appears to have nothing to do with Cider mode. I was able reproduce it when using Magit to work on this large file. Commenting out the line is insufficient to fix it in this case.

I have written a little program that automatically generates the composition char table for Fira Code. I used it to update the above table to Fira Code 2, see https://github.com/boystrange/EmacsFiraCode

I'd be happy to update the instructions with the workaround if you feel it's worth it.

I have been using https://github.com/johnw42/fira-code-emacs, it uses Fira Code 2.0. Although in some modes I am getting the wrong ligatures.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hatched picture hatched  路  3Comments

whatisaphone picture whatisaphone  路  3Comments

Gang-Yang picture Gang-Yang  路  3Comments

pamu picture pamu  路  3Comments

mlajtos picture mlajtos  路  4Comments