TIC-80
TIC-80 copied to clipboard
Tab vs Spaces in code editor
Currently it is impossible to distinguish between tab and space in code editor.
Tabs are represented by one character indent. Moonscript syntax is based on whitespace and if the tabs is mixed with whitespace the moonscript doesn't work correctly. (The syntax is usually broken)
I think the tabs in code editor should be automatically converted to one or more spaces.
Make an option for config to draw whitespace characters if that helps, dot for space and line/dash for tab (also without shadows of course, and that you can change the color).
Though IMO I don't want it to convert tabs into spaces by default.
You can already kind of do this, but this would ruin the GUI and in-game gameplay. (Space and tab symbols should be in BG then.)
jahodfra, a tab is a whitespace character.
@planer28 Is that anyhow related to the problem?
@AnastasiaDunbar I don't see why converting tab into space in code editor would break anything. Of course we would have to convert even content from the clipboard.
Another solution is to have displayable character for the tab character. I don't think it is necessary to change the font for space character.
Well, the solution for me is just to always use the tab key for indents. And, you can do that yourself - just open up the config and modify sprite 265 to your liking.
Then you use by accident space for indent and there is no difference in code editor only the cartridge fails and moonscript doesn't even signals on which line the problem is.
Letting everybody crash on this and then advising them to change tab visualization is really unfriendly.
Why? If you change it in the config cartridge and save, the difference should be visible in the code editor. And 2nd, if I were trying to be unfriendly, I wouldn't even reply in the first place.
And converting tabs to spaces would not always work correctly, for example if you wanted to store a memory slice as a string, then all of the 9's (tabs) would be changed into 32's (spaces). A solution to this would be to only replace them at the start of every line, until a different character (a non whitespace character) is met.
I spoke about friendliness to new users of TIC-80. I already know about the problem so I can take strategies to mitigate the problem e.g. editing code outside of TIC-80. I see that anybody using moonscript will eventually hit that. The problem will take couple of hours of energy for any new user. That's what I call unfriendly.
Can you enter any ascii character in code editor? I don't think you can enter characters which don't have associated key on the keyboard. Therefore this case is not really usable even now.
I see couple of solutions:
- In code editor tab can be replaced by 4 spaces.
- In code editor tab can be displayed as 4 spaces.
- There can be special symbol for tabs in code editor.
I would probably vote for 3., but the problem has to be solved in default configuration to mitigate the issue for new users. I'm leaving what should be appropriate solution on @nesbox.
Maybe I can't enter them directly into TIC, but I can enter them into notepad and then copy them into TIC. I've actually used this a few times for adding Polish letters to the font. And as for your solutions - I think there should be a selector for whether you want to have some of these to take place or not - I bet there are some people like me for whom this is not a problem, and who would prefer it to be the way it is now.
@planer28 I see that you dislike 1. solution. How would you be affected by 2. and 3. ?
- Only visual, could be annoying, nothing more to say.
- Same, but I ABSOLUTELY hate seeing actual characters instead of whitespaces.
Tabs can be converted into spaces if the tab indent width is one character (otherwise I'd dislike it) if you're suggesting that we should not print tab characters and drop it from TIC-80? I still feel comfortable with using tabs when I'm copying code from TIC-80 and pasting into my favorite text editor so I can regularly use my tab ident width that I'm comfortable with using, apart from that it would be disappointing to see them converted into spaces automatically for each time I need to transfer it into my text editor.
- There can be special symbol for tabs in code editor.
If spaces are visible as well, otherwise it wouldn't make sense.
Using external editors kinda defeats the point of using a fantasy console. You may as well replace TIC-80 with a library that just implements its API, so you can use external sprite and music editors as well.
At the moment, readability in the builtin code editor is an issue for some users, so there's a good reason for supporting external editors, but once one fantasy console has a workable solution, the others will copy it, and new consoles will never have a reason to support external tools.
If fantasy consoles are the next big thing in retro gaming, somebody will inevitably come up with a better approach (than telling people to use something else) soon, so any solution should be optimised for people using the builtin editors, not external tools. That should apply to Tabs Vs. Spaces too.
Such a PITA for me too. What would you say about config option tabexpand
and tabwidth
? If tabexpand
is set to true
, then every press of tab key will instead put tabwidth
of spaces. The only non-trivial thing here is fixing auto-indent behaviour of editor to produce spaces too.
Let's add Tab size
and Use spaces/tabs
to the config.
Moonscript syntax is based on whitespace and if the tabs is mixed with whitespace the moonscript doesn't work correctly. (The syntax is usually broken).
In Moonscript we could enforce a consistent indentation by showing an error like: "error at line 5: tab used for indentation instead of space" (if space was used for indentation on all previous lines) or "error at line 5: space used for indentation instead of tab" (if tab was used for indentation on all previous lines)
it should convert tab to space in moonscript.
Note that I have added instructions to custom tab character in the wiki configuration file page https://github.com/nesbox/TIC-80/wiki/System-Configuration-Cartridge#custom-tab-character.
@Skeptim do you know what happened to that wiki page?
Yes, it has been renamed to https://github.com/nesbox/TIC-80/wiki/config when I created wikipages for several console commands. Thanks for spotting that!