C/C++ comments: line wrap / format paragraph / auto fill [message #236275] |
Wed, 22 July 2009 09:51  |
Eclipse User |
|
|
|
Hi,
Is there a way to line-wrap comment blocks in CDT to width of say 80
chars? I tried code formatting (Ctrl+Shift+F), but that didn't seem to
work. I'm so much used to Emacs' Alt-q (i.e. c-fill-paragraph, or
fill-paragraph), which does the job beautifully. In Eclipse, without
automatic line-wrap, I've to either insert newlines myself, or fall back
to Emacs when I'm in a serious commenting mood.
Rhishi
|
|
|
|
|
|
|
|
|
|
|
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #831439 is a reply to message #831383] |
Wed, 28 March 2012 18:49   |
Eclipse User |
|
|
|
Sergey Prigonin,
Thanks for the quick response!
At least comment-reflow is on the to-do list of someone who is working on improving the system.
I imagine that the learning curve is steep enough so that my being able to contribute a patch is impractical, especially for a C++ guy like me who has never written a Java application. The CDT, as part of Eclipse, *is* written in Java, isn't it?
Anyway, I'm not complaining about this lack of functionality. Rather, I'm waiting for an opportunity to start using Eclipse. At the moment, the lack of comment-fill capability keeps me running back to vim. I spend a lot of time writing comments, and I reflow them often.
|
|
|
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #1096751 is a reply to message #236275] |
Wed, 28 August 2013 16:30  |
Eclipse User |
|
|
|
So I'd really like to see this feature implemented but in the meantime I have a hacky work around for users of eclipse on Gnome. I wrote a quick python script which monitors the Gtk clipboard. If the clipboard gets some text in the form of "/* blah blah */" it will reflow the text, and then put it back in the clipboard. Thust by starting the script, and then working in eclipse, doing ctrl+x followed by ctrl+v will reflow the text.
This is a complete hack and it only saves me time because I'm implementing something which has a lot of documentation so I'm copy-pasting the documetnation into eclipse as c++ comments along with their relevant structures. It will probably not be useful for anyone else. If you want to give it a try though, here it is:
#! /usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk # this is a gnome clipboard tool, not a kde one
import sys # printing
import re # regular expressions
import textwrap # wraps text
import time # sleep
def reflow(text):
# strip off the start
text = re.sub(r'^\s*/[\*\s]+','',text)
# strip off the end
text = re.sub(r'[\s\*]+/\s*$','',text);
# split the string at multiple newlines (paragraph boundaries)
cat = '';
for par in re.split(r'(\n[\s\*]*){2,}',text):
if re.search(r'^\n[\s\*]*$',par):
sys.stdout.write('skipping: ' + par + '\n')
continue;
sys.stdout.write('processing: ' + par + '\n')
# replace any newline star sequences (i.e. join multiple lines)
par = re.sub(r'\n[\s\*]*','',par)
for wrapped in textwrap.wrap(par,77):
cat = cat + ' * ' + wrapped + '\n';
cat = cat + ' * ' + '\n'
return '/**\n' + cat + ' */\n';
clipboard = gtk.clipboard_get()
copy_of_last = ''
while( 1 ):
text = clipboard.wait_for_text();
if( text == None ):
sys.stdout.write('not text!\n')
continue
elif( text == copy_of_last ):
time.sleep(0.100)
continue
else:
leftObj = re.search(r'^\s*/\*',text)
rightObj = re.search(r'\*/\s*$',text);
if leftObj and rightObj:
sys.stdout.write( "Found a c++ style comment block\n" )
copy_of_last = reflow( text )
sys.stdout.write( "Reflowed to:\n\n" )
sys.stdout.write( copy_of_last )
sys.stdout.write( "\n" )
clipboard.set_text( copy_of_last )
clipboard.store()
for instance if I have a block comment like this:
/**
* this one has multiple paragraphs that should not be flowed together
*
* this is the second paragraph
*
* this is the third paragraph which should be much longer than 80 chars and so
* should be wrapped up
*
* fourth
*
* fifth
*
* this paragraph is really long and actually goes over 80 char instead of being properly formatted like the previous one that went over 80 lines. In fact this one goes over 160 chars so it should even be wrapped to more than two lines.
*
*/
Then the script will replace it in the clipboard with:
/**
* this one has multiple paragraphs that should not be flowed together
*
* this is the second paragraph
*
* this is the third paragraph which should be much longer than 80 chars and
* soshould be wrapped up a lot
*
* fourth
*
* fifth
*
* this paragraph is really long and actually goes over 80 lines instead ofbeing
* properly formatted like the previous one that went over 80 lines. INfact this
* one goes over 160 chars so it should even be wrapped to more thantwo lines.
*
*/
|
|
|
Powered by
FUDForum. Page generated in 0.03667 seconds