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 )
开发者_StackOverflow社区{}
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?
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.)
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?
精彩评论