Ok, here is the macro which should work as you requested:
- Code: Select all
Find RegExp "%^t"
Replace All SelectText "^t"
Find RegExp "% ^*"
Replace All SelectText "CoMmEnT"
Find RegExp "% "
Replace All SelectText " *"
Find MatchCase RegExp "%CoMmEnT"
Replace All SelectText " "
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.