Wrong array initializer indentation while typing PHP in Eclipse

旧时模样 提交于 2019-12-07 02:15:35

问题


I set my preferred array initializer indentation on Preferences > PHP > Code Style > Fromatter > Line Wrapping, but while typing array initializers indentation is wrong:

$arr = array([ENTER]
····[CURSOR])

while I'm expecting:

$arr = array([ENTER]
··[CURSOR]
)

like it happens editing Javascript code. Note that the wrong indentation happens only while typing, whereas an explicit CTRL+SHIFT+F indents array initializer correctly. (So not a duplicate of many other questions asking how to set indentation, since here indentation is set but not applied while typing.)

How can I get the correct indentation while typing array initializers?


回答1:


My settings on Zend Eclipse for PHP Developers, under PHP > Code Style > Formatter:

  • Indentation > Tab policy > Spaces
  • Indentation > Indentation size > 2
  • Indentation > Tab size > 2
  • Indentation > Default indentation for array initializers > 2
  • Line Wrapping > Expressions > Array initializers > Indentation policy > Indent by one



回答2:


Try to set Indentation Policy to Indent by one (instead of Default Indentation) for Method Declarations -> parameters




回答3:


In Eclipse Juno, try with PHP -> Code Style -> Formatter -> Default indentation for array intializers = 1. It works for me.




回答4:


In my Windows instance, it is necessary to restart Eclipse to apply changes to this setting:

PHP > Code Style > Formatter > Default indentation for array intializers

On other instances it's not required. No idea why.



来源:https://stackoverflow.com/questions/13108241/wrong-array-initializer-indentation-while-typing-php-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!