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 244416 - Group Multiline Alignment -- Add a "threshold" value
Summary: Group Multiline Alignment -- Add a "threshold" value
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 8.0
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-10 13:59 UTC by bracketworks
Modified: 2014-05-10 14:01 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 bracketworks 2014-05-10 13:59:16 UTC
NetBeans has some great formatting features for PHP, especially the "Group Multiline Alignment", for assignments and array initialization.

However, sometimes this feature can cause a bit of a visual burden.

$someVar = 1;
$someOtherVar = 2;

Of course aligns to:

$someVar      = 1;
$someOtherVar = 2;

And that's great. However, sometimes (especially when dealing with array offsets) the alignment will (IMO) reduce readability:

$someVar = 1;
$someOtherVar['with']['array']['offsets'] = 2;

Will align to:

$someVar                                  = 1;
$someOtherVar['with']['array']['offsets'] = 2;

The massive whitespace injected is counter intuitive to making the code more readable.

I'm proposing that a modifiable numeric "threshold" value be introduced, alongside the options to enable/disable the alignment.

When formatting, as each line eligible for alignment is encountered, if alignment with the next/previous line would result in a number of whitespace characters greater than the threshold being injected, it would be ignored instead.

So, given the array example above, with a threshold of 12:

$someVar = 1;
$someOtherVar = 2;
$someOtherVar['with']['array']['offsets'] = 3;
$someOtherVar['with']['different']['offsets'] = 4;

1) It would inspect the first 2 lines:

$someVar = 1;
$someOtherVar = 2;

Modifying the position of "= 1" in the first assignment would require less than 12 whitespace characters; it is aligned:

$someVar      = 1;
$someOtherVar = 2;

2. It would inspect the next 2 lines:

$someOtherVar = 2;
$someOtherVar['with']['array']['offsets'] = 3;

Modifying the position of "= 2" in the first assignment would require more than 12 whitespace characters; it is ignored.

2. It would inspect the last 2 lines:

$someOtherVar['with']['array']['offsets'] = 3;
$someOtherVar['with']['different']['offsets'] = 4;

Modifying the position of "= 3" in the first assignment would require less than 12 whitespace characters; it is aligned:

$someOtherVar['with']['array']['offsets']     = 3;
$someOtherVar['with']['different']['offsets'] = 4;

Thus, the resulting formatted output would be:

$someVar      = 1;
$someOtherVar = 2;
$someOtherVar['with']['array']['offsets']     = 3;
$someOtherVar['with']['different']['offsets'] = 4;

I know there would be corner cases where previous alignments may be in conflict with subsequent calculations, and may require "undoing" previous alignment operations, but that's subject to discussion.

Hope that makes sense :-)
Comment 1 bracketworks 2014-05-10 14:01:38 UTC
*sigh* My proposed steps are numbered all wacky... Sorry about that.