Skip to content

Commit

Permalink
Merge pull request #4294 from PoeticPete/finish-multi-line
Browse files Browse the repository at this point in the history
Add support for new lining the rest of OC messages
  • Loading branch information
gmaurel committed May 10, 2024
2 parents dc58dfc + a50dd54 commit 71711ca
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 0 deletions.
4 changes: 4 additions & 0 deletions documentation/htdocs/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,10 @@ nl_oc_msg_args_min_params = 0 # unsigned number
# (OC) Max code width of Objective-C message before applying nl_oc_msg_args.
nl_oc_msg_args_max_code_width = 0 # unsigned number

# (OC) Whether to apply nl_oc_msg_args if some of the parameters are already
# on new lines. Overrides nl_oc_msg_args_min_params and nl_oc_msg_args_max_code_width.
nl_oc_msg_args_finish_multi_line = false # true/false

# Add or remove newline between function signature and '{'.
nl_fdef_brace = ignore # ignore/add/remove/force/not_defined

Expand Down
4 changes: 4 additions & 0 deletions documentation/htdocs/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,10 @@ nl_oc_msg_args_min_params = 0 # unsigned number
# (OC) Max code width of Objective-C message before applying nl_oc_msg_args.
nl_oc_msg_args_max_code_width = 0 # unsigned number

# (OC) Whether to apply nl_oc_msg_args if some of the parameters are already
# on new lines. Overrides nl_oc_msg_args_min_params and nl_oc_msg_args_max_code_width.
nl_oc_msg_args_finish_multi_line = false # true/false

# Add or remove newline between function signature and '{'.
nl_fdef_brace = ignore # ignore/add/remove/force/not_defined

Expand Down
4 changes: 4 additions & 0 deletions etc/defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,10 @@ nl_oc_msg_args_min_params = 0 # unsigned number
# (OC) Max code width of Objective-C message before applying nl_oc_msg_args.
nl_oc_msg_args_max_code_width = 0 # unsigned number

# (OC) Whether to apply nl_oc_msg_args if some of the parameters are already
# on new lines. Overrides nl_oc_msg_args_min_params and nl_oc_msg_args_max_code_width.
nl_oc_msg_args_finish_multi_line = false # true/false

# Add or remove newline between function signature and '{'.
nl_fdef_brace = ignore # ignore/add/remove/force/not_defined

Expand Down
9 changes: 9 additions & 0 deletions etc/uigui_uncrustify.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5256,6 +5256,15 @@ MinVal=0
MaxVal=10000
ValueDefault=0

[Nl Oc Msg Args Finish Multi Line]
Category=3
Description="<html>(OC) Whether to apply nl_oc_msg_args if some of the parameters are already<br/>on new lines. Overrides nl_oc_msg_args_min_params and nl_oc_msg_args_max_code_width.</html>"
Enabled=false
EditorType=boolean
TrueFalse=nl_oc_msg_args_finish_multi_line=true|nl_oc_msg_args_finish_multi_line=false
TrueFalseRegex=nl_oc_msg_args_finish_multi_line\s*=\s*true|nl_oc_msg_args_finish_multi_line\s*=\s*false
ValueDefault=false

[Nl Fdef Brace]
Category=3
Description="<html>Add or remove newline between function signature and '{'.</html>"
Expand Down
18 changes: 18 additions & 0 deletions src/newlines/oc_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ void newline_oc_msg(Chunk *start)
should_nl_msg = true;
}

bool finish_multi_line = options::nl_oc_msg_args_finish_multi_line();
if (finish_multi_line) {
size_t prev_line = -1;
for (Chunk *pc = start->GetNextNcNnl(); pc->IsNotNullChunk(); pc = pc->GetNextNcNnl())
{
if (pc->GetLevel() <= start->GetLevel())
{
break;
}

if (prev_line != -1 && pc->GetOrigLine() != prev_line)
{
should_nl_msg = true;
}
prev_line = pc->GetOrigLine();
}
}

// If both nl_oc_msg_args_min_params and nl_oc_msg_args_max_code_width are disabled
// we should newline all messages.
if ( max_code_width == 0
Expand Down
5 changes: 5 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,11 @@ nl_oc_msg_args_min_params;
extern BoundedOption<unsigned, 0, 10000>
nl_oc_msg_args_max_code_width;

// (OC) Whether to apply nl_oc_msg_args if some of the parameters are already
// on new lines. Overrides nl_oc_msg_args_min_params and nl_oc_msg_args_max_code_width.
extern Option<bool>
nl_oc_msg_args_finish_multi_line;

// Add or remove newline between function signature and '{'.
extern Option<iarf_e>
nl_fdef_brace;
Expand Down
9 changes: 9 additions & 0 deletions tests/cli/output/universalindent.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5247,6 +5247,15 @@ MinVal=0
MaxVal=10000
ValueDefault=0

[Nl Oc Msg Args Finish Multi Line]
Category=3
Description="<html>(OC) Whether to apply nl_oc_msg_args if some of the parameters are already<br/>on new lines. Overrides nl_oc_msg_args_min_params and nl_oc_msg_args_max_code_width.</html>"
Enabled=false
EditorType=boolean
TrueFalse=nl_oc_msg_args_finish_multi_line=true|nl_oc_msg_args_finish_multi_line=false
TrueFalseRegex=nl_oc_msg_args_finish_multi_line\s*=\s*true|nl_oc_msg_args_finish_multi_line\s*=\s*false
ValueDefault=false

[Nl Fdef Brace]
Category=3
Description="<html>Add or remove newline between function signature and '{'.</html>"
Expand Down
5 changes: 5 additions & 0 deletions tests/config/oc/nl_oc_msg_args_finish_multi_line.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nl_oc_msg_args = true
nl_oc_msg_args_finish_multi_line = true
indent_columns = 4
indent_with_tabs = 0
align_oc_msg_colon_span = 1
40 changes: 40 additions & 0 deletions tests/expected/oc/50634-nl_oc_msg_args_finish_multi_line.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
static void function() {
[object param1:nil
param2:nil
param3:nil];

[object param1:nil
param2:nil
param3:nil
param4:nil];

[object param1:nil
param2:nil];

[object param1:nil];

[object func];

[obj param1:nil
param2:nil
param3:[obj2 param1:nil
param2:nil]];

[obj param1:nil
param2:[obj2 param1:nil
param2:nil
param3:nil
param4:nil
param5:nil
param6:nil]
param3:nil];

[obj param1:nil
param2:[obj2 param1:nil
param2:nil
param3:nil
param4:nil
param5:nil
param6:nil]
param3:nil];
}
32 changes: 32 additions & 0 deletions tests/input/oc/nl_oc_msg_args_finish_multi_line.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
static void function() {
[object param1:nil
param2:nil param3:nil];

[object param1:nil param2:nil
param3:nil
param4:nil];

[object param1:nil param2:nil];

[object param1:nil];

[object func];

[obj param1:nil param2:nil param3:[obj2 param1:nil
param2:nil]];

[obj param1:nil param2:[obj2 param1:nil
param2:nil
param3:nil
param4:nil
param5:nil
param6:nil]
param3:nil];

[obj param1:nil param2:[obj2 param1:nil
param2:nil
param3:nil
param4:nil
param5:nil
param6:nil] param3:nil];
}
1 change: 1 addition & 0 deletions tests/objective-c.test
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@

50631 oc/nl_oc_msg_args_min_params.cfg oc/nl_oc_msg_args_min_params.m
50632 oc/nl_oc_msg_args_max_code_width.cfg oc/nl_oc_msg_args_max_code_width.m
50634 oc/nl_oc_msg_args_finish_multi_line.cfg oc/nl_oc_msg_args_finish_multi_line.m

50633 common/aet.cfg oc/ocpp_msg_access.mm

Expand Down

0 comments on commit 71711ca

Please sign in to comment.