mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 22:09:26 +01:00
Interactive-editing replacement modifiers now keep track of relative positions
This commit is contained in:
parent
18e57bb25e
commit
e1474f3a1b
@ -136,7 +136,10 @@ 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*'.*'\s*with\s*'.*'/i) {
|
||||
{
|
||||
my @replacements;
|
||||
|
||||
while($subcode =~ m/^\s*(and)?\s*replace\s*([^']+)?\s*'.*'\s*with\s*'.*'/i) {
|
||||
$got_sub = 1;
|
||||
my $modifier = 'first';
|
||||
|
||||
@ -172,13 +175,6 @@ while($subcode =~ m/^\s*(and)?\s*replace\s*([^']+)?\s*'.*'\s*with\s*'.*'/i) {
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if(defined $prevchange) {
|
||||
$code = $prevchange;
|
||||
} else {
|
||||
print "$nick: No recent code to change.\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
given($modifier) {
|
||||
when($_ eq 'all' ) {}
|
||||
when($_ eq 'last' ) {}
|
||||
@ -195,6 +191,36 @@ while($subcode =~ m/^\s*(and)?\s*replace\s*([^']+)?\s*'.*'\s*with\s*'.*'/i) {
|
||||
default { print "$nick: Bad replacement modifier '$modifier'; valid modifiers are 'all', 'first', 'second', ..., 'tenth', 'last'\n"; exit 0; }
|
||||
}
|
||||
|
||||
my $replacement = {};
|
||||
$replacement->{'from'} = $from;
|
||||
$replacement->{'to'} = $to;
|
||||
$replacement->{'modifier'} = $modifier;
|
||||
|
||||
push @replacements, $replacement;
|
||||
}
|
||||
|
||||
@replacements = sort { $a->{'from'} cmp $b->{'from'} or $a->{'modifier'} <=> $b->{'modifier'} } @replacements;
|
||||
|
||||
my ($previous_from, $previous_modifier);
|
||||
|
||||
foreach my $replacement (@replacements) {
|
||||
my $from = $replacement->{'from'};
|
||||
my $to = $replacement->{'to'};
|
||||
my $modifier = $replacement->{'modifier'};
|
||||
|
||||
if(defined $previous_from) {
|
||||
if($previous_from eq $from) {
|
||||
$modifier -= $previous_modifier;
|
||||
}
|
||||
}
|
||||
|
||||
if(defined $prevchange) {
|
||||
$code = $prevchange;
|
||||
} else {
|
||||
print "$nick: No recent code to change.\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $ret = eval {
|
||||
my $got_change;
|
||||
|
||||
@ -243,11 +269,14 @@ while($subcode =~ m/^\s*(and)?\s*replace\s*([^']+)?\s*'.*'\s*with\s*'.*'/i) {
|
||||
}
|
||||
|
||||
$prevchange = $code;
|
||||
}
|
||||
$previous_from = $from;
|
||||
$previous_modifier = $modifier;
|
||||
}
|
||||
|
||||
if($got_sub and not $got_changes) {
|
||||
if($got_sub and not $got_changes) {
|
||||
print "$nick: No replacements made.\n";
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
|
||||
while($subcode =~ m/^\s*(and)?\s*s\/.*\//) {
|
||||
@ -395,6 +424,7 @@ if($got_sub and not $got_changes) {
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
||||
open FILE, "> ideone_last_code.txt";
|
||||
|
||||
unless ($got_undo and not $got_sub) {
|
||||
|
Loading…
Reference in New Issue
Block a user