davidvarga / MBeautifier

MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indentation broken for some functions on MATLAB R2021b

danielmeer opened this issue · comments

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:

  • Working: MBeautify.formatFile(), MBeautify.formatFileNoEditor(), MBeautify.formatFiles()
  • Not working: MBeautify.formatCurrentEditorPage(), MBeautify.formatEditorSelection()

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.

Pull request #112 fixes the issue.

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