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 174873 - Improve formatting and indentations.
Summary: Improve formatting and indentations.
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 7.1
Hardware: PC Linux
: P3 blocker with 5 votes (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on: 173937 173979 174891 175118
Blocks:
  Show dependency tree
 
Reported: 2009-10-19 13:15 UTC by Petr Pisl
Modified: 2012-04-06 14:42 UTC (History)
6 users (show)

See Also:
Issue Type: TASK
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Pisl 2009-10-19 13:15:11 UTC
This task should improved the formatting and indentation in the PHP Editor. Please, paste there a samples, where the
formatting or indentation don't work as you expect. Every case should contain a code before and after formatting and
indentation.
Comment 1 marcusson 2009-10-19 14:57:50 UTC
One of the major (yet not easy to fix) problems I got with NetBeans is, that the current version lacks support for
PEAR-style formatting. NetBeans allows either line-breaks: a) before and after all curly braces b) just after opening
curly braces - but not a mixture. So it won't fit with either one - with weird result.

Example: If you tell NetBeans to stick with formatting style "b" (as described above)
foreach ($a as $b) <ENTER>
| <- expect cursor to go here
    | <- but actually it goes there

Actually it thinks, there was a curly brace in the line above. Well: it wasn't.

Same problem with classes, when adding a new property by clicking the light-bulb to the left of your code:
class foo
    | <- new member is created here
{
    | <- expected it here

So NetBeans relies too much on this setting.
This is why I feel that most of the formatting problems I came across during many months of working with it are not
bugs, but missing features.

Other IDEs work in another way. They just check for curly braces and add +1 to the indentation depth if one is opened
and -1 if one is closed. Thus: indentation is always right, no matter how the code is formatted.

In a long-term I would like to see a way to tell NetBeans how *my* coding-standard should look like by giving an
example. Or at least, I would like to be able to select the famous PEAR coding-standard, which is actually not possible.

Since *our* coding-standard is not supported, I currently never use the built-in formatting-feature in NetBeans IDE.
Instead I put it to a setting that is least annoying to us.
Comment 2 Tomas Mysik 2009-10-19 15:13:41 UTC
My main complains can be found in issue #173937, it's about indentation:

--- 1 ---
want to have:
$checks[] = new G_Check("PHP version",
        version_compare(PHP_VERSION, MIN_PHP_VERSION, ">="),|            // ENTER here
        "The minimum version of PHP is ".MIN_PHP_VERSION);

but get:
$checks[] = new G_Check("PHP version",
        version_compare(PHP_VERSION, MIN_PHP_VERSION, ">="),
    "The minimum version of PHP is ".MIN_PHP_VERSION);

--- 2 ---
    function test() {
        do {
            echo "test";
        } while ($condition);             // press ENTER here
    |                                                // you will get here
    }

--- 3 ---
<?php

    $arr = array(new ArrayIterator(array()), new ArrayObject(array()));|    // ENTER here

?>

--- 4 ---
if ($a == 10 |          // ENTER here, I want to type "&& $b == 20"
Comment 3 honzamarek 2009-10-19 16:00:34 UTC
I don't know if you remember all the bugs I have complaint about at webexpo.

1) Duplicate line by shortucut ctrl + shift + arrow down does not work on last line.

2) When pressing tab on template (if, for, ...) it will not jump to the last ${cursor}.

3) It is impossible to create template with shortcut containg other character then letter.
Comment 4 Petr Pisl 2009-10-19 16:42:56 UTC
To HonzaMarek:

ad 1. - The bug is already in this database ( issue #173827 ). I have talked about this issue with editor guy and they 
promised to fix it. 
ad 2. - I have talked about this with Tomas ( he improved the behavior of the template recently). See this blog: 
http://blogs.sun.com/netbeansphp/entry/php_templates_improved . So it can be fixed. Tomas, could you please comment this. 
ad 3. - I also talk about this issue with the editor guys. As a result I entered new issue for this and they will try to 
fix it. They already have a solution for this, but no time to implement it. (issue #174903)
Comment 5 beberlei 2009-10-19 19:27:10 UTC
another point of endless discussions in PHP formatting is the difference of a space between the end of decision
structures and the first ( or not, for example:

if($foo)
vs.
if ($foo)

Which would be nice to be supported in one or the other way.
Comment 6 ingoreinhart 2009-10-19 21:30:16 UTC
Another issuse is:

some source
$a = $b +1;
}
|/**                         // cursor at the pipe char, then press enter
 * a comment

Result:

some source
$a = $b +1;
}
/**  
 * |                       // cursor at the pipe char
 * a comment

But, I think, it's better to get a new line between } and /**



Comment 7 honzamarek 2009-10-20 08:13:57 UTC
Also I have a problem with code completion (ctrl + space).

class Something implements ArrayAccess {

    public function method() {
        /* @var $var OtherClass */
        $var = $this["key"];
        $var->               // it's offering methods for class Something
    }

    // ...

}

Comment 8 Tomas Mysik 2009-10-20 09:03:38 UTC
To honzamarek:

> ad 2. - I have talked about this with Tomas ( he improved the behavior of the template recently). See this blog:
> http://blogs.sun.com/netbeansphp/entry/php_templates_improved . So it can be fixed. Tomas, could you please
> comment this.

I don't know the particular use case so please file a new issue (editor/options) with _exact_ steps to reproduce.

Thanks.
Comment 9 Tomas Mysik 2009-10-20 09:13:19 UTC
To honzamarek:

> Also I have a problem with code completion (ctrl + space).

This issue is not about code completion. File a new issue, please. Thanks.
Comment 10 olexiyk 2009-10-20 10:46:56 UTC
BEFORE:
try{
;
}catch (Exception $e) {
;
}
AFTER it even has syntax error:
try {
    ;
}catch (Exception $e  {
    ;
}
Comment 11 olexiyk 2009-10-20 10:50:14 UTC
Code after formatting:
<?php
class Demo {
    public $var = array(
    'a',
    'b',
    'c' => array (
    'd',
    'f',
    ));
}

How it should be:
<?php
class Demo {
    public $var = array(
        'a',
        'b',
        'c' => array (
            'd',
            'f',
         )
    );
}
Comment 12 Petr Pisl 2009-10-20 16:10:36 UTC
to ingoreinhart: the issue that you mentioned is entered as issue #174891, which I fixed yesterday.
Comment 13 laurin1 2009-10-21 14:51:19 UTC
It removes the indentation for these comments:

//Gather Patient Data
//Sylvia Suarez
	if(Users::InGroupCheck('Billing_FO_OPT_EVALS') || 1){

		require_once 'superbills_pride_code.php';

		$aBillTemp['EVAL']	= Superbills_CreateArray('EVAL', $sDate);
		$aBillTemp['OPT']	= Superbills_CreateArray('OPT', $sDate);

	}

It should be like:

	//Gather Patient Data
	//Sylvia Suarez
	if(Users::InGroupCheck('Billing_FO_OPT_EVALS') || 1){

		require_once 'superbills_pride_code.php';

		$aBillTemp['EVAL']	= Superbills_CreateArray('EVAL', $sDate);
		$aBillTemp['OPT']	= Superbills_CreateArray('OPT', $sDate);

	}

Comment 14 Petr Pisl 2009-10-21 16:19:19 UTC
To laurin1: I think the behavior is right now. It formats the inline comments if don't start on the first column. If you 
will do a space before // then they will be formatted correctly. The reason is a functionality, which comments out a 
line or selection (CTRL + / shortcut). For example you don't want to move this comments:

      if(Users::InGroupCheck('Billing_FO_OPT_EVALS') || 1){

		require_once 'superbills_pride_code.php';

//		$aBillTemp['EVAL']	= Superbills_CreateArray('EVAL', $sDate);//
//		$aBillTemp['OPT']	= Superbills_CreateArray('OPT', $sDate);

	}
Comment 15 honzamarek 2009-10-21 19:15:57 UTC
abstract class PHPClass {
	public function method($a = 2, $b = null);
}

class ClassName extends PHPClass {
	// this is generated by 'generate method' feature and I don't like spaces after parameters
	public function method($a=2 , $b=null ) {
		parent::method($a, $b);
	}
}
Comment 16 rmatous 2009-10-21 21:06:14 UTC
spaces for honzamarek:
have a fix, will be applied tommorow
Comment 17 Tomas Mysik 2009-10-22 08:54:31 UTC
To Radek:
> have a fix, will be applied tommorow

Also, add spaces before and after "=" character, thanks.
Comment 18 wagnerluis1982 2009-10-22 18:44:34 UTC
My formatting option 'Braces Placement' is configured to 'New Line'.

When I'm typing 'if' or 'for' statements without templates and hit <Enter> to break line, cursor stays on position to
enter only one instruction, e.g.:

    if (true)
        |

If I type a brace and hit <Enter> to start 'if', braces stays on wrong position, e.g.:

    if (true)
        {
            |
        }

Pressing Alt+Shift-F to autoformat, that 'if' goes to right position, e.g:

    if (true)
    {
        |
    }
Comment 19 tombart 2009-10-26 13:41:38 UTC
code:     
        try {
            if($foo== 'bar'){
            }else{
            }
        }catch(InvalidArgumentException $e) {
        }
is formatted:

try {
    if($foo== 'bar') {
    }else {
    }
}catch(InvalidArgumentException $ ) {
}

(variable $e is missing -> syntax error)
Comment 20 Filip Zamboj 2009-10-26 15:08:14 UTC
I cannot reproduce the last comment, stating that after formatting of try - catch there is a variable missing. A unit
test has been created for this. 

@tombart: what version of netbeans are you using? thanks. 
Comment 21 nimmr 2009-10-30 13:22:12 UTC
Hi, I'm glad this is brought up, for this is a huge problem for me that my IDE tries to tell me how my code should be
indented. Sure, it's nice if it works exactly as you code, but I think theres too many coding styles to handle this.

Would it be too much of a problem to just add an option to do simple indentation in the options menu.
By simple indentation I mean that it should only remember what indentation level you're on, and continue on that.
Comment 22 nullbarriere 2011-09-09 08:49:12 UTC
Comment Newline Completion
--------------------------

/*| type Enter here 

will result in 

/*
 * |
 */

which is nice when one is about to start a PHPDoc Comment or another standards compliant Comment, but not when your are about outcommenting some Code Block, or just want to put some Thoughts in a multiline Comment.

If you do the latter much more than the first, this nice becomes annoying.

Especially so:

/* My Database
- doesn't work| <--type Enter here
- is great nevertheless
*/

becomes

/* My Database
- doesn't work
 * |
- is great nevertheless
*/

which is definitely not helpful, I need to hit Backspaces on every line.


Other example

//my 1st task| <--type Enter here
//my 2nd task

will result in

//my 1st task
// |
//my 2nd task

which again might be nice in some Situations because it assumes a multiline Comment. But, me for Instance, never make multiline Comments in the // Style. Above Example was about completing Sort of a TODO List with Code, keeping the (singleline) Comments for Explanation. The helpful Thought becomes, well, isn't really helpful. 


Preferred Solution:
- Make Comment Completion smarter, like being aware of Comment Style and having Stars already or not.
- Make it controllable. Some options when to put a Star on the next Line, Intendation, which Type of Comments to complete. 
- Maybe as a first Measure: Make it completely optional. If its not helping me, at least let me turn it off (prefarrably for each Style optional).
Comment 23 robert_h 2011-10-11 10:26:00 UTC
I set that the braces to be "New Line Indented" and checked everything in "New Lines" in Alignments but this happens: 

if(true)
    {
    // code
    } // ENTER
| <- expect cursor to go here
    | <- but actually it goes there

the funny thing is that when I do code formatting the cursor moves to the right potion

this bug is hunting me from the the beginning when these option where introduced