Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper indentation in array initialization, PDT/Zend Studio

I'm using the following style of array initialization in the code:

$a = array(
    'one' => 123,
    'two' => 456
);

But PDT/Zend Studio doesn't work properly in this case; after pressing [Return] key it places cursor under the $a (in my example) and ignores indentation. If array keys are numbers (at least not start with quotation marks) everything is working fine.

This is how it works currently (| — is a position where edtitor places caret after pressing [Return])

$a = array(
    'one' => 123,[RETURN]
|
);

This is expected result:

$a = array(
    'one' => 123,[RETURN]
    |
);

So is it possible to force editor follow my indentation rules?

like image 443
Sergey Stolyarov Avatar asked Aug 27 '09 05:08

Sergey Stolyarov


3 Answers

I had recently exactly the same issue. I solved it in the Zend Studio (Eclipse based IDE) by going to

Preferences -> PHP -> Code Style -> Formatter

and then choose edit on the screen next to the fortmatter preset name. In the opened window go to the Line Wrapping tab and in the list choose

Expressions -> Array Initializers.

Play with the settings to your likings.

Regards

Lukas

like image 197
Bery Avatar answered Oct 27 '22 04:10

Bery


I suggest you to create a account in the bugzilla tracklist, and voting for the following feature:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=320130

If there is enough people, they probably integrate such functionalities in further version of PDT.

like image 1
Sylvain Lecoy Avatar answered Oct 27 '22 03:10

Sylvain Lecoy


In ZendStudio you can apply the PhpCodeFormatter using Ctrl+Shift+F.

The formatter can be configured in window->preferences->PHP->Code Style->Formatter (Zend Studio 7.0) to Reformat arrays as described above.

PDT, (as far as i know) does not have this function.

like image 1
MGriesbach Avatar answered Oct 27 '22 02:10

MGriesbach