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.52 by root, Sat Dec 26 10:50:46 2009 UTC vs.
Revision 1.54 by root, Wed Jun 6 15:06:41 2012 UTC

1#! perl 1#! perl
2
3#:META:X_RESOURCE:%.pattern-0:string:first selection pattern
2 4
3sub on_user_command { 5sub on_user_command {
4 my ($self, $cmd) = @_; 6 my ($self, $cmd) = @_;
5 7
6 $cmd eq "selection:rot13" 8 $cmd eq "selection:rot13"
17 push @{ $self->{patterns} }, qr{\G [\Q$res\E[:space:]]* ([^\Q$res\E[:space:]]+) }x; 19 push @{ $self->{patterns} }, qr{\G [\Q$res\E[:space:]]* ([^\Q$res\E[:space:]]+) }x;
18 } 20 }
19 21
20 for (my $idx = 0; defined (my $res = $self->x_resource ("selection.pattern-$idx")); $idx++) { 22 for (my $idx = 0; defined (my $res = $self->x_resource ("selection.pattern-$idx")); $idx++) {
21 $res = $self->locale_decode ($res); 23 $res = $self->locale_decode ($res);
22 utf8::encode $res;
23 push @{ $self->{patterns} }, qr/$res/; 24 push @{ $self->{patterns} }, qr/$res/;
24 } 25 }
25 26
26 $self->{enabled} = 1; 27 $self->{enabled} = 1;
27 28
91 - $line->offset_of ($self->selection_beg); 92 - $line->offset_of ($self->selection_beg);
92 93
93 my @matches; 94 my @matches;
94 95
95 if ($markofs < $line->l) { 96 if ($markofs < $line->l) {
96 # convert markofs from character to UTF-8 offset space
97 {
98 my $prefix = substr $text, 0, $markofs;
99 utf8::encode $prefix;
100 $markofs = length $prefix;
101 }
102
103 # not doing matches in unicode mode helps speed
104 # enourmously here. working in utf-8 should be
105 # equivalent due to the magic of utf-8 encoding.
106 utf8::encode $text;
107 study $text; # _really_ helps, too :) 97 study $text; # _really_ helps, too :)
108 98
109 for my $regex (@mark_patterns, @{ $self->{patterns} }) { 99 for my $regex (@mark_patterns, @{ $self->{patterns} }) {
110 while ($text =~ /$regex/g) { 100 while ($text =~ /$regex/g) {
111 if ($-[1] <= $markofs and $markofs <= $+[1]) { 101 if ($-[1] <= $markofs and $markofs <= $+[1]) {
131 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { 121 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) {
132 my ($ofs, $len) = @$_; 122 my ($ofs, $len) = @$_;
133 123
134 next if $len <= $curlen; 124 next if $len <= $curlen;
135 125
136 # convert back from UTF-8 offset space to character space
137 {
138 my $length = substr "$text ", $ofs, $len;
139 utf8::decode $length;
140 $len = length $length;
141 }
142 {
143 my $prefix = substr $text, 0, $ofs;
144 utf8::decode $prefix;
145 $ofs = length $prefix;
146 }
147
148 $self->selection_beg ($line->coord_of ($ofs)); 126 $self->selection_beg ($line->coord_of ($ofs));
149 $self->selection_end ($line->coord_of ($ofs + $len)); 127 $self->selection_end ($line->coord_of ($ofs + $len));
150 return 1; 128 return 1;
151 } 129 }
152 130

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines