Author Topic: B3: Adaptive format and switch/case  (Read 2284 times)

jc44

  • Senior Community Member
  • Posts: 329
  • Hero Points: 22
B3: Adaptive format and switch/case
« on: August 30, 2018, 02:29:33 PM »
I enclose a file where adaptive format is convinced (100% in adaptive-format-stats) that "case" is indented from "switch".  Whilst this is probably more true than not, the formatting is definitely mixed.  This is particularly annoying when editing the minority case - I don't suppose the behaviour could be changed s.t. the indent of a new case matches the previous (or next if no previous) case in the switch statement and only uses the adaptive guess if the switch is currently empty?

So I guess I've got a combined bug report / feature request here.

Thanks

John Cox

mwb1100

  • Senior Community Member
  • Posts: 156
  • Hero Points: 13
Re: B3: Adaptive format and switch/case
« Reply #1 on: August 30, 2018, 10:06:47 PM »
That's a really good idea.  It never occurred to me that an editor could match a new case indent to the ones that are already around it.  Unfortunately a lot of the code I deal with are files that are very messy, so a feature like this would be welcome.  I hope this is something they can do.

Are there any existing editors that use this heuristic?

jc44

  • Senior Community Member
  • Posts: 329
  • Hero Points: 22
Re: B3: Adaptive format and switch/case
« Reply #2 on: September 10, 2018, 09:25:49 AM »
Bump: Still all true in B4

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: B3: Adaptive format and switch/case
« Reply #3 on: September 12, 2018, 03:10:15 PM »
I've added an experimental feature for this for beta 5. Not sure if this feature will be liked or not (it can be turned off but defaults to on right now). At the moment, it only supports C++, C#, Object-C, Java, PHP, and JavaScript. Beautify While Typing doesn't support this. If you turn Beautify While Typing on and type the close brace for the switch statement, the entire switch statement is beautified according to your beautifier settings which can be combined with adaptive formatting settings which may or may not have anything to do with the case indenting style for the current switch statement.

jc44

  • Senior Community Member
  • Posts: 329
  • Hero Points: 22
Re: B3: Adaptive format and switch/case
« Reply #4 on: September 12, 2018, 04:20:14 PM »
Thanks for that.
Did you also find out why adaptive-format-stats declared itself 100% sure that case was indented from switch with the attached file? (Its about 50/50 though the non-indented cases tend to be near the end of the file)

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: B3: Adaptive format and switch/case
« Reply #5 on: September 12, 2018, 04:24:47 PM »
100% does seem incorrect. I count 5/8. Note that it does not count every case statement. Just the first case statement of every switch. I will look into this.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: B3: Adaptive format and switch/case
« Reply #6 on: September 12, 2018, 04:40:26 PM »
There's a maximum number of lines to scan (def_max_adaptive_format_lines). However, it's not breaking on that. There are also hard coded sample sizes which are getting hit in this case. Once it gets enough samples, it stops looking for more samples.

It does look like there is a bug here. In this case, it isn't really getting enough samples of the switch/case statement but stopping due to plenty of samples of something else. This will be fixed in beta 5.
« Last Edit: September 12, 2018, 07:53:46 PM by Clark »

jc44

  • Senior Community Member
  • Posts: 329
  • Hero Points: 22
Re: B3: Adaptive format and switch/case
« Reply #7 on: October 01, 2018, 10:26:15 AM »
This all seems to work properly in B5.  And just for the record (as the feature is marked experimental) I really like the new case indent behaviour.

Many thanks

John Cox