Author Topic: Selection block comment  (Read 7473 times)

Mario Figueiredo

  • Community Member
  • Posts: 10
  • Hero Points: 0
Selection block comment
« on: November 18, 2006, 03:18:47 am »
Hello,

It strikes me as somewhat odd the decision to not provide quick access to the possibility of commenting a block of selected code. There's not even an option for this anywhere. I dealt with the problem by defining a new Surround With entry.

Just perhaps suggesting that you consider the possibility of making this option readily available at top level on the right-click menu.

Selecting a block of code and commenting it seems to me such a common thing, it would be great if access to it was almost mechanical.

Wanderer

  • Senior Community Member
  • Posts: 558
  • Hero Points: 23
Re: Selection block comment
« Reply #1 on: November 18, 2006, 01:44:51 pm »
Not sure what you are looking for here.
SlickEdit v11 (and for at least several previous versions), WinXP:  With text selected both Document->Comment Lines and Document->Block Comment are available.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Selection block comment
« Reply #2 on: November 19, 2006, 11:21:38 am »
Or see http://community.slickedit.com/index.php?topic=118.msg755#msg755 for another (customized) possibilty.

HS2

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2209
  • Hero Points: 275
Re: Selection block comment
« Reply #3 on: November 19, 2006, 02:12:51 pm »
I just retested this.  Surround with can be configured to create a block comment.  You may just have just gotten confused by the meaning of the "Surround with" checkbox on the aliases dialog, or you did not realize that surround with was configured through aliases in the first place.  Unfortunately, it is't blatantly obvious.

To create a block comment surround with alias.

1) Go to Tools > Options > File Extension Setup...
2) Select the file extension to customize, for example, "c" for C/C++
3) Switch to the General tab, and click on "Aliases..."
4) Check the "Surround with" check box to customize surround aliases
5) Click "New...", type in the name for the comment alias
6) Fill in the following for the comment text.
Code: [Select]
/*
%\m sur_text%
*/
7) Click OK when done

Of course, a more direct way to configure block comments is to go to "Document" > "Comment Setup...", and configure your block and line comment preferences.  Then you can use "Document" > "Comment Block" or "Comment Line" to comment out a block you have selected.

Let us know what works best for you.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Selection block comment
« Reply #4 on: November 19, 2006, 03:47:34 pm »
@Dennis: I don't get a surround-with 'parens' alias working :(
I want to surround a selection (intraline) with parens and padding SPACEs: '( '<sel.text>' )'.
How can I do that ?

HS2

Mario Figueiredo

  • Community Member
  • Posts: 10
  • Hero Points: 0
Re: Selection block comment
« Reply #5 on: November 20, 2006, 02:23:14 pm »
Thanks for the answers.

It was indeed a sad case of having not looked hard enough. The Document menu has the relevant items to comment blocks of code.

However, some problems still arise. For quicker access to commenting and uncommenting, I edited the selection context menu and include comment() for line comments. I can't however seem to find the function for block comments (I solved it by calling the previously defined surround-with alias), neither a function to uncomment.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Selection block comment
« Reply #6 on: November 20, 2006, 02:52:39 pm »
In this case you should consider to use the mentioned BlockComment.e module.
Load it 'Macro->Load Module' and add the BlockComment command to your context menu / shortcut.

This command toggles between comment / uncomment the current selection or curr. line if nth. is selected.
You may easily adopt it to support more/other file extensions.

HS2

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2209
  • Hero Points: 275
Re: Selection block comment
« Reply #7 on: November 20, 2006, 02:53:42 pm »
@HS2 --
Code: [Select]
( %\m sur_text% )
@Mario -- The commands are "box" for block comments, and "comment" for line comments.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Selection block comment
« Reply #8 on: November 20, 2006, 04:17:56 pm »
This is not working: 'a < b' -> surround-with parens -> '( a <  )b'
BTW: I tried a lot with 'sur_text' and got no good/strange results and ended up writing my own macro...
It seemed to me that it's not handling intraline selections very well.

HS2

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2209
  • Hero Points: 275
Re: Selection block comment
« Reply #9 on: November 20, 2006, 04:46:30 pm »
HS2:  I just retested this in 11.0.2 and reproduced what you were seeing if I used a block selection rather than a character selection.  Surround with isn't really intended for block selections, why aren't you using a character selection?  Either way, I will look into fixing that special case.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Selection block comment
« Reply #10 on: November 20, 2006, 09:35:32 pm »
I'm not sure b/c I tried explicit select-char selections w/ same results.
Maybe it's rather related to non-inclusive selections I'm using...

HS2

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2209
  • Hero Points: 275
Re: Selection block comment
« Reply #11 on: November 21, 2006, 02:05:16 pm »
@HS2:  Here is a (potential) fix for you.  Replace this function in macros/surround.e.

Code: [Select]
static void sur_end_select(_str markid)
{
   // go to the last line of the selection
   end_select(markid);

   // end_select does not move the cursor to the end of the line
   // in a line selection
   if (_select_type(markid)=='LINE') {
      end_line();
   } else if (_select_type(markid)=='BLOCK') {
      right();
   } else if (_select_type(markid, 'I')==1) {
      right();
   }
}

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Selection block comment
« Reply #12 on: November 21, 2006, 02:19:41 pm »
@Dennis: Thanks a lot - works fine !
My parens_selection - workaround macro looks quite similar but I really prefer this generic approach.

HS2