Tabs To Spaces Command Behavior

Tabs To Spaces Command Behavior

115
Power UserPower User
115

    Jun 17, 2015#1

    A while back I was working on a script to enclose comments in my code to make them stand out. I started out by modifying Mofi's equal sign alignment script and quickly had a working script that would locate the longest line in the selected comment block, space pad the rest of the lines to match and add the | character to build a box around the block.

    Except that it didn't work right when there were tabs on lines in the block. So I added in the Tabs To Spaces command in my script - and - it still didn't work.

    The help for the Tabs To Spaces command says that it converts ALL tabs to spaces in selected text or in the entire file if no text is selected. Even though not mentioned there is an exception to that of course in that tabs inside of a text string are not converted. Well it seems that I found another exception. But while protecting tabs in a text string makes complete sense, doing the same for a comment is usually not desired. Say for example when a block of code is commented out for testing.

    I did some more experimenting and found that if the comment is a block comment, then if you select the text so that all of it is between the start comment and end comment markers then the selected text will respond to the change command. If the inline comment marker is used, selected text cannot be changed even if the comment character is not part of the selection.

    This is in UE 21.20.0.1004 running on Windows Enterprise Edition 64bit.

    6,686585
    Grand MasterGrand Master
    6,686585

      Jun 22, 2015#2

      Hm, that is really interesting. I could not reproduce what you wrote whether with UE v21.20.0.1004 nor with v22.10.0.10.

      The command Format - Tabs to Spaces executed manually or from a script with UltraEdit.activeDocument.tabsToSpaces(); always converted all tabs to spaces in a *.c file syntax highlighting as C_LANG file.

      Horizontal tab characters in strings are converted to spaces. Also horizontal tab characters left to a block comment and inside a block comment are converted to spaces. And horizontal tab characters left and right of // are also converted to spaces.

      The *.c file did not contain any tab character inside the selection or in entire file after using this command on selection or entire file. It also did not matter what exactly I have selected, just everything after //, or the entire line with the line comment, or multiple lines just containing line comments, or the entire block comment, or just the text within /* and */.
      Best regards from an UC/UE/UES for Windows user from Austria

      115
      Power UserPower User
      115

        Jun 22, 2015#3

        The behavior happened in XML and IDL files but may extend to other languages. XML and IDL are the only files I've been working with in the past two weeks. In XML files all of the tabs between the <!-- and --> characters were not changed to spaces. And the conversion didn't work the other way either, spaces to tabs.

        In this first example I have highlighted a section of XML code so the tabs and spaces are visible against the background color. At the start the entire file only had spaces and no tab characters. Then I executed a spaces to tabs command. You can see that the XML lines before the block comment character have tabs but the lines in the block comment still have spaces.

        xml_tabs.png (18.26KiB)


        Then I manually replaced some of the spaces inside the block comment with tabs.

        xml_tab1.png (18.44KiB)


        Then I executed the tabs to spaces command. You can see that the tabs in the lines preceding the block comment now have spaces instead of tabs but the tabs inside of the comment remain.

        xml_tab2.png (21.51KiB)

        6,686585
        Grand MasterGrand Master
        6,686585

          Jun 23, 2015#4

          I could not reproduce what you have written for an XML file syntax highlighted with standard xml.uew.

          So I thought, there must be a configuration setting which is responsible for the different behavior on your machine and searched for it.

          Do not convert spaces and tabs inside comments or quotes at Advanced - Configuration - Editor Display - Formatting is the reason for the different behavior as this setting is not checked in my UltraEdit configuration, but is obviously checked in your configuration.
          Best regards from an UC/UE/UES for Windows user from Austria

          115
          Power UserPower User
          115

            Jun 23, 2015#5

            You are correct. That box is checked. I missed it when I was checking configuration settings. I knew that tabs inside of quoted text were protected but didn't know that they were because of this setting, which I may have set when we upgraded from UE v9 in 2011.

            I do think that there should be
            A) two separate check boxes, one for comments and one for quotes.
            or
            B) a check box for comments with quoted text never being converted.

            However, I don't think that my need alone is enough to ask for a feature change. I can't think of a reason to change tabs or spaces inside of quoted text.

            The main reason I change tabs to spaces is so that code stays aligned when viewed in UE and in vi or when displayed with a cat command on one of our Linux workstations. We are not allowed to have UE Linux on the workstations. When debugging a program we often have code blocks that are commented out on a temporary basis, and if those comments have tabs the file display is hard to view.