diff options
Diffstat (limited to 'incdec.pm')
| -rw-r--r-- | incdec.pm | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -28,7 +28,9 @@ sub incdec { $is_backward ||= 0; my $start_position = 0; + # my $previous_match_start = $point_position; my $previous_match_start = 0; + my $i = 0; while ($line =~ /(-?\d+)/g) { if ($is_backward) { # Set start position to the current match start. This gives us the @@ -36,6 +38,12 @@ sub incdec { # line. $start_position = $-[0]; + # Keep the start position of the first number if point is before + # the first number. + if ($i == 0 && $point_position < $-[0]) { + last; + } + # If point is not at the end, set start position to the number # closest to the point position. if ($point_position < $-[0]) { @@ -45,6 +53,7 @@ sub incdec { } $previous_match_start = $-[0]; + $i++; } else { if ($point_position < $+[0]) { @@ -56,13 +65,13 @@ sub incdec { } # Using `\G` when `pos` is 0 seems to cause occasional missed substitutions. - if ($start_position > 0) { + # if ($start_position > 0) { pos($line) = $start_position; $line =~ s/\G(-?\d+)/$1 + $increment_by/e; - } - else { - $line =~ s/(-?\d+)/$1 + $increment_by/e; - } + # } + # else { + # $line =~ s/(-?\d+)/$1 + $increment_by/e; + # } return ($line, $start_position); } |
