From 2096ac515f05cf524a441299d86493502b6f6397 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 28 Sep 2010 03:26:18 +0200 Subject: vim_mode: :b Ignore case. --- vim-mode/vim_mode.pl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'vim-mode') diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 5ae2467..f61ce95 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -726,12 +726,11 @@ sub cmd_ex_command { 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/) { + if ($window->{name} =~ /$buffer/i) { my $ratio = ($+[0] - $-[0]) / length($window->{name}); push @matches, { window => $window, item => undef, @@ -740,7 +739,7 @@ sub cmd_ex_command { } # Matching Window item names (= channels). foreach my $item ($window->items()) { - if ($item->{name} =~ /$regex/) { + if ($item->{name} =~ /$buffer/i) { my $length = length($item->{name}); $length-- if index($item->{name}, '#') == 0; my $ratio = ($+[0] - $-[0]) / $length; -- cgit v1.2.3 From a18dc0ebc72e2aba67506cdb5b57db3f7f5d50c0 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 28 Sep 2010 03:27:13 +0200 Subject: vim_mode: Add support for :b s/c Where s is the server (lowercase) and c is the channel (lowercase). --- vim-mode/vim_mode.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'vim-mode') diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index f61ce95..e5cf904 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -726,6 +726,15 @@ 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()) { @@ -739,6 +748,11 @@ sub cmd_ex_command { } # 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; -- cgit v1.2.3 From 5a67a6b83a96a44a350bd291dc84e15fa2e45d7f Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 28 Sep 2010 03:38:14 +0200 Subject: vim_mode: Move :b name code to own function. --- vim-mode/vim_mode.pl | 96 ++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 45 deletions(-) (limited to 'vim-mode') 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 { -- cgit v1.2.3 From 650b21755ced7d538fa4e846b6e100fd2f3c7135 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 28 Sep 2010 03:56:14 +0200 Subject: vim_mode: :b has vim_windows statusbar displaying matching channels. --- vim-mode/vim_mode.pl | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'vim-mode') diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 56982bb..c34db2d 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -62,6 +62,10 @@ # /statusbar window add vim_mode to get the status. +# And the following to let :b name display a list of matching channels + +# /statusbar window add vim_windows + # NOTE: This script is still under heavy development, and there may be bugs. # Please submit reproducible sequences to the bug-tracker at: # http://github.com/shabble/shab-irssi-scripts/issues @@ -762,7 +766,8 @@ sub _matching_windows { my $ratio = ($+[0] - $-[0]) / length($window->{name}); push @matches, { window => $window, item => undef, - ratio => $ratio }; + ratio => $ratio, + text => $window->{name} }; print ":b $window->{name}: $ratio" if DEBUG; } # Matching Window item names (= channels). @@ -778,7 +783,8 @@ sub _matching_windows { my $ratio = ($+[0] - $-[0]) / $length; push @matches, { window => $window, item => $item, - ratio => $ratio }; + ratio => $ratio, + text => $item->{name} }; print ":b $window->{name} $item->{name}: $ratio" if DEBUG; } } @@ -820,6 +826,26 @@ sub vim_mode_cb { $sb_item->default_handler($get_size_only, "{sb $mode_str}", '', 0); } +# :b window list item. +sub b_windows_cb { + my ($sb_item, $get_size_only) = @_; + + my $windows = ''; + + # A little code duplication of cmd_ex_command()! + my $arg_str = join '', @ex_buf; + if ($arg_str =~ m|b(?:uffer)?\s*(.+)$|) { + my $buffer = $1; + if ($buffer !~ /^[0-9]$/ and $buffer ne '#') { + # Display matching windows. + my $matches = _matching_windows($buffer); + $windows = join ',', map { $_->{text} } @$matches; + } + } + + $sb_item->default_handler($get_size_only, "{sb $windows}", '', 0); +} + sub got_key { my ($key) = @_; @@ -973,6 +999,8 @@ sub handle_command { _set_prompt(':' . join '', @ex_buf); } + Irssi::statusbar_items_redraw("vim_windows"); + } else { my $char = chr($key); @@ -1127,6 +1155,7 @@ sub vim_mode_init { Irssi::signal_add_first 'gui key pressed' => \&got_key; Irssi::signal_add 'setup changed' => \&setup_changed; Irssi::statusbar_item_register ('vim_mode', 0, 'vim_mode_cb'); + Irssi::statusbar_item_register ('vim_windows', 0, 'b_windows_cb'); Irssi::settings_add_str('vim_mode', 'vim_mode_cmd_seq', ''); Irssi::settings_add_bool('vim_mode', 'vim_mode_debug', 0); -- cgit v1.2.3 From 89a1e94b7f12bd29d91649dd9dd6952712701081 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 28 Sep 2010 04:20:05 +0200 Subject: vim_mode: Add special registers "* and "+ for irssi's cut buffer. --- vim-mode/vim_mode.pl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'vim-mode') diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index c34db2d..e40d15f 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -18,6 +18,8 @@ # * change/change/yank line: cc dd yy S # * Combinations like in Vi, e.g. d5fx # * window selection: :b, :b#, :b +# +# * special registers: "* "+ (contain irssi's cut-buffer) # TODO: # * History: @@ -683,6 +685,12 @@ sub cmd_movement_tilde { sub cmd_movement_register { my ($count, $pos, $char) = @_; + # + and * contain both irssi's cut-buffer + if ($char eq '+' or $char eq '*') { + $registers->{'+'} = Irssi::parse_special('$U'); + $registers->{'*'} = $registers->{'+'}; + } + $register = $char; print "Changing register to $register" if DEBUG; } -- cgit v1.2.3