How to reformat multi-line comments in Eclipse PDT?
Asked Answered
F

3

10

In Eclipse PDT, Ctrl-Shift-F reformats code. However, it doesn't modify comments at all. Is there some way to reformat ragged multi-line comments to 80 characters per line (or whatever)?

i.e. convert

// We took a breezy excursion and 
// gathered Jonquils from the river slopes.  Sweet Marjoram grew 
// in luxuriant 
// profusion by the window that overlooked the Aztec city.

to

// We took a breezy excursion and gathered Jonquils 
// from the river slopes.  Sweet Marjoram grew in 
// luxuriant profusion by the window that overlooked 
// the Aztec city.

(I think this applies to regular Eclipse as well.)

Update Turns out that Eclipse in Java mode will reformat the lines above, but only if they're /* */-style comments. It will shorten // lines that are too long, but it won't join lines that are too short together.

Fulgurite answered 25/9, 2008 at 10:27 Comment(2)
Those are in fact single line comments. Multiline comments always use the /*-notation.Asante
I think he means a comment spanning multiple single-line comments. That sort of thing is the typical way to do any sort of commenting besides docstrings in Python.Demolition
T
2

You probably need to configure the Java formatter to include comments.

Preferences -> Java -> Code Style -> Formatter -> Edit... -> Comments

Make sure that "Enable XXX comment formatting" is enabled.

Tubercle answered 25/9, 2008 at 11:13 Comment(1)
It seems that this does somewhat work in Java mode, but not with PDT. However, for some reason it will only fully reformat /* / or /* */ comments--it will make // lines that are too long shorter, but won't make shorter lines longer.Fulgurite
A
1

I've never really been able to get the Eclipse formatter to format my code exactly how I want, and this is just one of several shortcomings I've encountered. I've heard the Jalopy formatter is much better. There's both a commercial and free version available with Eclipse plugins for both. I've heard the commercial version is more sophisticated (development on the free version appears to have stalled), but I haven't actually used either personally.

Arnelle answered 9/10, 2008 at 22:34 Comment(0)
U
1

My solution involves using the vrapper plugin (free): http://vrapper.sourceforge.net/home/ which gives you vim support within your text editor.

Once the vrapper plugin is installed you can press v to go into visual mode, highlight your multi-line comment and then press G+Q to auto format the comment so that lines are 80 columns in width (default). You can change the default column width, but you'll need to read the documentation for the vrapper plugin. Cheers!

Unmanned answered 28/12, 2012 at 6:46 Comment(1)
THIS is the best solution. I did exactly this, installed Vrapper from the link above, then hit V within my code, selected the blocks that were messed up, simply: G+Q fixed the spacing! Rinse and repeat through code... THEN SET PREFERENCES TO NEVER WRAP THEM AGAIN!Cotillion

© 2022 - 2024 — McMap. All rights reserved.