Commit a2ab30ed authored by Miroslaw Stein's avatar Miroslaw Stein Committed by Gleb Popov

Support for indent-after-parens astyle option

Summary:
This change adds --indent-after-parens and --indent-continuation support in the custom astyle formatter config.
(see: http://astyle.sourceforge.net/astyle.html#_indent-after-parens)

Reviewers: #kdevelop, mwolff

Reviewed By: #kdevelop, mwolff

Subscribers: mwolff, kdevelop-devel

Tags: #kdevelop

Maniphest Tasks: T10373

Differential Revision: https://phabricator.kde.org/D18371
parent 7fd559bb
......@@ -87,6 +87,8 @@ void AStyleFormatter::updateFormatter()
AStyleFormatter::setLabelIndent(m_options[QStringLiteral("IndentLabels")].toBool());
AStyleFormatter::setBlockIndent(m_options[QStringLiteral("IndentBlocks")].toBool());
AStyleFormatter::setPreprocessorIndent(m_options[QStringLiteral("IndentPreprocessors")].toBool());
AStyleFormatter::setAfterParens(m_options[QStringLiteral("AfterParens")].toBool());
AStyleFormatter::setContinuation(m_options[QStringLiteral("Continuation")].toInt());
// continuation
AStyleFormatter::setMaxInStatementIndentLength(m_options[QStringLiteral("MaxStatement")].toInt());
......@@ -162,6 +164,8 @@ void AStyleFormatter::resetStyle()
setLabelIndent(true);
setBlockIndent(false);
setPreprocessorIndent(false);
setAfterParens(false);
setContinuation(1);
//padding
setOperatorPaddingMode(false);
setParensInsidePaddingMode(true);
......@@ -417,6 +421,18 @@ void AStyleFormatter::setMinConditionalIndentLength(int min)
ASFormatter::setMinConditionalIndentLength();
}
void AStyleFormatter::setAfterParens(bool on)
{
m_options[QStringLiteral("AfterParens")] = on;
ASFormatter::setAfterParenIndent(on);
}
void AStyleFormatter::setContinuation(int n)
{
m_options[QStringLiteral("Continuation")] = n;
ASFormatter::setContinuationIndentation(n);
}
void AStyleFormatter::setBracketFormatMode(astyle::BraceMode mode)
{
switch (mode) {
......
......@@ -59,6 +59,8 @@ public:
void setSwitchIndent(bool on);
void setMaxInStatementIndentLength(int max);
void setMinConditionalIndentLength(int min);
void setAfterParens(bool on);
void setContinuation(int n);
//brackets
void setBracketFormatMode(astyle::BraceMode mode);
void setBreakClosingHeaderBracketsMode(bool state);
......
......@@ -123,6 +123,9 @@ void AStylePreferences::init()
connect(cbPointerAlign, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &AStylePreferences::pointerAlignChanged);
connect(chkAfterParens, &QCheckBox::stateChanged, this, &AStylePreferences::afterParensChanged);
connect(inpContinuation, QOverload<int>::of(&QSpinBox::valueChanged), this, &AStylePreferences::afterParensChanged);
}
void AStylePreferences::load(const SourceFormatterStyle &style)
......@@ -175,6 +178,10 @@ void AStylePreferences::updateWidgets()
inpMaxStatement->setValue(m_formatter->option(QStringLiteral("MaxStatement")).toInt());
inpMinConditional->setValue(m_formatter->option(QStringLiteral("MinConditional")).toInt());
chkAfterParens->setChecked(m_formatter->option(QStringLiteral("AfterParens")).toBool());
inpContinuation->setValue(m_formatter->option(QStringLiteral("Continuation")).toInt());
inpContinuation->setEnabled(chkAfterParens->isChecked());
// brackets
QString s = m_formatter->option(QStringLiteral("Brackets")).toString();
if(s == QLatin1String("Attach"))
......@@ -431,3 +438,13 @@ void AStylePreferences::pointerAlignChanged()
updatePreviewText();
}
void AStylePreferences::afterParensChanged()
{
if(!m_enableWidgetSignals)
return;
m_formatter->setAfterParens(chkAfterParens->isChecked());
inpContinuation->setEnabled(chkAfterParens->isChecked());
m_formatter->setContinuation(inpContinuation->value());
updatePreviewText();
}
......@@ -55,6 +55,7 @@ private Q_SLOTS:
void paddingChanged();
void onelinersChanged();
void pointerAlignChanged();
void afterParensChanged();
private:
QScopedPointer<AStyleFormatter> m_formatter;
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>332</width>
<height>519</height>
<height>600</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
......@@ -250,6 +250,29 @@ relative to the previous line.</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="inpContinuation">
<property name="toolTip">
<string>Number of indents</string>
</property>
<property name="maximum">
<number>4</number>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="chkAfterParens">
<property name="toolTip">
<string>Indent, instead of align, continuation lines following lines that contain an opening paren '(' or an assignment '='.</string>
</property>
<property name="text">
<string>Continuation lines:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment