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

Indentation broken for some functions on MATLAB R2021b #111

Closed danielmeer closed 2 years ago

danielmeer commented 2 years ago

I don't know why but on MATLAB R2021b the call to editorPage.smartIndentContents(); does not always indent the code correctly.

Not all functions are affected:

Example:

function testfunc()
    a = 1;
    b = 2;
    if a == 1
        b = 3;
    else
        b = 4;
    end
    b = 6;
end

gets formatted to

function testfunc()
    a = 1;
    b = 2;
    if a == 1
        b = 3;
        else
            b = 4;
        end
        b = 6;
end

Interestingly, the smart indent works correctly if I have the cursor on an empty line.

I found a workaround by calling editorPage.smartIndentContents(); twice (in MBeautify.indentPage()). It's not the nicest solution though.

danielmeer commented 2 years ago

Pull request #112 fixes the issue.

davidvarga commented 2 years ago

I forgot to close the issue after merging your PR :)