From 55e8dbfa92eb9c549dfb28c808cfb1d3b978f104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 26 May 2021 14:52:21 +0200 Subject: mum: Fix ?? bug --- src/mum | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mum b/src/mum index 77751e0..7955a71 100755 --- a/src/mum +++ b/src/mum @@ -41,7 +41,7 @@ my $d = qr{ # Define program state my $MESSAGE = 0; # selected message -my $INDEX = '-'; # loaded mbox index +my $INDEX = ''; # loaded mbox index my @MESSAGES; # loaded messages my %MARKS; # saved marks my $SEARCH; # last search regex @@ -56,7 +56,7 @@ while () { $MESSAGE = 1 if $MESSAGE < 1; $MESSAGE = @MESSAGES if $MESSAGE > @MESSAGES; - print $tty "$MESSAGE:$INDEX& "; + print $tty "$INDEX:$MESSAGE& "; # Read next command from user @@ -187,6 +187,10 @@ sub toloc { elsif (exists $ref{next}) { $ref{next} = $SEARCH if not $ref{next}; $SEARCH = $ref{next}; + if (not $ref{next}) { + warn "missing pattern\n"; + return; + } $start = $MESSAGE+1 if not $start; $loc = $start-1; @@ -203,13 +207,17 @@ sub toloc { elsif (exists $ref{prev}) { $ref{prev} = $SEARCH if not $ref{prev}; $SEARCH = $ref{prev}; + if (not $ref{prev}) { + warn "missing pattern\n"; + return; + } $start = $MESSAGE-1 if not $start; - $loc = $start-1; + $loc = $start+1; - for (@MESSAGES[0..$start-1]) { + for (reverse @MESSAGES[0..$start-1]) { $loc--; - goto found if m?$ref{prev}?; + goto found if /$ref{prev}/; } warn "pattern ?$ref{prev}? not found\n"; -- cgit v1.2.3