diff options
| author | Teddy Wing | 2021-08-18 00:52:51 +0200 |
|---|---|---|
| committer | Teddy Wing | 2021-08-18 00:52:51 +0200 |
| commit | ea7e5214410ddb0ed53ccc27aed838a9c846e922 (patch) | |
| tree | ca538dce61e2aa81654c346caf751d57b08f9b72 /incdec.pm | |
| parent | c19b7066b9bd0f5849b0531ed829cdef9970fb1c (diff) | |
| download | readline-incdec-ea7e5214410ddb0ed53ccc27aed838a9c846e922.tar.bz2 | |
incdec: Ideas for a loop based on match position
Looking into a different algorithm for incrementing matches that's
easier to use in both forward and backward contexts.
Got a few ideas to get a match nearest to the cursor position. We could
then take that value and increment it, and replace the original
substring with the new incremented value.
Diffstat (limited to 'incdec.pm')
| -rw-r--r-- | incdec.pm | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -45,17 +45,35 @@ sub incdec { $point_position = $original_point_position; my @matches = $line =~ /(\d+)/g; print "[[@matches]]"; + print "-[[@-]]-.+[[@+]]+"; # for (my $i = 0; $i < scalar @+ - 1; $i++) { # print "..$-[$i]:$+[$i]..$point_position.."; # if ($point_position < $+[$i + 1]) { # print "x[$matches[$i]]x"; # } # } - for (my $i = 0; $i < scalar @- - 1; $i++) { - print "..$-[$i + 1]:$+[$i]..$point_position.."; - if ($point_position > $+[$i] && $point_position <= $-[$i + 1]) { + # for (my $i = 0; $i < scalar @- - 1; $i++) { + # print "..$-[$i + 1]:$+[$i]..$point_position.."; + # if ($point_position > $+[$i] && $point_position <= $-[$i + 1]) { + # print "x[$matches[$i]]x"; + # } + # } + # for (my $i = scalar @+ - 1; $i > 0; $i--) { + # print "..i[$i]..+[$+[$i]]..pos[$point_position].."; + # if ($point_position < $+[$i]) { + # print "x[$matches[$i - 1]]x"; + # } + # } + + my $i = 0; + while ($line =~ /(\d+)/g) { + my $pos = pos $line; + print "..+[@+]..perlpos[:$pos]..pos[$point_position].."; + if ($point_position < $+) { print "x[$matches[$i]]x"; } + + $i++; } # Final match, final match before point |
