Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Formatter: unwanted new lines, Typing: unwanted comment closure(A couple of features I can't seem to be able to disable...)
Formatter: unwanted new lines, Typing: unwanted comment closure [message #1724777] Thu, 25 February 2016 23:33 Go to next message
g4rb4g3 ju1c3 is currently offline g4rb4g3 ju1c3Friend
Messages: 3
Registered: February 2016
Junior Member
I've scoured Eclipse and searched the internet for hours trying to find a way to turn a couple of things off...

Linux Mint 17.1
Eclipse version: Mars.1 Release (4.5.1)
Eclipse build id: 20150924-1200
CDT version 8.8.0

The formatter is being a bit stupid with line breaks. This:

void LetsIncrementForNoReason(void)
{
   int a, b, c, d;

   for (a = 0; a < 42; a++) {
      b = c = d++;
   }
}

turns into:

void LetsIncrementForNoReason(void)
{
   int
            a,
            b,
            c,
            d;

   for (a = 0;
            a < 42;
            a++) {
      b = c = d++;
   }
}

The formatter is amazing for making other people's code readable, but this is just silly. The closest thing I can find is under White Space when editing the formatter profile. I can see the example code formatted like this but I see no option for new lines. In fact the whole New Lines tab is suspiciously empty aside from one check box and only shows C++ example code...

When starting a block comment with /* and pressing enter, comment is automatically closed around the new line as in:

/*<enter>   CodeToCommentOut();

turns into:

/*
 * <cursor>
 */   CodeToCommentOut();

This is great and all, but as you can see I'm not necessarily intending to write an actual comment. Yes, I know about the automatic code commenting feature, but I'd rather not be forced to use it. I've tried disabling every comment related option I can find and it still does it.

Is it possible to turn these features off? I really like Eclipse and this isn't stopping me from using it, but it's really annoying.

Thanks...
Re: Formatter: unwanted new lines, Typing: unwanted comment closure [message #1724882 is a reply to message #1724777] Fri, 26 February 2016 18:25 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
Formatter

For (1) it sounds like you have custom settings for formatter. The behaviour happens when you have "Force split, even if line is shorter than maximum width" when various "Wrap all elements" settings are used. To change edit formatter settings profile in "Line Wrapping" tab

Compare with the setting on:

index.php/fa/25122/0/

To the setting off:

index.php/fa/25123/0/

Auto Comment Close

For (2) I don't know how to turn off auto-close of block comments. It does not seem to have a control like closing quotes ("), braces ({) and others.

Shift-Enter maybe occasionally useful as it wraps the current line in the comment instead:

/*<shift-enter>   CodeToCommentOut();


becomes:
/*   CodeToCommentOut();
 * 
 */

followed by Ctrl-Z becomes:
/*   CodeToCommentOut(); */
  • Attachment: on.png
    (Size: 56.44KB, Downloaded 3723 times)
  • Attachment: off.png
    (Size: 48.46KB, Downloaded 3892 times)
Re: Formatter: unwanted new lines, Typing: unwanted comment closure [message #1724961 is a reply to message #1724882] Sun, 28 February 2016 05:48 Go to previous messageGo to next message
g4rb4g3 ju1c3 is currently offline g4rb4g3 ju1c3Friend
Messages: 3
Registered: February 2016
Junior Member
Thanks Jonah. You pointed me in the right direction to figure out the line break problem:

On the Line Wrapping tab I had everything set to 'Do not wrap', except enumerations which I forced to wrap so every element is on a separate line ('Wrap all elements...' and 'Force split...'). Apparently this ignores the maximum line width, but I also assumed anything set to 'Do not wrap' would also ignore it. Now that I do think about it, I'm not sure it should. Seems like a bug to me. Regardless, the problem was that I had the maximum line width set to 0, thinking that would mean unlimited. The solution was to set it to 9999. I'm not using a VT52 and I'd rather handle line breaks myself anyway. Thing is, 'Do not wrap' is now enforced. Any long lines like function declarations that are manually broken up at logical points get joined back together into one. This is easily averted with the 'Never join already wrapped lines' option however.

I didn't know about Shift+Enter, and that combined with Ctrl+Z is better, but still not quite what I'd like. I'm looking to put the comment start and close on their own separate lines with no * in front of everything. What I omitted to say was I'm usually commenting out multiple lines of code and what I'm doing is /*<enter> at the beginning of the first line, cursor down however far, and */<enter> at the beginning of the line after the last. Selecting lines and using Ctrl+Shift+/ produces what I'm looking for and isn't really that much more typing, I'm just not used to it. Seems weird there is no option for this. There's an 'Automatically close' section in the editor typing options, and seemingly everything except comments have an option to enable/disable automatic closure. I did have a quick look at the CDT source to see if I could easily disable (absolutely love open source for this) it but holy crap, there's a *lot* of code to wade through. Might be easier to make some suggestions to the developers...

Thanks for your help.
Re: Formatter: unwanted new lines, Typing: unwanted comment closure [message #1724969 is a reply to message #1724961] Sun, 28 February 2016 08:52 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
Glad I could help point you in the correct direction. I would be happy to help advise if you did want to wade through CDT to improve things!
Re: Formatter: unwanted new lines, Typing: unwanted comment closure [message #1725237 is a reply to message #1724969] Wed, 02 March 2016 00:50 Go to previous message
g4rb4g3 ju1c3 is currently offline g4rb4g3 ju1c3Friend
Messages: 3
Registered: February 2016
Junior Member
I'd work on everything if I could! I've been messing around a bit with Xfce and I managed to fix a couple of things that were annoying me. It just takes me quite a while to figure out even the simplest things in my spare time since I'm relatively new to Linux, GNU, X, etc, etc -- especially programming for it. Then there's figuring out someone else's code in a large project that's not particularly ripe with comments. Then I'm not the greatest with Java. But maybe at some point I'll look into the automatic comment close thing since I'm now using Eclipse more and it might start to annoy me too much. If I decide to dive into CDT it's good to know I could ask some questions here.
Previous Topic:Help in setting up remote debugging on ARM Linux
Next Topic:Use flex/bison in build
Goto Forum:
  


Current Time: Fri Apr 26 08:55:08 GMT 2024

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

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

Back to the top