eclipse 从换行中停止日食?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/890805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Stop eclipse from line wrapping?
提问by Craig P. Motlin
Is there a way to get eclipse to stop erasing existing line breaks? If I have a method signature like this, I can't figure out how to get eclipse to leave it alone:
有没有办法让日食停止擦除现有的换行符?如果我有这样的方法签名,我无法弄清楚如何让 eclipse 不理会它:
void foo(
int arg1,
int arg2,
int arg3,
int arg4)
{
// ...
}
With various settings it will either collapse the arguments down to one line, or wrap them at some margin like this:
使用各种设置,它要么将参数折叠为一行,要么像这样将它们包装在某个边距处:
void foo(
int arg1, int arg2,
int arg3, int arg4)
{
// ...
}
With "Wrap all elements, every element on a new line" it does preserve this whitespace, but it will ALWAYS wrap, which isn't what I want. I'd like eclipse to apply formatting for indentation and braces and such, just without ever deleting (or inserting) any line breaks.
使用“换行所有元素,每个元素都在一个新行上”它确实保留了这个空白,但它总是会换行,这不是我想要的。我希望 eclipse 为缩进和大括号等应用格式,只是不删除(或插入)任何换行符。
回答by VonC
The formatting of arguments is an old subject, but the one new formatting feature introduced in 3.5 is:
参数的格式化是一个古老的主题,但 3.5 中引入的一个新的格式化特性是:
- eclipse3.5M4"Formatter option to preserve user line breaks"
- eclipse3.5M4“保留用户换行符的格式化程序选项”
The Java code formatter can now optionally preserve user line breaks by not joining lines in code or comments.
Java 代码格式化程序现在可以通过不在代码或注释中加入行来选择性地保留用户换行符。
For example, the wrapped lines of the return statement in following test case:
例如,以下测试用例中 return 语句的包装行:
Example of Code to Format
要格式化的代码示例
will be preserved by the formatter when the "Never Join Lines" preference is used, and now produces the following result:
当使用“从不加入行”首选项时,格式化程序将保留,现在产生以下结果:
Coded Formatted with Never Join Lines
编码格式从不加入行
This preference can be configured on the Java > Code Style > Formatter
preference page. See the Never join lines
option on the Line Wrapping
and Comments
tab.
可以在Java > Code Style > Formatter
首选项页面上配置此首选项。请参阅和选项卡Never join lines
上的选项。Line Wrapping
Comments
That may help, but otherwise there is not much new features on that front in 3.5.
这可能会有所帮助,但除此之外,3.5 中这方面的新功能并不多。
回答by Brian Headlee
When I used the 'format' feature in Eclipse on my Java code, it tended split or break my lines of code in various places to make sure the content would always fit to a certain width. I found this to be less than optimal if you have a wide monitor. I worked around this issue by doing the following:
当我在 Java 代码上使用 Eclipse 中的“格式”功能时,它倾向于在不同的地方拆分或中断我的代码行,以确保内容始终适合特定宽度。我发现如果你有一个宽显示器,这不是最佳选择。我通过执行以下操作解决了这个问题:
In eclipse 3.5, you can open preferences and search for "Format" or select Java->Code Style->Formatterfrom the left menu. The default profile is called "Eclipse [built-in]" and if you want to make changes to the Java Formatter you will need to copy it and create your own profile. This can be done with the "New" button right below the profile name.
在 eclipse 3.5 中,您可以打开首选项并搜索“格式”或从左侧菜单中选择Java-> Code Style-> Formatter。默认配置文件称为“Eclipse [内置]”,如果您想对 Java Formatter 进行更改,您需要复制它并创建您自己的配置文件。这可以通过配置文件名称正下方的“新建”按钮完成。
Once you have created your own Java Formatter in eclipse, make sure it's selected and hit the editbutton. There a lot of features in here you can customize, but to fix the wrapping issue I selected the "Line Wrapping" tab. Under general settings you will see "Maximum line width:". This numerical value is the max line length the formatter will work with. I bumped my up to a more reasonable sizefor larger monitors such as 180characters. Save and applythat and return to your code.
在 Eclipse 中创建了自己的 Java Formatter 后,请确保选中它并点击编辑按钮。这里有很多功能可以自定义,但为了解决环绕问题,我选择了“换行”选项卡。在一般设置下,您将看到“最大线宽:”。此数值是格式化程序将使用的最大行长度。对于更大的显示器,例如180 个字符,我增加了更合理的尺寸。 保存并应用它并返回到您的代码。
When you next try to format a java file, the line wrapping should only happen if you are above the new max size.
当您下次尝试格式化 java 文件时,仅当您超过新的最大大小时才会发生换行。
Happy Coding!
快乐编码!
回答by Thorbj?rn Ravn Andersen
You can use comments to guide the formatter.
您可以使用注释来指导格式化程序。
void foo( //
int arg1, //
int arg2, //
int arg3, //
int arg4)
will preserve the line breaks at the comments.
将保留注释处的换行符。
回答by tunaranch
Eclipse 3.5 supports this. (It hit release candidate a a few days ago, so could be worth checking out)
Eclipse 3.5 支持这一点。(几天前它击中了候选版本,所以值得一试)