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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines