From 818ed4509a8381104e1914f00ea7898ea1cb3e59 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 22 Aug 2021 20:33:15 +0200 Subject: incdec: Try new negative last number handling in the Readline bindings This works! Also, a while ago, I changed the Perl program to not use hyphenated command line arguments and quoted variable names `${"increment-by"}` because this seemed to be causing unexpected issues. --- incdec | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'incdec') diff --git a/incdec b/incdec index 8e2c421..2a99d4f 100644 --- a/incdec +++ b/incdec @@ -64,17 +64,33 @@ sub incdec { $is_backward ||= 0; my $start_position = 0; + # my @match_ranges; my $previous_match_start = 0; - while ($line =~ /(\d+)/g) { + # my $previous_match_end = 0; + while ($line =~ /(-?\d+)/g) { if ($is_backward) { + # print "p[$point_position] -[$-[0]] +[$+[0]]\n"; + # print "p[$point_position] -[$previous_match_start] +[$previous_match_end]\n"; + # print "last match: $^N\n"; + # print $previous_match_end - 1 . " <= $point_position < $-[0]\n"; + # if ($previous_match_end - 1 <= $point_position + # && $point_position < $-[0]) { + + # TODO: document, last number handline + $start_position = $-[0]; + if ($point_position < $-[0]) { + # print "match at [$previous_match_start]"; $start_position = $previous_match_start; last; } $previous_match_start = $-[0]; + # $previous_match_end = $+[0]; + # my @range = ($-[0], $+[0]); + # push @match_ranges, \@range; } else { if ($point_position < $+[0]) { @@ -85,24 +101,20 @@ sub incdec { } } - if ($is_backward && $point_position == length $line) { - $start_position = $previous_match_start; - } - pos($line) = $start_position; - $line =~ s/\G([^\d]*)(\d+)/$1 . ($2 + $increment_by)/e; + $line =~ s/\G([^-\d]*)(-?\d+)/$1 . ($2 + $increment_by)/e; return $line; } # print "$line, ${\"increment-by\"}, ${\"point-position\"}, $backward"; - my $output = incdec($line, ${"increment-by"}, ${"point-position"}, $backward); + my $output = incdec($line, $increment_by, $point_position, $backward); print $output; ' \ -- \ -line="$READLINE_LINE" \ - -increment-by="$increment_by" \ - -point-position="$READLINE_POINT" \ + -increment_by="$increment_by" \ + -point_position="$READLINE_POINT" \ -backward="$backward" ) -- cgit v1.2.3