Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any hidden code formatting settings for Javascript in NetBeans?

I do PHP/Javascript development in NetBeans, and I really like the environment, except for one thing - in Javascript, when I press ENTER after a statement, and type the opening brace, it is indented. Like this:

if ( a == b )
    {}

I want the brace to stay on the same level, like this:

if ( a == b )
{}

So that when I press ENTER again, I'd get this:

if ( a == b )
{

}

Can this be done and how?

like image 329
Vilx- Avatar asked Jan 13 '11 23:01

Vilx-


2 Answers

Sorry, I don't have the answer to your question. I too have searched in vain for somewhere in NetBeans 6 to configure JavaScript formatting.

However, you should note the following:
In languages like Java it's legitimate to choose between opening brace on the same line vs. opening brace on a newline. In JavaScript, however, you should really stick to the former as the latter can give rise to ambiguities that can affect the interpretation of the code. See here. (I know the example you cite relates to the if statement, but presumably you want to be consistent.)

like image 102
David Easley Avatar answered Sep 28 '22 07:09

David Easley


Great news for netbeans devotes here: (netbeans 7.0)

Tools -> Options > Editor > Code Templates: choose Language (Javascript in this case)

Look for "if" Abbreviation:

Change Expanded text definition:

from this:

if (${expr}){
    ${cursor}
}

to this:

if (${expr})
{
    ${cursor}
}

Save options.

Now inside a js file type if and press [tab]... and you got it...

Can you imagine all possibilities with these templates?

like image 44
Igor Parra Avatar answered Sep 28 '22 07:09

Igor Parra