Skip to content

Instantly share code, notes, and snippets.

@kaz-utashiro
Last active January 1, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaz-utashiro/8155175 to your computer and use it in GitHub Desktop.
Save kaz-utashiro/8155175 to your computer and use it in GitHub Desktop.
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