turbo icon indicating copy to clipboard operation
turbo copied to clipboard

handle indentation properly when saving

Open amay5267 opened this issue 2 years ago • 1 comments

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

amay5267 avatar Aug 13 '22 15:08 amay5267

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:

  • Please make sure you are using current master (05e6014f0e0d6e66b4498ceb3b0b70fdb353daf4) and not an older version of Turbo.
  • If you still experience the issue you described, please share a screen recording showing it.

Cheers.

magiblot avatar Aug 13 '22 21:08 magiblot

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 » ?

amay5267 avatar Oct 13 '22 10:10 amay5267

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", "");

magiblot avatar Oct 13 '22 13:10 magiblot

Thanks for the hint. Perfect!

amay5267 avatar Oct 13 '22 14:10 amay5267