Closed fangq closed 2 years ago
There is no way to do this right now. Let me see how hard it would be to add...
So I think this is really specific, right? You just want this for top-level functions in function files. All other functions (nested, in class files, etc.) would be indentend normally? At least that is what a cursory survey of the various coding snippets on the mathworks website suggests...
thanks for looking into this - only disabling the indentation for the main/top function is fine for me. because most of my toolboxes have a single function per unit/file. having a leading indentation for every line looks a little bit clunky and redundant for such format.
but of course, if it takes more efforts to separately handle top function and embedded functions, it is also fine to have a flag to disable both. whichever is easier to implement.
I have pushed a proposal fix for this. Could you try it please and let me know if it meets your needs?
The CHANGELOG entry should explain how to activate it:
Add a new configuration option "indent_function_file_body" for MH Style. This is true by default. If you set it to false, then you get the odd indentation style that somewhat common in the MATLAB world, where functions in function files do not have their body indented. For example:
function z = Potato(w)
z = -w;
Note that this option only affects top-level functions in function files. Any other function (e.g. a method, or a nested function) is not affected.
thank you so much! works like a charm! feel free to close the issue.
I noticed one thing: when I set redundant_brackets: true
in the cfg file, mh_style
failed to recognize it
miss_hit.cfg: error: config file contains errors
In miss_hit.cfg, line 3
| redundant_brackets: true
| ^^^^^^^^^^^^^^^^^^ error: expected valid style configuration name (did you mean align_round_brackets?)
.: error: cannot find project root because the config file contains errors: please add a config file with the 'project_root' directive
MISS_HIT Style Summary: 2 file(s) analysed, 3 error(s)
I wonder if this is the right place to set this flag?
never mind. I figured out, need to use suppress_rule: "redundant_brackets"
to disable this rule (which does not have a configuration).
I know this might belong to a separate issue - would it be possible to add an option to only remove indentation of the docstrings (the block of commented lines right before or after the function declaration) of each top level function? sorry for asking too many wishes.
@fangq please make that a separate ticket with an example of what you need.
What kind of feature is this?
I have been following the default MATLAB formatting styles to format my own toolboxes/functions, something looks like this:
I just tried miss_hit, and found that the formatted function has indentations for all docstring and command lines
I am wondering if there is an option to disable this leading indentation for the root-level of a function, so that the formatted file follows MATLAB's style?
thanks
Your MATLAB/Octave environment