Skip to content

Commit

Permalink
Does this tool provide a way to insert new lines after every semicolon?
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvarga committed Mar 14, 2018
1 parent f480e4e commit 1c5ea2a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
18 changes: 11 additions & 7 deletions MFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end

properties(Access = private, Constant)
WhiteSpaceToken = '#MBeauty_WhiteSpace_Token';
WhiteSpaceToken = '#MBeauty_WhiteSpace_Token#';
ContainerOpeningBrackets = {'[', '{', '('};
ContainerClosingBrackets = {']', '}', ')'};
TokenStruct = MFormatter.getTokenStruct();
Expand Down Expand Up @@ -436,7 +436,7 @@
% (operators, containers, ...) -> restore strings -> restore transponations.

code = obj.replaceStrings(obj.replaceTransponations(code));
code = obj.performFormattingSingleLine(code);
code = obj.performFormattingSingleLine(code, false, '', false);
code = obj.restoreTransponations(obj.restoreStrings(code));
end

Expand Down Expand Up @@ -555,7 +555,7 @@
end
end

function data = performFormattingSingleLine(obj, data, doIndexing, contType)
function data = performFormattingSingleLine(obj, data, doIndexing, contType, isContainerElement)
% Performs formatting on a code snippet, where the strings and transponations are already replaced:
% operator, container formatting

Expand Down Expand Up @@ -737,6 +737,10 @@
end
end

if ~isContainerElement && ~str2double(obj.SettingConfiguration.SpecialRules.AllowMultipleStatementsPerLineValue)
data = regexprep(data, ';(?!\s*$)', ';\n');
end

data = regexprep(data, obj.WhiteSpaceToken, ' ');

data = regexprep(data, ' \)', ')');
Expand Down Expand Up @@ -866,7 +870,7 @@
if ~strcmp(openingBracket, '(')
if doIndexing
strNew = strtrim(str);
strNew = [strNew(1), strtrim(obj.performFormattingSingleLine(strNew(2:end - 1), doIndexing, contType)), strNew(end)];
strNew = [strNew(1), strtrim(obj.performFormattingSingleLine(strNew(2:end - 1), doIndexing, contType, true)), strNew(end)];
else
elementsCell = regexp(str, ' ', 'split');

Expand Down Expand Up @@ -904,7 +908,7 @@
currElemStripped = regexprep(currElem, ['[', openingBracket, closingBracket, ']'], '');
nextElemStripped = regexprep(nextElem, ['[', openingBracket, closingBracket, ']'], '');

currElem = strtrim(obj.performFormattingSingleLine(currElem, doIndexing));
currElem = strtrim(obj.performFormattingSingleLine(currElem, doIndexing, contType, true));

if strcmp(openingBracket, '[')
addCommas = str2double(obj.SettingConfiguration.SpecialRules.AddCommasToMatricesValue);
Expand All @@ -924,13 +928,13 @@
end
end

elementsCell{end} = strtrim(obj.performFormattingSingleLine(elementsCell{end}, doIndexing));
elementsCell{end} = strtrim(obj.performFormattingSingleLine(elementsCell{end}, doIndexing, contType, true));

strNew = [openingBracket, elementsCell{:}, closingBracket];
end
else
strNew = strtrim(str);
strNew = [strNew(1), strtrim(obj.performFormattingSingleLine(strNew(2:end - 1), doIndexing, contType)), strNew(end)];
strNew = [strNew(1), strtrim(obj.performFormattingSingleLine(strNew(2:end - 1), doIndexing, contType, true)), strNew(end)];
end

datacell = cell(1, 3);
Expand Down
3 changes: 3 additions & 0 deletions resources/settings/MBeautyConfigurationRules.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@

this.SpecialRules.MatrixIndexing_ArithmeticOperatorPadding = struct();
this.SpecialRules.MatrixIndexing_ArithmeticOperatorPaddingValue = '0';

this.SpecialRules.AllowMultipleStatementsPerLine = struct();
this.SpecialRules.AllowMultipleStatementsPerLineValue = '0';
end
4 changes: 4 additions & 0 deletions resources/settings/MBeautyConfigurationRules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,9 @@
<Key>MatrixIndexing_ArithmeticOperatorPadding</Key>
<Value>0</Value>
</SpecialRule>
<SpecialRule>
<Key>AllowMultipleStatementsPerLine</Key>
<Value>0</Value>
</SpecialRule>
</SpecialRules>
</MBeautifyRuleConfiguration>

0 comments on commit 1c5ea2a

Please sign in to comment.