R2021b - code folding in switch/case not fully available

52 views (last 30 days)
Gabriele
Gabriele on 7 Oct 2021
Commented: Gabriele on 13 Oct 2021
Hello,
I've moved from R2021a to R2021b, and I have an issue with code folding in the editor for switch/case statements.
In the R2021a editor, I could fold the entire "switch...end" block, and it was also possible to separately fold the code block associated with each "case", see below:
Now, with R2021b, I can see how to fold the entire "switch...end" code clock, but I do not see anymore the possibility of folding each "case", see below:
I checked the Editor preferences, but I could not find any specific option to enable/disable code folding of "case" blocks. I could only find the option related to the entire swith
Do you know how to enable the possibility of folding each "case" in R2021b?
Thanks,
Gabriele

Accepted Answer

Prateek Rai
Prateek Rai on 13 Oct 2021
Hi Gabriele,
The case folding wasn't removed intentionally. MATLAB has switched to a new editor from R2021b and so, it has a new backend for the code folding data. The editor does not recognize switch case branches as a foldable construct.
The concerned development team is aware of the same and the feature might be available in a future MATLAB release.
Thanks
  1 Comment
Gabriele
Gabriele on 13 Oct 2021
Hi Prateek,
thanks for the update.
Then, for the time being, let's use the workaround you suggested!
Gabriele

Sign in to comment.

More Answers (1)

Prateek Rai
Prateek Rai on 9 Oct 2021
To my understanding, you want to fold each "case" block in R2021b.
One possible workaround could be-
Step 1: Go to Editor preferences and enable Code Folding for "Sections" and "Switch/case blocks".
Step 2: Now you can use %% to create sections after each "case" blocks and this will give you an option for folding them.
The code will look like:
int i =1
switch 1
case 1
%%
p =2;
case 2
%%
p=3;
end
This time you will get the option for code folding after each case.
  1 Comment
Gabriele
Gabriele on 9 Oct 2021
Hello Prateek,
thank you for your reply. I appreciate the suggestion for the workaround, that indeed works.
However, since "case" blocks are part of the "switch...case...otherwise...end" matlab syntax, it seems to me that the code folding behaviour prior to R2021b (=possibility of folding "case" blocks) was better.
Is this change of editor behaviour in R2021b a bug or is it an intended removal of feature?
If it is an intended removal of feature, then, for my typical use of "switch...case", the previous "automatic" behaviour was more handy (now I should systematically add %% after the majority of "case" statements), and I would therefore suggest to consider going back to the possibility of folding case blocks directly (best would be giving an option to activate folding for "case"/"otherwise" blocks in the preferences).
Gabriele

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!