diff options
author | Simon Ruderich <simon@ruderich.org> | 2010-09-28 01:38:14 +0000 |
---|---|---|
committer | Simon Ruderich <simon@ruderich.org> | 2010-09-28 01:38:14 +0000 |
commit | 5a67a6b83a96a44a350bd291dc84e15fa2e45d7f (patch) | |
tree | a1230750e25dedb332cb9df1cde1d451f7b8cc88 /vim-mode/vim_mode.pl | |
parent | vim_mode: Add support for :b s/c (diff) | |
download | irssi-scripts-5a67a6b83a96a44a350bd291dc84e15fa2e45d7f.tar.gz irssi-scripts-5a67a6b83a96a44a350bd291dc84e15fa2e45d7f.zip |
vim_mode: Move :b name code to own function.
Diffstat (limited to 'vim-mode/vim_mode.pl')
-rw-r--r-- | vim-mode/vim_mode.pl | 96 |
1 files changed, 51 insertions, 45 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index e5cf904..56982bb 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -726,51 +726,10 @@ sub cmd_ex_command { Irssi::command('window last'); # Go to best regex matching window. } else { - my $server; - - if ($buffer =~ m{^(.+)/(.+)}) { - $server = $1; - $buffer = $2; - } - - print ":b searching for channel $buffer" if DEBUG; - print ":b on server $server" if $server and DEBUG; - - my @matches; - foreach my $window (Irssi::windows()) { - # Matching window names. - if ($window->{name} =~ /$buffer/i) { - my $ratio = ($+[0] - $-[0]) / length($window->{name}); - push @matches, { window => $window, - item => undef, - ratio => $ratio }; - print ":b $window->{name}: $ratio" if DEBUG; - } - # Matching Window item names (= channels). - foreach my $item ($window->items()) { - # Wrong server. - if ($server and (!$item->{server} or - $item->{server}->{chatnet} !~ /^$server/i)) { - next; - } - if ($item->{name} =~ /$buffer/i) { - my $length = length($item->{name}); - $length-- if index($item->{name}, '#') == 0; - my $ratio = ($+[0] - $-[0]) / $length; - push @matches, { window => $window, - item => $item, - ratio => $ratio }; - print ":b $window->{name} $item->{name}: $ratio" - if DEBUG; - } - } - } - - if (scalar @matches > 0) { - @matches = sort {$b->{ratio} <=> $a->{ratio}} @matches; - - $window = $matches[0]->{window}; - $item = $matches[0]->{item}; + my $matches = _matching_windows($buffer); + if (scalar @$matches > 0) { + $window = @$matches[0]->{window}; + $item = @$matches[0]->{item}; } } @@ -783,6 +742,53 @@ sub cmd_ex_command { } } +sub _matching_windows { + my ($buffer) = @_; + + my $server; + + if ($buffer =~ m{^(.+)/(.+)}) { + $server = $1; + $buffer = $2; + } + + print ":b searching for channel $buffer" if DEBUG; + print ":b on server $server" if $server and DEBUG; + + my @matches; + foreach my $window (Irssi::windows()) { + # Matching window names. + if ($window->{name} =~ /$buffer/i) { + my $ratio = ($+[0] - $-[0]) / length($window->{name}); + push @matches, { window => $window, + item => undef, + ratio => $ratio }; + print ":b $window->{name}: $ratio" if DEBUG; + } + # Matching Window item names (= channels). + foreach my $item ($window->items()) { + # Wrong server. + if ($server and (!$item->{server} or + $item->{server}->{chatnet} !~ /^$server/i)) { + next; + } + if ($item->{name} =~ /$buffer/i) { + my $length = length($item->{name}); + $length-- if index($item->{name}, '#') == 0; + my $ratio = ($+[0] - $-[0]) / $length; + push @matches, { window => $window, + item => $item, + ratio => $ratio }; + print ":b $window->{name} $item->{name}: $ratio" if DEBUG; + } + } + } + + @matches = sort {$b->{ratio} <=> $a->{ratio}} @matches; + + return \@matches; +} + # vi mode status item. sub vim_mode_cb { |