diff options
| author | Teddy Wing | 2021-08-22 20:33:15 +0200 |
|---|---|---|
| committer | Teddy Wing | 2021-08-22 20:33:15 +0200 |
| commit | 818ed4509a8381104e1914f00ea7898ea1cb3e59 (patch) | |
| tree | 6ac3cf9210c3c36230a24ee30028f4ae4a2c7b6b | |
| parent | ebce4b2272bcb8299d0ab4fa1524b6f4af9976c3 (diff) | |
| download | readline-incdec-818ed4509a8381104e1914f00ea7898ea1cb3e59.tar.bz2 | |
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.
| -rw-r--r-- | incdec | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -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" ) |
