Introduce ‘matcher.matchlist-keys’ resource to the matcher pluging
which configures the set of hotkeys used.

It is often easier to press keys on a home row rather so users may be
inclined to configure the shortcuts for ergonomics, however another
aspect is that the default does not work on keyboard layout when digits
are on shifted positions (most notably classic Dvorak or Programmer
Dvorak layouts) since the overlay closes as soon as shift is pressed.
---
 src/perl/matcher | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/perl/matcher b/src/perl/matcher
index 17cb1a6..c738669 100644
--- a/src/perl/matcher
+++ b/src/perl/matcher
@@ -9,6 +9,7 @@
 #:META:RESOURCE:%.pattern.:string:extra pattern to match
 #:META:RESOURCE:%.launcher.:string:custom launcher for pattern
 #:META:RESOURCE:%.rend.:string:custom rendition for pattern
+#:META:RESOURCE:%.matchlist-keys.:string:custom hotkeys on matchlist
 
 =head1 NAME
 
@@ -32,7 +33,9 @@ The launcher can also be overridden on a per-pattern basis.
 
 It is possible to activate the most recently seen match or a list of matches
 from the keyboard.  Simply bind a keysym to "matcher:last" or
-"matcher:list" as seen in the example below.
+"matcher:list" as seen in the example below.  When displaying the list
+digits from 0 to 9 (or keys specified by C<matcher.matchlist-keys> can
+be used to jump to particular URL).
 
 The C<matcher:select> action enables a mode in which it is possible to
 iterate over the matches using the keyboard and either activate them
@@ -106,7 +109,7 @@ sub matchlist_key_press {
    delete $self->{overlay};
    $self->disable ("key_press");
 
-   my $i = ($keysym == 96 ? 0 : $keysym - 48);
+   my $i = index $self->{matchlist_keys}, $self->locale_decode($octets);
    if ($i >= 0 && $i < @{ $self->{matches} }) {
       my @exec = @{ $self->{matches}[$i] };
       $self->exec_async (@exec[5 .. $#exec]);
@@ -150,12 +153,16 @@ sub on_action {
 sub matchlist {
    my ($self) = @_;
 
+   my $keys = $self->{matchlist_keys};
+   my $max = length $keys;
+   $max = $self->nrow - 2 if $max > $self->nrow - 2;
+
    my $row = $self->nrow - 1;
    my @matches = ();
    my $width = 0;
 
    my $text = '';
-   while ($row >= 0 && @matches < 10) {
+   while ($row >= 0 && @matches < $max) {
       my $line = $self->line ($row);
       my @m = $self->find_matches ($row);
 
@@ -163,11 +170,11 @@ sub matchlist {
          next if $_->[4] eq $text;
 
          $text = $_->[4];
-         my $w = $self->strwidth (scalar(@matches) . '-' . $text);
+         my $w = $self->strwidth (substr($keys, scalar(@matches), 1) . '-' . 
$text);
          $width = $w if $w > $width;
 
          push @matches, $_;
-         last if @matches == 10;
+         last if @matches == $max;
       }
 
       $row = $line->beg - 1;
@@ -180,9 +187,7 @@ sub matchlist {
    $self->{overlay} = $self->overlay (0, 0, $width, scalar (@matches), 
urxvt::OVERLAY_RSTYLE, 2);
    my $i = 0;
    for my $match (@matches) {
-      my $text = $match->[4];
-
-      $self->{overlay}->set (0, $i, "$i-$text");
+      $self->{overlay}->set (0, $i, substr($keys, $i, 1) . '-' . $match->[4]);
       $i++;
    }
 
@@ -262,6 +267,8 @@ sub on_start {
    }
    $self->{matchers} = \@matchers;
 
+   $self->{matchlist_keys} = $self->my_resource ("matchlist-keys") // 
"0123456789";
+
    ()
 }
 
-- 
2.16.2


_______________________________________________
rxvt-unicode mailing list
rxvt-unicode@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/rxvt-unicode

Reply via email to