Auto-indent of function blocks for C/C++

Auto-indent of function blocks for C/C++

6

    Dec 22, 2010#1

    I don't have UE installed on Win/Linux or I'd test this myself, but with UE for Mac if I do "void MyObj::fn()" and hit ENTER the cursor ends up indented instead of lined up under the 'v'. Looking at the wordfile for C/C++ I have:

    Code: Select all

    /Indent Strings = "{" "if" "else" ":"
    So this indent shouldn't be occurring, correct?

    6,603548
    Grand MasterGrand Master
    6,603548

      Dec 23, 2010#2

      Indentation is caused by the defined indent strings which you can modify to your needs. The standard wordfile for C/C++ contains /Indent Strings = "{" "if" "else" ":" as you already posted. But most users just need:

      /Indent Strings = "{"
      /Unindent Strings = "}"


      "if" "else" are for those users writing if conditions with a single code line like

      Code: Select all

      if( bTest == true )
         iVar = 50;
      else
         iVar = *piInterface;
      If you write such conditions like

      Code: Select all

      if( bTest == true ) iVar = 50;
      else iVar = *piInterface;
      or like

      Code: Select all

      if( bTest == true )
      {
         iVar = 50;
      }
      else
      {
         iVar = *piInterface;
      }
      you should remove from "if" "else" the indent strings line.

      ":" is mainly for

      Code: Select all

      switch( eType )
      {
         case Standard:
            printf("Standard type\n");
            break;
         case Extended:
            printf("Extended type\n");
            break;
      }
      If you code your switch conditions like

      Code: Select all

      switch( eType )
      {
         case Standard:   printf("Standard type\n");
                          break;
         case Extended:   printf("Extended type\n");
                          break;
      }
      or like

      Code: Select all

      switch( eType )
      {
         case Standard:
                        printf("Standard type\n");
                        break;
         case Extended: 
                        printf("Extended type\n");
                        break;
      }
      or if you code in C++, you should remove ":" from the indent strings (or replace it with "case"). ":" is also present for goto target labels.
      Best regards from an UC/UE/UES for Windows user from Austria

      6

        Dec 23, 2010#3

        But according to DaveS, UE behaves differently on Windows, which is consistent with my memory of UE on Windows. Also, I think the rule should apply based on the last character, not the presence of a character in a line at all. Otherwise, I'd think UE for Mac would incorrectly indent this as well:

        Code: Select all

        int x = 1 > 2 ? 1 : 2;
        // is this line indented because of the colon above?

        6,603548
        Grand MasterGrand Master
        6,603548

          Dec 23, 2010#4

          complexmath wrote:But according to DaveS, UE behaves differently on Windows, which is consistent with my memory of UE on Windows.
          Yes, that is right for the user interface and file locations, but surely not for the core functions as auto-indent is one.
          complexmath wrote:Also, I think the rule should apply based on the last character, not the presence of a character in a line at all.
          There is no other rule than if an indent string is found on a line not inside a comment or string, the next line will be indented. So your code line results in indenting the next line.

          Please take into consideration that UltraEdit (for any platform) is a general text editor not written for certain programming languages. I use auto-indent for text files which do not contain a programming language. So there are no special rules for some programming languages included. The IDE solution of IDM - UEStudio - is more specialized for some programming languages and offers additional features for faster writing C/C++ code, but indenting works the same way.

          Best is you simply remove ":" from indent strings definition in the wordfile for C/C++.
          Best regards from an UC/UE/UES for Windows user from Austria

          6

            Dec 23, 2010#5

            I just tested windows and it exhibits the same behavior, including wrongly indenting below a "a<b?c:d" expression, so you're right that this is expected behavior rather than a bug in the Mac implementation. I'll change my wordfile. Thanks :-)