diff --git a/src/dfmt/config.d b/src/dfmt/config.d index 10c504f..8bf3318 100644 --- a/src/dfmt/config.d +++ b/src/dfmt/config.d @@ -28,6 +28,13 @@ enum TemplateConstraintStyle always_newline_indent } +enum SpacesAroundBrackets +{ + unspecified, + none, + inside +} + /// Configuration options for formatting struct Config { @@ -51,6 +58,8 @@ struct Config OptionalBoolean dfmt_compact_labeled_statements; /// TemplateConstraintStyle dfmt_template_constraint_style; + /// + SpacesAroundBrackets spaces_around_brackets; mixin StandardEditorConfigFields; @@ -76,6 +85,8 @@ struct Config dfmt_selective_import_space = OptionalBoolean.t; dfmt_compact_labeled_statements = OptionalBoolean.t; dfmt_template_constraint_style = TemplateConstraintStyle.conditional_newline_indent; + + spaces_around_brackets = SpacesAroundBrackets.none; } /** diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 237cbd6..5430b19 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -507,6 +507,10 @@ private: spaceAfterParens = true; parenDepth++; } + + if( config.spaces_around_brackets == SpacesAroundBrackets.inside && !currentIs(tok!")") && !currentIs(tok!"]") ) + write(" "); + immutable bool arrayInitializerStart = p == tok!"[" && linebreakHints.length != 0 && astInformation.arrayStartLocations.canFindIndex(tokens[index - 1].index); if (arrayInitializerStart) @@ -535,6 +539,9 @@ private: } body { + if( config.spaces_around_brackets == SpacesAroundBrackets.inside ) + write(" "); + parenDepth--; indents.popWrapIndents(); while (indents.topIsOneOf(tok!"!", tok!")")) @@ -1084,6 +1091,9 @@ private: formatColon(); break; case tok!"]": + if( config.spaces_around_brackets == SpacesAroundBrackets.inside ) + write(" "); + indents.popWrapIndents(); if (indents.topIs(tok!"]")) newline();