SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: jorick on November 07, 2007, 02:07:20 PM

Title: Comment wrapping doesn't work right
Post by: jorick on November 07, 2007, 02:07:20 PM
I use block comments in my code where the entire block is surrounded by asterisks.  The comment wrap is set for a right column of 79.  Comment wrap works great for a while but then gets confused and the right column jumps from 79 to 82 or more.   From then on, all block comments are formatted to right column 82.  Going into the File Extension Setup box, Comment Wrap tab shows that wrapping is still supposed to be at column 79.  Changing the column doesn't work after SlickEdit gets confused.  The only way to reset it is to exit SlickEdit and restart.  Is this a bug or am I doing something wrong?

SlickEdit Version 12.0.3.0
OS: Windows XP 5.01.2600 SP2

Enable comment wrap = on
Enable block comment wrap = on
Enable doc comment wrap = on
Enable line comment wrap = on
Fixed right margin = on
   Right column = 79
All other checkboxes are off
Title: Re: Comment wrapping doesn't work right
Post by: David_O on November 08, 2007, 02:43:56 PM
It doesn't sound like you are doing anything wrong.  Unfortunately, until we can reproduce it exactly, I can not determine whether this is a bug.  If you could send some screen shots of what is happening (before and after) to support@slickedit.com, perhaps we could narrow it down.

It could be the fact that you have the "entire block is surrounded by asterisks."  When comment wrap believes that it has found such a comment (that is, one with a right border) it will ignore the the setting for right column 79 and maintain the right border of the existing comment.  This is in line with comment wrap's principle of focusing only on local changes.  If one were to start typing in a comment with a border that did not end at col 79, the only way to honor the 79 setting would be to reformat the entire comment.  If not, the border would not be consistent.  Granted this is a compromise that may not be optimal for everyone.

Title: Re: Comment wrapping doesn't work right
Post by: jorick on November 08, 2007, 07:00:34 PM
"it will ignore the the setting for right column 79 and maintain the right border of the existing comment."

The entire comment has the right border at 79.  When it starts placing it at 82, I delete the extra characters to put it back to 79 but it doesn't matter to SlickEdit.  It just keeps putting the right border asterisk at 82 again.

I can't tell you how to reproduce it because it's intermittent.  Usually it happens after using clipboard inserts and block deletes.

However, I have found another problem with comment wrap that's reproducable.  Consider the following code section:


/******************************************************************************
* MCU functions                                                               *
******************************************************************************/
/******************************************************************************
*~    MCU_WriteData              Write data to the MCU                        *
*******************************************************************************
*                                                                             *
* This function writes a byte to the MCU data lines.  The data lines reside   *
* on the GPIO2 port as pins 10 to 17.  To write to them, the other pins are   *
* write protected so that a writable hole opens up.  The data is shifted 10   *
* bits to the left in order to align the data with the hole.  After writing   *
* data, the write protection is removed from the port.                        *
*                                                                             *
******************************************************************************/


Notice that there are two comment blocks with no blank lines between them.  Comment wrapping works in the first block but doesn't work in the second.  Comment width doesn't matter since this problem appears with different width blocks as well.

If I place a blank line between the two blocks, comment wrapping works in the second block again.
Title: Re: Comment wrapping doesn't work right
Post by: David_O on November 09, 2007, 09:55:26 PM
Thanks for the example.  I was able to get the consecutive block comments to happen and the problem is a bug in the handling of block comments in languages that do not allow nested block comments.  That explains why you saw it in C and Java, but not Slick-C.  There will be a hotfix out for this shortly.

I believe I know what was happening with the other problem of comment wrapping extending the right margin.  It has to do with pasting.  Actually, comment wrapping does not handle most paste events.  This is simply because its impossible to know what to do on every possible paste.  It could be one word or hundreds of lines.  So we don't actually wrap or format on a paste and instead rely on the next keystroke triggering a wrap or format, which usually is acceptable.

You have stumbled on the case when this doesn't work.  What the right margin should be for a comment is calculated on the first key stroke when you start editing that comment.  If you keep typing there, we just use the cached value for the right margin.  If you leave the comment, edit some place else, and then come back, the right margin is again calculated on the first keystroke.  Letting long lines from pastes be wrapped on the next keystroke usually works because we just use the cached value for what the right margin should be.

What I think is happening to you is that you enter a comment and you do a paste before hitting any other key.  This can leave a line past your desired right margin.  Then you hit a key and the right margin in calculated.  But because you have a right border, that long line is used as the right margin.  This would not happen if you did not use a right border or if you were to type something else before the paste.

The good news is that the hotfix will address this problem as well.  It will more intelligently handle simple paste events.  Still no multiline or block pastes, but for most cases you will get wrapping on a paste event.

Thanks for reporting this,

-David-

Title: Re: Comment wrapping doesn't work right
Post by: Ding Zhaojie on November 10, 2007, 05:13:47 PM
Seems comment wrapping does not support DBCS very well. When I was using Chinese to write comments the comment wrapping often messed my comments up :(

btw: the Mini HTML can not wrap East Asian languages correctly, too. There no spaces to separate words in CJK(Chinese, Japanese, Korea) languages, so the Mini HTML can not wrap the line to fit width :-\, very annoying when reading function documents. The XMLmind XML Editor has the same problem, but it applied an option (see my screen shot) to let CJK user avoid it. If SE can apply similar settings, that would be very appreciated.
Title: Re: Comment wrapping doesn't work right
Post by: David_O on November 13, 2007, 04:35:51 PM
First, I'll post the two files necessary for the hotfix here.  If they cause any problems let me know.  Again, this hotfix should repair the consecutive block comments issue reported in this thread and add handling of simple paste events to comment wrapping.  There are a few other minor tweaks that should be safe.

Note there are two files you will need to replace.  Please rename/backup your original commentformat.e and clipbd.e macro files from your <SlickEdit installation directory>\macros directory.  Save the new ones to the same location.  Don't forget to load the new versions via Macro-->Load Module.

Second, Ding Zhaojie's ideas for handing long words common to CJK users are great.  (Thanks for the screen shot.  That really helps explain your idea.)  We will file a feature request and try to get something to address this is a future release. 

Thanks for the feedback.
Title: Re: Comment wrapping doesn't work right
Post by: David_O on November 14, 2007, 04:53:39 PM
I had to make an update to the two macros files posted here.  If you've already downloaded them, please download again.  Hope that is the last change.

-David
Title: Re: Comment wrapping doesn't work right
Post by: jorick on November 16, 2007, 08:39:37 PM
I just saw comment wrapping do the same thing again.  I have all of the hotfixes installed.

Oh well.  Even with the problem, SlickEdit's comment handling is by far better than anything else out there.
Title: Re: Comment wrapping doesn't work right
Post by: David_O on November 16, 2007, 10:04:15 PM
By "same thing" do you mean fail to keep the right border after a paste or fail on consecutive block comments?