ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection
(Generate patch)

Comparing rxvt-unicode/src/perl/selection (file contents):
Revision 1.18 by root, Mon Jan 9 01:06:55 2006 UTC vs.
Revision 1.23 by root, Thu Jan 12 12:05:28 2006 UTC

7 and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); 7 and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection);
8 8
9 () 9 ()
10} 10}
11 11
12sub on_init {
13 my ($self) = @_;
14
15 for (my $idx = 0; defined (my $res = $self->x_resource ("selection.pattern-$idx")); $idx++) {
16 no re 'eval'; # just to be sure
17 push @{ $self->{patterns} }, qr/$res/;
18 }
19
20 ()
21}
22
12# "find interetsing things"-patterns 23# "find interetsing things"-patterns
13my @mark_patterns = ( 24my @mark_patterns = (
14 # urls, just a heuristic 25 qr{([[:word:]]+)},
15 qr{(
16 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
17 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often
18 )}x,
19 26
20 # common "parentheses" 27 # common "parentheses"
21 qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x, 28 qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x,
22 qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x, 29 qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x,
23 qr{ \{ ([^{}]+?) \} }x, 30 qr{ \{ ([^{}]+?) \} }x,
24 qr{ \[ ([^{}]+?) \] }x, 31 qr{ \[ ([^{}]+?) \] }x,
32 qr{ \( ([^()]+?) \) }x,
33
34 # urls, just a heuristic
35 qr{(
36 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
37 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic)
38 )}x,
25 39
26 # shell-like argument quoting, basically always matches 40 # shell-like argument quoting, basically always matches
27 qr{\G [\ \t|&;<>()] *( 41 qr{\G [\ \t|&;<>()] *(
28 (?: 42 (?:
29 [^\\"'\ \t|&;<>()]+ 43 [^\\"'\ \t|&;<>()]+
39 qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple 53 qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple
40 qr{^(.*)[,\-]$}, # strip off trailing , and - 54 qr{^(.*)[,\-]$}, # strip off trailing , and -
41); 55);
42 56
43sub on_sel_extend { 57sub on_sel_extend {
44 my ($self) = @_; 58 my ($self, $time) = @_;
45 59
46 my ($row, $col) = $self->selection_mark; 60 my ($row, $col) = $self->selection_mark;
47 my $line = $self->line ($row); 61 my $line = $self->line ($row);
48 my $offset = $line->offset_of ($row, $col);
49 my $text = $line->t; 62 my $text = $line->t;
63 my $markofs = $line->offset_of ($row, $col);
64 my $curlen = $line->offset_of ($self->selection_end)
65 - $line->offset_of ($self->selection_beg);
50 66
51 for my $regex (@mark_patterns) { 67 my @matches;
68
69 for my $regex (@mark_patterns, @{ $self->{patterns} }) {
52 while ($text =~ /$regex/g) { 70 while ($text =~ /$regex/g) {
53 if ($-[1] <= $offset and $offset <= $+[1]) { 71 if ($-[1] <= $markofs and $markofs <= $+[1]) {
54 my $ofs = $-[1]; 72 my $ofs = $-[1];
55 my $match = $1; 73 my $match = $1;
74
75 push @matches, [$ofs, length $match];
56 76
57 for my $regex (@simplify_patterns) { 77 for my $regex (@simplify_patterns) {
58 if ($match =~ $regex) { 78 if ($match =~ $regex) {
59 $match = $1; 79 $match = $1;
60 $ofs += $-[1]; 80 $ofs += $-[1];
61 } 81 }
62 } 82 }
63 83
64 $self->selection_beg ($line->coord_of ($ofs)); 84 push @matches, [$ofs, length $match];
65 $self->selection_end ($line->coord_of ($ofs + length $match));
66 return 1;
67 } 85 }
68 } 86 }
69 } 87 }
70 88
89 # whole line
90 push @matches, [0, ($line->end - $line->beg + 1) * $self->ncol];
91
92 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) {
93 my ($ofs, $len) = @$_;
94
95 next if $len <= $curlen;
96
97 $self->selection_beg ($line->coord_of ($ofs));
98 $self->selection_end ($line->coord_of ($ofs + $len));
99 return 1;
100 }
101
71 () 102 ()
72} 103}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines