--- rxvt-unicode/src/perl/selection 2006/01/03 19:42:53 1.7 +++ rxvt-unicode/src/perl/selection 2006/01/04 20:43:38 1.11 @@ -9,8 +9,41 @@ () } +my @patterns = ( + # urls, just a heuristic + qr{( + (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),]+ + [^.] # do not include a trailing dot, its wrong too often + )}x, + + # shell-like argument quoting + qr{\G [\ \t|&;<>()] *( + (?: + [^\\"'\ \t|&;<>()]+ + | \\. + | " ([^\\"]+ | \\. )* " + | ' [^']* ' + )+ + )}xs, +); + sub on_sel_extend { my ($self) = @_; - warn $self->selection; + + 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 ($-[1] <= $offset and $offset <= $+[1]) { + $self->selection_beg ($line->coord_of ($-[1])); + $self->selection_end ($line->coord_of ($+[1])); + return 1; + } + } + } + () }