ReIndent Selection

Syntax highlighting, code folding, brace matching, code indenting, and function list

ReIndent Selection

Postby bibi » Fri Oct 14, 2005 11:35 pm

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);
                  }
                }
User avatar
bibi
Newbie
 
Posts: 6
Joined: Sun Jan 30, 2005 12:00 am

Re: ReIndent Selection

Postby Mofi » Sat Oct 15, 2005 11:46 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: ReIndent Selection

Postby bibi » Sat Oct 15, 2005 3:24 pm

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
User avatar
bibi
Newbie
 
Posts: 6
Joined: Sun Jan 30, 2005 12:00 am

Re: ReIndent Selection

Postby Mofi » Sun Oct 16, 2005 2:09 pm

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 would have expected.

/Indent Strings = "{" "if" "else" ":"
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: ReIndent Selection

Postby bibi » Sun Oct 16, 2005 2:25 pm

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!
User avatar
bibi
Newbie
 
Posts: 6
Joined: Sun Jan 30, 2005 12:00 am

Re: ReIndent Selection

Postby Mofi » Sun Oct 16, 2005 3:52 pm

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. I for example use a bad style for multiple }, because I put all } in one line instead of multiple lines. A }}}} situation for example is still not correct solved by the reindent feature, but that's no problem for me because I was never forced to reindent my own written code.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: ReIndent Selection

Postby bibi » Sun Oct 16, 2005 4:06 pm

Now I understand,

Many Thanks
Sylvain
User avatar
bibi
Newbie
 
Posts: 6
Joined: Sun Jan 30, 2005 12:00 am

Re: ReIndent Selection

Postby Caterwaul » Wed Nov 23, 2005 7:46 am

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! :)
User avatar
Caterwaul
Newbie
 
Posts: 3
Joined: Wed Nov 23, 2005 12:00 am

Re: ReIndent Selection

Postby Caterwaul » Fri Jun 16, 2006 2:33 am

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!
User avatar
Caterwaul
Newbie
 
Posts: 3
Joined: Wed Nov 23, 2005 12:00 am

Re: ReIndent Selection

Postby Mofi » Fri Jun 16, 2006 10:16 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: ReIndent Selection

Postby toddm » Fri Jun 16, 2006 1:32 pm

Have you tried Artistic Style? It's a good formatter for C code and is integrated with UE 12.
User avatar
toddm
Advanced User
Advanced User
 
Posts: 83
Joined: Wed Jul 28, 2004 11:00 pm

Re: ReIndent Selection

Postby Caterwaul » Fri Jun 16, 2006 1:40 pm

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.
User avatar
Caterwaul
Newbie
 
Posts: 3
Joined: Wed Nov 23, 2005 12:00 am

Re: ReIndent Selection

Postby dleach » Fri May 25, 2007 11:12 pm

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.
User avatar
dleach
Newbie
 
Posts: 3
Joined: Thu May 24, 2007 11:00 pm

Re: ReIndent Selection

Postby Bego » Mon May 28, 2007 6:56 pm

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

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: ReIndent Selection

Postby Mofi » Tue May 29, 2007 6:53 am

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"
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Next

Return to Syntax Highlighting