summaryrefslogtreecommitdiffstats
path: root/scripts/complete_at.pl
blob: 597e81e3f80e3d1cbcc6e4e83250c4a48ea6c9ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use strict;
use warnings;

our $VERSION = '0.2'; # 49f841075725906
our %IRSSI = (
    authors     => 'Nei',
    contact     => 'Nei @ anti@conference.jabber.teamidiot.de',
    url         => "http://anti.teamidiot.de/",
    name        => 'complete_at',
    description => 'Complete nicks after @ (twitter-style)',
    license     => 'ISC',
   );

# Usage
# =====
# write @ and type on the Tab key to complete nicks

{ package Irssi::Nick }

my $complete_char = '@';

sub complete_at {
    my ($cl, $win, $word, $start, $ws) = @_;
    if ($cl && !@$cl
	    && $win && $win->{active}
	    && $win->{active}->isa('Irssi::Channel')) {
	if ((my $pos = rindex $word, $complete_char) > -1) {
	    my ($pre, $post) = ((substr $word, 0, $pos), (substr $word, $pos + 1));
	    my $pre2 = length $start ? "$start $pre" : $pre;
	    my $pre3 = length $pre2 ? "$pre2$complete_char" : "";
	    Irssi::signal_emit('complete word', $cl, $win, $post, $pre3, $ws);
	    unless (@$cl) {
		push @$cl, grep { /^\Q$post/i } map { $_->{nick} } $win->{active}->nicks();
	    }
	    map { $_ = "$pre$complete_char$_" } @$cl;
	}
    }
}

Irssi::signal_add_last('complete word' => 'complete_at');