magiblot / turbo

An experimental text editor based on Scintilla and Turbo Vision.
Other
466 stars 36 forks source link

handle indentation properly when saving #32

Closed amay5267 closed 1 year ago

amay5267 commented 2 years ago

Hi Can Turbo handle tab indentation properly at saving? Please take a closer look at aabb.cc example. It was written with indentation 4. It opens correctly in Turbo but when saving it converts my 1 tab 4 spaces indentation to actual 4 empty spaces. Some people use tab indentation 2 or even indentation 8.

As a workaround I use bcpp utillity which can hadle indentation properly. Is there any easy fix or can we merge bcpp into Turbo?

https://invisible-island.net/bcpp/ aabb.zip

magiblot commented 2 years ago

Hi @amay5267!

Although the aabb.cc file was written so that it looks good with indentation 4, it uses tab characters (ASCII 0x09) instead of space characters (ASCII 0x20).

Tab characters do not have a specific width. It depends on the text editor to display them as 2, 4, 8, etc. columns wide. Therefore, either the user has to tell the editor which indentation width should be used for tab characters, or the editor has to inspect the source code in order to guess the indentation it was written with.

Currently, Turbo does not allow you specify a width for tab characters (it's always 8), it does not allow you to indent text with tab characters (the Tab key always inserts spaces, with indentation 4), and it is unable to auto-detect indentation width. Furthermore, when you select text already indented with tab characters (such as in aabb.cc) and press Tab or Shift+Tab (in order to indent or unindent the selection), these tabs are replaced with spaces.

These are the things an ideal text editor would do but Turbo doesn't. Therefore, all problems related to tabs vs. spaces should be gone after implementing these missing features, but I can't promise anything with regards to this.

However, you mention Turbo converting tab characters into spaces when saving. This is not the behaviour I would expect, and it is not the behaviour I see in current master (05e6014f0e0d6e66b4498ceb3b0b70fdb353daf4). Thus, I ask you:

Cheers.

amay5267 commented 1 year ago

Hi @magiblot

OK. If you open my aabb.cc sample you will see tabs represented by Right-Pointing Double Angle Quotation Mark. Unicode Character “»” (U+00BB). I think it is kind of annoying. No one needs that. How can I disable seeing this » ?

magiblot commented 1 year ago

Hi @amay5267.

That symbol is there so that you can easily distinguish between spaces and tabs, and there are several other text editors which also have this feature (Kate, Midnight Commander, Tilde...).

I think this is especially relevant in Turbo since it currently doesn't support indenting text with anything other than spaces. Therefore, as I see it, it would be frustrating to mix spaces and tabs and not being able to see where tabs are. That's why this is the default.

But I absolutely agree that this behaviour should be customizable. However, customization is also not yet supported. Therefore, all you can do at the moment is to edit line 41 of source/turbo-core/tscintilla.cc like this:

-        reprs.SetRepresentation("\t", "»        ");
+        reprs.SetRepresentation("\t", "");
amay5267 commented 1 year ago

Thanks for the hint. Perfect!