davidvarga / MBeautifier

MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.
GNU General Public License v3.0
478 stars 75 forks source link

Incorrect reformatting that breaks code #87

Closed VorpalBlade closed 4 years ago

VorpalBlade commented 4 years ago

Using Matlab R2015b I had the following code fragment:

Q=0.7*diag([(.04)^2 (.04)^2]);

Using the installed shortcut the format the editor page results in:

Q = 0.7 * diag([(.04)^2(.04)^2]);

These code snippets are not equivalent. The space after the first ^2 is important.

I have not changed the default configuration for MBeautifier.

I have tested with the latest release of MBeautifier (v1.3.2) as well as the latest git revision as of writing this (c77308e). Both versions exhibit the issue.

augustjohansson commented 4 years ago

For what is worth, this also happens for Q = [1 (1)]; which turns into Q = [1(1)]; This is also with the commit https://github.com/davidvarga/MBeautifier/commit/c77308e3d58956a6493da0520e53f327f97e6eb0 .

I guess it could be fixed by first adding commas between elements in a vector, and then fix the spacing.

davidvarga commented 4 years ago

Hello guys,

I just solved this issue which happen to be the same problem.

I close this issue as duplicate - if the problem is not fixed, please comment on this one and I will reopen it.

Thanks!

davidvarga commented 4 years ago

Sorry, I had to revert the commit(s), it casues something else to break - this issue is much trickier than I thought.

davidvarga commented 4 years ago

Fixed the problem once again using a different solution.