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

I am developing PHP / Javascript in NetBeans, and I really like the environment, except for one thing - in Javascript, when I press ENTER after the statement and type the open bracket, it is indented. Like this:

if ( a == b ) {} 

I want the brace to stay at the same level, for example:

 if ( a == b ) {} 

So, when I press ENTER again, I get the following:

 if ( a == b ) { } 

Can this be done and how?

+7
source share
2 answers

Sorry, I have no answer to your question. I also searched in vain somewhere in NetBeans 6 to tweak JavaScript formatting.

However, you should note the following:
In languages ​​like Java, it is legal to choose between opening a brace on the same line and opening a brace on a new line. In JavaScript, however, you really should stick to the former, as the latter can cause ambiguities that can affect the interpretation of the code. See here . (I know that the example you are quoting refers to an if statement, but presumably you want to be consistent.)

+2
source

Great news for netbeans is dedicated here: (netbeans 7.0)

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

Look for " if " Abbreviation:

Edit Advanced Text Definition:

from this:

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

:

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

Save settings.

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

Can you imagine all the possibilities with these templates?

+1
source

All Articles