You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected new_line after function call with ternary condition #1218
I do not know how can i resolve this.
When I set ls_code_width = true, it does not add new line but ternary condition is splited then and I do not want that. I would be very pleased if you could help me resolve this problem.
Here goes codes.
The ternary condition is not splitted in your result, but there is an extra newline. So I assume that is your problem? Yes, its right there in the title that I skipped reading.
The newline is (wrongly) added by
# Try to limit code width to N number of columns
code_width =80# unsigned number
Interestingly enough that does not happen when the expression is not inside the if block. So this seems to be related to the virtual if close brace. I will take a look.
If
# Whether to split lines as close to code_width as possible and ignore some groupings
ls_code_width = true # false/true
is added (which, as you wrote, you don't want to use), then the ternary is broken up:
The break up happens too soon as the semicolon is not above col pos 80 as specified (it is at col 78)
Well so it seems to be deeper problem then.
As I understand ls_code_width = true results in ignoring groupings am I correct?
So I have such a scenerio.
Sometimes it breakes only last argument (first case) and sometimes it starts breaking at first argument (second case). Little confusing. Hope so it will provide something more to the problem.
The problem is that Uncrustify by default indents with 8 chars, the tab width by default is also set to 8, with that in mind the semicolon is actually at col 81 (not 73).
Set
# The number of columns to indent per level.# Usually 2, 3, 4, or 8. Default=8
indent_columns =4# unsigned number
and it should work as expected.
The default 8 is fairly confusing as most editors have it set to something other than that, this caused the miscalculation in my last comment.
Related:
# The original size of tabs in the input. Default=8
input_tab_size =8# unsigned number
Not (here) related (only used if ...):
# The size of tabs in the output (only used if align_with_tabs=true). Default=8
output_tab_size =8# unsigned number
Adding this to your config:
# The number of columns to indent per level.# Usually 2, 3, 4, or 8. Default=8
indent_columns =4# unsigned number# Whether to split lines as close to code_width as possible and ignore some groupings
ls_code_width = true # false/true
should occur even if ls_code_width = false. When I set it to true it breakes as expected but it will ruin my previous goal. And in description of that setting it is written that if true it is ignoring groupings.
Ok here is what is currently happening with case 3:
With the 'xxxx...' string chunk, it is determined that its token is too long and the function split_line proceeds to cut the line properly.
In round two like previously in the do_code_width function, the function is_past_width - L142 determines that the comma after the string is problematic, the split_line function is called which itself calls the split_fcn_params function.
Inside it first the opening parenthesis - L636-L643 of the function call is searched, then the first comma above max col - L654-L683 (the one that was deemed to be problematic) and finally a comma before the problematic comma is tried to be found.
There is none, but a newline (the one that was inserted in the first run) is found which breaks the loop - L693. The prev var (which should have been either a comma or a closing parenthesis) at this point is that loop breaking newline and so the line is not broken up in L719-L728
That goes on this way until the closing parenthesis is also deemed to be problematic. In that case instead of the split_fcn_params function the split_before_chunk function is called, resulting that ddddddddd); is on a new line.
Ok, so it is a bug.
I would live with that but there is my original problem with newline after ternary condition.
Tell me, can you do sth with that or how things going here?
Your original problem with the extra newline should be fixed once the first PR (1219) for this issue is merged, the other problems will also be fixed soon with a new PR. It will take a while though until the PRs are actually getting merged in.
You can always integrate those earlier in your local repo if you want to.
Activity
CDanU commentedon Jun 23, 2017
The ternary condition is not splitted in your result, but there is an extra newline.
So I assume that is your problem?Yes, its right there in the title that I skipped reading.The newline is (wrongly) added by
Interestingly enough that does not happen when the expression is not inside the if block. So this seems to be related to the virtual if close brace. I will take a look.
If
is added (which, as you wrote, you don't want to use), then the ternary is broken up:
The break up happens too soon as the semicolon is not above col pos 80 as specified (it is at col (input) 78, after processing (tabs) 73)
Shohoo commentedon Jun 23, 2017
Well so it seems to be deeper problem then.
As I understand ls_code_width = true results in ignoring groupings am I correct?
So I have such a scenerio.
debug: https://pastebin.com/i02ePEEE
file:
results:
expected:
Sometimes it breakes only last argument (first case) and sometimes it starts breaking at first argument (second case). Little confusing. Hope so it will provide something more to the problem.
CDanU commentedon Jun 23, 2017
The problem is that Uncrustify by default indents with 8 chars, the tab width by default is also set to 8, with that in mind the semicolon is actually at col 81 (not 73).
Set
and it should work as expected.
The default 8 is fairly confusing as most editors have it set to something other than that, this caused the miscalculation in my last comment.
Related:
Not (here) related (only used if ...):
Adding this to your config:
Creates this output for your new examples:
If
input_tab_size = 4tabs will be used for the indention.Shohoo commentedon Jun 26, 2017
I think you did not understand. In my opinion result:
should occur even if ls_code_width = false. When I set it to true it breakes as expected but it will ruin my previous goal. And in description of that setting it is written that if true it is ignoring groupings.
And indenting with 4 is not my goal, I need 8.
Shohoo commentedon Jun 26, 2017
I have added third case to previous two:
results in:
The difference between 2 and 3 case is that I made string as long as in 1 case. And as you see in 3 case arguments are breaking inproperly.
CDanU commentedon Jun 26, 2017
Yes, you are right I had mixed up the two problems a bit. I am going to see why the breaks are happening this way.
CDanU commentedon Jun 26, 2017
Ok here is what is currently happening with case 3:
With the 'xxxx...' string chunk, it is determined that its token is too long and the function split_line proceeds to cut the line properly.
In round two like previously in the
do_code_widthfunction, the function is_past_width - L142 determines that the comma after the string is problematic, thesplit_linefunction is called which itself calls thesplit_fcn_paramsfunction.Inside it first the opening parenthesis - L636-L643 of the function call is searched, then the first comma above max col - L654-L683 (the one that was deemed to be problematic) and finally a comma before the problematic comma is tried to be found.
There is none, but a newline (the one that was inserted in the first run) is found which breaks the loop - L693. The prev var (which should have been either a comma or a closing parenthesis) at this point is that loop breaking newline and so the line is not broken up in L719-L728
That goes on this way until the closing parenthesis is also deemed to be problematic. In that case instead of the
split_fcn_paramsfunction thesplit_before_chunkfunction is called, resulting thatddddddddd);is on a new line.Shohoo commentedon Jun 28, 2017
Ok, so it is a bug.
I would live with that but there is my original problem with newline after ternary condition.
Tell me, can you do sth with that or how things going here?
CDanU commentedon Jun 28, 2017
Your original problem with the extra newline should be fixed once the first PR (1219) for this issue is merged, the other problems will also be fixed soon with a new PR. It will take a while though until the PRs are actually getting merged in.
You can always integrate those earlier in your local repo if you want to.
guy-maurel commentedon Feb 28, 2018
May we close ?
CDanU commentedon Feb 28, 2018
No
guy-maurel commentedon Dec 16, 2021
The current git version works pretty fine under Linux Mint.
https://github.com/uncrustify/uncrustify
Please test it and report!