Comment a block of code using ' single quotes

Comment a block of code using ' single quotes

10
Basic UserBasic User
10

    Aug 03, 2007#1

    Hello,
    Will someone guide me on making a macro to comment a block of code? Given a selection of a block of n number of lines, I would like to place a single quote at the beginning of each line. And, likewise, a macro to remove the single quote from the beginning of a selection of n lines.

    Ex. Need to use macro A:
    if i = 1 then
    response.write (i)
    end if

    After using macro A:
    'if i = 1 then
    ' response.write (i)
    'end if

    Then after using macro B, I want it to revert back:
    if i = 1 then
    response.write (i)
    end if

    Thanks for any guidance or examples that might help me on this.

    206
    MasterMaster
    206

      Aug 04, 2007#2

      At its most basic:

      Comment Selection

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOn
      Find RegExp "^"
      Replace All SelectText "'"



      Uncomment Selection

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOn
      Find RegExp "^'"
      Replace All SelectText ""
      Software For Metalworking
      http://closetolerancesoftware.com

      10
      Basic UserBasic User
      10

        Aug 04, 2007#3

        That works great, thanks :)

        The only thing is that the line where the selection begins does not get commented/uncommented with the macro unless the selection began at the very beginning of a line.
        Ex:
        te[begin selection]xt text text text text text
        text text text text te[end selection]xt text

        Result: using comment macro
        text text text text text text
        'text text text text text text

        However Ex:
        [begin selection]text text text text text text
        text text text text[end selection] text text


        Result: using comment macro (desired result)
        'text text text text text text
        'text text text text text text

        And, for uncommenting, all of the 's need to be included in the selection.
        Ex.
        't[begin selection]ext text text text text text
        '[end selection]text text text text text text

        Result: using uncomment macro
        'text text text text text text
        text text text text text text

        Ex. (similar)
        [begin selection]'text text text text text text
        [end selection]'text text text text text text

        Result: using uncomment macro
        text text text text text text
        'text text text text text text

        Ex. (showing what's required for desired result)
        [begin selection]'text text text text text text
        '[end selection]text text text text text text

        Result: using uncomment macro
        text text text text text text
        text text text text text text

        Thanks again, works great if selecting appropriately.

        6,675585
        Grand MasterGrand Master
        6,675585

          Aug 04, 2007#4

          Have you a syntax highlighting definition for your file?

          Why? Because if you have a syntax highlighting definition for your file and it contains at the language definition line Noquote Line Comment = ' which means your language does not have strings or Line Comment = ' String Chars = " which means your language uses only double quotes for strings, then you can use Edit - Comment Add and Edit - Comment Remove.

          That would also insert/remove the single quote of the selected block even when the block selection does not start at the beginning of a line.

          By the way: The first macro simply searches in the selected area for the start of a line and inserts a single quote. The second macro searches in the selected area for a single quote at start of a line and deletes it. So it is not really surprising that it works only perfect for selected areas with only full lines selected. The macros use the Unix regular expression engine. You should know this for future usage of regular expression finds and replaces.
          Best regards from an UC/UE/UES for Windows user from Austria

          10
          Basic UserBasic User
          10

            Re: Comment a block of code using ' single quotes

            Aug 12, 2007#5

            Thanks a lot to you both. I didn't know there was a line comment tool already built-in. I mapped the line tool insert/delete to ctrl+ins and ctrl+del, which is great :)

            The other thing I have came into is that I need a quick way to comment and uncomment html and css. I know UE can handle syntax highlighting very well, so I'm wondering can it also do the comment adding and deleting based on the language that it realizes I am coding in? I would really like to use ctrl+ins and ctrl+del to insert and remove comments no matter which language I am in. I saw the example of a file extension check, but I don't think that would work since, for example in an asp page, I can do multiple languages in the same file.
            html: viewtopic.php?f=9&t=4358
            css: viewtopic.php?f=9&t=4344

            Thanks again.

            6,675585
            Grand MasterGrand Master
            6,675585

              Re: Comment a block of code using ' single quotes

              Aug 12, 2007#6

              As described in the 2 topics you linked to, Comment Add and Comment Remove works only with line comments. But HTML and CSS don't have line comments. So what you like is not possible.

              You must write macros for those languages which do not have a line comment. You can combine all macros for "Insert Block Cmt" and all macros for "Remove Block Cmt" by using the IfExtIs command. But you will always need 4 keys - 2 for "Line Comment Add/Remove" (built-in) and 2 for "Insert/Remove Block Cmt" macros. For multi-language files like ASP you must take care where you press which hotkey.
              Best regards from an UC/UE/UES for Windows user from Austria