Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 nested switch() statement auto formatting

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
jcforster Posted - Aug 05 2013 : 5:15:43 PM
Using VC 2005, pasting text or otherwise modifying nested switch statements indentation is always wrong, doesn't see the nested switch, uses indentation of outer switch().
5   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Dec 09 2013 : 7:20:03 PM
Experimenting a bit with your code sample, the code formatting command in VS2005 is not doing much of use with your code, but if you change the line:

switch (variable) {

to read:

switch (variable)
{


then VS2005 is a lot more helpful, and actually does something more sensible when code formatting. Can you try the same test please and see what results you get?

VA will indent code when you use surround with {}, but when using Format after paste we ask the IDE to do the code formatting, since we don't have any current plans to get involved with code formatting. Code formatting requires lots of options, to allow people to specify how they want their code formatted, since everyone seems to have a different standard and policy on what they want.
pbrown Posted - Nov 30 2013 : 09:03:14 AM
I think the problem is with VS2005's indentation engine and "Format Selection". I can reproduce a similar problem using VAX's "surround with {}".

The behavior I expect in this case would be that my entire selection be indented by one extra tab stop. But I think what happens here is the editor takes the code with VAX's extra braces and then re-indents line by line, starting with:


{
switch (variable) {
case 1:
  do_stuff();
  break;
default:
  do_default_stuff();
  break;
}


After re-indenting the switch statement, it comes across the first label:


{
  switch (variable) {
vvvvv -- current line
case 1:
  do_stuff();
  break;
default:
  do_default_stuff();
  break;
}


I think the intent behind the Format Selection logic is that it leaves switch statement labels with their original indentation, assuming that the user indented them the way they want. Some people don't like indenting case labels; others do. In this case, the labels appear to be "outdented" by one tab stop, because "Format Selection" indented the switch statement without indenting its corresponding block. And so, it leaves it that way, resulting in ugly ugly code.

You can see a similar effect without VAX by running "Format Selection" on my first example. It appears that VS2013 does not have this problem.

It seems like VAX could help in "surround with ()" by indenting the selection first and then letting the formatting engine have its way with the code. You could do something similar when pasting:

(1) insert a blank line first, let the formatting engine decide where it should be indented

(2) remove the blank line

(3) compare the indentation from (1) against the indentation level of the code being pasted

(4) if different, re-indent the code being pasted

(5) then let the formatting engine do its thing
feline Posted - Aug 08 2013 : 1:02:50 PM
You might want to look into this IDE extension, which is specifically designed to do code formatting, letting you format your code the way you want it:

http://www.profactor.co.uk/stylemanager.php

This requires a lot of settings, and its not something we are currently looking to add to VA.
jcforster Posted - Aug 07 2013 : 12:03:22 PM
Yeah, I'm eminently aware of control Z believe me. It's a bug in the parser deciding how much to indent a given piece of code and it doesn't see nested C switch() statements. They all indent at the outer switch statements indentation level.
accord Posted - Aug 06 2013 : 3:45:15 PM
Visual Assist applies formatting after paste as per the following setting:
VA Options -> Advanced -> Corrections -> Format after paste

The formatting is done by Visual Studio, and you can do the same via selection a block of code and than selecting the below command:
Edit -> Advanced -> Format Selection

We cannot alter how this formatting work, however you can either turn it off completely, or keep it turned on and undo the formatting action: we save 2 undo buffers separately, so the first undo operation will just undo the formatting and only a second undo will delete the pasted text itself.

Hope it makes sense.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000