Toggle COBOL comment in selected text

Toggle COBOL comment in selected text

3
NewbieNewbie
3

    Jul 08, 2007#1

    I'm looking for a macro that will toggle a comment in COBOL code for every line of selected text.  Comments in COBOL are indicated with a star in column 7.  

    For example, if the following three lines were highlighted:

    Code: Select all

         * commented before
             not commented before
             some random text
    Upon executing the macro, the text would change to:

    Code: Select all

            commented before
          * not commented before
          * some random text
    Thanks in advance.

    6,605547
    Grand MasterGrand Master
    6,605547

      Jul 08, 2007#2

      Before I can give you the simple macro which does the job I need the information how the lines are indented: with spaces or with a tab?

      And should the inserted asterisk replace the space/tab at column 7 or should it be inserted?

      And should the existing asterisk at column 7 of comment lines replaced by a space/tab or should it only be deleted?

      I can't see with your example which rule should be used for the indentation.
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        Jul 08, 2007#3

        Mofi wrote:Before I can give you the simple macro which does the job I need the information how the lines are indented: with spaces or with a tab?
        With spaces. If it wouldn't add too much overhead, it might be nice at the beginning for all tabs to be converted to spaces, in case a tab might inadvertently have been left in there. Sometimes I work on code done by other programmers, so I can't really guarantee there won't be a tab.
        Mofi wrote:And should the inserted asterisk replace the space/tab at column 7 or should it be inserted?
        Please have it replace the space in column 7 with the asterisk, not insert. Although an insert would achieve the same result, the replace looks much cleaner.
        Mofi wrote:And should the existing asterisk at column 7 of comment lines replaced by a space/tab or should it only be deleted?
        The asterisk in column 7 should be replaced with a single space.

        Thanks again!

        6,605547
        Grand MasterGrand Master
        6,605547

          Jul 08, 2007#4

          Okay, here is the macro which should work as you requested:

          Code: Select all

          IfSel
          InsertMode
          ColumnModeOff
          HexOff
          UnixReOff
          Find RegExp "%^t"
          Replace All SelectText "^t"
          IfFound
          TabsToSpaces
          EndIf
          Find RegExp "%      ^*"
          Replace All SelectText "CoMmEnT"
          Find RegExp "%       "
          Replace All SelectText "      *"
          Find MatchCase RegExp "%CoMmEnT"
          Replace All SelectText "       "
          EndIf
          Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro before command EndIf if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

          How the macro works:

          First it checks if currently a selection exists and if not, it does nothing (security).

          Next it checks if there is a tab at start of any selected line. If this is true, all tabs in the current selection are converted to spaces using the current tab stop value(s) configured for this file. This command breaks the Undo chain. You must consider this!!!

          The rest are very simple UltraEdit style regular expressions. First all existing comment lines are temporarily marked with a special string. Then all other lines are converted to comment lines. And last the previous special marked comment lines are converted to normal code lines.
          Best regards from an UC/UE/UES for Windows user from Austria

          3
          NewbieNewbie
          3

            Jul 09, 2007#5

            Thank you for the fast response, works fine. Sometimes trailing spaces are found at the end of a line of code as well. I guess the 'trim trailing spaces' could be utilized in the same manner as the [color=#00800]TabsToSpaces[/color], but we would still have the problem of the patterns existing in a string.