0

My Eclipse formatter invoked on the save command 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. Here is an example.

If I write:

    /**
 * 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>
 * 
 */

the Eclipse formatter will turn this into:

/**
 * 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>
 * 
 */

which I don't want. I know I can prevent each line to wrap with <li> as below but that gets cumbersome very quickly, makes the comments more confusing, and still does not prevent Eclipse from changing the indentation:

    /**
 * 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>
 * 
 */

Is there something I could put before "Example output" to tell Eclipse to ignore the formatter so that it preserves the indentation and line wrapping I chose for a portion of my comments only?

Lolo
  • 3,935
  • 5
  • 40
  • 50
  • 1
    Assuming this is for Java, http://stackoverflow.com/questions/1820908/how-to-turn-off-the-eclipse-code-formatter-for-certain-sections-of-java-code . – nitind Feb 25 '14 at 06:36
  • Perfect. This was exactly what I was looking for. What's the protocol here? Do you want to have this as an answer so that I check it? Or do we mark this question as a duplicate? – Lolo Feb 25 '14 at 06:53

2 Answers2

0

Increasing line width for comments in code style formatter should solve your problem.

cerberus
  • 531
  • 4
  • 14
  • No: I set my formatter exactly to the way I want. I just want to ignore it occasionally on portions of a file. – Lolo Feb 25 '14 at 06:21
  • Eclipse 3.6 above allows ignoring or section of a code. Go to preference -> Code style -> Formatter. Edit the existing formatter. Go to Off/On tags. You can define your own tags and use it in comment to ignore that section from formatting. – cerberus Feb 25 '14 at 06:56
0

Eclipse 3.6 above allows ignoring or section of a code. Go to preference -> Code style -> Formatter. Edit the existing formatter. Go to Off/On tags. You can define your own tags and use it in comment to ignore that section from formatting.

cerberus
  • 531
  • 4
  • 14
  • Yes. This is indeed what the answer that nitind pointed me to said. That is exactly what I had been looking for. – Lolo Feb 25 '14 at 15:24