Discussion:
Disable all auto indenting
labythan
2010-08-11 14:46:54 UTC
Permalink
Netbeans is perfect - EXCEPT, it has its own idea of how to auto indent my code. For example, I am trying to write:

function foo($bar)
{
[indent]stuff();
}

My muscle memory writes:

function foo($bar)[return]{[return]}[up][enter][tab]stuff();

But when I do this netbeans thinks that it should auto indent the second curly brace and I end up with:


function foo($bar)
{
[tab]}

So at this point I press [left][backspace] and clear the tab to correct. Then press enter to enter one line. What I expect is:


function foo($bar)
{
[cursor is here]
}

But what I get is:


function foo($bar)
{
[empty line]
[indent][cursor is here]
}

Where does the second line come from? Why is my cursor indented?

For sweet mercy why can't netbeans just work like a normal text editor like vi or textmate or visual studio? Why does it have to press keys for me to incorrectly format my code?

On a side note, does anyone know a PHP IDE that can do xdebug debugging and watches like netbeans, code completion, but just put on the screen what I type in?

Thanks!
Mike Riley
2010-08-12 16:49:21 UTC
Permalink
Post by labythan
function foo($bar)
{
[indent]stuff();
}
function foo($bar)[return]{[return]}[up][enter][tab]stuff();
function foo($bar)
{
[tab]}
function foo($bar)
{
[cursor is here]
}
function foo($bar)
{
[empty line]
[indent][cursor is here]
}
Where does the second line come from? Why is my cursor indented?
For sweet mercy why can't netbeans just work like a normal text editor like vi or textmate or visual studio? Why does it have to press keys for me to incorrectly format my code?
You have complete control over this in Tools->Options. Select Editor and then the Formatting
tab. Now choose your language that you wish to change (it defaults to all languages). Your
code example could have been Java or C. Look at each possible category and play with it until
the example code looks like what you want.

However the way you are asking it to behave is counter to all standards of coding style I have
ever seen. Not sure how you expect the next level of braces to be indented.

You might also want look into the Hints and Code Completion tabs. If you are working with C or
C++ look at the C/C++ tab as well. Heck look at them all. It is quite configurable.

If in the end you find it can't do what you wish then file an enhancement request so they can
consider adding it later.

Mike
tjosinga
2010-08-18 09:31:44 UTC
Permalink
However the way you are asking it to behave is counter to all standards of coding style I have ever seen. Not sure how you expect the next level of braces to be indented.
I use exactly the same keystrokes as labythan. The only difference between this formatting and 'the standard way' is that the opening brace is on a new line.

Don't know what the correct definitions for smart-indent and auto-indent are, but I see them like this:
Smart-indent = Indent to the (probably) correct place based on (several) formatting styles.
Auto-indent = Indent equally as the previous line.

I was very surprised NetBeans doesn't have an option to disable smart-indent. Shouldn't be too hard to implement (I asume), but would be a lifesaver.
Mike Riley
2010-08-18 16:46:27 UTC
Permalink
Post by tjosinga
However the way you are asking it to behave is counter to all standards of coding style I have ever seen. Not sure how you expect the next level of braces to be indented.
I use exactly the same keystrokes as labythan. The only difference between this formatting and 'the standard way' is that the opening brace is on a new line.
Smart-indent = Indent to the (probably) correct place based on (several) formatting styles.
Auto-indent = Indent equally as the previous line.
I was very surprised NetBeans doesn't have an option to disable smart-indent. Shouldn't be too hard to implement (I asume), but would be a lifesaver.
His example had no indenting at all, as I recall.

I have Netbeans set for Java to indent this way (taken from inside one of my methods):

for (i = 0; i < cardImageFiles.length; i++)
{ // Load all the possible card backs we have images of.
if (cardImageFiles[i].isFile())
{
cardBacks[i] = new ImageIcon(cardImageFiles [i].toString());
}
}

You have control over the level of indentation and if the opening brace starts a new line or
not. Indentation is controlled by the tabs and indents settings and the braces are controller
by the Braces settings.

I have "Braces Placement" set to New Line in all 3 cases. I also have "Braces Generation" set
to Generate in all four of those cases.

Another setting that applies to this is the "Alingment" one. I have "New Lines" enabled for
'else', 'finally', and 'catch' - but not for 'while' or 'after modifiers'.

The "smart indent" as you call it could be disabled by setting "Number of Spaces per Indent" to
0, if I understand your description correctly.

Mike
tjosinga
2010-08-18 19:09:08 UTC
Permalink
Hi Mike,
Post by Mike Riley
His example had no indenting at all, as I recall.
He does have indents, it's before "stuff();"

I guess this forum removed your tabs in your example, so we probably code the same way. Normal indentation with braces on new lines.

What happens in your version when pressing the following line?
if ()[enter]
In my case the cursor is already indented 2 spaces deeper than the if. Could make a screencast if it helps to explain.
Post by Mike Riley
You have control over the level of indentation and if the opening brace starts a new line or not. Indentation is controlled by the tabs and indents settings and the braces are controller by the Braces settings.
Aren't these settings only used when 'formatting your code' by using the 'format' feature of NetBeans? I have set it everything to "new line" when I tested NetBeans.
Post by Mike Riley
Another setting that applies to this is the "Alingment" one. I have "New Lines" enabled for 'else', 'finally', and 'catch' - but not for 'while' or 'after modifiers'.
Same here, but also in this case it seems it's only used in the 'format' feature, not in the editor's behaviour when pressing enter.
Post by Mike Riley
The "smart indent" as you call it could be disabled by setting "Number of Spaces per Indent" to 0, if I understand your description correctly.
Normally "Number of spaces per indent" is used in the way that pressing [tab] would not generate a tab-character put X spaces instead (2 in my case). Logically, the setting can not be set to 0.

Regards,
Taco
Mike Riley
2010-08-18 22:48:41 UTC
Permalink
Post by tjosinga
Hi Mike,
Post by Mike Riley
His example had no indenting at all, as I recall.
He does have indents, it's before "stuff();"
I guess this forum removed your tabs in your example, so we probably code the same way. Normal indentation with braces on new lines.
Could be that tabs were removed. I force it to always use spaces, because they always expand
correctly no matter the system being used. It uses more space, but disks are cheap.
Post by tjosinga
What happens in your version when pressing the following line?
if ()[enter]
In my case the cursor is already indented 2 spaces deeper than the if. Could make a screencast if it helps to explain.
You might be right about the screen shot. I have attached one here. Hopefully it gets
displayed here, as I have noticed some posts that were supposed to have attachments where it
gets lost....

The comments show how the two if statements get indented as I entered them.

I have my indent set to 4 spaces, as I find 2 spaces is a bit too small to distinguish sometimes.

I like the flexibility of the Netbeans style settings, but there might still be room for
improvement to make it work for everyone. If a specific feature you require is not there then
file a bug to have it added in the future. Including an example of how it works now versus how
you would like it to work should be included, of course.

Mike
labythan
2010-08-19 21:47:24 UTC
Permalink
This ended up fustrating me enough that I went back to textmate. I do love all of netbeans interface work, especially the live debugger, and autocomplete, but that is all secondary to a basic text editor that behaves the way I expect it to. I'd love to know that I am wrong somehow.

And, for the record, I also code with open brace on same line, but that shouldn't be relevant as far as the editor is concerned.
Mike Riley
2010-08-20 05:49:05 UTC
Permalink
Post by labythan
This ended up fustrating me enough that I went back to textmate. I do love all of netbeans interface work, especially the live debugger, and autocomplete, but that is all secondary to a basic text editor that behaves the way I expect it to. I'd love to know that I am wrong somehow.
And, for the record, I also code with open brace on same line, but that shouldn't be relevant as far as the editor is concerned.
If no bug is filed about the issue it will never be addressed...

Mike

Continue reading on narkive:
Loading...