diff options
author | Simon Ruderich <simon@ruderich.org> | 2010-09-28 00:28:30 +0000 |
---|---|---|
committer | Simon Ruderich <simon@ruderich.org> | 2010-09-28 00:28:30 +0000 |
commit | 288da6a76b7d55684f93db3a2e49b54462f32513 (patch) | |
tree | 83c73695a1dd79b50919ed48701bba17c64e6a31 | |
parent | vim_mode: Remove G, instead use Ex-mode :b (:buffer) to switch windows. (diff) | |
download | irssi-scripts-288da6a76b7d55684f93db3a2e49b54462f32513.tar.gz irssi-scripts-288da6a76b7d55684f93db3a2e49b54462f32513.zip |
vim_mode: Implement :b# and :b window-name.
-rw-r--r-- | vim-mode/vim_mode.pl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 26f950b..46ae7cc 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -686,14 +686,53 @@ sub cmd_ex_command { } elsif ($arg_str =~ m|b(?:uffer)?\s*(.+)$|) { my $window; + my $item; my $buffer = $1; + # Go to window number. if ($buffer =~ /^[0-9]+$/) { $window = Irssi::window_find_refnum($buffer); + # Go to previous window. + } elsif ($buffer eq '#') { + Irssi::command('window last'); + # Go to best regex matching window. + } else { + my $regex = qr/\Q$buffer\E/; + + my @matches; + foreach my $window (Irssi::windows()) { + # Matching window names. + if ($window->{name} =~ /$regex/) { + my $ratio = ($+[0] - $-[0]) / length($window->{name}); + push @matches, { window => $window, + item => undef, + ratio => $ratio }; + } + # Matching Window item names (= channels). + foreach my $item ($window->items()) { + if ($item->{name} =~ /$regex/) { + my $length = length($item->{name}); + $length-- if index($item->{name}, '#') == 0; + push @matches, { window => $window, + item => $item, + ratio => ($+[0] - $-[0]) / $length }; + } + } + } + + if (scalar @matches > 0) { + @matches = sort {$b->{ratio} <=> $a->{ratio}} @matches; + + $window = $matches[0]->{window}; + $item = $matches[0]->{item}; + } } if ($window) { $window->set_active(); + if ($item) { + $item->set_active(); + } } } } |