数组初始化中的正确缩进,PDT/Zend Studio

发布于 2024-08-03 00:08:14 字数 459 浏览 5 评论 0原文

我在代码中使用以下样式的数组初始化:

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

但是 PDT/Zend Studio 在这种情况下无法正常工作;按 [Return] 键后,它将光标置于 $a 下方(在我的示例中)并忽略缩进。如果数组键是数字(至少不以引号开头),则一切正常。

这就是它目前的工作方式(| — 是编辑器在按 [Return] 后放置插入符号的位置)

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

这是预期的结果:

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

那么是否可以强制编辑器遵循我的缩进规则?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

独自唱情﹋歌 2024-08-10 00:08:14

我最近遇到了完全相同的问题。我通过转到

Preferences -> > 在 Zend Studio(基于 Eclipse 的 IDE)中解决了这个问题。 PHP->代码风格-> Formatter

,然后在屏幕上选择 formatter 预设名称旁边的“编辑”。在打开的窗口中,转到“换行”选项卡,然后在列表中选择

“表达式”->“表达式”。数组初始化器。

根据您的喜好调整设置。

问候

卢卡斯

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

余罪 2024-08-10 00:08:14

我建议您在 bugzilla 跟踪列表中创建一个帐户,并为以下功能投票:

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

如果有足够多的人,他们可能会在 PDT 的进一步版本中集成此类功能。

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.

踏月而来 2024-08-10 00:08:14

在 ZendStudio 中,您可以使用 Ctrl+Shift+F 应用 PhpCodeFormatter。

可以在窗口 -> 首选项 -> PHP -> 代码样式 -> 格式化程序 (Zend Studio 7.0) 中配置格式化程序,以如上所述重新格式化数组。

PDT,(据我所知)没有这个功能。

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.

勿挽旧人 2024-08-10 00:08:14

我不确定 Eclipse,但我在 TextMate 中遇到了同样的问题。我切换到软制表符(又名 4 个空格)而不是制表符,现在它的行为符合“预期”。 ZendStudio 有这个选项吗?

I'm not sure about Eclipse, but I had the same problem in TextMate. I switched to soft tabs (aka 4 spaces) instead of tabs and it now acts as "expected." Does ZendStudio have that option?

鹊巢 2024-08-10 00:08:14

@MGriesbach:实际上PDT(Eclipse)确实有这个功能(在Source->Format下)

@Sergei:Eclipse没有这个问题,但这听起来像是你的配置有问题。您确定您已经查看了所有选项吗?您还可以向 Zend 团队发送电子邮件,这听起来像是继承人方面的一个非常微不足道的错误,因为它鼓励开发人员编写不正确缩进的代码。

-- 编辑 --

我的错,Eclipse PDT 确实有这个问题,但我只是习惯了:) 如果我按 Tab 键,问题就会消失,所以它会缩进第一行。其他行将正确遵循。

@MGriesbach:Actually PDT(Eclipse) does have this function (under Source->Format)

@Sergei: Eclipse doesn't have this problem, but this sounds like something is wrong with your config. Are you sure you looked through all the options? You may also send an email to the Zend team, this sounds like a pretty trivial bug on heir side, as it encourages developers to write code not indented correctly.

-- edit--

My bad, Eclipse PDT does have this problem but i just got used to it:) The problem dissapears if i press tab, so it will indent the first line. The other lines will follow correctly.

相思碎 2024-08-10 00:08:14

不,那是 Eclipse 的错误。

我使用所有 Eclipse 文本编辑器(SQL、XML、YML、ShellEd 等)都遇到过这个问题。

但是,这种情况仅发生在我在 x86_64 上安装的 Linux (Kubuntu Karmic) Eclipse 中。
我在工作中在 i386 Karmic 上对其进行了测试,效果很好。

No, that's Eclipse bug.

I've faced it using ALL the Eclipse text editors (SQL, XML, YML, ShellEd, and o on).

However, it happens only to my Eclipse installation for Linux (Kubuntu Karmic) on x86_64.
I've tested it on i386 Karmic at my work and it works fine.

欲拥i 2024-08-10 00:08:14

尝试

窗口->首选项
PHP->代码风格->格式化程序
缩进 -> 数组初始值设定项的默认缩进 = 1

Try

Window->Preferences
PHP->Code Style->Formatter
Indentation->Dafault Indentation for array initializers = 1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文