3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-19 10:29:30 +01:00

Trying out 'replace' command in interactive-editing -- p.s., all of interactive-editing needs refactoring

This commit is contained in:
Pragmatic Software 2010-05-15 22:44:54 +00:00
parent cf77a89855
commit 629d1c7286

View File

@ -132,10 +132,72 @@ while($subcode =~ s/^\s*(and)?\s*undo//) {
}
}
{
my $prevchange = $last_code[0];
my $got_changes = 0;
while($subcode =~ m/^\s*(and)?\s*replace\s*'.*'\s*with\s*'.*'/i) {
$got_sub = 1;
$subcode =~ s/^\s*(and)?\s*replace\s*//i;
my ($from, $to);
my ($e, $r) = extract_delimited($subcode, "'");
if(defined $e) {
$from = $e;
$from =~ s/^'//;
$from =~ s/'$//;
$from = quotemeta $from;
$subcode = $r;
$subcode =~ s/\s*with\s*//i;
} else {
print "$nick: Unbalanced single quotes. Usage: !cc replace 'from' with 'to' [and replace ... with ... [and ...]]\n";
exit 0;
}
($e, $r) = extract_delimited($subcode, "'");
if(defined $e) {
$to = $e;
$to =~ s/^'//;
$to =~ s/'$//;
$subcode = $r;
} else {
print "$nick: Unbalanced single quotes. Usage: !cc replace 'from' with 'to' [and replace ... with ... [and ...]]\n";
exit 0;
}
if(defined $prevchange) {
$code = $prevchange;
} else {
print "$nick: No recent code to change.\n";
exit 0;
}
my $ret = eval {
my $got_change;
while($code =~ s/(\W)$from(\W)/$1$to$2/) {
$got_change = 1;
}
return $got_change;
};
if($@) {
print "$nick: $@\n";
exit 0;
}
if($ret) {
$got_changes = 1;
}
$prevchange = $code;
}
if($got_sub and not $got_changes) {
print "$nick: No replacements made.\n";
exit 0;
}
while($subcode =~ m/^\s*(and)?\s*s\/.*\//) {
$got_sub = 1;
$subcode =~ s/^\s*(and)?\s*s//;
@ -280,7 +342,6 @@ while($subcode =~ s/^\s*(and)?\s*undo//) {
print "$nick: No changes made.\n";
exit 0;
}
}
open FILE, "> ideone_last_code.txt";