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
483 stars 77 forks source link

incorrect indentation in nest for loop #118

Closed zousiyu1995 closed 1 year ago

zousiyu1995 commented 2 years ago

As shown in figure below, image

stinos commented 2 years ago

Cannot reproduce, but also depends on using whitespace or tabs and Matlab version. Actually there are various other indentation issues and they seem to originate form an incorrect interaction between MBeauttify's IndentationCount setting and Matlab's own settings (Preferences-Editor/Debugger->Tab). Changing line 372 in MBeautify to

skipIndentation = true;

which lets Matlab do all indentation, without MBeautify changing it afterwards, seems to work ok for me on R2021b.

edit also there's a difference between using formatFile and formatFileNoEditor, the latter indeed producing errors like you show.

anakinsleftleg commented 2 years ago

I have the same issue as OP. I'm on 21b, my editor tabs are spaces and set for 2. Same settings in MBeautify config. I get the same outcome when run on an open file in the editor.

~~Update: I upgraded from 1.3.1 to 1.3.2 and it no longer behaves that way. ~~

Update 2: Actually, it just happened again. No idea what the conditions are on this happening.

Looks like i'll be using @stinos fork