Author Topic: Single line no-wrap comment  (Read 12795 times)

dunkers

  • Senior Community Member
  • Posts: 594
  • Hero Points: 27
Single line no-wrap comment
« on: August 17, 2006, 11:40:38 pm »
I've checked the other thread, but it doesn't appear to mention this one...

If one starts a comment line with "//" then it doesn't wrap when you get to the right margin. However, if you then start another comment line that does wrap at the margin.

This is for a .c extension, and I have "Enable block comment wrap" ticked, "Enable line comment wrap" ticked, "Enable Javadoc wrap" ticked, and "Fixed right margin" set to 80. Note that I ticked the "Enable block..." thing when it didn't wrap and I thought it might need that ticking.

Dswag89

  • Community Member
  • Posts: 63
  • Hero Points: 4
Re: Single line no-wrap comment
« Reply #1 on: August 18, 2006, 01:44:20 pm »
Yep, sure does.  To further enhance your description.  start a C++style comment:
Code: [Select]
                // fdjfa;lfjafj ljf fjsfljsdfljf jflkjas aj fajasf ljajkf asldfj sjksflaskjfsalkdf
Hitting "enter" won't do anything.  Document... Reflow comment is not allowed.

Then, starting a new C++ comment on the next line will properly comment-wrap on the second comment.  The first still will not reflow.

Code: [Select]
                // fdjfa;lfjafj ljf fjsfljsdfljf jflkjas aj fajasf ljajkf asldfj sjksflaskjfsalkdf
                // dfas faffjsl;fjsfjs lskjf slkfj sf fjdlfjdf j lj j sfj
                // lj faskf ja fj flaksjfsal fkjsf ljf lksjf
                // salfjsflksjfskljf s;kf jks sdf

This actually appears to be the opposite of the problem that the developers have acknowledged with block comments.
There: A block comment after another comment (with no space between) will not wrap.
Here: A C++ line comment will not wrap.  Another C++ line comment after a C++ line comment (with no space between) will wrap.

Another interesting tidbit for the developers, there's no "Help" on the "Enable Line Comment Wrap" feature, so it must be very new... the Help hasn't caught up yet. ;)

Of course, if it is really a line comment, it should be short enough that it doesn't need to wrap... a line comment that wraps, should by default be called (IMO), a block comment!

dunkers

  • Senior Community Member
  • Posts: 594
  • Hero Points: 27
Re: Single line no-wrap comment
« Reply #2 on: August 18, 2006, 01:57:36 pm »
Quote
if it is really a line comment, it should be short enough
I thought about that. Then I realised that if the comment were far enough to the right at the start I'd want to wrap to the same indent in most cases. A quick way to disable just for one line would be nice, but I could live without it.

With previous version of SlickEdit, hitting return at the end of the line would automatically put the starting "//" on the next line. That could be a blessing or pain depending on what one was doing, but it doesn't happen now and I have to say I miss it.

Phil Barila

  • Senior Community Member
  • Posts: 746
  • Hero Points: 61
Re: Single line no-wrap comment
« Reply #3 on: August 18, 2006, 03:30:22 pm »
It's been my observation that if the next line in your doc is not a comment, you need at least one character to the right of the cursor when you hit the enter key to get the comment on the new line.  Even a single space char is sufficient to trigger the new comment line.  If the next line is already a comment, then a new line is just treated as an addition to the comment block you are currently editing.

dunkers

  • Senior Community Member
  • Posts: 594
  • Hero Points: 27
Re: Single line no-wrap comment
« Reply #4 on: August 18, 2006, 03:38:41 pm »
Wow, you're right! That would explain why I sometimes get caught by surprise when it works, but can't replicate it to make sure.

dunkers

  • Senior Community Member
  • Posts: 594
  • Hero Points: 27
Re: Single line no-wrap comment
« Reply #5 on: August 25, 2006, 01:59:11 am »
A bit more on this. I like the wrap but it gets in the way...

I start writing a comment:

    // First, see if ... blah blah ... end of line... here
    // one connection at a time .. blah .. done.

OK, so now I hit return to start writing actual code on the next line, but I get the "// " automatically placed. No problem, happened with V10 etc. Backspace to zap the extra // but after the first one I'm back on the previous line (the one with the last of the real comment). Er.. ok, so hit return then shift-home to mark to the start of the comment (needs it twice, since the first only gets to the start of the comment text - nice feature but in there way here). Now I start typing and the line below is concatenated onto what I'm typing - the eol character appears to have been zapped:

Code: [Select]
    // commment ....
    // comment ...
    //                        <-- zap this and type
    someRealCode();

From that to this:
Code: [Select]
    // commment ....
    // comment ...
    addedCode     someRealCode();

Hope you can follow that. If this happen once in a blue moon it would be just one of those things, but I seem to be spending more time getting out of inadvertant automagic features than writing code at the moment. Gonna have to think about turning 'em off.

dunkers

  • Senior Community Member
  • Posts: 594
  • Hero Points: 27
Re: Single line no-wrap comment
« Reply #6 on: August 25, 2006, 12:34:39 pm »
I just had a really very bad experience with this, and during the ensuing swearing it occured to me that all I really need is an override key to just stop the wrap for this instance. Like shift-space prevents the "if " expansion. Does one already exist or should I be looking a code my own?

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: Single line no-wrap comment
« Reply #7 on: August 25, 2006, 01:38:52 pm »
You're quite right that comment wrapping for line comments was a late addition. As with block comments, this is a difficult feature to determine when to wrap and when not to wrap so that it feels natural. Sorry about not getting the help in on time for this.

We decided to wrap line comments beginning with the third line. When you hit a carriage return on the second line comment, we auto-insert the comment characters, "//". It's at this point that we enable the comment wrapping. Unlike block comments, we don't know when your intent is to write a long comment or a single line comment, so we defer turning on wrapping until there are a couple consecutive line comments. We wanted to make sure that we provided the wrapping assistance where needed but didn't mess with individual line comments. We're certainly open to changing this behavior or adding additional options. Let us know what you think would be better.

As for getting out of this mode, use Shift+Enter (in CUA emulation) to insert a carriage return without the comment characters. To reindent the line, moving the cursor the correct indent for the code, I just hit tab. That works if you have the following option enabled: Tools > Options > Line Extension Setup, Indent tab, for "When tab key reindents the line" select "In leading blanks" and put a check in "Strict", or select Always.

I hope this helps.

--Scott

dunkers

  • Senior Community Member
  • Posts: 594
  • Hero Points: 27
Re: Single line no-wrap comment
« Reply #8 on: August 25, 2006, 02:35:28 pm »
Scott, thanks very much for explaining how it really works. Knowing that, and the shift-enter escape, makes it much more fun to use and a great tool :)

pearish

  • Community Member
  • Posts: 11
  • Hero Points: 0
Re: Single line no-wrap comment
« Reply #9 on: February 09, 2007, 01:36:35 am »
Scott -

You asked for opinions, so...

It seems that there are 2 basic styles of commenting  multiple lines of C or C++ code: either you use the /*....*/ construct, or you simply prepend // to every line. I fall into the latter camp, and consequently, the current implementation of "single line" comments is unusable. The majority of the time a "single line" comment will extend to perhaps 2 or 3 lines, so the heuristic to only start wrapping after the 2nd line fails to address the common case.

Here's a suggestion: if the user has selected the automatic wrap option for single line comments, wrap "single line" comments starting with the very first line, and continue to wrap up to the point the user enters an explicit return. Once the user enters a return, the cursor would move to the next line, and you would not  automatically add //. If the user wanted to start a new line but have the // prepended and word wrap continue, they could enter the shift-return.

Phil Barila

  • Senior Community Member
  • Posts: 746
  • Hero Points: 61
Re: Single line no-wrap comment
« Reply #10 on: February 09, 2007, 05:05:04 pm »
I second this suggestion, though I'm naively assuming it won't be too difficult.   :D  If not the default behavior, at least make it selectable? 

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: Single line no-wrap comment
« Reply #11 on: February 09, 2007, 08:15:08 pm »
Thanks for the input. We are approaching lock down on the v12 release, so we won't be able to make a change like this as part of that release. We will be doing more work on bug fixes and enhancements to comment wrapping in 12.0.1, and we'll take a look at these suggestions at that time.

--Scott

Phil Barila

  • Senior Community Member
  • Posts: 746
  • Hero Points: 61
Re: Single line no-wrap comment
« Reply #12 on: February 09, 2007, 09:03:16 pm »
Oh, I had no delusions it would be in the RTM.  I just want it on your TODO: list.  Thanks for putting it on your TODO: list.  Comment wrapping is very cool, except when it doesn't do what I want it to do, then it's annoying in large measure.   :D  But then, isn't just about every feature like that?

alex

  • Community Member
  • Posts: 64
  • Hero Points: 6
Re: Single line no-wrap comment
« Reply #13 on: February 10, 2007, 03:12:11 am »
I agree with the suggestions previously made.

I'd like to add one more suggestion: allow use of tabs instead of spaces for comment wrapping.  My company always uses tabs for indentation, so using spaces in comment-wrapping causes lines to look funny when doing diffs, etc.  It's not entirely obvious how to implement this in a generally correct way, but if you could give some direction on how to implement a simple version of this in such a way that every N spaces are converted to a tab during the wrapping, that would be really nice.

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: Single line no-wrap comment
« Reply #14 on: February 11, 2007, 06:58:40 pm »
Quote
My company always uses tabs for indentation, so using spaces in comment-wrapping causes lines to look funny when doing diffs, etc.  It's not entirely obvious how to implement this in a generally correct way, but if you could give some direction on how to implement a simple version of this in such a way that every N spaces are converted to a tab during the wrapping, that would be really nice.

Alex,

I did look into this, and I *think* I found the correct way to fix this problem.

First, jump to the macro function named CW_fixBorders2 by executing fp CW_fixBorders2 in the command line.  This will take you to that function found within commentformat.e.  Save a copy of this file somewhere else to avoid modifying the original file.

About 2/3rds into this function, you'll find this line

Code: [Select]
_begin_line(); delete_end_line();
Now, replace that line with the following line

Code: [Select]
replace_line(indent_string(CW_commentBorderLeftCol));
then load the file to have the change take effect.  With this change, the comment wrap honors the "Indent with tabs" setting in the File Extension Setup dialog when it inserts a new line.  So, if you have this check box checked, then it should insert tab characters instead.

After making sure that this change will not break any existing behavior, I'll make sure this change will go into the next major release.

Kohei