Tapatalk

ReIndent Selection

ReIndent Selection

6
NewbieNewbie
6

    Oct 15, 2005#1

    Hi,

    I try to use the ReIndent Selection for C code and it's don't work, it's always putting everything like this.

    Any hints
    Thanks
    Sylvain Bissonnette

    Code: Select all

    void DoKey(ushort ReGen)
    {
      static ushort KeyFirst,KeySecond,Value,Update;
    
      Update = FALSE;
    
      if (ReGen)
        {
          LCDClrSCR();
          LCDGotoXY(1,1);
          LCDWriteConstString("  InterComm  V:1.0\0");
          LCDGotoXY(1,2);
          LCDWriteData(LCD_DATA,KeySecond+48);
          LCDWriteData(LCD_DATA,KeyFirst+48);
          Value = (KeySecond * 10) + KeyFirst;
          Update = TRUE;
        }
        else
          {
            KeyScan();
    
            if ((Key != 0xff) && (Key != 10) && (Key != 11))
              {
                KeySecond = KeyFirst;
                KeyFirst = Key;
                LCDGotoXY(1,2);
                LCDWriteData(LCD_DATA,KeySecond+48);
                LCDWriteData(LCD_DATA,KeyFirst+48);
                Value = (KeySecond * 10) + KeyFirst;
                Update = TRUE;
                Key = 0xff;
              }
            }
    
            if (Update == TRUE)
              {
                if (Value == 0)
                  {
                    LCDGotoXY(3,2);
                    LCDWriteConstString("->Broadcast Call #\0");
                  }
                  else if ((Value >= 1) && (Value < 40))
                    {
                      LCDGotoXY(3,2);
                      LCDWriteConstString("->Calling #       \0");
                    }
                    else if ((Value >= 40) && (Value < 100))
                      {
                        LCDGotoXY(3,2);
                        LCDWriteConstString("->                \0");
                      }
                    }
    
    
                    if ((Key == 11) && (Value >= 0) && (Value < 40))
                      {
                        Key = 0xff;
                        StationCall(Value);
                      }
                    }
    

    6,685587
    Grand MasterGrand Master
    6,685587

      Oct 15, 2005#2

      I copied your code example and executed the reindent selection. The output looks fine with my settings. What is your problem?

      Is the file highlighted as 'C' file - look at menu View - View As.

      What are your indent settings at Advanced - Configuration - Edit for files with the extension c and h.
      Best regards from an UC/UE/UES for Windows user from Austria

      6
      NewbieNewbie
      6

        Oct 15, 2005#3

        Hi,

        Thanks for your reply. I just re-edited my first message and like you will see, the indentation don't work when I use reindent selection, I have checked the advance/configuration/edit and it's look fine, auto indent is set, use spaces in place of tabs is set, tab stop and indent spaces at 2. And view as C/C++ is set in the view menu.

        Thanks
        Sylvain Bissonnette

        6,685587
        Grand MasterGrand Master
        6,685587

          Oct 16, 2005#4

          OK. I have found the problem! You are using the standard wordfile.txt for syntax highlighting and yesterday as I tried your example, I have used my personally created highlighting file.

          The problem is the indent strings definition in the standard wordfile.txt. Click on the Open button at the Advanced - Configuration - Syntax Highlighting tab to open the wordfile and close the dialog with Cancel. Goto line 9 and delete the red part shown below. Save wordfile.txt and now the reindent selection will produce the result which you expect.

          /Indent Strings = "{" "if" "else" ":"
          Best regards from an UC/UE/UES for Windows user from Austria

          6
          NewbieNewbie
          6

            Oct 16, 2005#5

            Hi Mofi,

            You found the problem! Thanks a lot for all your work. Can you explain why the default indent strings are not correct?

            Thanks again
            Yours truly
            Sylvain Bissonnette
            __________________
            Regards from Canada!

            6,685587
            Grand MasterGrand Master
            6,685587

              Oct 16, 2005#6

              What is correct and what is not is a matter of opinion.

              These are all correct codes:

              Code: Select all

              if (condition) {
                 statement(s);
              }
              else {
                 statement(s);
              }
              
              if (condition)
              {
                 statement(s);
              }
              else
              {
                 statement(s);
              }
              
              if (condition)
              {
                 single statement;
              }
              else
              {
                 single statement;
              }
              
              variable = (condition) ? value1 : value2;
              
              if (condition)
                 single statement;
              else
                 single statement;
              
              if (condition) { single statement; } else single statement;
              
              ...
              Can you see the problem with indentations on this examples?

              UltraEdit is a very good editor, because it's indent capability can be configured by the user for it's personal style. But by default it's defined for all styles, even if this is bad for reindenting a selection. For example I use at the moment a bad style for multiple } because I put all } in one line instead of multiple lines. A }}}} case is still not correct solved by the reindent feature as it does not recognize the multiple unindent strings on same line. But that's no problem for me because I was never forced to reindent my own written code.
              Best regards from an UC/UE/UES for Windows user from Austria

              6
              NewbieNewbie
              6

                Oct 16, 2005#7

                Now I understand,

                Many Thanks
                Sylvain

                3
                NewbieNewbie
                3

                  Nov 23, 2005#8

                  OK, so I have the same general issue, but the syntax is slightly different.

                  Here is some example PHP code, could be any C style syntax though.

                  Code: Select all

                  <?
                  if($something == $somethingelse) {
                  	//do something
                  } elseif($something != $somethingelse) {
                  	//dont do something
                  } else {
                  	//flake out
                  }
                  ?>
                  Ok, now when I reindent it... this is what it looks like.

                  Code: Select all

                  <?
                  if($something == $somethingelse) {
                  	//do something
                  	} elseif($something != $somethingelse) {
                  		//dont do something
                  		} else {
                  			//flake out
                  		}
                  		?>
                  I brought this up in an email to IDM, they said its a known issue... but this was almost 9 months ago.

                  I was wondering if you had a wordfile hack to get around this?

                  Let me remind you that this works PERFECTLY fine in 10.x, only in 11.x does it mess up like this.

                  IT HAS TO BE THIS SYNTAX FORMAT (conditionals on the same line as the brackets)! I don't want to have to change my coding style to fit a text editor.

                  Thanks! :)

                    Jun 16, 2006#9

                    Bump!

                    OK This is really starting to bother me.

                    I have to use v12 of Ultraedit32 at work (I use 10 at home, as that is the best version IMO because of this issue).


                    See above post, is there a fix for this? It worked in 10.xx but every version after 10 it is BROKEN.

                    IDM even said they know this is a problem, and that was a year and a half ago that they said they knew about this.

                    PLEASE!

                    If there isn't a solution, does 12's license cover 10.xx? I would love to go back to that at work if there is not a solution for this!

                    6,685587
                    Grand MasterGrand Master
                    6,685587

                      Jun 16, 2006#10

                      Try this, which works for your example and hopefully also for all other situations.

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

                      I'm not sure, but I think you can get the key for v10.10c if you have one for v12. Ask IDM.
                      Best regards from an UC/UE/UES for Windows user from Austria

                      80
                      Advanced UserAdvanced User
                      80

                        Jun 16, 2006#11

                        Have you tried Artistic Style? It's a good formatter for C code and is integrated with UE 12.

                        3
                        NewbieNewbie
                        3

                          Jun 16, 2006#12

                          It kind of works. It now doesn't keep tabbing out forever till the end of the file, but it also doesn't ever tab out more than one tab. :(

                          I am using artistic style at work, but since it is for C it has some weird little issues with some PHP code, like if a object has a method called get() or something like that it puts it on another line for some reason. I also have to write elseif as else if for it to format correctly (though thats not as big of a deal as putting { } on their own lines).

                          If getting 10 is not an option at work (it should be though) I might end up rewriting astyle for PHP... but I would rather not have to go that route.


                          I really like all the other features in 12 though, its a shame they broke the one though that keeps me really happy with this program.

                          3
                          NewbieNewbie
                          3

                            May 26, 2007#13

                            Mofi wrote:Try this, which works for your example and hopefully also for all other situations.

                            /Indent Strings = "{"
                            /Unindent Strings = "{" "}"
                            Okay, I'm struggling with this stuff and I'm ready to give up. What it looks like is that the indenting won't work correctly because if the braces are on the same line, "} else {", then the indent/unindent gets confused. I tried the above but that didn't work.

                            So if I have code that looks like this:

                            Code: Select all

                            if (a==1) 
                            {
                               foo();
                            } else {
                               boo();
                            }
                            I can't figure out how to get the editor to setup to format the code the way we have our indents set. With the above I would get:

                            Code: Select all

                            if (a==1)
                            {
                               foo();
                               } else { 
                                  boo();
                               }
                            Help before I through this thing out.

                            344
                            MasterMaster
                            344

                              May 28, 2007#14

                              I am no code formatting specialist. So maybe other people may help you.
                              There is a code formatter called "artistic style" that is supported somehow by UE. Did you look at this?
                              Just type "artistic" in the UE help. Maybe this will get you further.

                              rds Bego
                              Normally using all newest english version incl. each hotfix. Win 10 64 bit

                              6,685587
                              Grand MasterGrand Master
                              6,685587

                                May 29, 2007#15

                                Hi dleach!

                                Forget

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


                                This works for your code example, but causes other code parts to be wrongly indented.

                                Use instead this one for your coding style:

                                /Indent Strings = "{" "else"
                                /Unindent Strings = "}" "else"
                                Best regards from an UC/UE/UES for Windows user from Austria

                                Read more posts (6 remaining)