|
Align C++ comment
[Back]
This macro aligns a // comment with
the one on the previous line.
process_up()
beginning_of_line()
beginLine = $cursor
find("//", "forward", "literal")
refPos = $cursor - beginLine - 2
find("//", "forward", "literal")
backward_character()
backward_character()
commPos = $cursor
beginning_of_line()
beginPos = $cursor
if( ( commPos - beginPos ) >= 20 )
{
if( ( commPos - beginPos ) < refPos )
{
find("//", "forward", "literal")
backward_character()
backward_character()
while( ( $cursor - beginPos ) != refPos )
insert_string(" ")
}
if( ( commPos - beginPos ) > refPos )
{
find("//", "forward", "literal")
backward_character()
backward_character()
flag = 0
while( ( ( $cursor - beginPos ) != refPos ) && ( flag == 0 ) )
{
previousChar = get_character( $cursor - 1 )
if ( previousChar == " " )
{
delete_previous_character()
previousChar = get_character( $cursor - 1 )
if( previousChar != " " )
{
insert_string(" ")
flag = 1
}
}
else
flag = 1
}
}
}
process_down()
beginning_of_line()
While this macro moves the // to column 40, obviously you can change
this to fit your coding style:
find("//", "forward", "literal")
backward_character()
backward_character()
commPos = $cursor
beginning_of_line()
beginPos = $cursor
if( ( commPos - beginPos ) >= 20 )
{
if( ( commPos - beginPos ) < 40 )
{
find("//", "forward", "literal")
backward_character()
backward_character()
while( ( $cursor - beginPos ) != 40 )
insert_string(" ")
}
if( ( commPos - beginPos ) > 40 )
{
find("//", "forward", "literal")
backward_character()
backward_character()
flag = 0
while( ( ( $cursor - beginPos ) != 40 ) && ( flag == 0 ) )
{
previousChar = get_character( $cursor - 1 )
if ( previousChar == " " )
{
delete_previous_character()
previousChar = get_character( $cursor - 1 )
if( previousChar != " " )
{
insert_string(" ")
flag = 1
}
}
else
flag = 1
}
}
}
process_down()
beginning_of_line()
[Back]
Released on Wed, 21 Nov 2001
by
C. Denat
|
|