MATLAB-extension-for-vscode
MATLAB-extension-for-vscode copied to clipboard
Feature Request - More Code Formatting Authority / Options
It would be incredibly useful for teams to be able to enforce code style guidelines a la something like clang-format. Additionally, features like those provided in clang-tidy for variable/function/class naming conventions would help teams to produce more uniform MATLAB codebases with minimal manual effort.
A simpler start to this could just include a "comfortable" vs. "compact" preference on auto formatting:
Comfortable: matlab_function(arg1, arg2, arg3);
Compact: matlab_function(arg1,arg2,arg3);
or
Comfortable: var = x * y;
Compact: var=x*y;
It would also be nice to have some control over the indentation. Currently when I save a file it flattens everything within a function that isn't part of a code block to have no indentation. I can imagine someone preferring this, but indenting functions makes it much easier for me to see where it starts and ends, and I'd prefer not to have the formatter "fix" it.
Thanks for this suggestion! We will consider adding greater configurability in the future.
Currently when I save a file it flattens everything within a function that isn't part of a code block to have no indentation.
@Whyhow314 - Document formatting currently listens to the preferences defined in MATLAB. If you open MATLAB, you should be able to modify the Function indenting format
preference under "MATLAB > Editor/Debugger > Language". Perhaps the behavior with Indent all functions
is closer to what you would prefer?
@dklilley Looks like that fixed it, thanks! I didn't realize that it respected the preferences from my matlab installation.
Does this extension include auto indenting?
@tongyaop this extension provides both format document capability as well as indenting as you type. Is this what you mean by auto indenting?
@dklilley Thank you for the reply. The code does indent when I type. However, I am looking for a command that is similar to cmd + i
(or control + i
) in MATLAB desktop that auto indents a piece of already-typed code. When pieces of code are copied from somewhere else, they are not always in the right indentation.
Edit: In MATLAB editor tab, it's called "smart indent"
@tongyaop You can use Format Document for this. I believe the keyboard shortcut for this is shift + option + F
(or shift + alt + F
). There is not currently support in the extension for Format Selection, although this is something we hope to add in the future.
Thank you! This works for me
We are also desperately waiting for auto-formatting functionality as mentioned by the original feature requestor (not just indentation, but code formatting - the same actually holds for the MATLAB IDE). Our dream would be a Matlab counterpart to Python's black code formatter.
It is often not software developers (but engineers or similar) that use Matlab, and hence auto-formatting of Matlab code can result in massive improvements of code quality, without the need to bother the contributing engineers with coding style rules.
@dklilley @nickchoi-mw The request has been open since April, any estimate on when this will be released?
This is an area we want to expand upon and are looking into as part of a multi-team effort. I am not able to provide any estimates at this time.