macro to comment block of code

macro to comment block of code

10
Basic UserBasic User
10

    Jun 13, 2007#1

    Hello,

    I would like to have a macro that comment several lines of code like that.

    Before:

    Code: Select all

    if(...)
      ...
    endif
    ...
    After:

    Code: Select all

    //  ...
    //endif
    //if(...)
    //...
    How to do it?

    Thank you in advance for your help.

    6,686585
    Grand MasterGrand Master
    6,686585

      Jun 13, 2007#2

      No need for a macro, click on Edit - Comment Add after selecting the block. If it is greyed out, your syntax highlighting language for your current file does not have a Line Comment = entry.

      10
      Basic UserBasic User
      10

        Jun 13, 2007#3

        Ok, but I think I have to write a macro for adding a block comment; I write this:

        InsertMode
        ColumnModeOff
        HexOff
        PerlReOn
        Copy
        "/*"
        Paste
        "*/"

        But I would rather prefer to avoid to copy the selected text in the clipboard. Is there any other way to do that?
        I would also uncomment the text if no text is selected and the mouse cursor is between /* and */ with the same macro. How can I do that?

        6,686585
        Grand MasterGrand Master
        6,686585

          Jun 14, 2007#4

          Add the block comment with a template as I have described at CSS add/remove comment button greyed out.

          10
          Basic UserBasic User
          10

            Jun 14, 2007#5

            Thank you. And how to uncomment a text when the mouse cursor is situated between /* and */?

            6,686585
            Grand MasterGrand Master
            6,686585

              Oct 15, 2007#6

              Here is a macro which works only on a selection without a template and automatically detects if the selected block is already a commented block (contains /* anywhere) or not.

              It is not possible to restrict the search for /* to only start of the selected text. But you can use a regular expression search for "/*" with additional regular expression characters if you want to restrict it a little bit.

              Disadvantage of this solution: It works only for blocks up to 30,000 bytes.

              IfSel
              Find "/*"
              Replace All SelectText ""
              IfFound
              Find "*/"
              Replace All SelectText ""
              Else
              Find "^s"
              Replace "/*^s*/"
              EndIf
              EndIf

              Here is a different solution using a user clipboard and therefore practically no length limit.

              IfSel
              Find "/*"
              Replace All SelectText ""
              IfFound
              Find "*/"
              Replace All SelectText ""
              Else
              Clipboard 9
              Cut
              "/*"
              Paste
              "*/"
              ClearClipboard
              Clipboard 0
              EndIf
              EndIf

              10
              Basic UserBasic User
              10

                Oct 16, 2007#7

                Ok, I've just installed UES 6.40 and it works! I'm so lucky.