Eclipse Java 中的自动换行?

发布于 2024-10-10 08:08:52 字数 218 浏览 0 评论 0原文

我已经有了 Eclipse PHP 的自动换行(如何让 PHP 文件在 Eclipse PDT 中自动换行?)。 Eclipse Java 怎么样?有没有类似的工具来包装Java代码行?

I already have word wrap for Eclipse PHP (How can I get word wrap to work in Eclipse PDT for PHP files?). What about Eclipse Java? Is there a similar tool to wrap Java code lines?

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

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

发布评论

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

评论(5

阳光下的泡沫是彩色的 2024-10-17 08:08:52

Ctrl+Shift+F 将在 Eclipse 中格式化文件,将长行分成多行,并很好地自动换行注释。您还可以仅突出显示文本的一部分并设置其格式。

我意识到这不是自动软/硬自动换行,但我不认为这个问题要求任何花哨的东西。

Ctrl+Shift+F will format a file in Eclipse, breaking long lines into multiple lines and nicely word-wrapping comments. You can also highlight just a section of text and format that.

I realize this is not an automatic soft/hard word wrap, but I don't think the question was asking for anything fancy.

灰色世界里的红玫瑰 2024-10-17 08:08:52

只是想指出,在代码中自动换行是一个糟糕的想法。我想每个人都有自己的风格,但通常您应该重构或重新考虑比单个平均水平屏幕占用更多的代码块。 (大约 1280 像素)

当然总是有例外......例如详细异常,但这些对于代码理解并不重要。

扫描超出单个水平屏幕的行,或者必须阅读堆叠在多行上的思想将使您的代码更难以理解。

此外,行数会很奇怪,因为自动换行会让一行看起来像是占用了 2、3 行,或者让人不寒而栗……4 行代码。

就评论而言,行返回对任何人来说都不应该是一个大问题。

另请记住,自动换行代码并不是一种常见的做法,您实质上是在说每个阅读您代码的人都应该打开自动换行,我很遗憾地说,这是让其他人与您一起工作的不必要的痛苦。代码做....

如果嵌套导致您需要自动换行...那么这也是一种非常糟糕的代码味道。

这是我的两分钱。

Just like to point out that word wrapping is a terrible idea in code. I suppose everyone has their own style, but typically you should refactor or rethink blocks of code that take much more than a single average horizontal screen. (about 1280 pixels)

Of course there are always exceptions... like verbose exceptions for example, but these are not critical for code understanding.

Scanning a line that goes beyond a single horizontal screen, or having to read a thought that stacks on multiple lines will make your code much more difficult to figure out.

Additionally, line counts will be weird, as word wrapping will make a single line seem like it takes up 2, 3, or shudder the thought... 4 lines of code.

As far as comments go, line returns should not be much of a problem for anyone.

Also keep in mind, word wrapping code is not a common practice, and you are essentially saying that everyone reading your code should turn word wrapping on, which is, I'm sorry to say, an unnecessarily painful thing to make others working with your code do....

If nesting is causing you the need for word wrap... well this is also a very bad code smell.

That's my two-cents.

乖乖公主 2024-10-17 08:08:52

这适用于在 Texlipse 中使用“Ahtik”自动换行插件时遇到以下问题的任何人:插件安装正常,但使用上下文菜单(或按 ctrl+alt+w)选择“自动换行”选项会导致文本暂时换行,然后轻弹回到展开状态(这可能包括使用 Windows 7 的任何人)。

这是一个修复...直接来自开发人员本人!我给 Ahti Kitsik 发了电子邮件,试图找到解决办法,当他真的找到解决方案时,我感到很惊讶,并在第二天将其发送给我。他建议作为回报,我可以将这些信息广泛传播。

因此,修复方法如下:

查找 texlipse 插件位置。这可能位于 Eclipse 文件夹中,并且地址可能以:...\eclipse\plugins\net.sourceforge.texlipse_1.5.0 结尾。

备份plugin.xml文件以防万一,然后通过删除以下代码块来编辑原始文件:

-首先,“操作”(从第843行开始):

操作

          class="net.sourceforge.texlipse.actions.TexWordWrapAction"
           definitionId="net.sourceforge.texlipse.commands.texWordWrap"
           icon="icons/wrap.gif"
           id="net.sourceforge.texlipse.actions.texWordWrap"
           label="W&rap text"
           menubarPath="net.sourceforge.texlipse.menus.latex/latexGroup"
           style="toggle"
           toolbarPath="latexGroup"
           tooltip="Use word wrap"

-其次,“命令”(从第843行开始) 972):

命令

        categoryId="net.sourceforge.texlipse.latexEditingCategory"
        name="Wrap text"
        id="net.sourceforge.texlipse.commands.texWordWrap"

(完成此操作后,文件长度应为 1257 行,而不是 1271 行)。

最后,Ahti 说:“使用 -clean 命令行参数启动 eclipse 以强制重新加载 plugin.xml。” (我个人不知道该怎么做,所以我只是删除并重新安装了他的插件,然后退出 Eclipse,并在重新启动之前编辑了代码)。

该功能现在应该可以正常工作了。希望这对某人有帮助。再次感谢阿蒂!

This is for anyone who is having the following problem with the "Ahtik" word-wrap plugin in Texlipse: the plugin installs fine, but selecting the "word-wrap" option using the context menu (or pressing ctrl+alt+w) causes the text to wrap momentarily, and then just flick back to being unwrapped (this probably includes anyone using Windows 7).

Here is a fix...straight from the developer himself! I emailed Ahti Kitsik in a last-ditch attempt to find a way round, and was amazed when he actually found a solution, and sent it to me the next day. He suggested that in return I could just make this information widely available.

So, the way to fix it as follows:

Look up the texlipse plugin location. This will probably be in the Eclipse folder, and the address will probably end: ...\eclipse\plugins\net.sourceforge.texlipse_1.5.0.

Backup the plugin.xml file there just in case, and then edit the original by deleting the following chunks of code:

-Firstly, the "action" (starting at line 843):

action

          class="net.sourceforge.texlipse.actions.TexWordWrapAction"
           definitionId="net.sourceforge.texlipse.commands.texWordWrap"
           icon="icons/wrap.gif"
           id="net.sourceforge.texlipse.actions.texWordWrap"
           label="W&rap text"
           menubarPath="net.sourceforge.texlipse.menus.latex/latexGroup"
           style="toggle"
           toolbarPath="latexGroup"
           tooltip="Use word wrap"

-Secondly, the "command" (starting at line 972):

command

        categoryId="net.sourceforge.texlipse.latexEditingCategory"
        name="Wrap text"
        id="net.sourceforge.texlipse.commands.texWordWrap"

(When you have done this, the file should be 1257 lines long, instead of 1271).

Finally, Ahti says: "Start eclipse with -clean command line argument to force reloading of plugin.xml." (Personally I had no idea how to do this, so I just removed and reinstalled his plugin, then exited Eclipse, and edited the code before I restarted it).

The function should work fine now. Hope this helps someone. And thanks again Ahti!

夜夜流光相皎洁 2024-10-17 08:08:52

与此同时,Ahtik 的自动换行插件出现了一个分支,我必须说,它工作得非常好,并且修复了混乱的行编号错误: Eclipse 自动换行插件

In the meantime, there has been an fork to Ahtik's word wrap plugin which, I must say, works very nice and fixes jumbled line numbering bug: Eclipse Word-Wrap Plug-In

美男兮 2024-10-17 08:08:52

打开 Eclipse ->帮助->安装新软件 ->单击“添加..”按钮并复制此行“http://dev.cdhq.de /eclipse/updatesite/luna/" 进入字段名称和位置 ->点击确定

检查->行号标尺和自动换行功能 ->下一步->下一步->完成->重启 Eclipse!

在此处输入图像描述

Open Eclipse -> Help -> Install New Software -> Click "Add.." button and copy this line "http://dev.cdhq.de/eclipse/updatesite/luna/" into field Name and Location -> Click OK

Check -> Line Number Ruler and Word Wrap Feature -> Next -> Next -> Finish -> Restard Eclipse!

enter image description here

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