better comment selection on xcode3

menu > script (a script icon) > edit user scripts… > comments > Un/Comment Selection

#! /usr/bin/perl -w
#
# un_commentLines.pl -  Comments or uncomments the selected lines
# Uses '# ' for Perl, Python, and shell scripts; '// ' otherwise

my $outputString = "";
my $perlCmt = "#";
my $cCmt = "//";

# get path to document
my $headerPath = <<'HEADERPATH';
%%%{PBXFilePath}%%%
HEADERPATH
chomp $headerPath;my $commentString;
if ($headerPath =~m/\.(sh|pl|py)$/) {
    $commentString = $perlCmt;
} else {
 $commentString = $cCmt;
}

my @selection = ;       # read the selection from standard input

# no chars in selection, so create an empty selection
if (!@selection) {
    push @selection, "";
};

# add or remove comment markers depending on the state of the first line of the selection
# if it is uncommented, comment all lines.  If it is commented, remove comment markers, if present
my $firstLineOfSelection = $selection[0]; #get first line
my $addingCommentsString = 1;
if ($firstLineOfSelection =~ /^\s*$commentString/) { #selection starts with comment
    $addingCommentsString = 0;
}

foreach my $line (@selection) {
    if ($addingCommentsString == 1) {
        $line =~ s/^(\s*)([^\s])/$1$commentString $2/;
        $outputString .= $line;
    } else {
        $line =~ s/^(\s*)$commentString\s?/$1/;
        $outputString .= $line;
    }
}

print "%%%{PBXSelection}%%%";
print $outputString;
print "%%%{PBXSelection}%%%";

contact: form / email / +33 6 49 52 84 01