comment and uncomment blocks of text

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
bumbo

comment and uncomment blocks of text

Post by bumbo »

Hi there:

I want or shall I say I need a macro that puts "/*" (without the quotes) in front of a line of text AND a marco that removes "/*" (without the quotes) when line(s) of text are selected. This macro request is very similar to the one that is called "Comment" available on the marcos page but instead of the "#", I want to comment with "/*"

thanx

bumbo

bumbo64@hotmail.com
Xenos

Re: comment and uncomment blocks of text

Post by Xenos »

This is pretty trival to do. I've done it for Ada, C++, and the C/C++ preprocessor (#if 0 ... #endif). What you need to do it selected some text, and record the steps you take with the keyboard to put the comment construct around the code. Do this:
1) select some lines of text
2) start macro recording
3) use ctrl-x to cut the text
4) type /* (add a carriage return for taste)
5) paste the text using ctrl-v
6) type */ (and again, a carriage return)
7) stop the recording and save the macro.

Now anytime you selected some text and execute the macro, it will surround the selected lines with /* and */

Do something similar to reverse the action.

Beware of nested comments doing this, though! Line comments like Ada's and C++'s are better (and easier to make a macro for) for this type of thing.
luke airig

Re: comment and uncomment blocks of text

Post by luke airig »

1. select some lines of text to comment
2. bring up 'replace' dialog box by hitting f8 key
3. select 'Regular expression' on 'replace' dialog box
4. select 'Selected text' on 'replace' dialog box
5. enter '^' (without the quotes) in 'Find what:' drop down list box
6. enter '/*' (without the quotes) in 'Replace with:' drop down list box
7. start recording macro
8. click 'Replace All' button on 'replace' dialog box
9. stop recording macro
10. save it as slash_splat_comment.tpm

1. select some lines of text that are commented with '/*'
2. bring up 'replace' dialog box by hitting f8 key
3. select 'Regular expression' on 'replace' dialog box
4. select 'Selected text' on 'replace' dialog box
5. enter '^/\*' (without the quotes) in 'Find what:' drop down list box
6. enter NOTHING in 'Replace with:' drop down list box (THIS IS CRITICAL)
7. start recording macro
8. click 'Replace All' button on 'replace' dialog box
9. stop recording macro
10. save it as slash_splat_uncomment.tpm

TEST THEM BOTH THOROUGHLY and take note that there appears to be a bug in some versions of Textpad: sometimes macro behavior is unpredictable if executed when the 'Find' dialog box is visible. Verify that for yourself as well.
Since I documented all of this for you, it would be nice if you reported the bug to
Textpad.

Good luck
Post Reply