Skip to content

Commit

Permalink
The proposal uncrustify#477 is implemented.
Browse files Browse the repository at this point in the history
It would be really nice to have a feature similar to nl_fdef_brace and nl_if_brace...
    [dataArray enumerateObjectsUsingBlock:^(dataType *data, NSUInteger idx, BOOL *stop)
     {
         // Do stuff!
     }];
...to place the opening curly bracket with or without newline.

The new option is:
  nl_oc_block_brace
  • Loading branch information
gmaurel committed May 26, 2016
1 parent a094c39 commit 14ae8a5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -4,13 +4,15 @@ Change highlights in uncrustify-0.xx (xxx 2016)
New:

New options:
- nl_oc_block_brace
- nl_split_if_one_liner
- nl_split_for_one_liner
- nl_split_while_one_liner
- nl_after_func_class_proto
- nl_after_func_class_proto_group

Bugfix:
- Proposal #477 is implemented
- Issue #405 is fixed
- Proposal #409 is implemented
- Issue #481 is fixed
Expand Down
11 changes: 8 additions & 3 deletions src/newlines.cpp
Expand Up @@ -2332,8 +2332,13 @@ void newlines_cleanup_braces(bool first)

if ((pc->parent_type == CT_CLASS) && (pc->level == pc->brace_level))
{
newlines_do_else(chunk_get_prev_nnl(pc),
cpd.settings[UO_nl_class_brace].a);
newlines_do_else(chunk_get_prev_nnl(pc), cpd.settings[UO_nl_class_brace].a);
}

if (pc->parent_type == CT_OC_BLOCK_EXPR)
{
// issue # 477
newline_iarf_pair(chunk_get_prev(pc), pc, cpd.settings[UO_nl_oc_block_brace].a);
}

next = chunk_get_next_nnl(pc);
Expand Down Expand Up @@ -2439,7 +2444,7 @@ void newlines_cleanup_braces(bool first)
{
if ((pc->flags & PCF_ONE_LINER) == 0)
{
/* Make sure the } is preceded by two newlines */
/* Make sure the brace is preceded by two newlines */
prev = chunk_get_prev(pc);
if (!chunk_is_newline(prev))
{
Expand Down
2 changes: 2 additions & 0 deletions src/options.cpp
Expand Up @@ -754,6 +754,8 @@ void register_options(void)
"Don't split one-line while statements - 'while(a) b++;'");
unc_add_option("nl_oc_msg_leave_one_liner", UO_nl_oc_msg_leave_one_liner, AT_BOOL,
"Don't split one-line OC messages");
unc_add_option("nl_oc_block_brace", UO_nl_oc_block_brace, AT_IARF,
"Add or remove newline between Objective-C block signature and '{'");

unc_add_option("nl_start_of_file", UO_nl_start_of_file, AT_IARF,
"Add or remove newlines at the start of the file");
Expand Down
1 change: 1 addition & 0 deletions src/options.h
Expand Up @@ -628,6 +628,7 @@ enum uncrustify_options
UO_nl_oc_msg_args, // Whether to put each OC message parameter on a separate line
// See nl_oc_msg_leave_one_liner
UO_nl_oc_msg_leave_one_liner, // Don't split one-line OC messages
UO_nl_oc_block_brace, // Add or remove newline between Objective-C block signature and '{'

UO_pos_arith, // position of trailing/leading arithmetic ops
UO_pos_assign, // position of trailing/leading =
Expand Down
1 change: 1 addition & 0 deletions tests/config/bug_i_477.cfg
@@ -0,0 +1 @@
nl_oc_block_brace = force
3 changes: 3 additions & 0 deletions tests/input/oc/bug_i_477.m
@@ -0,0 +1,3 @@
[dataArray enumerateObjectsUsingBlock:^(dataType *data, NSUInteger idx, BOOL *stop) {
// Do stuff!
}];
2 changes: 2 additions & 0 deletions tests/objective-c.test
Expand Up @@ -85,3 +85,5 @@

50510 gh293.a.cfg oc/gh293.m
50511 gh293.b.cfg oc/gh293.m

50600 bug_i_477.cfg oc/bug_i_477.m
4 changes: 4 additions & 0 deletions tests/output/oc/50600-bug_i_477.m
@@ -0,0 +1,4 @@
[dataArray enumerateObjectsUsingBlock:^(dataType *data, NSUInteger idx, BOOL *stop)
{
// Do stuff!
}];

0 comments on commit 14ae8a5

Please sign in to comment.