mirror of
https://github.com/pragma-/pbot.git
synced 2025-04-14 03:48:03 +02:00
Interactive-editing replacement modifiers now keep track of relative positions
This commit is contained in:
parent
18e57bb25e
commit
e1474f3a1b
@ -136,6 +136,9 @@ while($subcode =~ s/^\s*(and)?\s*undo//) {
|
|||||||
my $prevchange = $last_code[0];
|
my $prevchange = $last_code[0];
|
||||||
my $got_changes = 0;
|
my $got_changes = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
my @replacements;
|
||||||
|
|
||||||
while($subcode =~ m/^\s*(and)?\s*replace\s*([^']+)?\s*'.*'\s*with\s*'.*'/i) {
|
while($subcode =~ m/^\s*(and)?\s*replace\s*([^']+)?\s*'.*'\s*with\s*'.*'/i) {
|
||||||
$got_sub = 1;
|
$got_sub = 1;
|
||||||
my $modifier = 'first';
|
my $modifier = 'first';
|
||||||
@ -172,13 +175,6 @@ while($subcode =~ m/^\s*(and)?\s*replace\s*([^']+)?\s*'.*'\s*with\s*'.*'/i) {
|
|||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(defined $prevchange) {
|
|
||||||
$code = $prevchange;
|
|
||||||
} else {
|
|
||||||
print "$nick: No recent code to change.\n";
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
given($modifier) {
|
given($modifier) {
|
||||||
when($_ eq 'all' ) {}
|
when($_ eq 'all' ) {}
|
||||||
when($_ eq 'last' ) {}
|
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; }
|
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 $ret = eval {
|
||||||
my $got_change;
|
my $got_change;
|
||||||
|
|
||||||
@ -243,12 +269,15 @@ while($subcode =~ m/^\s*(and)?\s*replace\s*([^']+)?\s*'.*'\s*with\s*'.*'/i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$prevchange = $code;
|
$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";
|
print "$nick: No replacements made.\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while($subcode =~ m/^\s*(and)?\s*s\/.*\//) {
|
while($subcode =~ m/^\s*(and)?\s*s\/.*\//) {
|
||||||
$got_sub = 1;
|
$got_sub = 1;
|
||||||
@ -395,6 +424,7 @@ if($got_sub and not $got_changes) {
|
|||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open FILE, "> ideone_last_code.txt";
|
open FILE, "> ideone_last_code.txt";
|
||||||
|
|
||||||
unless ($got_undo and not $got_sub) {
|
unless ($got_undo and not $got_sub) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user