Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Please improve the handling of TAB characters in the DWC editor

    Scheduled Pinned Locked Moved
    Duet Web Control wishlist
    6
    19
    682
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • zaptaundefined
      zapta @dc42
      last edited by

      @dc42, I gave Vi as a example. I use it to view files I sync to my computer but do all the editing using DWC.

      It's common these days not to rely on the Tab character for indentation (not to be confused with the Tab key which is often a shortcut for indentation). E.g.

      https://insanelab.com/blog/notes/spaces-vs-tabs/

      https://google.github.io/styleguide/cppguide.html#Spaces_vs._Tabs

      Anyway, this is not a show stopper, just a lingering nuisance.

      1 Reply Last reply Reply Quote 0
      • resamundefined
        resam @zapta
        last edited by

        I think we are all aware of the long history and arguments of tab vs. spaces - so let's not rekindle that old war.

        @zapta said in Please improve the handling of TAB characters in the DWC editor:

        DWC inserts tabs characters in the file

        @zapta what do you mean with this statement? Is DWC inserting tabs all by itself, or because you (the user) has pressed the Tab key to indent some code? At the moment this feels like a "you are holding it wrong" kinda argument.

        If you don't want tabs, well, then don't insert any... or what aspect of your UX flow am I missing? Are you asking for DWC to explicitly rewrite gcode files because you "were careless" when editing them with other tools?

        Or are you proposing to make the DWC "editing window" more like a proper IDE / smart editor where you can choose/configure how many spaces should be inserted when pressing the Tab key (instead of inserting an actual tab character)?

        zaptaundefined 1 Reply Last reply Reply Quote 0
        • zaptaundefined
          zapta @resam
          last edited by zapta

          @resam said in Please improve the handling of TAB characters in the DWC editor:

          Are you asking for DWC to explicitly rewrite gcode files because you "were careless" when editing them with other tools?

          I am proposing that DWC will have the common behavior of code editors these days. TAB key as a shortcut for 'indent' and writing spaces only in the files it generates.

          DWC developers can choose the indent size they like to support (I think it's currently 4 but am not sure).

          Baenwortundefined 1 Reply Last reply Reply Quote 0
          • Baenwortundefined
            Baenwort @zapta
            last edited by

            Can those of us who feel that a tab is a tab and a space is a space and I'll well and good press the one I intend get a request also?

            zaptaundefined 1 Reply Last reply Reply Quote 0
            • zaptaundefined
              zapta @Baenwort
              last edited by

              @baenwort, of course, you can.

              And if you also want that pressing the delete key will insert a delete character and pressing the backspace key will insert a backspace character you can ask for it as well.

              😉

              1 Reply Last reply Reply Quote 2
              • zaptaundefined
                zapta @dc42
                last edited by

                @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

                da00ae12-cfa3-4b9f-b9c1-8303b9b8024f-image.png

                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
                

                6ae36eb8-d94e-4c2e-8fc8-7bc3ddbbc5e9-image.png

                Sticking to spaces eliminate this ambiguity.

                dc42undefined 1 Reply Last reply Reply Quote 0
                • dc42undefined
                  dc42 administrators @zapta
                  last edited by

                  @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.

                  Duet WiFi hardware designer and firmware engineer
                  Please do not ask me for Duet support via PM or email, use the forum
                  http://www.escher3d.com, https://miscsolutions.wordpress.com

                  zaptaundefined 1 Reply Last reply Reply Quote 1
                  • zaptaundefined
                    zapta @dc42
                    last edited by zapta

                    @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.

                    dc42undefined 1 Reply Last reply Reply Quote 0
                    • dc42undefined
                      dc42 administrators @zapta
                      last edited by

                      @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.

                      Duet WiFi hardware designer and firmware engineer
                      Please do not ask me for Duet support via PM or email, use the forum
                      http://www.escher3d.com, https://miscsolutions.wordpress.com

                      zaptaundefined 1 Reply Last reply Reply Quote 1
                      • zaptaundefined
                        zapta @dc42
                        last edited by

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

                        a3769ee9-73e1-492a-8e9c-e7d67a1eb201-image.png

                        dc42undefined 1 Reply Last reply Reply Quote 0
                        • dc42undefined
                          dc42 administrators @zapta
                          last edited by

                          @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.

                          Duet WiFi hardware designer and firmware engineer
                          Please do not ask me for Duet support via PM or email, use the forum
                          http://www.escher3d.com, https://miscsolutions.wordpress.com

                          zaptaundefined 1 Reply Last reply Reply Quote 1
                          • zaptaundefined
                            zapta @dc42
                            last edited by

                            Today I learned that DWC inserts tabs even if I don't use the tab key.

                            To reproduce:

                            1. Start with a command indented by four spaces.
                            <four spaces>G1
                            
                            1. 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.

                            gloomyandyundefined dc42undefined 2 Replies Last reply Reply Quote 0
                            • gloomyandyundefined
                              gloomyandy @zapta
                              last edited by

                              @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!).

                              1 Reply Last reply Reply Quote 0
                              • dc42undefined
                                dc42 administrators @zapta
                                last edited by

                                @zapta I've asked @chrishamm to look into this.

                                Duet WiFi hardware designer and firmware engineer
                                Please do not ask me for Duet support via PM or email, use the forum
                                http://www.escher3d.com, https://miscsolutions.wordpress.com

                                1 Reply Last reply Reply Quote 1
                                • zaptaundefined
                                  zapta
                                  last edited by

                                  @dc42 said in Please improve the handling of TAB characters in the DWC editor:

                                  @zapta I've asked @chrishamm to look into this.

                                  Thanks.

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post
                                  Unless otherwise noted, all forum content is licensed under CC-BY-SA