From e00687f266b9c8c8ab8567405e94cb20443fd5e2 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 11 Dec 2010 04:43:34 +0000 Subject: ido_switch: C-e toggles selection of only active windows --- ido-mode/ido_switcher.pl | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'ido-mode') diff --git a/ido-mode/ido_switcher.pl b/ido-mode/ido_switcher.pl index de7bbd9..dc7c542 100644 --- a/ido-mode/ido_switcher.pl +++ b/ido-mode/ido_switcher.pl @@ -75,6 +75,8 @@ my @search_matches = (); my $match_index = 0; my $search_str = ''; +my $active_only = 0; + # /set configurable settings my $ido_show_count; @@ -97,7 +99,7 @@ sub _print { $win->print($str, Irssi::MSGLEVEL_NEVER); } -sub _debug_print { +sub _debug_print { my $win = Irssi::active_win; my $str = join('', @_); $win->print($str, Irssi::MSGLEVEL_CLIENTCRAP); @@ -184,6 +186,7 @@ sub ido_switch_start { # refresh in case we toggled it last time. $ido_use_flex = Irssi::settings_get_bool('ido_use_flex'); + $active_only = 0; _debug_print "Win cache: " . join(", ", @window_cache) if DEBUG; @@ -209,6 +212,7 @@ sub get_all_windows { type => 'WINDOW', num => $win->{refnum}, server => $win->{active_server}, + active => $win->{data_level} > 0, }; } elsif (scalar @items) { @@ -219,6 +223,7 @@ sub get_all_windows { server => $item->{server}, num => $win->{refnum}, itemname => $item->{name}, + active => $win->{data_level} > 0, }; } } else { @@ -291,14 +296,32 @@ sub update_prompt { 'UP_INNER'); } +sub _check_active { + my ($obj) = @_; + return 1 unless $active_only; + return $obj->{active}; +} + sub update_matches { if ($search_str =~ m/^\d+$/) { - @search_matches = grep { $_->{num} == 0+$search_str } @window_cache; + @search_matches = + grep { + _check_active($_) + and $_->{num} == 0+$search_str + } @window_cache; } elsif ($ido_use_flex) { - @search_matches = grep { flex_match($search_str, $_->{name}) } @window_cache; + @search_matches = + grep { + _check_active($_) and + flex_match($search_str, $_->{name}) + } @window_cache; } else { - @search_matches = grep { $_->{name} =~ m/\Q$search_str\E/i } @window_cache; + @search_matches = + grep { + _check_active($_) + and $_->{name} =~ m/\Q$search_str\E/i + } @window_cache; } } @@ -372,6 +395,14 @@ sub handle_keypress { return; } + if ($key == 5) { # C-e + $active_only = not $active_only; + Irssi::signal_stop(); + update_matches(); + update_prompt(); + return; + } + if ($key == 6) { # C-f $ido_use_flex = not $ido_use_flex; -- cgit v1.2.3