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 186452 - PHP code formatter ignores "Expand Tabs to Spaces" setting
Summary: PHP code formatter ignores "Expand Tabs to Spaces" setting
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 6.x
Hardware: Macintosh (x86) Mac OS X
: P3 normal with 1 vote (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-20 18:07 UTC by bobw
Modified: 2011-09-27 12:48 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Screenshot of before and after showing spaces v. tabs (66.45 KB, image/png)
2010-05-20 18:14 UTC, bobw
Details
Settings that resulted in attachment 99269 (26.75 KB, image/png)
2010-05-20 18:44 UTC, bobw
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bobw 2010-05-20 18:07:12 UTC
The new PHP code formatter appears to ignore the "Expand Tabs to Spaces" setting in Options->Editor->Formatting. My global options are:

	[ ] Expand Tabs to Spaces
	Number of Spaces per Indent: 4
	Tab Size: 4

My PHP options were set just to use the globals. I tried overriding at the PHP level, but it makes no difference.

What's happening is that leading tab characters are being converted to spaces even though that option is off. For example, this code:

	if (0 != $status) {
		$details = "$status - $details";
	}

gets converted to this when I do a format:

    if (0 != $status) {
        $details = "$status - $details";
    }

i.e., each leading tab character is replaced with spaces when I'd expect the tabs to be left alone. Notably, as soon as I left- or right-shift the code, the spaces are converted back to tabs, suggesting that things are working somewhere along the line. Also of note, I've not paid any attention to whether this happens within a line; I've only looked at the leading whitespace.

There are three reasons why this is a really bad bug:

1) The obvious, it messes up the formatting of the code, breaking its consistency and making it hard to read in other editors or with different settings. It'll also cause version control to show many more changes than necessary.
2) The lack of a "show invisibles" feature in NB can make this particularly hard to catch, meaning that ill-formatted code is likely to live on.
3) This bug affects the insertion of templates, since the formatter is run on them at insertion time - see bug 181644.

BTW, aside from this bug, you folks have done a great job on the new formatter - I love it!

Config details:

Product Version: NetBeans IDE 6.9 Beta (Build 201004200117)
Java: 1.6.0_17; Java HotSpot(TM) 64-Bit Server VM 14.3-b01-101
System: Mac OS X version 10.6.2 running on x86_64; MacRoman; en_US (nb)
Userdir: /Users/bob/.netbeans/6.9beta
Comment 1 bobw 2010-05-20 18:14:09 UTC
Created attachment 99269 [details]
Screenshot of before and after showing spaces v. tabs

Just noticed that the tabs in my code example got converted to spaces, either by my browser or by Bugzilla. To illustrate the problem properly, I copied the original and formatted text into BBEdit and turned on the feature to show whitespace characters. Tabs are depicted as triangles and spaces as diamonds.
Comment 2 bobw 2010-05-20 18:44:25 UTC
Created attachment 99272 [details]
Settings that resulted in attachment 99269 [details]

I forgot to turn off the PHP settings override for my screenshot, so there are actually five spaces per indent and five spaces per tab, versus the four that I previously stated. This attachment shows the settings that were in effect.
Comment 3 Filip Zamboj 2010-06-08 11:21:24 UTC
reproduced 
Product Version: NetBeans IDE Dev (Build 100607-272cdc06fedb)
Java: 1.6.0_16; Java HotSpot(TM) 64-Bit Server VM 14.2-b01

1. disable expand tabs to spaces 
2. add 1 tab 
if (0 != $status) {
    $detail = $detail; //there are spaces in the beginning 
}
3. add 2 tabs 
if (0 != $status) {
	$detail = $detail; //tab is there now 
}

4. format code and you are back on spaces. 

Now, you change tab size to 4 (so it equals to indent size) and it looks like everything works. 

5. enable expand tabs to spaces and it works. 

Therefore I think that the only problem here is that users do not know that when you disable the feature you need to set up indent and tab size. 

@ppisl: are we going to make something about it? (just close if not, please)
Comment 4 bobw 2010-06-08 18:33:03 UTC
Unless I'm misunderstanding, I *had* properly set up the indent and tab sizes. Can you verify from my settings screenshot? I realized those were issues upon reading related bugs, before I filed this one.

That said, testing now, with build 201006050001, this problem does seem to be fixed. One thing I'm noticing that may be the same issue is that many of the default PHP code templates have spaces for initial indentation. Depending on how many spaces there are, they may or may not be converted to tabs on insertion. Shouldn't the code templates *always* have tabs, which are then converted (or not) on insertion by the formatting engine?
Comment 5 Petr Pisl 2011-09-27 12:48:19 UTC
This issue I have fixed a few month ago. I can not reproduce it in NB 7.1, so closing as fix. Please reopen, if it still doesn't work for you.