Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » C/C++ comments: line wrap / format paragraph / auto fill
C/C++ comments: line wrap / format paragraph / auto fill [message #236275] Wed, 22 July 2009 09:51 Go to next message
Eclipse UserFriend
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 #545860 is a reply to message #236275] Fri, 09 July 2010 08:52 Go to previous messageGo to next message
Eclipse UserFriend
Ping... I've been wondering the same thing. Any ideas out there?
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #653194 is a reply to message #545860] Tue, 08 February 2011 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Ping: I've also wondered if this is possible.
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #666002 is a reply to message #236275] Mon, 18 April 2011 10:52 Go to previous messageGo to next message
Eclipse UserFriend
Were you ever able to get an answer to this? I have the very same question.
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #666859 is a reply to message #666002] Sat, 23 April 2011 10:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I tried asking this question CDT DEV mailing list. Maybe they will know the answer: http://dev.eclipse.org/mhonarc/lists/cdt-dev/msg21674.html

Thanks,
Yevgeny
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #666882 is a reply to message #666859] Sat, 23 April 2011 15:52 Go to previous messageGo to next message
Eclipse UserFriend
CDT formatter doesn't currently support reflowing of comments. This feature is on my todo list, but is not likely to make it into CDT 8.0.
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #667019 is a reply to message #666882] Mon, 25 April 2011 10:41 Go to previous messageGo to next message
Eclipse UserFriend
I used opening C++ file with Java editor and formatting comments in the past but it does not seem to work well in Indigo last time I tried.

Andrew
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #831371 is a reply to message #666882] Wed, 28 March 2012 16:38 Go to previous messageGo to next message
Eclipse UserFriend
Sergey Prigogin,

Thank you very much for keeping this on your to-do list.

As I write this, 8.0.2 of CDT is out.

Is there any hope for comment reflow in 8.1/9.0?

I don't see any mention of it on the planned features list.

[Updated on: Wed, 28 March 2012 16:39] by Moderator

Re: C/C++ comments: line wrap / format paragraph / auto fill [message #831383 is a reply to message #831371] Wed, 28 March 2012 16:57 Go to previous messageGo to next message
Eclipse UserFriend
Unfortunately, not in 8.1. More important things, like making C++ refactorings usable, pushed it down the todo list. I would gladly review a good quality patch implementing comment reflow.
Re: C/C++ comments: line wrap / format paragraph / auto fill [message #831439 is a reply to message #831383] Wed, 28 March 2012 18:49 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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.
 * 
 */


Previous Topic:Hello world: CDT+cygwin
Next Topic:Configure Eclipse to include the system includes before the user includes during a build
Goto Forum:
  


Current Time: Wed May 21 11:44:38 EDT 2025

Powered by FUDForum. Page generated in 0.03667 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top