Conflict of multiple greater ligature >>
/ >>>
#275
subframe7536
started this conversation in
Ideas
Replies: 1 comment
-
Wow, I must say that I'm really impressed at the lengths you're going to to make such a versatile font. This level of attention to detail and listening to feedback is awesome. Like you say, most would just provide an option to disable the ligature and call it a day. I'm very happy to have found this typeface. Great work :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Introduction
There exists a long-standing conflict in programming font ligatures:
>>
. I searched through most popular open-source monospace fonts' GitHub repositories, and in their issues, there is always at least one open issue complaining about>>
ligature. Further responses are rare, or just provide a style set to disable it.Conflict
In my experience, there exist two kinds of usages of
>>
:>>
is a bitwise operator, starting or ending with a number or variable, and the language formatter often inserts a space between the operator and number/variable.Typescript
,Java
,Rust
) or template (C++
) is often used for powerful DX improvements and provides compile-time safety. In some complex use cases,>>
is part of the end symbol, likeArray<Partial<T>>
.The main conflict is that if the ligature is enabled, the space between two
>
is reduced for beauty, but at the same time,>
inArray<Partial<T>>
will also be squeezed, and the balance between<
and>
is broken, see details in #233.It will also render wrong syntax highlighting if you are using VSCode bracket pair colorization, like this Fira Code issue
History
V5 and V6
Before V6, I lacked coding experience and was struggling with exploring algorithms and design patterns. I had little time to deeply consider this issue. So I just followed the mainstream ways on ligature designation except for some unbearable parts.
V7 Beta 28 and 29
Issue #233 reminded me of this conflict, so I started to rethink the solution.
I presumptuously thought that everyone who replaced their default font with a programming font with ligatures would care about code formatting, so I simply changed the ligature rule to require that
<<
/<<<
should have a trailing space and>>
/>>>
should have a leading space, and setss07
to disable them in V7 Beta28. But in fact, in this part, the font itself should not be opinionated, or at least, it should be a configurable option. Also,<<
/>>
is more commonly used than<<<
/>>>
from my experience, so the limitations on<<
and>>
were removed in V7 Beta29.It works, but not so well.
Make it "smarter"
AFAIK, there is nothing like AI to make the font ligature "smart", not even a concept like Regular Expression. Ligatures are just "if-else" rules that make the font render engine efficiently match and replace the glyphs. Everything is "if-else" and hard-coded. So, the font ligature cannot be a perfect solution for all usages of
>>
.So, I searched the use cases for
>>
in grep.app and listed the most common cases here:Enable Cases:
1>>1
/1 >>1
/1>> 1
/1 >> 1
1>>>1
/1 >>>1
/1>>> 1
/1 >>> 1
a>>1
/a>>b
/a1>>_var
/2>>$jsVar
Disable Cases:
Solution
So, I have to make a trade-off for the usages of
>>
since they are quite different. I finally chose to make generic type/template as the first-class support, based on my experience. I tried to make the ligature rule more context-sensitive: if>>
has a leading variable or trailing symbol, the ligature will be disabled.During this period, I encountered some things that I had not considered before, such as in VSCode, the Unicode of space is
0020
when copying, but it is00A0
(non-breaking space) when displaying, which caused some rules to not take effect.Result:
Exception
Although the ligature rules are context-sensitive, there are some exceptions due to the limitation of the render engine or the conflict of usages of
>>
:a>> b
) and generic type onimplements
(class A<T extends Partial<Obj>> implements B
).<<Bin/binary, 0>>.
inErlang
andICollection<KeyValuePair<Key, Value>>.Property
inC++
/C#
.Make it "normal"
In V7 Beta30, you can disable the ligature rule by enabling the
ss07
feature.Conclusion
The ligature conflict of
>>
is a long-standing problem in programming font ligatures. To solve this conflict, I have to make a trade-off between the usages of>>
as operator and generic type/template. My solution is to make the ligature rule more context-sensitive, and it is not perfect. But I believe that this solution is better than the previous ones in most cases.If you have any suggestions or thoughts, feel free to leave a comment.
Beta Was this translation helpful? Give feedback.
All reactions