Skip to content

Commit

Permalink
Merge pull request #2938 from guy-maurel/PR2930
Browse files Browse the repository at this point in the history
addd a new option donot_indent_func_def_close_paren
  • Loading branch information
gmaurel committed Sep 28, 2020
2 parents 3dff242 + b61b795 commit 8bce9a8
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/indent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3431,9 +3431,38 @@ void indent_text(void)
}
}
}
size_t indent_value = 0;
LOG_FMT(LINDENT, "%s(%d): orig_line is %zu, closing parenthesis => %zu, text is '%s'\n",
__func__, __LINE__, pc->orig_line, indent_column, pc->text());
reindent_line(pc, indent_column);
LOG_FMT(LINDENT, "%s(%d): [%s/%s]\n",
__func__, __LINE__,
get_token_name(pc->type), get_token_name(get_chunk_parent_type(pc)));
chunk_t *prev = chunk_get_prev(pc); // Issue #2930
LOG_FMT(LINDENT, "%s(%d): prev is orig_line is %zu, text is '%s'\n",
__func__, __LINE__, prev->orig_line, prev->text());
chunk_t *next = chunk_get_next(pc);
LOG_FMT(LINDENT, "%s(%d): next is orig_line is %zu, text is '%s'\n",
__func__, __LINE__, next->orig_line, next->text());

if ( get_chunk_parent_type(pc) == CT_FUNC_DEF
&& chunk_is_newline(prev)
&& chunk_is_newline(next))
{
if (options::donot_indent_func_def_close_paren())
{
indent_value = 1;
}
else
{
reindent_line(pc, indent_column);
indent_value = indent_column;
}
}
else
{
indent_value = indent_column;
}
reindent_line(pc, indent_value);
}
else if (chunk_is_token(pc, CT_COMMA))
{
Expand Down
5 changes: 5 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,11 @@ indent_single_after_return;
extern Option<bool>
indent_ignore_asm_block;

// Don't indent the close parenthesis of a function definition,
// if the parenthesis is on its own line.
extern Option<bool>
donot_indent_func_def_close_paren;

//END

///////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions tests/cli/output/mini_d_uc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ indent_off_after_return = false
indent_off_after_return_new = false
indent_single_after_return = false
indent_ignore_asm_block = false
donot_indent_func_def_close_paren = false
nl_collapse_empty_body = false
nl_assign_leave_one_liners = false
nl_class_leave_one_liners = false
Expand Down
4 changes: 4 additions & 0 deletions tests/cli/output/mini_d_ucwd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,10 @@ indent_single_after_return = false # true/false
# have their own indentation).
indent_ignore_asm_block = false # true/false

# Don't indent the close parenthesis of a function definition,
# if the parenthesis is on its own line.
donot_indent_func_def_close_paren = false # true/false

#
# Newline adding and removing options
#
Expand Down
1 change: 1 addition & 0 deletions tests/cli/output/mini_nd_uc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ indent_off_after_return = false
indent_off_after_return_new = false
indent_single_after_return = false
indent_ignore_asm_block = false
donot_indent_func_def_close_paren = false
nl_collapse_empty_body = false
nl_assign_leave_one_liners = false
nl_class_leave_one_liners = false
Expand Down
4 changes: 4 additions & 0 deletions tests/cli/output/mini_nd_ucwd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,10 @@ indent_single_after_return = false # true/false
# have their own indentation).
indent_ignore_asm_block = false # true/false

# Don't indent the close parenthesis of a function definition,
# if the parenthesis is on its own line.
donot_indent_func_def_close_paren = false # true/false

#
# Newline adding and removing options
#
Expand Down
4 changes: 4 additions & 0 deletions tests/cli/output/show_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,10 @@ indent_single_after_return = false # true/false
# have their own indentation).
indent_ignore_asm_block = false # true/false

# Don't indent the close parenthesis of a function definition,
# if the parenthesis is on its own line.
donot_indent_func_def_close_paren = false # true/false

#
# Newline adding and removing options
#
Expand Down
8 changes: 8 additions & 0 deletions tests/cli/output/universalindent.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2999,6 +2999,14 @@ EditorType=boolean
TrueFalse=indent_ignore_asm_block=true|indent_ignore_asm_block=false
ValueDefault=false

[Donot Indent Func Def Close Paren]
Category=2
Description="<html>Don't indent the close parenthesis of a function definition,<br/>if the parenthesis is on its own line.</html>"
Enabled=false
EditorType=boolean
TrueFalse=donot_indent_func_def_close_paren=true|donot_indent_func_def_close_paren=false
ValueDefault=false

[Nl Collapse Empty Body]
Category=3
Description="<html>Whether to collapse empty blocks between '{' and '}'.<br/>If true, overrides nl_inside_empty_func</html>"
Expand Down
15 changes: 15 additions & 0 deletions tests/config/Issue_2930.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output_tab_size = 4
sp_before_ptr_star = add
sp_between_ptr_star = remove
sp_func_def_paren = add
indent_columns = 4
indent_with_tabs = 0
donot_indent_func_def_close_paren = true
nl_func_type_name = add
nl_func_def_start = add
nl_func_def_args = add
nl_func_def_end = add
nl_fdef_brace = add
align_on_tabstop = true
align_func_params = true
align_var_def_star_style = 2
1 change: 1 addition & 0 deletions tests/cpp.test
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
30264 Issue_2668.cfg cpp/Issue_2668.cpp
30265 long_br_cmt.cfg cpp/long_br_cmt.cpp
30266 Issue_2921.cfg cpp/Issue_2921.cpp
30267 Issue_2930.cfg cpp/Issue_2930.cpp

30270 const_throw.cfg cpp/const_throw.cpp
30271 sp_throw_paren-r.cfg cpp/sp_throw_paren.cpp
Expand Down
8 changes: 8 additions & 0 deletions tests/expected/cpp/30267-Issue_2930.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int
main (
int argc,
char ** argv
)
{
return 0;
}
3 changes: 3 additions & 0 deletions tests/input/cpp/Issue_2930.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(int argc, char** argv) {
return 0;
}

0 comments on commit 8bce9a8

Please sign in to comment.