html/complete_lastspoke.pl
1 use strict;
2 use vars qw($VERSION %IRSSI);
3
4 use Irssi;
5 $VERSION = '2.1';
6 %IRSSI = (
7 authors => 'Daenyth',
8 contact => 'Daenyth /at/ gmail /dot/ com',
9 name => 'Complete Last-Spoke',
10 description => 'When using tab completion on an empty input buffer, complete to the nick of the person who spoke most recently.',
11 license => 'GPL2',
12 );
13
14 my %list_of_speakers;
15
16 sub complete_to_last_nick {
17 my ($strings, $window, $word, $linestart, $want_space) = @_;
18 return unless ($linestart eq '' && $word eq '');
19
20 my $last_speaker = get_last_speaker($window);
21 return unless defined $last_speaker;
22 my $suffix = Irssi::settings_get_str('completion_char');
23 @$strings = $last_speaker . $suffix;
24 $$want_space = 1;
25 Irssi::signal_stop();
26 }
27
28 sub get_last_speaker {
29 my $window = shift;
30 return $list_of_speakers{$window->{active}->{name}};
31 }
32
33 sub store_last_speaker {
34 my ($server, $message, $speaker, $address, $target) = @_;
35 $list_of_speakers{$target} = $speaker;
36 }
37
38 sub store_last_actor {
39 my ($server, $args, $actor, $address, $target) = @_;
40 $list_of_speakers{$target} = $actor;
41 }
42
43 Irssi::signal_add_first( 'complete word', \&complete_to_last_nick );
44 Irssi::signal_add_last ( 'message public', \&store_last_speaker );
45 Irssi::signal_add_last ( 'ctcp action', \&store_last_actor );
46