davidvarga/MBeautifier

Indent function content

kupiqu opened this issue ยท 11 comments

Would you consider adding this option?

do you mean

function myFunction()
     a = 'Should be indented?';
end

?

Yes, as an option

Would you please consider adding a rule for this?

I was thinking about this one. Theoretically the idea that I came up with could work, but I have to try it out. Hopefully next week you'll get an update on the issue.

@davidvarga This option is really something we desperately miss. Would be really great to have it. Other than that: Great work :-D

Yes, please!

You can configure MATLAB on how to indent your functions. This also affects MBeautifier because it uses the smart indenting feature from MATLAB.

Just go to Preferences -> MATLAB -> Editor/Debugger -> Language
Under "Indenting" there is a a field "Function indenting format" with three options:

  • Indent nested functions
  • Indent all functions
  • Classic

The one in bold is the one you want (I prefer this style as well).

Unfortunately, there is no official MATLAB function to set this option. But there is an undocumented one:

com.mathworks.services.Prefs.setStringPref('EditorMFunctionIndentType', 'AllFunctionIndent')

You can configure MATLAB on how to indent your functions. This also affects MBeautifier because it uses the smart indenting feature from MATLAB.

Just go to Preferences -> MATLAB -> Editor/Debugger -> Language
Under "Indenting" there is a a field "Function indenting format" with three options:

* Indent nested functions

* **Indent all functions**

* Classic

The one in bold is the one you want (I prefer this style as well).

Unfortunately, there is no official MATLAB function to set this option. But there is an undocumented one:

com.mathworks.services.Prefs.setStringPref('EditorMFunctionIndentType', 'AllFunctionIndent')

Thank you very much! Now I finally get it. The MATLAB-Formatter for VS Code indent all functions as well. Since I use VS Code occasionally, it is very nice to unify the style.

Thank you @meerdan !

Then actually this could be introduced as an option for MBeauty, and controlled through the undocumented MATLAB feature.

nice!

Implemented a new special indentation rule based on the proposal of @meerdan: "Indentation_Strategy". MBeautifier provides the exact three options to select from, used in the time of the formatting (then resetting to the one set in MATLAB preferences).

Thanks again all the constructive comments!
Closing the issue.