5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Uncrustifyのセッティング (3) インデント編 後編

Posted at

INDENT_FUNC_CLASS_PARAM

indent_func_class_param.cpp
// indent_func_class_param = true
// 引数リストをインデントする。
class MyClass
{
    MyClass(int param1,
        int param2,
        int param3,
        int param4);
};

// indent_func_class_param = false
// 引数リストを'('の下に位置揃えする。
class MyClass
{
    MyClass(int param1,
            int param2,
            int param3,
            int param4);
};

INDENT_FUNC_CTOR_VAR_PARAM

indent_func_ctor_var_param.cpp
// indent_func_ctor_var_param = true
// 引数リストをインデントする。
{
    MyClass object(param1,
        param2,
        param3,
        param4);
}

// indent_func_ctor_var_param = false
// 引数リストを'('の下に位置揃えする。
{
    MyClass object(param1,
                   param2,
                   param3,
                   param4);
}

INDENT_TEMPLATE_PARAM

indent_template_param.cpp
// indent_template_param = true
// 引数リストをインデントする。
template<typename T1,
    typename T2,
    typename T3,
    typename T4>
class Foo
{
};

// indent_template_param = false
// 引数リストを'<'の下に位置揃えする。
template<typename T1,
         typename T2,
         typename T3,
         typename T4>
class Foo
{
};

INDENT_FUNC_PARAM_DOUBLE

indent_func_param_double.cpp
// indent_func_param_double = false
// 引数リストをインデントする。
void function(int param1,
    int param2,
    int param3,
    int param4);

// indent_func_param_double = true
// 引数リストのインデントを倍にする。
void function(int param1,
        int param2,
        int param3,
        int param4);

INDENT_FUNC_CONST

indent_func_const.cpp
// indent_func_const = 0
// 何もしない。
class MyClass
{
    const
    string getString(const string& key)
    const;
}

// indent_func_const = 1
// 行頭(カラム=1)にconstが位置揃えされる。
class MyClass
{
    const
    string getString(const string& key)
const;
}

INDENT_FUNC_THROW

indent_func_throw.cpp
// indent_func_throw = 0
// 何もしない。
class MyClass
{
    void function(void)
    throw;
}

// indent_func_throw = 1
// 行頭(カラム=1)にthrowが位置揃えされる。
class MyClass
{
    void function(void)
throw;
}

INDENT_MEMBER

indent_member.cpp
// indent_member = 2
// '->'や'.'で行送りしたら、空白2個位置揃えする。
{
    instance.
      member = 2;
    pointer
      ->member = 2;
    instance
      .method();
    pointer->
      method();
}

INDENT_SING_LINE_COMMENTS

indent_sing_line_comments.cpp
// indent_sing_line_comments = 2
// コード直前の'//'で始まるコメント行 (複数行OK) が半角空白2個分位置揃えされる。
// 行頭から始まる一行コメントは整形されないので注意。
void func(void)
{
      // align with two spaces...
      // are you happy with this?
    if (true) {

    }
}

INDENT_RELATIVE_SINGLE_LINE_COMMENTS

indent_relative_single_line_comments.cpp
// 整形前のコード
void func(void)
{
    int i = 1;      // this is first comment
        int j = 2;  // this is second comment
}

// 整形後のコード
// indent_relative_single_line_comments = false
// コードの後ろの一行コメントのカラム位置はキープされる。(キープできない場合もある)
void func(void)
{
    int i = 1;      // this is first comment
    int j = 2;      // this is second comment
}

// indent_relative_single_line_comments = true
// コードの後ろの一行コメントはコードのインデントに合わせて相対的にインデントされる。
void func(void)
{
    int i = 1;      // this is first comment
    int j = 2;  // this is second comment
}

INDENT_SWITCH_CASE

indent_switch_case.cpp
// indent_switch_case = 4
// 'case'が'switch'から半角空白4個分インデントされる。
{
    switch (type)
    {
        case FIRST:
        case SECOND:
        case THIRD:
        default:
    }
}

INDENT_CASE_SHIFT

indent_case_shift.cpp
// indent_case_shift = 2
// 'case'だけ半角空白2個分インデントされる。
// ちなみに、'case'の中の行はindent_switch_caseにインデントされる。
switch (type) {
  case FIRST:
    break;
  case SECOND:
    break;
}

INDENT_CASE_BRACE

indent_case_brace.cpp
// indent_case_brace = 2
// 'case'の次の行に続く'{'から先の行をindent_switch_caseから半角空白2個だけインデントする。
// さらに、ブロック内はindent_columnsだけインデントされる。
switch (type) {
    case FIRST:
      {
          int i;
      }
      break;
}

INDENT_COL1_COMMENT

indent_col1_comment.cpp
// indent_col1_comment = false
// 行頭コメントはインデントしない。
{
// this is a remarkable comment.
    int i;
    int j;
}

// indent_col1_comment = true
// 行頭コメントもインデントする。
{
    // this is a remarkable comment.
    int i;
    int j;
}

INDENT_LABEL

indent_label.cpp
// indent_label = 1
// 行頭にgotoラベルを配置する。
{
    goto failed;

failed:
    return -1;
}

// indent_label = -4
// '{'のインデント位置から相対的に半角空白4個分左にインデントする。
// 0だと、'{"のインデント位置にインデントされる。
{
    {
        goto label;

    label:
        retval = -1;
    }
}

INDENT_ACCESS_SPEC

indent_access_spec.cpp
// indent_access_spec = 1
// 行頭にアクセス指定子を配置する。
class Foo
{
public:
    class Bar
    {
public:
        void foobar(void);
    };
};

// indent_access_spec = -2
// '{'のインデント位置から半角空白2個分左にインデントする。
class Foo
{
  public:
    class Bar
    {
      public:
        void foobar(void);
    };
}

INDENT_ACCESS_SPEC_BODY

indent_access_spec_body.cpp
// indent_access_spec_body = true
// アクセス指定子もインデントされ、ボディもインデントされる。
class Foo
{
    public:
        class Bar
        {
            public:
                void foobar(void);
        };
};

INDENT_PAREN_NL

indent_paren_nl.cpp
// indent_paren_nl = true
// こんな感じで、'('の直後に改行されていたら、'('の下まで位置揃えされる。
    function(
             param1,
             param2);

    if (
        cond1 &&
        cond2)

INDENT_PAREN_CLOSE

indent_paren_close.cpp
// indent_paren_close = 0
// 改行直後の')'はボディレベルに位置揃えされる。
void function(
    int param1,
    int param2
    );

// indent_paren_close = 1
// 改行直後の')'はペアとなる'('の位置に位置揃えされる。
void function(
    int param1,
    int param2
             );

// indent_paren_cloase = 2
// 改行直後の')'はブレースレベルに位置揃えされる。
void function(
    param1,
    param2
);

INDENT_COMMA_PAREN

indent_comma_paren.cpp
// indent_comma_paren = true
// '('の下に','が位置揃えされる。こういう書き方が好きな方はどうぞ。
void func( int param1
         , int param2
         , int param3);

INDENT_BOOL_PAREN

indent_bool_paren.cpp
// indent_bool_paren = true
// '('の下に'||'が位置揃えされる。
if (cond1
   || cond2
   || cond3)

INDENT_FIRST_BOOL_EXPR

indent_first_bool_expr.cpp
// indent_first_bool_expr = true (&& indent_bool_paren = true)
// 最初の評価式を続く評価式のインデントに位置揃えする。
if (  cond1
   || cond2
   || cond3)

INDENT_SQUARE_NL

indent_square_nl
// indent_square_nl = true
// '['の位置に改行後のコードが位置揃えされる。
int value = table[
                  index];

INDENT_ALIGN_ASSIGN

indent_align_assign.cpp
// indent_align_assign = true
int score = input1 * factor +
            input2;

int score =
    input1 * factor +
    inptu2;

// indent_align_assign = false
int score = input1 * factor +
    intput2;

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?