--- rxvt-unicode/src/perl/selection 2006/01/03 19:10:54 1.5 +++ rxvt-unicode/src/perl/selection 2006/01/03 20:47:36 1.8 @@ -1,15 +1,36 @@ #! perl sub on_keyboard_command { - my ($term, $cmd) = @_; + my ($self, $cmd) = @_; $cmd eq "selection:rot13" - and $term->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $term->selection); + and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); () } -sub on_selection_event { - warn "hiya\n";#d# +my @patterns = ( + # urls + qr{ ([a-z0-9.+\-]+://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),]+) }x, +); + +sub on_sel_extend { + my ($self) = @_; + + my ($row, $col) = $self->selection_mark; + my $line = $self->line ($row); + my $offset = $line->offset_of ($row, $col); + my $text = $line->t; + + for my $regex (@patterns) { + while ($text =~ /$regex/g) { + if ($-[0] <= $offset and $offset <= $+[0]) { + $self->selection_beg ($line->coord_of ($-[0])); + $self->selection_end ($line->coord_of ($+[0])); + return 1; + } + } + } + () }