Multiple styles of commenting?

Syntax highlighting, code folding, brace matching, code indenting, and function list

Multiple styles of commenting?

Postby snoop » Wed Mar 16, 2005 4:24 pm

Is there a way to specify multiple styles of commenting?

For example:

Comment lines starting with two dashes are one color,
Comment lines starting with two dashes and a pipe are another color.

I tried playing around with the wordfile and looking in the help, but could not come up with an answer.

Thanks in advance for any help
User avatar
snoop
Newbie
 
Posts: 2
Joined: Wed Mar 16, 2005 12:00 am

Re: Multiple styles of commenting?

Postby Mofi » Thu Mar 17, 2005 2:52 am

Yes, it is possible in general with block and alternative block comments. If block comment off is not specified, the block comments act as additional line comments.

But in your special case, this could be a problem, because comment 1 is also part of begin of comment 2. So it depends on the internal compare order of UltraEdit, if two dashes and pipe or only two dashes is found first. You will have to play with it to find out which comment definition has to be defined with two dashes only, so both comments are highlighted really as different comments.

So try first
Line Comment = -- Block Comment On Alt = --|
and if it doesn't work try
Line Comment = --| Block Comment On Alt = --

Post the result of your test, because I'm also interested in the order which is necessary to get this to work.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Multiple styles of commenting?

Postby snoop » Tue Mar 29, 2005 10:29 am

Thanks

This is what works for multiple styles of commenting in this case.

Line Comment = --| Block Comment On Alt = --
User avatar
snoop
Newbie
 
Posts: 2
Joined: Wed Mar 16, 2005 12:00 am

Re: Multiple styles of commenting?

Postby rmayer » Tue Jan 23, 2007 12:22 pm

Hi... excuse me for dragging up an old thread... consequence of using search before blindly posting questions ;-)

But in fact, this thread is exactly the question I had too and has to a large part already helped me.

In my case its: Line Comment = --^ Block Comment On Alt = --

But I'm still stuck with a small problem... I'd prefer -- to be my primary comment style. Or, in other words, when I select a block of code and choose "Comment Add" from the context menu, I want -- to be used and not --^

So is there a way to use "alternative" comments for "Comment Add" or some other way to actually define my normal/alt comments the reverse way around (to the above example) ?

TIA,
Rich
User avatar
rmayer
Newbie
 
Posts: 3
Joined: Tue Jan 23, 2007 12:00 am

Re: Multiple styles of commenting?

Postby mrainey56 » Tue Jan 23, 2007 12:44 pm

A macro to insert your choice of characters at the beginning of each selected line. Assign to a keystroke for ease of use.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Find RegExp "%"
Replace All SelectText "-- "
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Multiple styles of commenting?

Postby Mofi » Tue Jan 23, 2007 1:06 pm

If you do not always have a space after the 2 dashes the macro is the only solution. If you always have a space after the 2 dashes, you can use following:

Line Comment Num = 3--  Block Comment On Alt = --^

Note: There are 2 spaces between 3-- and Block Comment.

UltraEdit uses always the first line comment specification for the commands Comment Add and Comment Remove.

By the way: Thanks to use the old thread with the same topic instead of creating a new one. Very well done!
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Multiple styles of commenting?

Postby rmayer » Tue Jan 23, 2007 2:10 pm

Great stuff, thanks to both of you - used a combination of both suggestions to meet 99% of my needs.

Mofi's suggestion works most of the time, since there 'usually' a space following the --. Exceptions are occasional use of "-----------", for which I simply use mrainy's macro, searching instead for "%--" (resulting in "-- --------", which is fine)

The other exception, which I'm stuck with is where I very occasionally insert -- to separate and 'deactivate' the rest of a line of code and prefer not to have a space. eg...
Code: Select all
val = a & b --& c


I thought of a macro to colour some selected text (as per comments), then insert -- but couldn't find a macro command to set colour? And ultimately, life's just too short to be fussing about something this trivial!

Thanks again for the help!
User avatar
rmayer
Newbie
 
Posts: 3
Joined: Tue Jan 23, 2007 12:00 am

Re: Multiple styles of commenting?

Postby Mofi » Tue Jan 23, 2007 4:34 pm

Use following macro to insert a space after -- and the follwing character if the following character is not already a space, a ^ or a DOS line termination in current selection only or the whole file from current position to end of the file.

InsertMode
ColumnModeOff
HexOff
UnixReOff
IfSel
Find RegExp "--^([~ ^^^p]^)"
Replace All SelectText "-- ^1"
Else
Find RegExp "--^([~ ^^^p]^)"
Replace All "-- ^1"
EndIf
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Multiple styles of commenting?

Postby rmayer » Tue Jan 23, 2007 5:02 pm

Great stuff! Danke Mofi!

I was just too lazy to crank my rusty RegEx braincells back into action :-)
User avatar
rmayer
Newbie
 
Posts: 3
Joined: Tue Jan 23, 2007 12:00 am


Return to Syntax Highlighting