diff options
| author | Teddy Wing | 2021-08-18 20:24:57 +0200 |
|---|---|---|
| committer | Teddy Wing | 2021-08-18 20:24:57 +0200 |
| commit | 7b6610832b2a4244b048e0565ef2d299495012c3 (patch) | |
| tree | 0c70fd0a2e61d738e7820e609d9b99fbcfc9d1b6 | |
| parent | 990ca11c40881d6c4c407007b045d66b61d979d9 (diff) | |
| download | readline-incdec-7b6610832b2a4244b048e0565ef2d299495012c3.tar.bz2 | |
incdec: Work out positions for new match algorithm
This updated loop gets the start position of the appropriate number
nearest to point. It currently only works left to right, but seems like
it should be easy enough to extend to be right to left.
| -rw-r--r-- | incdec.pm | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -46,7 +46,7 @@ sub incdec { my @matches = $line =~ /(\d+)/g; print "[[@matches]]"; # TODO: @- and @+ hold a list of captured groups. You need to loop through matches to get positions for each match with $-+[0]. It doesn't give you a list of positions of all matches. - print "-[[@-]]-.+[[@+]]+"; + # print "-[[@-]]-.+[[@+]]+"; # for (my $i = 0; $i < scalar @+ - 1; $i++) { # print "..$-[$i]:$+[$i]..$point_position.."; # if ($point_position < $+[$i + 1]) { @@ -67,15 +67,21 @@ sub incdec { # } my $i = 0; + my $start_position = 0; while ($line =~ /(\d+)/g) { my $pos = pos $line; - print "..+[@+]..perlpos[:$pos]..pos[$point_position].."; - if ($point_position < $+) { - print "x[$matches[$i]]x"; + print "\n-[$-[0]]-+[$+[0]]+\n"; + # print "..+[@+]..perlpos[:$pos]..pos[$point_position].."; + if ($point_position < $+[0]) { + print "//[$matches[$i]]//"; + $start_position = $-[0]; + + last; } $i++; } + print "\npos[$start_position]\n"; # Final match, final match before point |
