Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What would it take to get ligatures working in emacs? #42

Open
ticviking opened this issue Aug 21, 2015 · 23 comments
Open

What would it take to get ligatures working in emacs? #42

ticviking opened this issue Aug 21, 2015 · 23 comments

Comments

@ticviking
Copy link

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.

@tonsky
Copy link
Owner

tonsky commented Aug 27, 2015

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

@tonsky
Copy link
Owner

tonsky commented Oct 18, 2015

Check this out though https://github.com/tonsky/FiraCode/wiki/Setting-up-Emacs

@weavejester
Copy link

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.

@minimal
Copy link

minimal commented Nov 9, 2015

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). minimal/emacs@812dd51

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.

@tonsky
Copy link
Owner

tonsky commented Nov 9, 2015

Ok, I’m not an emacs user, so I don’t really understand what’s going on. I put a link to this issue to the wiki page with Emacs setup instruction

@falood
Copy link

falood commented Dec 23, 2015

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

@RadicalZephyr
Copy link

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

@glyph
Copy link

glyph commented May 13, 2016

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

@emmanueltouzery
Copy link

emmanueltouzery commented Jul 23, 2016

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.

@emmanueltouzery
Copy link

emmanueltouzery commented Jul 24, 2016

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.

@ghost
Copy link

ghost commented Aug 8, 2016

@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.

@emmanueltouzery
Copy link

emmanueltouzery commented Aug 8, 2016

@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!

@ghost
Copy link

ghost commented Aug 8, 2016

@emmanueltouzery

@mordocai said:

But it is not working for me

;(

@emmanueltouzery
Copy link

Ah yes sorry, misread you

@ghost
Copy link

ghost commented Aug 8, 2016

@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.

@ghost
Copy link

ghost commented Aug 8, 2016

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.

@ghost
Copy link

ghost commented Aug 11, 2016

I got this working over here: #211 (comment)

@benbot
Copy link

benbot commented Dec 28, 2018

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

@RadicalZephyr
Copy link

RadicalZephyr commented Dec 28, 2018

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]))))

@To1ne
Copy link

To1ne commented Dec 28, 2018

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

@equwal
Copy link

equwal commented Nov 24, 2019

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.

@boystrange
Copy link

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.

@To1ne
Copy link

To1ne commented Dec 30, 2019

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.

Losangelosgenetics pushed a commit to Losangelosgenetics/FiraCode that referenced this issue Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests