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.13 by root, Fri Jan 6 17:03:14 2006 UTC vs.
Revision 1.18 by root, Mon Jan 9 01:06:55 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 @patterns = ( 13my @mark_patterns = (
13 # urls, just a heuristic 14 # urls, just a heuristic
14 qr{( 15 qr{(
15 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ 16 (?: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 17 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often
17 )}x, 18 )}x,
18 19
19 # shell-like argument quoting 20 # common "parentheses"
21 qr{(?:^|\s) ‘ ([^‘’]+?) ’ (?:\s|\)|$)}x,
22 qr{(?:^|\s) ` ([^`']+?) ' (?:\s|\)|$)}x,
23 qr{ \{ ([^{}]+?) \} }x,
24 qr{ \[ ([^{}]+?) \] }x,
25
26 # shell-like argument quoting, basically always matches
20 qr{\G [\ \t|&;<>()] *( 27 qr{\G [\ \t|&;<>()] *(
21 (?: 28 (?:
22 [^\\"'\ \t|&;<>()]+ 29 [^\\"'\ \t|&;<>()]+
23 | \\. 30 | \\.
24 | " (?: [^\\"]+ | \\. )* " 31 | " (?: [^\\"]+ | \\. )* "
25 | ' [^']* ' 32 | ' [^']* '
26 )+ 33 )+
27 )}xs, 34 )}x,
35);
36
37# "correct obvious? crap"-patterns
38my @simplify_patterns = (
39 qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple
40 qr{^(.*)[,\-]$}, # strip off trailing , and -
28); 41);
29 42
30sub on_sel_extend { 43sub on_sel_extend {
31 my ($self) = @_; 44 my ($self) = @_;
32 45
33 my ($row, $col) = $self->selection_mark; 46 my ($row, $col) = $self->selection_mark;
34 my $line = $self->line ($row); 47 my $line = $self->line ($row);
35 my $offset = $line->offset_of ($row, $col); 48 my $offset = $line->offset_of ($row, $col);
36 my $text = $line->t; 49 my $text = $line->t;
37 50
38 for my $regex (@patterns) { 51 for my $regex (@mark_patterns) {
39 while ($text =~ /$regex/g) { 52 while ($text =~ /$regex/g) {
40 if ($-[1] <= $offset and $offset <= $+[1]) { 53 if ($-[1] <= $offset and $offset <= $+[1]) {
54 my $ofs = $-[1];
55 my $match = $1;
56
57 for my $regex (@simplify_patterns) {
58 if ($match =~ $regex) {
59 $match = $1;
60 $ofs += $-[1];
61 }
62 }
63
41 $self->selection_beg ($line->coord_of ($-[1])); 64 $self->selection_beg ($line->coord_of ($ofs));
42 $self->selection_end ($line->coord_of ($+[1])); 65 $self->selection_end ($line->coord_of ($ofs + length $match));
43 return 1; 66 return 1;
44 } 67 }
45 } 68 }
46 } 69 }
47 70

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines