--- rxvt-unicode/src/perl/selection 2006/01/12 03:32:56 1.20 +++ rxvt-unicode/src/perl/selection 2006/01/12 12:05:28 1.23 @@ -9,15 +9,27 @@ () } +sub on_init { + my ($self) = @_; + + for (my $idx = 0; defined (my $res = $self->x_resource ("selection.pattern-$idx")); $idx++) { + no re 'eval'; # just to be sure + push @{ $self->{patterns} }, qr/$res/; + } + + () +} + # "find interetsing things"-patterns my @mark_patterns = ( - qr{([[:alnum:]]+)}, + qr{([[:word:]]+)}, # common "parentheses" qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x, qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x, qr{ \{ ([^{}]+?) \} }x, qr{ \[ ([^{}]+?) \] }x, + qr{ \( ([^()]+?) \) }x, # urls, just a heuristic qr{( @@ -43,7 +55,7 @@ ); sub on_sel_extend { - my ($self) = @_; + my ($self, $time) = @_; my ($row, $col) = $self->selection_mark; my $line = $self->line ($row); @@ -54,7 +66,7 @@ my @matches; - for my $regex (@mark_patterns) { + for my $regex (@mark_patterns, @{ $self->{patterns} }) { while ($text =~ /$regex/g) { if ($-[1] <= $markofs and $markofs <= $+[1]) { my $ofs = $-[1]; @@ -74,6 +86,9 @@ } } + # whole line + push @matches, [0, ($line->end - $line->beg + 1) * $self->ncol]; + for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { my ($ofs, $len) = @$_; @@ -84,9 +99,5 @@ return 1; } - # whole line - $self->selection_beg ($line->beg, 0); - $self->selection_end ($line->end, $self->ncol); - - return 1; + () }