diff options
author | Tom Feist <shabble@metavore.org> | 2011-03-04 01:23:30 +0000 |
---|---|---|
committer | Tom Feist <shabble@metavore.org> | 2011-03-04 01:23:30 +0000 |
commit | 4e35bc22e052bd4ef74b8ad2d23f2b1a6e51fc7d (patch) | |
tree | 55dc389d3aee8ef985ff93767a603cdc630e405e /vim-mode/vim_mode.pl | |
parent | Merge branch 'master' of github.com:shabble/irssi-scripts (diff) | |
download | irssi-scripts-4e35bc22e052bd4ef74b8ad2d23f2b1a6e51fc7d.tar.gz irssi-scripts-4e35bc22e052bd4ef74b8ad2d23f2b1a6e51fc7d.zip |
vim-mode/vim_mode: make :mapped commands use appropriate context when calling
irssi commands.
Diffstat (limited to 'vim-mode/vim_mode.pl')
-rw-r--r-- | vim-mode/vim_mode.pl | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index 7f4832e..551fbb6 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -2537,13 +2537,7 @@ sub handle_command_cmd { } elsif ($cmd->{type} == C_IRSSI) { print "Processing irssi-command: $map->{char} ($cmd->{char})" if DEBUG; - # TODO: fix me more better (general server/win/none context?) - my $server = Irssi::active_server; - if (defined $server) { - $server->command($cmd->{func}); - } else { - Irssi::command($cmd->{func}); - } + _command_with_context($cmd->{func}); $numeric_prefix = undef; return 1; # call _stop(); @@ -3206,3 +3200,29 @@ sub _warn { print '%_vim_mode: ', $warning, '%_'; } + +sub _command_with_context { + my ($command) = @_; + my $context; + my $window = Irssi::active_win; + if (defined $window) { + my $witem = $window->{active}; + if (defined $witem and ref($witem) eq 'Irssi::Windowitem') { + $context = $witem; + } else { + $context = $window; + } + } else { + my $server = Irssi::active_server; + if (defined $server) { + $context = $server; + } + } + if (defined $context) { + print "Command $command Using context: " . ref($context) if DEBUG; + $context->command($command); + } else { + print "Command $command has no context" if DEBUG; + Irssi::command($command); + } +} |