Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Scala & IntelliJ, show unicode arrows but don't change source-code

Scala allows to use the Unicode characters (\u2190) for <- and (\u21D2) for =>

There are questions with answers on how to replace these characters (e.g. here and here) upon writing and even using post-processing (e.g. scala-style). These solutions however change the actual source-code. This means that if I'm using the Unicode style and my colleague isn't, we'll get a mix of styles in our source-code. Which in turn is something I dislike. (Meaning I'd rather use ASCII style arrows to prevent mixing styles.)

So I'm looking for a way to have a solution in the presentation-layer and not in representation. (like changing number-format using dot or comma for the decimal separator,.. it's not stored differently on disk.)

I'm aware that I could have Git do some funky stuff like it it does with line-endings for Windows, but I don't want to depend on Git for this. I just want IntelliJ (or Eclipse if someone knows how to fix it in Eclipse) to show me the Unicode arrows when it encounters the ASCII character version (preferably at the appropriate place, i.e. pattern-matching and for-comprehension).

Is this even possible in editors like IntelliJ and Eclipse? I'm willing to do some digging and writing plugins etc., but I'd rather not if it's not needed.

like image 862
mhogerheijde Avatar asked Nov 16 '15 09:11

mhogerheijde


2 Answers

Since posting the question, IntelliJ has added native support to view arrows as if they are 1 character (called ligatures apparently).

From their whats new page:

We've added support for monospace font ligatures. To enable ligatures, go to Settings → Editor → Colors & Fonts → Font, choose a font that supports ligatures, e.g. FiraCode, Hasklig, Monoid or PragmataPro and select Enable font ligatures option.

like image 135
mhogerheijde Avatar answered Sep 28 '22 02:09

mhogerheijde


If you want to see the lambdas as an arrow you can use the IDE settings. I will go to IntelliJ Editor settings -> background, now enable the option "Enable ligatures".

Enable ligatures

like image 22
andreshincapier Avatar answered Sep 28 '22 01:09

andreshincapier