【问题标题】:How to prevent Eclipse from wrapping around sections of comments如何防止 Eclipse 环绕注释部分
【发布时间】:2014-03-27 04:37:08
【问题描述】:

我在 save 命令上调用的 Eclipse 格式化程序设置为换行 cmets,因为这是我大部分时间想要的。但是,我偶尔希望 Eclipse 不要包装一些 cmets 行。这是一个例子。

如果我写:

    /**
 * My Eclipse formatter is set to wrap lines of comments, as this is what I
 * desire most of the time. However, I occasionally want Eclipse NOT to wrap
 * some lines of comments such as when I provide a simple example of an
 * output format like here:
 * 
 * Example output:
 * <comments>
 *   <comment>This should be on one line</comment>
 *   <comment>And this on the next</comment>
 * </comments>
 * 
 */

Eclipse 格式化程序会将其转换为:

/**
 * My Eclipse formatter is set to wrap lines of comments, as this is what I
 * desire most of the time. However, I occasionally want Eclipse NOT to wrap
 * some lines of comments such as when I provide a simple example of an
 * output format like here:
 * 
 * Example output: <comments> <comment>This should be on one line</comment>
 * <comment>And this on the next</comment> </comments>
 * 
 */

这是我不想要的。我知道我可以阻止每一行用&lt;li&gt; 换行,如下所示,但这很快就会变得很麻烦,使 cmets 更加混乱,并且仍然不能阻止 Eclipse 更改缩进:

    /**
 * My Eclipse formatter is set to wrap lines of comments, as this is what I
 * desire most of the time. However, I occasionally want Eclipse NOT to wrap
 * some lines of comments such as when I provide a simple example of an
 * output format like here:
 * 
 * Example output:<li>
 * <comments><li>
 * <comment>This should be on one line</comment><li>
 * <comment>And this on the next</comment><li>
 * </comments><li>
 * 
 */

我可以在“示例输出”之前添加一些内容来告诉 Eclipse 忽略格式化程序,以便它只保留我为部分 cmets 选择的缩进和换行吗?

【问题讨论】:

  • 假设这是用于 Java,stackoverflow.com/questions/1820908/…
  • 完美。这正是我想要的。这里的协议是什么?你想把这个作为答案让我检查一下吗?还是我们将此问题标记为重复?

标签: eclipse formatting comments


【解决方案1】:

在代码样式格式化程序中增加 cmets 的线宽应该可以解决您的问题。

【讨论】:

  • 否:我将格式化程序完全设置为我想要的方式。我只是想偶尔在文件的某些部分忽略它。
  • Eclipse 3.6 以上允许忽略或部分代码。转到首选项-> 代码样式-> 格式化程序。编辑现有的格式化程序。转到关闭/打开标签。您可以定义自己的标签并在注释中使用它来忽略该部分的格式化。
【解决方案2】:

Eclipse 3.6 以上允许忽略或部分代码。转到首选项-> 代码样式-> 格式化程序。编辑现有的格式化程序。转到关闭/打开标签。您可以定义自己的标签并在注释中使用它来忽略该部分的格式化。

【讨论】:

  • 是的。这确实是nitind指向我的答案所说的。这正是我一直在寻找的。​​span>
猜你喜欢
  • 1970-01-01
  • 2021-04-01
  • 1970-01-01
  • 2015-10-18
  • 2016-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-14
  • 2010-10-07
相关资源
最近更新 更多