summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-05-26 14:39:37 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-05-26 14:39:37 +0200
commit2e44e619a89589f79253f95d3d6428f411b842e4 (patch)
tree03b14f93d631f34c7dcf644416f18a824a1b74a2
parent2c4d11d53fc2ce6d99d520cb42b13ec06b5baf16 (diff)
downloadmum-2e44e619a89589f79253f95d3d6428f411b842e4.tar.gz
mum: Support // and ?? (search using last regex)
-rwxr-xr-xsrc/mum27
1 files 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;
}