Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
print function to remove wdiff control sequence for greple command
sub print_wdiff {
my %arg = @_;
my @matched = @{$arg{matched}};
for (my $i = $#matched; $i >= 0; $i--) {
my($s, $e) = @{$matched[$i]};
my $t = substr($_, $s, $e - $s);
if ($t =~ s/\A (?:\{\+|\[\-) (.*) (?:\+\}|\-\]) \Z/$1/sx) {
substr($_, $s, $e - $s) = $t;
$matched[$i][0] = $s - $i * 4;
$matched[$i][1] = $e - $i * 4 - 4;
} else {
die;
}
}
$_;
}
1;
__DATA__
option --wdiffcolor \
--all \
--print print_wdiff --continue \
--re '(?s)\[\-.*?\-\]' --addcolor R \
--re '(?s)\{\+.*?\+\}' --addcolor G
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment