This commit is contained in:
Hackerpilot 2015-06-08 03:05:11 -07:00
parent 959405eda5
commit bef02a3b55
8 changed files with 53 additions and 13 deletions

View file

@ -36,7 +36,6 @@ found in .editorconfig files.
* **--max_line_length**: See **max_line_length** below
* **--soft_max_line_length**: See **dfmt_soft_max_line_length** below
* **--outdent_attributes**: See **dfmt_outdent_attributes** below
* **--outdent_labels**: See **dfmt_outdent_labels** below
* **--space_after_cast**: See **dfmt_space_after_cast** below
* **--split_operator_at_line_end**: See **dfmt_split_operator_at_line_end** below
* **--tab_width**: See **tab_width** below
@ -90,7 +89,6 @@ Property Name | Allowed Values | Default Value | Description
--------------|----------------|---------------|------------
dfmt_brace_style | `allman`, `otbs`, or `stroustrup` | `allman` | [See Wikipedia](https://en.wikipedia.org/wiki/Brace_style)
dfmt_soft_max_line_length | positive integers | `80` | The formatting process will usually keep lines below this length, but they may be up to max_line_length columns long.
dfmt_outdent_labels (Not yet implemented) | `true`, `false` | `true` | Decrease the indentation of labels
dfmt_align_switch_statements (Not yet implemented) | `true`, `false` | `true` | Align labels, cases, and defaults with their enclosing switch
dfmt_outdent_attributes (Not yet implemented) | `true`, `false` | `true` | Decrease the indentation level of attributes
dfmt_split_operator_at_line_end | `true`, `false` | `false` | Place operators on the end of the previous line when splitting lines

View file

@ -29,8 +29,6 @@ struct Config
///
OptionalBoolean dfmt_outdent_attributes;
///
OptionalBoolean dfmt_outdent_labels;
///
int dfmt_soft_max_line_length = -1;
///
OptionalBoolean dfmt_space_after_cast;

View file

@ -475,6 +475,8 @@ private:
{
if (isCase && !indents.topIs(tok!"case") && config.dfmt_align_switch_statements == OptionalBoolean.f)
indents.push(tok!"case");
else if (isAttribute && !indents.topIs(tok!"@") && config.dfmt_outdent_attributes == OptionalBoolean.f)
indents.push(tok!"@");
newline();
}
@ -1120,7 +1122,7 @@ private:
else if (currentIs(tok!"}"))
{
indents.popTempIndents();
if (indents.topIs(tok!"case"))
while (indents.topIs(tok!"case") || indents.topIs(tok!"@"))
indents.pop();
if (indents.topIs(tok!"{"))
{
@ -1144,16 +1146,24 @@ private:
}
else if (astInformation.attributeDeclarationLines.canFindIndex(current.line))
{
immutable l = indents.indentToMostRecent(tok!"{");
if (l != -1)
indentLevel = l;
if (config.dfmt_outdent_attributes == OptionalBoolean.t)
{
immutable l = indents.indentToMostRecent(tok!"{");
if (l != -1)
indentLevel = l;
}
else
{
if (indents.topIs(tok!"@"))
indents.pop();
indentLevel = indents.indentLevel;
}
}
else
{
while (indents.topIsTemp() && (peekBackIsOneOf(true, tok!"}", tok!";") && indents.top != tok!";"))
{
while (indents.topIsTemp() && (peekBackIsOneOf(true, tok!"}", tok!";")
&& indents.top != tok!";"))
indents.pop();
}
indentLevel = indents.indentLevel;
}
indent();

View file

@ -12,7 +12,8 @@ import std.d.lexer;
*/
bool isWrapIndent(IdType type) pure nothrow @nogc @safe
{
return type != tok!"{" && type != tok!"case" && type != tok!"]" && isOperator(type);
return type != tok!"{" && type != tok!"case" && type != tok!"@"
&& type != tok!"]" && isOperator(type);
}
/**
@ -20,7 +21,7 @@ bool isWrapIndent(IdType type) pure nothrow @nogc @safe
*/
bool isTempIndent(IdType type) pure nothrow @nogc @safe
{
return type != tok!"{" && type != tok!"case";
return type != tok!"{" && type != tok!"case" && type != tok!"@";
}
/**

View file

@ -0,0 +1,11 @@
class SomeClass
{
public:
int x;
int y;
private:
int z;
}
public:
void doStuff();

1
tests/issue0130.args Normal file
View file

@ -0,0 +1 @@
--outdent_attributes=false

11
tests/issue0130.d Normal file
View file

@ -0,0 +1,11 @@
class SomeClass
{
public:
int x;
int y;
private:
int z;
}
public:
void doStuff();

View file

@ -0,0 +1,10 @@
class SomeClass {
public:
int x;
int y;
private:
int z;
}
public:
void doStuff();