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.51 by root, Sat Dec 26 09:42:16 2009 UTC vs.
Revision 1.53 by sf-exg, Sun Mar 13 17:07:36 2011 UTC

17 push @{ $self->{patterns} }, qr{\G [\Q$res\E[:space:]]* ([^\Q$res\E[:space:]]+) }x; 17 push @{ $self->{patterns} }, qr{\G [\Q$res\E[:space:]]* ([^\Q$res\E[:space:]]+) }x;
18 } 18 }
19 19
20 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++) {
21 $res = $self->locale_decode ($res); 21 $res = $self->locale_decode ($res);
22 utf8::encode $res;
23 push @{ $self->{patterns} }, qr/$res/; 22 push @{ $self->{patterns} }, qr/$res/;
24 } 23 }
25 24
26 $self->{enabled} = 1; 25 $self->{enabled} = 1;
27 26
39 38
40 # common types of "parentheses" 39 # common types of "parentheses"
41 qr{ (?<![^[:space:]]) [`'] ([^`']+) [`'] (?![^[:space:]]) }x, 40 qr{ (?<![^[:space:]]) [`'] ([^`']+) [`'] (?![^[:space:]]) }x,
42 qr{ (?<![^[:space:]]) ‘ ([^‘’]+) ’ (?![^[:space:]]) }x, 41 qr{ (?<![^[:space:]]) ‘ ([^‘’]+) ’ (?![^[:space:]]) }x,
43 qr{ (?<![^[:space:]]) “ ([^“”]+) ” (?![^[:space:]]) }x, 42 qr{ (?<![^[:space:]]) “ ([^“”]+) ” (?![^[:space:]]) }x,
44 qr{ (?<![^[:space:]]) “ ([^“”]+) ” (?![^[:space:]]) }x,
45 43
46 qr{ (?<![^[:space:]]) (' [^[:space:]] [^']* ') }x, 44 qr{ (?<![^[:space:]]) (' [^[:space:]] [^']* ') }x,
47 qr{ (' [^']* [^[:space:]] ') (?![^[:space:]]) }x, 45 qr{ (' [^']* [^[:space:]] ') (?![^[:space:]]) }x,
46 qr{ (?<![^[:space:]]) (` [^[:space:]] [^']* ') }x,
47 qr{ (` [^']* [^[:space:]] ') (?![^[:space:]]) }x,
48 qr{ (?<![^[:space:]]) (" [^[:space:]] [^"]* ") }x, 48 qr{ (?<![^[:space:]]) (" [^[:space:]] [^"]* ") }x,
49 qr{ (" [^"]* [^[:space:]] ") (?![^[:space:]]) }x, 49 qr{ (" [^"]* [^[:space:]] ") (?![^[:space:]]) }x,
50 50
51 qr{ \{ ([^\{\}]+) \} }x, 51 qr{ \{ ([^\{\}]+) \} }x,
52 qr{ \( ([^\(\)]+) \) }x, 52 qr{ \( ([^\(\)]+) \) }x,
90 - $line->offset_of ($self->selection_beg); 90 - $line->offset_of ($self->selection_beg);
91 91
92 my @matches; 92 my @matches;
93 93
94 if ($markofs < $line->l) { 94 if ($markofs < $line->l) {
95 # convert markofs from character to UTF-8 offset space
96 {
97 my $prefix = substr $text, 0, $markofs;
98 utf8::encode $prefix;
99 $markofs = length $prefix;
100 }
101
102 # not doing matches in unicode mode helps speed
103 # enourmously here. working in utf-8 should be
104 # equivalent due to the magic of utf-8 encoding.
105 utf8::encode $text;
106 study $text; # _really_ helps, too :) 95 study $text; # _really_ helps, too :)
107 96
108 for my $regex (@mark_patterns, @{ $self->{patterns} }) { 97 for my $regex (@mark_patterns, @{ $self->{patterns} }) {
109 while ($text =~ /$regex/g) { 98 while ($text =~ /$regex/g) {
110 if ($-[1] <= $markofs and $markofs <= $+[1]) { 99 if ($-[1] <= $markofs and $markofs <= $+[1]) {
130 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { 119 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) {
131 my ($ofs, $len) = @$_; 120 my ($ofs, $len) = @$_;
132 121
133 next if $len <= $curlen; 122 next if $len <= $curlen;
134 123
135 # convert back from UTF-8 offset space to character space
136 {
137 my $length = substr "$text ", $ofs, $len;
138 utf8::decode $length;
139 $len = length $length;
140 }
141 {
142 my $prefix = substr $text, 0, $ofs;
143 utf8::decode $prefix;
144 $ofs = length $prefix;
145 }
146
147 $self->selection_beg ($line->coord_of ($ofs)); 124 $self->selection_beg ($line->coord_of ($ofs));
148 $self->selection_end ($line->coord_of ($ofs + $len)); 125 $self->selection_end ($line->coord_of ($ofs + $len));
149 return 1; 126 return 1;
150 } 127 }
151 128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines