Code Monkey home page Code Monkey logo

mbeautifier's People

Contributors

aaronwebster avatar asmfstatoil avatar casperdcl avatar cnheying avatar davidvarga avatar maxgaukler avatar mkr3mer avatar mriesch-tum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mbeautifier's Issues

Suggestion: power operator should not be separated

I suggest that power operators ^ and .^ should not be separated by default.
The reason is that in function calls (seems they are affected by matrix indexing settings) it becomes barely readable:
sqrt(a+b^2) becomes sqrt(a+b ^ 2)
While better variants are:
sqrt(a+b^2) or sqrt(a + b^2)

Indentation in multiline condition.

I assume that in the case of a condition, it is better to align to condition on previous line.
I think this code:

if a + b > 0 && ...
   a * b > 0
    a = b;
end   

better than generated by MBeautifier:

if a + b > 0 && ...
        a * b > 0
    a = b;
end

So, this is true for while too.

Inconsistencies in formatting within braces

The latest version with default settings produces this output:

length(x) + 1;
a(length(x)+1);

a(b:b+n-1);
b + n - 1;

So the sameexpressions gets formatted in different ways depending on where it appears. This was not the case in older versions; is this by design now?

Performance improve, code simplification

The current codebase should be simplified and cleaned-up for the final Matlab based release. As it is planned - to avoid problems between different Matlab releases - a Java based (compilant with Java6) reimplementation will be done and release with version 2...

The performance of the current implementation should be analyzed and the bottlenecks should be removed.

Special arithmetic operator cases

Formatting of arithmetic operators needs to address special cases.

Two cases I have found were:

  • [1 -1] becomes [1 - 1] which has a whole different meaning
  • 7E+5 becomes 7E + 5 which is invalid

I have just used it on one file so there might be more cases that have to be considered.

Handling of containers: matrices and cell arrays

Problems covered in this issue

  • At the moment embedded matrices [[],[]] are not processed property
  • New option to add commas also for cell arrays
  • With this new option, embeded cell arrays should be also processed

New configuration setting: operators in case of indexing ( (), {})

The purpose of this issue to provide addtional settings for replacing operators when they are used in indexing (matrixes and cell arrays) like:

namesCell{ind+1} = 'Andy'; rather than namesCell{ind + 1} = 'Andy';

Two new configuration rule could be introduced:

  • CellArrayIndexing_ArithmeticOperatorPadding
  • MatrixIndexing_ArithmeticOperatorPadding

Both contains a boolean value, and indicates wheter in case of cell-array/matrix indexing (cellArray{ind+1} and matrix(ind+1)) te arithmetic operators (+, -, *, /) should be padded with white spaces (using the configuration rules of these operators) or not.

Based on these configuration rules, the example output can be

% Both set to false
cellArray{end+1} = 'dog';
matric(end+1) = 11;

% Both set to true
cellArray{end + 1} = 'dog';
matric(end + 1) = 11;

New working modes: Editor selection and file

Currently the only stable working mode is to format the current page of Matlab Editor.
Two new working modes could be added:

  • Editor selection mode: Implemented but not stable
  • Format files (with and without saving)

Token handling: Improvements

Getting tokens for String, Continuosment is implemented really badly now.
Think it over and implement a faster, more intelligent way.

Multi line matrices and cell arrays without ellipsis line continuation indicator

Currently, if matrices and cell arrays are declared using multiple lines, but no ellipsis line continuation indicator (...) is used, the elements of these containsers dont get formatted.

In these cases the ellipsis line continuation indicator (...) should be also inserted.

Example

c = { 1+2+3 1*2  -12  -10/5
   -1    -2    -3   -4
10*(6+5) 10 10 10}

b = [1+2 2 3
    4 5+4 6
    7 8+4 9
    10 11+4 12]

The expected formatting is

c = {1 + 2 + 3, 1 * 2, -12, -10 / 5; ...
    -1, -2, -3, -4; ...
    10 * (6 + 5), 10, 10, 10}

b = [1 + 2, 2, 3; ...
    4, 5 + 4, 6; ...
    7, 8 + 4, 9; ...
    10, 11 + 4, 12]

AddCommasToMatrices=0 doesn't affect some matrices

Hi!
[[I, Z]; [h * (K-L), I]]changes to [[I, Z]; [h, * (K-L), I]] while

<SpecialRule>
<Key>AddCommasToMatrices</Key>
<Value>0</Value>
</SpecialRule>
<SpecialRule>
<Key>AddCommasToCellArrays</Key>
<Value>0</Value>
</SpecialRule>
<SpecialRule>

Commit b931478, MATLAB 2016b.

Index exceeds matrix dimensions.

When applied to testfile.m the following errors appear in MATLAB 2016a on Linux:

Index exceeds matrix dimensions.

Error in MBeautify/performFormatting>processContainer (line 559)
    indexes = find([containerBorderIndexes{:, 2}] == maxDepth, 2);

Error in MBeautify/performFormatting>performReplacementsSingleLine (line 362)
[data, arrayMapCell] = processContainer(data, settingConf);

Error in MBeautify/performFormatting>performReplacements (line 151)
actCodeTemp = performReplacementsSingleLine(actCodeTemp, settingConf);

Error in MBeautify/performFormatting (line 91)
    actCodeFinal = performReplacements(actCode, settingConf);

Error in MBeautify.beautify (line 18)
formattedSource = MBeautify.performFormatting(codeToFormat, settingConf);

Auto-wrapping long lines

It's probably a quite tricky thing to implement, but it would be nice if there was an option to autowrap long (e.g., > 79 chars) lines. Some sort of heuristics could be used to figure out where to break the lines, e.g., first try breaking at "=". Then if either of parts is still too long, break farthest down the line that puts the line (w/ added ...) under the line limit.

Problem when using +/- signs in the first element of matrix assignments

[-1, 2, 3, 4] -> [-, 1, 2, 3, 4]
[+1, 2, 3, 4] -> [+, 1, 2, 3, 4]

If the +/- sign is on a later position it behaves fine
[1, -2, 3, 4] -> [1, - 2, 3, 4]
however, there is an additional withespace create between the +/- sign and the number
I think -2 is easier to read than - 2 in this case

Expression, that MBeautifier can't handle

Hey, David.

Looks like Beautifier fails on the following code:

[out1, out2] = func([str1, str2], [str3, str4]);

it removes last ");" and code becomes non-compilable.

Denis

MatrixIndexing and CellArrayIndexing setting not respected

Despite having MatrixIndexing_ArithmeticOperatorPadding and CellArrayIndexing_ArithmeticOperatorPadding set to 0 in both the m and xml configuration files, code such as

b = a(1:end-2);
c = a(end-1);
e = d{1:end-2};
f = d{end-1};

is converted to

b = a(1:end - 2);
c = a(end - 1);
e = d{1:end - 2};
f = d{end - 1};

The configuration files are the default ones, have not been edited.

Tested on both R2016a and R2017a

Inconsistent spacing around minus sign

Hi,
[[I,Z];[h*(-K-L),I]] * [[I,Z];[h*(K-L),I]]
becomes
[[I, Z]; [h * (-K - L), I]] * [[I, Z]; [h * (K-L), I]]
with spaces added only in the first parenthesis.
Commit b931478, MATLAB 2016b.

Somewhat relevant config:

<SpecialRule>
<Key>CellArrayIndexing_ArithmeticOperatorPadding</Key>
<Value>0</Value>
</SpecialRule>
<SpecialRule>
<Key>MatrixIndexing_ArithmeticOperatorPadding</Key>
<Value>0</Value>
</SpecialRule>

Single indent with multiple lines of comment

MBeautify add a single indent every line of multiple lines comment after run command MBeautify.formatCurrentEditorPage(). This isn't happening with single line comment.

Before call command:

%This is one line comment
%{
This is
multiline
comment
%}

After call MBeautify.formatCurrentEditorPage() 10 times.

%This is one line comment
%{
          This is
          multiline
          comment
%}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.