Author Topic: Problem with automatic surround  (Read 2979 times)

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Problem with automatic surround
« on: July 07, 2010, 05:58:56 pm »
Start with this:
Code: [Select]
if (true)
    shout();
Open a line below the if statement and type '{'; the cooresponding '}' is added, and the two lines appear indicating the block can be adjusted.
Resize the block to include the line with shout(), and the result is:
Code: [Select]
if (true)
{
        shout();
}
Note the extra level of indentation.

SlickEdit Version 15.0.0.6    Build Date: May 07, 2010    Emulation: Vim
OS: Windows Vista    OS Version: 6.00.6002  Service Pack 2
Project Type:
Language: .cs (C#)
Hotfixes:
C:\Users\Administrator\Documents\My SlickEdit Config\15.0.0\hotfixes\hotfix_se1500_7_cumulative.zip (Revision: 7)



Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2713
  • Hero Points: 413
Re: Problem with automatic surround
« Reply #1 on: July 07, 2010, 06:55:18 pm »
This can look like a bug if you leave out the steps in between, but if you look at what you did in detail, you see that it's kind of what you should expect.

You started with:
Code: [Select]
if (true)
   shout();

Then opened a line, leaving "shout();" hanging.
Code: [Select]
if (true)

   shout();

Then added a brace block, now "shout();" is orphaned.
Code: [Select]
if (true)
{
}
   shout();

Then used dynamic surround to pull the statement back in, "shout();" is double-indented, as expected.
Code: [Select]
if (true)
{
     shout();
}

Dynamic surround doesn't try to be excessively smart.  When it pulls code into a block, it indents it, when it pulls it out, it outdents it.  If the code was already hanging there at an incorrect indentation level, all dynamic surround will do is pull it into the block at a different incorrect indentation level, as you have observed.

There are times when code is intentionally indented outside of convention.  Dynamic surround handles that by assuming that the coder liked the way it was indented before, which is the case 99% of the time, and just wants to pull it inside a block, so it makes minimal modificaitons to the code's indentation level.  If dynamic surround had additional logic built into it to re-indent lines intelligently, it might work better for your case where you give dynamic surround incorrectly indented code, and want it fixed, but it was be extremely annoying for the other case where you have code that is indented in a very specific manner and you don't want dynamic surround to drastically reformat it.

Now for a suggustion.  What you wanted to do could have been done with only a few keystrokes if you used smart-brace.

Start with:
Code: [Select]
if (true)
   shout();

Put curser where you want the open brace:
Code: [Select]
if (true)
<cursor>   shout();

Type the open brace and let smart-brace fix the statement.
Code: [Select]
if (true)
{
   shout();
}

That will work great as long as you haven't disabled smart-brace / unbrace.

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Problem with automatic surround
« Reply #2 on: July 07, 2010, 08:11:06 pm »
Thanks for the detailed explanation.
Unfortunately, I can't get the behavior you describe.  I searched the Options dialog for smart-brace, but couldn't find it.  Attached are screenshots of C# indent and formatting options.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2713
  • Hero Points: 413
Re: Problem with automatic surround
« Reply #3 on: July 07, 2010, 09:09:37 pm »
OK. I see the problem.  C# doesn't support statement tagging, and parts of the quick brace/unbrace feature depends on statement tagging.  I will put in a workaround for 15.0.1 for languages that do not have statement tagging to support quick brace.

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Problem with automatic surround
« Reply #4 on: July 14, 2010, 09:39:02 pm »
Fixed in latest patch, thanks....