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.30 by elmex, Tue Jan 17 16:53:47 2006 UTC vs.
Revision 1.35 by root, Wed Jan 25 13:24:45 2006 UTC

10} 10}
11 11
12sub on_init { 12sub on_init {
13 my ($self) = @_; 13 my ($self) = @_;
14 14
15 if (defined (my $res = $self->resource ("cutchars"))) {
16 $res = $self->locale_decode ($res);
17 push @{ $self->{patterns} }, qr{\G [\Q$res\E[:space:]]* ([^\Q$res\E[:space:]]+) }x;
18 }
19
15 for (my $idx = 0; defined (my $res = $self->x_resource ("selection.pattern-$idx")); $idx++) { 20 for (my $idx = 0; defined (my $res = $self->x_resource ("selection.pattern-$idx")); $idx++) {
16 no re 'eval'; # just to be sure
17 $res = utf8::encode $self->locale_decode ($res); 21 $res = $self->locale_decode ($res);
22 utf8::encode $res;
18 push @{ $self->{patterns} }, qr/$res/; 23 push @{ $self->{patterns} }, qr/$res/;
19 } 24 }
20 25
21 () 26 ()
22} 27}
23 28
24# "find interetsing things"-patterns 29# "find interesting things"-patterns
25my @mark_patterns = ( 30my @mark_patterns = (
26 # common types of "parentheses" 31 # common types of "parentheses"
27 qr{ (?<![^[:space:]]) ‘ ([^‘’]+) ’ (?![^[:space]]) }x, 32 qr{ (?<![^[:space:]]) ‘ ([^‘’]+) ’ (?![^[:space]]) }x,
28 qr{ (?<![^[:space:]]) ` ([^`']+) ' (?![^[:space]]) }x, 33 qr{ (?<![^[:space:]]) ` ([^`']+) ' (?![^[:space]]) }x,
29 qr{ (?<![^[:space:]]) (" [^[:space:]] [^"]* ") }x, 34 qr{ (?<![^[:space:]]) (" [^[:space:]] [^"]* ") }x,
38 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ 43 (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+
39 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic) 44 [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27()~] # exclude some trailing characters (heuristic)
40 )}x, 45 )}x,
41 46
42 # shell-like argument quoting, basically always matches 47 # shell-like argument quoting, basically always matches
43 qr{\G [\ \t|&;<>()] *( 48 qr{\G [\ \t|&;<>()]* (
44 (?: 49 (?:
45 [^\\"'\ \t|&;<>()]+ 50 [^\\"'\ \t|&;<>()]+
46 | \\. 51 | \\.
47 | " (?: [^\\"]+ | \\. )* " 52 | " (?: [^\\"]+ | \\. )* "
48 | ' [^']* ' 53 | ' [^']* '
66 my $curlen = $line->offset_of ($self->selection_end) 71 my $curlen = $line->offset_of ($self->selection_end)
67 - $line->offset_of ($self->selection_beg); 72 - $line->offset_of ($self->selection_beg);
68 73
69 my @matches; 74 my @matches;
70 75
71 # not doing matches in unicode mode helps speed 76 if ($markofs < $line->l) {
72 # enourmously here. working in utf-8 should be 77 # convert markofs form character to UTF-8 offset space
73 # equivalent due to the magic of utf-8 encoding. 78 {
79 my $prefix = substr $text, 0, $markofs;
74 utf8::encode $text; 80 utf8::encode $prefix;
75 study $text; # _really_ helps, too :) 81 $markofs = length $prefix;
82 }
76 83
77 for my $regex (@mark_patterns, @{ $self->{patterns} }) { 84 # not doing matches in unicode mode helps speed
78 while ($text =~ /$regex/g) { 85 # enourmously here. working in utf-8 should be
79 if ($-[1] <= $markofs and $markofs <= $+[1]) { 86 # equivalent due to the magic of utf-8 encoding.
80 my $ofs = $-[1]; 87 utf8::encode $text;
81 my $match = $1; 88 study $text; # _really_ helps, too :)
82 89
90 for my $regex (@mark_patterns, @{ $self->{patterns} }) {
91 while ($text =~ /$regex/g) {
92 if ($-[1] <= $markofs and $markofs <= $+[1]) {
93 my $ofs = $-[1];
94 my $match = $1;
95
83 for my $regex (@simplify_patterns) { 96 for my $regex (@simplify_patterns) {
84 if ($match =~ $regex) { 97 if ($match =~ $regex) {
85 $match = $1; 98 $match = $1;
86 $ofs += $-[1]; 99 $ofs += $-[1];
100 }
87 } 101 }
102
103 push @matches, [$ofs, length $match];
88 } 104 }
89
90 push @matches, [$ofs, length $match];
91 } 105 }
92 } 106 }
93 } 107 }
94 108
95 # whole line 109 # whole line
98 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { 112 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) {
99 my ($ofs, $len) = @$_; 113 my ($ofs, $len) = @$_;
100 114
101 next if $len <= $curlen; 115 next if $len <= $curlen;
102 116
117 # convert back from UTF-8 offset space to character space
118 {
119 my $length = substr "$text ", $ofs, $len;
120 utf8::decode $length;
121 $len = length $length;
122 }
123 {
124 my $prefix = substr $text, 0, $ofs;
125 utf8::decode $prefix;
126 $ofs = length $prefix;
127 }
128
103 $self->selection_beg ($line->coord_of ($ofs)); 129 $self->selection_beg ($line->coord_of ($ofs));
104 $self->selection_end ($line->coord_of ($ofs + $len)); 130 $self->selection_end ($line->coord_of ($ofs + $len));
105 return 1; 131 return 1;
106 } 132 }
107 133

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines