From 61201d51e788b9dce5cebc612814774f8af86cc0 Mon Sep 17 00:00:00 2001
From: Tom Feist <shabble@metavore.org>
Date: Mon, 27 Sep 2010 20:39:55 +0100
Subject: made commit_line use the most appropriate context (window item,
 window or server) to execute commands, falling back to Irssi::command only if
 none of them are available.

---
 vim-mode/vim_mode.pl | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl
index 58f402b..a8e1cbb 100644
--- a/vim-mode/vim_mode.pl
+++ b/vim-mode/vim_mode.pl
@@ -1100,13 +1100,36 @@ sub _commit_line {
 
     return unless length $line; # ignore empty lines
 
+    my $server = Irssi::active_server();
+    my $win = Irssi::active_win();
+    my $witem = ref $win ? $win->{active} : undef;
+
+    my $context;
+    if (defined $witem) {
+        $context = $witem;
+    } elsif (defined $win) {
+        $context = $win;
+    } elsif (defined $server) {
+        $context = $server;
+    } else {
+        $context = undef;
+    }
+
     if ($line =~ /^[\Q$cmdchars\E]/) {
         print "Committing line as command" if DEBUG;
-        Irssi::command($line);
+        if (defined $context) {
+            $context->command($line);
+        } else {
+            Irssi::command($line);
+        }
 
     } else {
         print "Committing line as text" if DEBUG;
-        Irssi::command("/say $line");
+        if (defined $context) {
+            $context->command("/say $line");
+        } else {
+            Irssi::command("/say $line");
+        }
     }
 }
 
-- 
cgit v1.2.3