SlickEdit Community

Archived Read Only Forums => SlickEdit 2018 v23 Beta Discussion => Topic started by: jc44 on August 30, 2018, 02:29:33 pm

Title: B3: Adaptive format and switch/case
Post by: jc44 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
Title: Re: B3: Adaptive format and switch/case
Post by: mwb1100 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?
Title: Re: B3: Adaptive format and switch/case
Post by: jc44 on September 10, 2018, 09:25:49 am
Bump: Still all true in B4
Title: Re: B3: Adaptive format and switch/case
Post by: Clark 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.
Title: Re: B3: Adaptive format and switch/case
Post by: jc44 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)
Title: Re: B3: Adaptive format and switch/case
Post by: Clark 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.
Title: Re: B3: Adaptive format and switch/case
Post by: Clark 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.
Title: Re: B3: Adaptive format and switch/case
Post by: jc44 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