Please improve the handling of TAB characters in the DWC editor
-
@dc42 said in Please improve the handling of TAB characters in the DWC editor:
@zapta IMO it makes no sense to have tabs positions set to every 8 columns in an editor.
It seems that this is this forum system also assumes 8 chars per tab
Non indented Indented by a single tab
And the preview is rendered like this
The ambiguity of the tab character is especially problematic with languages such as RRF gcode whose semantic depends on indentation. That is for example why RRF complains about the code below because it mixes spaces and tabs in the same nested block
if 1 < 2 if 1 < 2 ; indented by two spaces echo "aaa" ; indented by a single tab
Sticking to spaces eliminate this ambiguity.
-
@zapta said in Please improve the handling of TAB characters in the DWC editor:
Sticking to spaces eliminate this ambiguity.
Sticking to tabs also eliminates it; but many people using programming languages that use indentation to indicate block scope prefer to use only spaces.
-
@dc42 said in Please improve the handling of TAB characters in the DWC editor:
Sticking to tabs also eliminates it;
I don't see how it will eliminate the ambiguity, since the tab character doesn't have a standard interpretation and editors use 2, 4 or 8 positions.
@dc42 said in Please improve the handling of TAB characters in the DWC editor:
many people using programming languages that use indentation to indicate block scope prefer to use only spaces.
I wonder if this is the case. For example, python is a popular indentation sensitive language and its official style guide says "Spaces are the preferred indentation method".
https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces,
The Tab character used to have a single agreed upon interpretation (moving to next 8 positions column) but over the years people came with their own interpretations to the point that it's common these days to avoid it all together.
BTW, this became an issue with DWC when conditional gcode was introduced. Before that we didn't use to indent.
-
@zapta said in Please improve the handling of TAB characters in the DWC editor:
I don't see how it will eliminate the ambiguity, since the tab character doesn't have a standard interpretation and editors use 2, 4 or 8 positions.
Because for the purposes of indenting command blocks, all that matters is how many tabs you have at the start of the line; and it doesn't matter whether those tabs are displayed as 4, 8 or some other nonzero number of characters.
-
@dc42 said in Please improve the handling of TAB characters in the DWC editor:
it doesn't matter whether those tabs are displayed as 4, 8 or some other nonzero number of characters.
4 vs 8 will render the indentation differently to the user, right? Is this is why you warn if the same IF block contains both tabs and spaces? Because of the potential ambiguity?
-
@zapta said in Please improve the handling of TAB characters in the DWC editor:
4 vs 8 will render the indentation differently to the user, right? Is this is why you warn if the same IF block contains both tabs and spaces? Because of the potential ambiguity?
Yes and yes. It's only the indentation characters that need to be all spaces or all tabs so as to show the correct block scope in any editor. It doesn't matter whether the end-of-line comment is preceded by tabs, space, or a mixture - but of course if tabs are used, the editor tab setting will affect where the comment is displayed.
I usually use 2 spaces to indent a conditional GCode block, and tabs to place the end-of-line comments.
-
Today I learned that DWC inserts tabs even if I don't use the tab key.
To reproduce:
- Start with a command indented by four spaces.
<four spaces>G1
- Position the cursor at the end of the line, press Enter, and type the second command, e.g. G2. Notice how the second line is indented with a single tab rather than four spaces.
<four spaces>G1 <tab>G2
It seems that DWC not only supports tabs but actually prefers them over spaces.
-
@zapta Yep I've also noticed it does this (and it is very irritating!).
Having to deal with files that contain mixed tabs/spaces for indentation is a personal bugbear of mine and creating them is in my view a terrible crime (though not as bad as the folks that reformat entire files to fit in with "the one true way" that they think the layout should look!). For many years now I've tried to practise (not always successfully!) an approach of using whatever style the original author has been using when making changes to existing source code. Personally I'd prefer to have some sort of option to use spaces for indentation (and to use the tab key to generate that indentation rather then insert a tab character), which is common in many other editors. Even better (IMHO) would be to have it auto adjust based on the exiting style(like some more advanced editors try to do, sometimes it works!).
-
@zapta I've asked @chrishamm to look into this.
-
@dc42 said in Please improve the handling of TAB characters in the DWC editor:
@zapta I've asked @chrishamm to look into this.
Thanks.