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 207195 - Comments which start at column 1 are not moved by formatter since upgrade to 7.1
Summary: Comments which start at column 1 are not moved by formatter since upgrade to 7.1
Status: REOPENED
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 7.1
Hardware: All All
: P3 normal (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-12 05:44 UTC by berniev
Modified: 2013-02-09 16:56 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description berniev 2012-01-12 05:44:25 UTC
Product Version = NetBeans IDE 7.1 (Build 201112071828)
Operating System = Linux version 3.0.0-14-generic-pae running on i386
Java; VM; Vendor = 1.6.0_23
Runtime = OpenJDK Client VM 20.0-b11

Example:
<?php
function funct() {
    $a = '';
// comment
}
?>
Source->Format (Alt-Shift-F) will not indent the comment line unless it is already off the left edge.

Initial formats of existing code since upgrading to 7.1 from 7.0x seem to have moved some (or all ?) comments to the left edge.
Am having to fix each one by indenting manually then formatting.
Comment 1 Ondrej Brejla 2012-04-27 13:27:48 UTC
Sorry, but it's a feature. It's the same behavior as is for Java files. Line comments which are at the start of the line, are not indented by formatter.
Comment 2 berniev 2012-09-10 23:27:00 UTC
More on this one ...

If the formatter can't format due to error in code, it will remove all formatting.

This places everything at column one. 

If you now fix the code (eg put in the missing }) it formats again, but now all comments are left at column one due to the `feature` mentioned earlier.

The only way out is to undo the format before making the fix, or manually move all your comments off the left column and format again.

I guess it would be nice if somehow the formatter could `remember` which lines were indented when it removes all formatting and restore them.
Comment 3 Ondrej Brejla 2012-09-11 07:13:48 UTC
Such a behavior may be an enhancement, definitely not a defect. But the effort to make it is much bigger than a benefit from the result.
Comment 4 berniev 2012-09-11 07:39:16 UTC
I hear you re the work/benefit tradeoff, but it is these little things that drive one nuts (there are of course a few of them).

FWIW: Perhaps the answer is not to look at what the formatter is not doing, but what it does ... 

On being unable to format:

Curently:
All code is left unindented.
Undo gets previous indenting back, but focus goes to (near?) top of file.
This is a PITA as you have now lost your position, which is often where the error was created.

Suggest:
Restore to pre-formatting state, including curser position.
Throw a warning (dialogue?).

This would fix BOTH problems!

Thoughts?
Comment 5 Ondrej Brejla 2012-09-11 08:03:47 UTC
I'm afraid that that "back" action is not handled by PHP itself, but by the upper infrastructure...so we can't restore the previous caret position.
Comment 6 berniev 2012-09-11 08:19:58 UTC
Apologies for laboring the point (last shot). 

Maybe it is nothing like what it appears to me dumb end user!

After a ~successful~ format the curser (same as caret?) is placed where it was before .. which suggest PHP may be able to place the curser. 

If PHP can indeed somehow place curser ...

So leave out the undo.

If the formatter kept a copy of the original (and curser position) and simply wrote the original as output on failure, and set the curser ... ?? and released it on success.

Not so simple?
Comment 7 berniev 2012-09-14 02:46:25 UTC
One more thought ..

The editor knows when there is an error condition, it indicates red markers in the right of the screen.

Can the formatter detect the error condition and simply do nothing, similar to how highlighting refuses to work?
Comment 8 berniev 2013-02-09 16:56:18 UTC
For mine you can close this one.

I see (finally!) the answer is use c-style comments if you want them always to indent to the surrounding code.

The question remains re formatter removing all indentation when it encounters an error. Should I keep that alive by opening a new report?