From 2e44e619a89589f79253f95d3d6428f411b842e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 26 May 2021 14:39:37 +0200 Subject: mum: Support // and ?? (search using last regex) --- src/mum | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/mum b/src/mum index 07cec1d..77751e0 100755 --- a/src/mum +++ b/src/mum @@ -44,6 +44,7 @@ my $MESSAGE = 0; # selected message my $INDEX = '-'; # loaded mbox index my @MESSAGES; # loaded messages my %MARKS; # saved marks +my $SEARCH; # last search regex # Open TTY for reading and writing @@ -76,8 +77,8 @@ while () { elsif (/^(?&range) \Z $d/x) { # select last message in range my ($a, $b); - $a = toloc(0, $RANGE[0]) if @RANGE > 1; - $b = toloc($a, $RANGE[$#RANGE]) or next; + $a = toloc(0, shift @RANGE) or next if @RANGE > 1; + $b = toloc($a, shift @RANGE) or next; $MESSAGE = $b; } @@ -104,7 +105,9 @@ h: # p elsif (/^ (?&range)? p \Z $d/x) { - print Dumper(@RANGE), "\n"; + my ($a, $b); + $a = toloc(0, shift @RANGE) or next if @RANGE > 1; + $b = toloc($a, shift @RANGE) or next if @RANGE; print "p\n"; } @@ -181,24 +184,34 @@ sub toloc { $loc = scalar @MESSAGES if $ref{spec} eq '$'; } - elsif ($ref{next}) { - $start = 1 if not $start; + elsif (exists $ref{next}) { + $ref{next} = $SEARCH if not $ref{next}; + $SEARCH = $ref{next}; + + $start = $MESSAGE+1 if not $start; $loc = $start-1; + for (@MESSAGES[$start-1..$#MESSAGES]) { $loc++; goto found if /$ref{next}/; } + warn "pattern /$ref{next}/ not found\n"; return; } - elsif ($ref{prev}) { - $start = @MESSAGES if not $start; + elsif (exists $ref{prev}) { + $ref{prev} = $SEARCH if not $ref{prev}; + $SEARCH = $ref{prev}; + + $start = $MESSAGE-1 if not $start; $loc = $start-1; + for (@MESSAGES[0..$start-1]) { $loc--; goto found if m?$ref{prev}?; } + warn "pattern ?$ref{prev}? not found\n"; return; } -- cgit v1.2.3