2

I recently switched from gnome terminal to urxvt (and installed tabbed extensions). I am also a heavy emacs user which uses a lot of key combinations similar to urxvt (tab related stuff) like Shift-Left and Shift-Right. These key-combinations are set for selecting text in emacs.

Is there a way to map ALT-1, ALT-2, ALT-3 for tabs 1, 2, 3 ..?

Is there an extension to do that ? Can it be achieved through the ~/.Xdefaults file ?

1

1 Answer 1

0

You can do this manually by modifying the perl extension for tabs (tabbed) and changing the keys it responds to. I got it to change tabs with alt + 1 ... alt + 9 by modifying the tab_key_press method:

You can get the original tabbed script from the source distribution of urxvt in the folder rxvt-unicode-9.15/src/perl/tabbed, find the function, and replace it with the method below.

When that is done, you can save the modified file in /some/folder/tabz and run urxvt with urxvt --perl-lib /some/folder -pe tabz

I think it should be possible to configure this with with X resources (~/.Xdefaults), so perhaps I'll make a version of the script that reads from there in the future and mail it to the urxvt maintainer, but for now:

sub tab_key_press {
   my ($self, $tab, $event, $keysym, $str) = @_;
   warn "keysym: ", $keysym;

   #if ($event->{state} & urxvt::ShiftMask) {
   if ($event->{state} & urxvt::Mod1Mask) {
      if ($keysym == 0xff51 || $keysym == 0xff53) {
         my ($idx) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };

         --$idx if $keysym == 0xff51;
         ++$idx if $keysym == 0xff53;

         $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);

         return 1;
      } elsif ($keysym == 0xff54) {
         $self->new_tab;

         return 1;
      } elsif ( $keysym == 0x31 || $keysym == 0x32 || $keysym == 0x33 ||
                $keysym == 0x34 || $keysym == 0x35 || $keysym == 0x36 ||
                $keysym == 0x37 || $keysym == 0x38 || $keysym == 0x39
      ) {
         my $idx = 0;
         $idx = 0 if $keysym == 0x31;
         $idx = 1 if $keysym == 0x32;
         $idx = 2 if $keysym == 0x33;
         $idx = 3 if $keysym == 0x34;
         $idx = 4 if $keysym == 0x35;
         $idx = 5 if $keysym == 0x36;
         $idx = 6 if $keysym == 0x37;
         $idx = 7 if $keysym == 0x38;
         $idx = 8 if $keysym == 0x39;
         warn scalar @{  $self->{tabs} };
         $self->make_current ($self->{tabs}[ $idx ]) if ($idx <  (scalar @{$self->{tabs}})) ;
         return 1;
      }
   }
   elsif ($event->{state} & urxvt::ControlMask) {
      if ($keysym == 0xff51 || $keysym == 0xff53) {
         my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };
         my  $idx2  = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} };

         ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) =
            ($self->{tabs}[$idx2], $self->{tabs}[$idx1]);

         $self->make_current ($self->{tabs}[$idx2]);

         return 1;
      }
   }

   ()
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .