In addition to arrows et al support more key bindings for navigating
matches in matcher:select mode, in particular:
- ‘j’, ‘k’, ‘g’ and ‘G’ to make Vi users comfortable (this is also what
  less is using),
- Ctrl+N, Ctrl+P, Ctrl+J and Ctrl+G to make Emacs users comfortable and
- Ctrl+C which is universally understood as aborting operation.

With those new key bindings it’s possible to use matcher:select mode
without leaving the alphanumeric part of one’s keyboard.
---
 src/perl/matcher | 60 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 53 insertions(+), 7 deletions(-)

diff --git a/src/perl/matcher b/src/perl/matcher
index 903499b..120ce5c 100644
--- a/src/perl/matcher
+++ b/src/perl/matcher
@@ -457,29 +457,75 @@ sub select_refresh {
    ()
 }
 
+{
+   package urxvt::ext::matcher::key;
+
+   sub new {
+      my ($pkg, $event, $keysym) = @_;
+      bless [$keysym, !!($event->{state} & urxvt::ControlMask)], $pkg
+   }
+
+   sub is_enter {
+      my ($keysym, $ctrl) = @{$_[0]};
+      $keysym == 0xff0d || $keysym == 0xff8d || ($ctrl && $keysym == 'j')
+   }
+
+   sub is_yank {
+      my ($keysym) = @{$_[0]};
+      $keysym == ord 'y'
+   }
+
+   sub is_escape {
+      my ($keysym, $ctrl) = @{$_[0]};
+      $keysym == 0xff1b || ($ctrl && ($keysym == ord 'g' || $keysym == ord 
'c'))
+   }
+
+   sub is_home {
+      my ($keysym) = @{$_[0]};
+      $keysym == 0xff50 || $keysym == ord 'g'
+   }
+
+   sub is_end {
+      my ($keysym) = @{$_[0]};
+      $keysym == 0xff57 || $keysym == ord 'G'
+   }
+
+   sub is_up {
+      my ($keysym, $ctrl) = @{$_[0]};
+      $keysym == 0xff52 || $keysym == ord 'j' || ($ctrl && $keysym == ord 'p')
+   }
+
+   sub is_down {
+      my ($keysym, $ctrl) = @{$_[0]};
+      $keysym == 0xff52 || $keysym == ord 'k' || ($ctrl && $keysym == ord 'n')
+   }
+}
+
 sub select_key_press {
    my ($self, $event, $keysym, $string) =  @_;
 
-   if ($keysym == 0xff0d || $keysym == 0xff8d) { # enter
+   my $key = new urxvt::ext::matcher::key($event, $keysym);
+
+   if ($key->is_enter) {
       if ($self->{matches}) {
          my @match = @{ $self->{matches}[$self->{id}] };
          $self->exec_async (@match[5 .. $#match]);
       }
       $self->select_leave;
-   } elsif ($keysym == 0x79) { # y
+   } elsif ($key->is_yank) {
       if ($self->{matches}) {
          $self->selection ($self->{matches}[$self->{id}][4], 1);
          $self->selection_grab (urxvt::CurrentTime, 1);
       }
       $self->select_leave;
-   } elsif ($keysym == 0xff1b) { # escape
+   } elsif ($key->is_escape) { # escape
       $self->view_start ($self->{view_start});
       $self->select_leave;
-   } elsif ($keysym == 0xff50) { # home
+   } elsif ($key->is_home) { # home
       $self->select_search (+1, $self->top_row)
-   } elsif ($keysym == 0xff57) { # end
+   } elsif ($key->is_end) { # end
       $self->select_search (-1, $self->nrow - 1)
-   } elsif ($keysym == 0xff52) { # up
+   } elsif ($key->is_up) {
       if ($self->{id} > 0) {
          $self->{id}--;
          $self->want_refresh;
@@ -488,7 +534,7 @@ sub select_key_press {
          $self->select_search (-1, $line->beg - 1)
             if $line->beg > $self->top_row;
       }
-   } elsif ($keysym == 0xff54) { # down
+   } elsif ($key->is_down) {
       if ($self->{id} < @{ $self->{matches} } - 1) {
          $self->{id}++;
          $self->want_refresh;
-- 
2.16.2


_______________________________________________
rxvt-unicode mailing list
[email protected]
http://lists.schmorp.de/mailman/listinfo/rxvt-unicode

Reply via email to