-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
indentation problem in nested functions with line continuations #245
Comments
And this kind of line continuations will just work fine (however the github matlab code syntax highlighting seems to be broken here): before: a = b...
(c...
(d...
(e...
(f...
(g...
(h...
)...
)...
)...
)...
)...
); after: a = b ...
(c ...
(d ...
(e ...
(f ...
(g ...
(h ...
) ...
) ...
) ...
) ...
) ...
); |
Yes, this is a known issue (see https://github.com/florianschanda/miss_hit/blob/master/CHANGELOG.md#tooling) The way the indenter and pretty printer works is weird, and that largely explains this behaviour. It generally works by just adding or removing a few spaces; plus line continuations are really awkward in MATLAB anyway, and my handling of them is not ideal either. I do plan to produce a totally new (ast-based) pretty printer; I just need to work out how to correctly deal with comments. But I can look at this case and see if I can maybe fix something, but please don't expect too much in the short term... |
Got it, no hurry. It's already an excellent work and fits my needs. Thanks! |
I have a guess what is happening; the line continuation will be based on where the opening brace is; but we use the un-fixed position for determining the column number not the fixed one. |
Ugh, as expected it's nasty. So the continuation is of course based on the last encountered bracket and we derive the indentation based on it's (fixed) location. But this logic only works if the bracket is the first thing in a line. This will be very nasty to fix, but I will see what I can do. |
👍 Good to know the reason! And I find another case where similar problem occurs, I'm not sure if it fits your explanation regarding if the bracket is the first thing in a line: a = [
b( ...
c, ...
d ...
)
]; format once: a = [
b( ...
c, ...
d ...
)
]; twice: a = [
b( ...
c, ...
d ...
)
]; Yet the following code will only need once: b( ...
c, ...
d ...
); |
Yep, same thing, same issue. So there is three ways of fixing this, all with immense down-sides:
That said, I have totally re-written the fixer one before, so maybe it's time to re-design again with this kind of issue in mind. I'll file the test-cases you made (thanks btw) and will keep this open, but nothing will happen this year pretty sure. |
Maybe I will do option 2, but as an additional option (i.e. non-default behaviour), just in case somebody is willing to pay the performance hit. |
MISS_HIT Component affected
Please choose one from:
Your MATLAB/Octave environment
Your operating system and Python version
Python 3.9.1
Describe the bug
When I use
mh_style
with--fix
option to style the following codethe output will be
which is not a final steady indentation style and can be further styled multiple times till
I'm assuming this is not intended and there may be some problem when calculating the indentation in this kind of nested functions with line continuations?
The text was updated successfully, but these errors were encountered: