Commenting macro

Commenting macro

36
Basic UserBasic User
36

    Mar 08, 2005#1

    Hi, haven't really used macroing for a lot as I've found it too limited to do something to my taste.

    Anyways, I'd like to have a macro that does this:

    Code: Select all

            GLOBAL $HTTP_COOKIE_VARS;
            if (isset($HTTP_COOKIE_VAR["PHPSESSID"]))
                header("Location: $page");
            else
                header("Location: $page?" . SID);
    
    run the macro and have it like this:

    Code: Select all

    /*        GLOBAL $HTTP_COOKIE_VARS;                  */
    /*        if (isset($HTTP_COOKIE_VAR["PHPSESSID"]))  */
    /*            header("Location: $page");             */
    /*        else                                       */
    /*            header("Location: $page?" . SID);      */
    
    Now, I made a macro that does this, but I don't like it, so I was wondering if someone who has more knowledge of the macroing facilities has a better idea. If possible, I'd like to have it run without having to open a new tab, but as I can't store linenumbers etc, I dunno how to.

    Here's the macro anyways (need to have code selected before running it):

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    Clipboard 9
    Copy 
    NewFile
    Paste 
    SelectAll
    Find RegExp "%*$"
    Replace All SelectText "/*   */"
    Key RIGHT ARROW
    Key RIGHT ARROW
    Key RIGHT ARROW
    ColumnModeOn
    StartSelect
    Key RIGHT ARROW
    EndSelect
    Paste 
    ColumnModeOff
    SelectAll
    StartSelect
    Copy 
    CloseFile NoSave
    Paste 
    Clipboard 0
    
    The same with the uncomment macro:

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    Clipboard 9
    Copy 
    NewFile
    Paste 
    Top
    Find RegExp "%/^* ^(*^)^*/$"
    Replace All "^1"
    TrimTrailingSpaces
    SelectAll
    Copy 
    CloseFile NoSave
    Paste 
    Clipboard 0
    

    21
    Basic UserBasic User
    21

      Mar 09, 2005#2

      Following two macros do what you I think you asked.
      Assumptions are:
      1) you have desired code highlighted
      2) highlight was done in normal mode not column mode
      3) your highlighting entire lines (put mouse left of column 1 click and drag down)

      What macro does is COPY the offending code (not cut it)
      It then takes this highlighted range and turns everyline into a constant "tag /* */"
      we then go to top of file and find the first tag
      arrow over into the center of our /* */ pair and in column mode paste our code
      last step ist to remove all occurances of the tag string and put us back into normal mode.


      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Copy
      Find RegExp "%*$"
      Replace All SelectText "/* */"
      Top
      EndSelect
      Find "/*"
      Key RIGHT ARROW
      Key RIGHT ARROW
      ColumnModeOn
      Paste
      Key HOME
      Find "/*"
      Replace All "/*"
      ColumnModeOff



      To undo what the other macro did is very easy.
      Use same assumptions as other macro and simply do two replaces
      WITHIN the selected range, one for "beginning of line /*"
      and the other for "*/ end of line"

      Find RegExp "%/^*"
      Replace All SelectText ""
      Find RegExp "^*/$"
      Replace All SelectText ""

      36
      Basic UserBasic User
      36

        Mar 10, 2005#3

        Well, that doesn't really work as I intended ^^

        1. is correct
        2. is correct
        3. is correct

        The problem with your version is:

        you can't have several sections commented, as it will always find the topmost section (which will cause it to look... funny ^^).

        The format is also not correct. it gives the result of
        /* * here comes the code/ (easy fixed tho).

        I appreciate the time taken tho =) If one could just have something like 'Top' and keep it inside the selection.

        I redid the uncomment macro as it was kinda unnecessary to have it like that. Now I use: (this however leave part of it selected on exit, dunno how to get it off without inserting a cursor move...)

        Code: Select all

        InsertMode
        ColumnModeOff
        HexOff
        UnixReOff
        Find RegExp Select "%/^* ^(*^) ^*/$"
        Replace All SelectText "^1"
        

        21
        Basic UserBasic User
        21

          Mar 11, 2005#4

          I'm pressed for time, and gotta go however the code in my 1st reply doesn't look right. There was supposed to be a "myuniquestring" in there.
          The following should resolve your concerns. I did one quick test seems to work just fine but as I said, gotto go.
          bye.


          InsertMode
          ColumnModeOff
          HexOff
          UnixReOff
          Copy
          Find RegExp "%*$"
          Replace All SelectText "myuniquestring/* */"
          Top
          EndSelect
          Find "myuniquestring/*"
          Key RIGHT ARROW
          Key RIGHT ARROW
          ColumnModeOn
          Paste
          Key HOME
          Find "myuniquestring/*"
          Replace All "/*"
          ColumnModeOff