ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection-autotransform
Revision: 1.1
Committed: Thu Jan 12 12:05:28 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 sub msg {
4 my ($self, $msg) = @_;
5
6 my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1);
7 $overlay->set (0, 0, $msg);
8 my $iow; $iow = urxvt::timer->new->start (urxvt::NOW + 2)->cb (sub {
9 undef $overlay;
10 undef $iow;
11 });
12 }
13
14 sub on_init {
15 my ($self) = @_;
16
17 unless (urxvt::safe) {
18 warn "running with elevated privileges, ignoring selection-autotransform patterns";
19 return;
20 }
21
22 for (my $idx = 0; defined (my $res = urxvt::untaint $self->x_resource ("selection-autotransform.$idx")); $idx++) {
23 my $transform = eval "sub { $res }";
24
25 if ($transform) {
26 push @{ $self->{transforms} }, $transform;
27 } else {
28 warn "$res: $@";
29 }
30 }
31
32 ()
33 }
34
35 sub on_sel_grab {
36 my ($self) = @_;
37
38 my $text = $self->selection;
39 local $_ = $text;
40
41 for my $transform (@{ $self->{transforms} }) {
42 $transform->();
43 if ($text ne $_) {
44 $self->selection ($_);
45 s/[\x00-\x1f\x80-\x9f]/ยท/g;
46 $self->msg ($self->special_encode ("auto-transformed to $_"));
47 }
48
49 last;
50 }
51
52 ()
53 }
54