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.19 by root, Tue Jan 10 21:20:53 2006 UTC vs.
Revision 1.24 by root, Thu Jan 12 23:11:23 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 = (
25 # common types of "parentheses"
26 qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x,
27 qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x,
28 qr{ \{ ([^{}]+?) \} }x,
29 qr{ \[ ([^{}]+?) \] }x,
30 qr{ \( ([^()]+?) \) }x,
31
14 # urls, just a heuristic 32 # urls, just a heuristic
15 qr{( 33 qr{(
16 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ 34 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
17 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) 35 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic)
18 )}x, 36 )}x,
19
20 # common "parentheses"
21 qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x,
22 qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x,
23 qr{ \{ ([^{}]+?) \} }x,
24 qr{ \[ ([^{}]+?) \] }x,
25 37
26 # shell-like argument quoting, basically always matches 38 # shell-like argument quoting, basically always matches
27 qr{\G [\ \t|&;<>()] *( 39 qr{\G [\ \t|&;<>()] *(
28 (?: 40 (?:
29 [^\\"'\ \t|&;<>()]+ 41 [^\\"'\ \t|&;<>()]+
39 qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple 51 qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple
40 qr{^(.*)[,\-]$}, # strip off trailing , and - 52 qr{^(.*)[,\-]$}, # strip off trailing , and -
41); 53);
42 54
43sub on_sel_extend { 55sub on_sel_extend {
44 my ($self) = @_; 56 my ($self, $time) = @_;
45 57
46 my ($row, $col) = $self->selection_mark; 58 my ($row, $col) = $self->selection_mark;
47 my $line = $self->line ($row); 59 my $line = $self->line ($row);
48 my $offset = $line->offset_of ($row, $col);
49 my $text = $line->t; 60 my $text = $line->t;
61 my $markofs = $line->offset_of ($row, $col);
62 my $curlen = $line->offset_of ($self->selection_end)
63 - $line->offset_of ($self->selection_beg);
50 64
51 for my $regex (@mark_patterns) { 65 my @matches;
66
67 for my $regex (@mark_patterns, @{ $self->{patterns} }) {
52 while ($text =~ /$regex/g) { 68 while ($text =~ /$regex/g) {
53 if ($-[1] <= $offset and $offset <= $+[1]) { 69 if ($-[1] <= $markofs and $markofs <= $+[1]) {
54 my $ofs = $-[1]; 70 my $ofs = $-[1];
55 my $match = $1; 71 my $match = $1;
72
73 push @matches, [$ofs, length $match];
56 74
57 for my $regex (@simplify_patterns) { 75 for my $regex (@simplify_patterns) {
58 if ($match =~ $regex) { 76 if ($match =~ $regex) {
59 $match = $1; 77 $match = $1;
60 $ofs += $-[1]; 78 $ofs += $-[1];
61 } 79 }
62 } 80 }
63 81
64 $self->selection_beg ($line->coord_of ($ofs)); 82 push @matches, [$ofs, length $match];
65 $self->selection_end ($line->coord_of ($ofs + length $match));
66 return 1;
67 } 83 }
68 } 84 }
69 } 85 }
70 86
87 # whole line
88 push @matches, [0, ($line->end - $line->beg + 1) * $self->ncol];
89
90 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) {
91 my ($ofs, $len) = @$_;
92
93 next if $len <= $curlen;
94
95 $self->selection_beg ($line->coord_of ($ofs));
96 $self->selection_end ($line->coord_of ($ofs + $len));
97 return 1;
98 }
99
71 () 100 ()
72} 101}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines