This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 192127

Summary: Request for braces indenting that is "new line, indented"
Product: cnd Reporter: sandover
Component: EditorAssignee: Alexander Simon <alexvsimon>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description sandover 2010-11-18 17:47:50 UTC
Our company coding style has us put braces (brackets) on a new line, indented, like so:

if (true)
  { 
    // do stuff
  }

Netbeans does not have a braces indenting option that will support this style.  It would be much appreciated!
Comment 1 Alexander Simon 2010-11-18 18:15:35 UTC
Try to change formatting options:
Tools->Options->Formatting->C++ (or/and C or/and C/C++ Headers)
Section Braces Placement, property Other, value New Line Half Indented
Comment 2 sandover 2010-11-19 20:08:33 UTC
(In reply to comment #1)
> Try to change formatting options:
> Tools->Options->Formatting->C++ (or/and C or/and C/C++ Headers)
> Section Braces Placement, property Other, value New Line Half Indented

The labelling is accurate: the "half indented" option only indents half way.  Our hope was for an "indented" option.
Comment 3 Alexander Simon 2010-11-19 20:14:37 UTC
(In reply to comment #2)
> The labelling is accurate: the "half indented" option only indents half way. 
> Our hope was for an "indented" option.
I do not understand what you mean. Please, provide steps to reproduce your problem.
Comment 4 sandover 2010-11-19 20:57:45 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > The labelling is accurate: the "half indented" option only indents half way. 
> > Our hope was for an "indented" option.
> I do not understand what you mean. Please, provide steps to reproduce your
> problem.

This is an enhancement request for a feature that does not yet exist, but which Petr Pisl mentioned (in a blog comment) would be fairly easy to implement.

The desired behavior is that braces be *fully* indented.  In my example, they are indented by 2 spaces from the column of the "if".  Content within the braces ("// do stuff") is fully indented again, by another 2 spaces.  This is our company coding style, so I'm hoping that Netbeans can help us better support it.

In Tools->Options->Formatting->C++->(braces), the options for braces placement are:  
 1 same line
 2 new line
 3 new line half indent

We would like to see
 4 new line (full) indent
Comment 5 Alexander Simon 2010-11-19 21:10:22 UTC
Your case is:
---------------
if (true)
  { 
    // do stuff
  }
---------------
It is *exactly* what does "new line half indent" options.
Again, provide code example.
Comment 6 sandover 2011-01-19 20:20:36 UTC
Sorry, but this code example already perfectly illustrates the issue.  Let me try to be more precise, though.  I'll describe it three ways.

Visually:
if (true)
  { 
    // do stuff
  }

Visually with whitespace made explicit:
if (true)
[space][space]{ 
[space][space][space][space]// do stuff
[space][space]}

Verbally: With an indent size set to 2, be able to have Netbeans automatically put braces on the next line and indent them a full 2 spaces.  Within the block, content is indented an addition 2 lines.  Again, the braces need to be fully indented -- not half.

Here is what Netbeans actually does with the setting at "new line":

if (true)
{
[space][space]// do stuff
}

Here is what Netbeans does with the setting at "new line half indented":

if (true)
[space]{
[space][space][space]// do stuff
[space]}


I think these are reasonable options.  They're just not what our company style is.

In Tools->Options->Formatting->C++->(braces), the options for braces placement
are:  
 1 same line
 2 new line
 3 new line half indent

We would like to see
 4 new line (full) indent

This would mean that on the new line, the content is indent by the exact indent size (in our case, 2).

Thanks!
Comment 7 Alexander Simon 2011-01-19 20:37:31 UTC
(In reply to comment #6)
> Here is what Netbeans does with the setting at "new line half indented":
> 
> if (true)
> [space]{
> [space][space][space]// do stuff
> [space]}
Set "indent size = 4" and "new line half indented". NB formats:
if (true)
[space][space]{
[space][space][space][space]// do stuff
[space][space]}
Comment 8 Alexander Simon 2011-01-19 20:48:48 UTC
(In reply to comment #6)
> We would like to see
>  4 new line (full) indent
"new line (full) indent" is following formating style:

if (true)
[space][space]{ 
[space][space]// do stuff
[space][space]}

So you suggested unknown formatting style. Please provide full formatting style description (all C/C++ construction such as if, else, switch, case, do, while, namespace, function/member definition, code block).
Comment 9 sandover 2011-01-19 20:50:27 UTC
> Set "indent size = 4" and "new line half indented". NB formats:
> if (true)
> [space][space]{
> [space][space][space][space]// do stuff
> [space][space]}

Thanks for your response; yes, this is our current workaround.  If there is any mixing of indentations rules, however, the workaround starts to break down.  Classes often feature non-indented braces, for example, and this is our company style as well.  See this example, where we want all the class members indented by 2, but they are indented by 4.

class foo
{
[space][space][space][space]int a;
    ...
    int z;
    void foo ();
};

All the variables and class definintions are indented 4 spaces.  And since we've got Netbeans set to indent 4, we can't simply fix this by hand by selecting all the members and pressing tab or shift-tab to move them left or right.  They'll only left or right by increments of 4 spaces now.  The only option is to format this whole file manually using the space bar, which sort of defeats the purpose of IDE code formatting.

So for this and other reasons, it would be better if we could set Netbeans to our "real" indent size (2), and add slightly more configurability to the options.
Comment 10 sandover 2011-01-19 20:54:16 UTC
> So you suggested unknown formatting style. Please provide full formatting style
> description (all C/C++ construction such as if, else, switch, case, do, while,
> namespace, function/member definition, code block).

I think we're not asking for a whole style -- simply for a new rule.  Currently there is a rule called "new line half indented", which can be applied to different constructs (class declarations, switch, etc.) as people see fit.  I don't know exactly how Netbeans implements it, but the general logic of this rule has to be as follows:

  Given a line indented by X, the next line shall be indented by X + indent / 2.

The logic of the "new line" rule would be 

  Given a line indented by X, the next line shall be indented by X.

I think Netbeans' power as a code formatting tool would be enhanced by the addition of a rule whose logic is:
 
   Given a line indented by X, the next line shall be indented by X + indent.
Comment 11 Alexander Simon 2011-01-19 21:03:06 UTC
(In reply to comment #9)
> class foo
> {
> [space][space][space][space]int a;
>     ...
>     int z;
>     void foo ();
> };
Set half indent for class declarations and indent 4:
class foo
{
[space][space][space]int a;
  ...
  int z;
  void foo ();
};

It seems you should set half indent for all braces placement.
Comment 12 Alexander Simon 2011-01-19 21:09:02 UTC
Could you try predefined GNU code style?
It seem you try to invent GNU style.
Comment 13 Alexander Simon 2011-01-19 22:56:18 UTC
Close as "works for me" because user code style is GNU code style that already implemented.
Comment 14 Alexander Simon 2011-01-19 23:06:47 UTC
sandover,

If you going to reopen issue, could you point to coding style you want in:
http://en.wikipedia.org/wiki/Indent_style
Indeed "Wishart style" is not implemented in Netbeans.
Is you request about "Wishart style"?
Comment 15 sandover 2011-02-10 18:59:54 UTC
 > If you going to reopen issue, could you point to coding style you want in:
> http://en.wikipedia.org/wiki/Indent_style
> Indeed "Wishart style" is not implemented in Netbeans.
> Is you request about "Wishart style"?

Actually, what we have is more like Horstmann style, except that the braces are indented by 2, instead of 0.    Do you know of any way to achieve that?
Comment 16 Alexander Simon 2011-02-10 19:59:22 UTC
(In reply to comment #15)
> Actually, what we have is more like Horstmann style, except that the braces are
> indented by 2, instead of 0.    Do you know of any way to achieve that?
No.
Comment 17 Let_Me_Be 2011-05-01 11:29:02 UTC
This is extremely annoying problem.

It is impossible to replicate the Whitesmiths indentation in Netbeans right now:

int function()
  {
  int var;
  
  if (x)
    {
    do_stuff;
    }
  }
Comment 18 Eric106 2011-06-18 22:51:31 UTC
(In reply to comment #4)
> This is an enhancement request for a feature that does not yet exist, but which
> Petr Pisl mentioned (in a blog comment) would be fairly easy to implement.
> 
> The desired behavior is that braces be *fully* indented.  
...
> 
> In Tools->Options->Formatting->C++->(braces), the options for braces placement
> are:  
>  1 same line
>  2 new line
>  3 new line half indent
> 
> We would like to see
>  4 new line (full) indent



I am also looking for this exact functionality to be ale to support a particular code style requirement.  That is, I would also like to have a fourth option for new line with a normal/full indent.  As noted, this should be a fairly straight forward addition.

-Eric
Comment 19 sandover 2011-08-19 00:58:49 UTC
Any progress on this bug?  I see that it was scheduled to appear in 7.0.1, but that it then reverted back to "TBD" status.
Comment 20 Eric106 2012-01-28 20:58:45 UTC
I was also checking back to see the status of this request as I noticed it is still not implemented yet.  

Is there a better way to elevate this issue?  It seems like it would be such a simple fix.

-Eric
Comment 21 Alexander Simon 2012-01-29 08:26:25 UTC
(In reply to comment #20)
> I was also checking back to see the status of this request as I noticed it is
> still not implemented yet.  
> 
> Is there a better way to elevate this issue?  It seems like it would be such a
> simple fix.
> 
> -Eric
The best way to elevate this issue is:
- provide a patch.

Alexander
Comment 22 Eric106 2012-01-29 16:24:26 UTC
(In reply to comment #21)
> The best way to elevate this issue is:
> - provide a patch.
> 
> Alexander

Alexander, thank you for taking the time to look at this.

I'd love to be able to fix this issue myself and would happily share a patch if I did but I'm not familiar with Java.  I work in C and on embedded microcontroller platforms at that.  I could probably figure out enough Java by combining and modifying the existing options to make this change if I knew where to look and if I knew how to set up the development environment for working with Java.  As much as I would like to help it's just not feasible.  

The sad and frustrating part is that it seems like such a simple change.  All we want is to take the code from the "new line half indent" option, copy it, call it "new line (full) indent" and then change the code that does the indenting so that instead in inserting half an indent worth of space before the brace it inserts a full indent.

I'm not that familiar with NetBeans development and was wondering if there was another or better place to request this type of enhancement.

-Eric
Comment 23 Vladimir Voskresensky 2012-01-30 10:41:44 UTC
(In reply to comment #20)
> I was also checking back to see the status of this request as I noticed it is
> still not implemented yet.  
> 
> Is there a better way to elevate this issue?  It seems like it would be such a
> simple fix.
> 
> -Eric
Hi Eric,

We've discussed with Alexander this issue and looks like meaning of Indent/Half-indent, first level statements, nesting statements are the constructions which significantly affect formatting and that's the reason of so many named formatting styles.
Fortunately most of named formatting styles have clear specification documents describing all rules in this terms.
Looks like providing wiki page with specification of what you want with samples is the right way to get it implemented.
Once you create it, we'll review and try to decide is it just "one more option" to existing styles (i.e. GNU style looks very similar to what you want with small difference) or there are more differences => new named style worth to create.
Please. create specification document and will be glad to review and comment on it.

Thanks,
Vladimir.
Comment 24 Eric106 2012-02-01 03:15:22 UTC
Vladimir,

Thank you for looking into this further.  After reading the Wikipedia page at that was referenced in an earlier post I see that the brace style I am trying to follow is called Whitesmiths style.

http://en.wikipedia.org/wiki/Indent_style#Whitesmiths_style

A Google search for "Whitesmiths style" turns up a number of pages further describing the style but I found one page that does a better job of describing the rationale for the style.

http://activeclickweb.com/whitesmiths/index.html

I do not believe it is necessary to have a whole new named style since the difference only applies to the "Brace Placement" subsection of the style settings with no impact on any of the other settings.  All that would be required is a fourth option to the drop down selection for the Brace Placement settings.  To be consistent with the naming of the three current choices someone suggested the name of "new line (full) indent" which I believe would be the most straightforward way to implement this.  This change would still be required even if a new named style was created.  Given how easy it is to add, remove or change styles I do not feel a new named style is required but if you wish to include one as well to make option more obvious that would be fine.

While searching I found that a request specifically for this functionality was requested several years ago with no further comment in Bug 106529.

http://netbeans.org/bugzilla/show_bug.cgi?id=106529

Thank you again for considering this enhancement and please let me know if it would be helpful for me to provide any additional information.

-Eric
Comment 25 Alexander Simon 2012-02-01 09:27:19 UTC
fixed, change set:
http://hg.netbeans.org/cnd-main/rev/0d4f328eaf02
- added new style "Whitesmiths"
- added new brace format mode "New Line Full Indented"

Eric, please, try development build (http://bits.netbeans.org/download/trunk/nightly/latest/) that will include the fix day after.
Is new style acceptable for you?