Replace words main and return

Hi everyone. I’m struggling with this for few hours now and I need your help since I can not figure it out.

I’m trying to create font for PyCharm which will do the following:

  • replace main( with (
  • replace main ( with (
  • remove/hide return

Please help. I’ve found out today about all this stuff and I need as much info as possible. I’m not sure if I understand the difference between different replacements so which feature do I need to put in all this stuff?

Problem I’m facing is that everything works in Glyphs app and Font Book, but I does not work in PyCharm and I have no idea what I’m doing wrong :frowning:

I’ve tried following:
sub m a i n parenleft by parenleft;
sub m a i n space parenleft by parenleft;

Have no idea what to try for return.

Thanks in advance :slight_smile:

Three things: misrepresenting user input is not what OpenType features are for, not every character is represented with a glyph from the font (especially space and newline), and not every app supports OpenType features. PyCharm may be one of those apps.

Question: why would you want such a substitution in the first place?

Even if the feature is functional in the intended app, the user input, the actual code, remains the same, and you are only changing how it looks (not actually altering the text). OpenType is not a spell check.

SublimeText doesn’t handle OpenType either.

@mekkablue @Tosche

I do not want to change the user input since that would break the code syntax and make it invalid. I just want to change the visual representation so the syntax would look cleaner and follow out new guidelines.

Is there a way to check for sure that PyCharm does not support this OpenType feature or to do this? A I saw PyCharm supports all ligatures from Fira Code font which has some similar substitutions like for !=, ==, etc…

If main( will look identical to ( then I will have serious problem reading the code though. I am still not supporting the idea. It’s not like connecting two equal signs.

If Fira Code’ ligatures work in PyCharm, then it might be just a font issue. It may be a font cache issue though. If it’s working in FontBook, you may need to just restart PyCharm.

@Tosche that is what I’m trying to test to see if it will look better or worse.

I’ve always restarted it but nothing helped. Is there any app that I can assert that it works and then conclude that it is the PyCharm’s issue?

Could you please provide me with details how to do this so I can test it?

Check https://www.glyphsapp.com/tutorials/eliminating-font-cache-problems

@GeorgSeifert But this is for system cache problem if I’m correct? Since it’s always working in Font Book I guess it’s not system font cache problem but issue with PyCharm.

Font Book is the system.

@GeorgSeifert But since it’s working in Font Book there is no need to clear the cache. Right?

No. Font Book (or system behind it) is causing the cache problems.

@GeorgSeifert OK. Now I understand what you are trying to say. If I export a font with a new name will that help me avoid the cache issue/problem so I do not have to restart my computer all the time since that is very time consuming?

Please read the tutorial:

OpenType substitutions only exchange glyphs (=what you see), not characters (=what you type). You would not be changing the user input, you would be misrepresenting it: The user will not see what he or she typed.

Still not sure what you are trying to achieve, but it does not appear to make much sense in this case to substitute glyphs with a Unicode with another glyph with a Unicode value.

@mekkablue OK. Let me give you a real world example.

When I’m looking at someone’s code like for example JavaScript some syntax looks ugly to my eyes since I’ve switched to ES6.

country: function () {
    return this.user.country;
}

I would like it to be

country: () {
    this.user.country
}

or

country() {
    this.user.country
}

Ideally it would be

country: () => this.user.country

This is not something that anyone but me would use (or any other freak like me) so I do not think about how it’s going to affect the users of that font.

It’s just a quick solution which will serve as a proof of concept which requires time to test out before starting on a new compiler.

I don’t think at all that you should try to achieve this with OT feature code or the font itself. The glyph substitutions in Fira Code you were referring to, are an entirely different thing than your recently posted example.

If you really want to replace text, you should probably consider creating snippets (those can replace or add text based on your input as a trigger. Those have nothing to do with the font itself (and never will).

Or if the text was already typed and you want to change it, use find and replace, or create a tool with regular expressions.

@Mark that is the thing, I do not want to change other’s people code. Just want a cleaner syntax for me. Since no one wants to help I will have to drop this idea since I have no time to research to that extent. Also there is not much about this topic on Google.

Yes I also think that this is not a good task for OT Features. In your case, the main problem is that anything that involves spaces and CR/LF is not reliable in OT substitutions, so I would rather look for an option on the app level. I don’t know the app you mentioned, but I am thinking of the code folding in apps like TextMate.

OK. Now this is a problem I do understand. But even without the space it is not working?

Yes, there are several levels where it is likely to fail. The OT support built into the app is already an uncertainty factor. Then even if there is support, it is unlikely that certain things may work. And separator characters are very likely candidates in that case.

@mekkablue is there any reason why it would not want to replace a sequence of characters followed by a symbol at the end? Since it can replace word return without a problem.