File: tab_stop.pl

package info (click to toggle)
irssi-scripts 20100512
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,420 kB
  • ctags: 2,479
  • sloc: perl: 58,204; sh: 171; makefile: 33
file content (59 lines) | stat: -rw-r--r-- 1,424 bytes parent folder | download | duplicates (6)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
#
# Created by Stefan "tommie" Tomanek [stefan@kann-nix.org]
# to free the world from  the evil inverted I
#
# 23.02.2002
# *First release
#
# 01.03.200
# *Changed to GPL

use strict;
use vars qw($VERSION %IRSSI);
use Irssi;

$VERSION = "2002123102";
%IRSSI = (
    authors     => "Stefan 'tommie' Tomanek",
    contact     => "stefan\@pico.ruhr.de",
    name        => "tab_stop",
    description => "This script replaces the evil inverted 'I' with a configurable number of whitespaces ",
    license     => "GPLv2",
    changed     => "$VERSION",
);

sub event_server_incoming {
    my ($server, $data) = @_;
    my $newdata;
    if (has_tab($data)) {
	$newdata = replace_tabs($data);
	Irssi::signal_continue($server, $newdata);
    }
}

# FIXME Experimental!
sub sig_gui_print_text {
    my ($win, $fg, $bg, $flags, $text, $dest) = @_;
    return unless $text =~ /\t/;
    my $newtext = replace_tabs($text);
    Irssi::signal_continue($win, $fg, $bg, $flags, $newtext, $dest);
}

sub has_tab {
    my ($text) = @_;
    return $text =~ /\t/;
}

sub replace_tabs {
    my ($text) = @_;
    my $replacement = Irssi::settings_get_str('tabstop_replacement');
    $text =~ s/\t/$replacement/g;
    return($text);
}

#Irssi::signal_add('gui print text', \&sig_gui_print_text);
Irssi::signal_add_first('server incoming', \&event_server_incoming);

Irssi::settings_add_str('misc', 'tabstop_replacement', "    ");