ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/matcher
(Generate patch)

Comparing rxvt-unicode/src/perl/matcher (file contents):
Revision 1.21 by sf-exg, Thu Jun 12 12:13:52 2014 UTC vs.
Revision 1.25 by sf-exg, Fri Jun 13 21:49:19 2014 UTC

111 111
112 @{ $self->{matches} } = (); 112 @{ $self->{matches} } = ();
113 my $row = $self->nrow - 1; 113 my $row = $self->nrow - 1;
114 while ($row >= 0 && @{ $self->{matches} } < 10) { 114 while ($row >= 0 && @{ $self->{matches} } < 10) {
115 my $line = $self->line ($row); 115 my $line = $self->line ($row);
116 my @matches = $self->find_matches ($row, 0); 116 my @matches = $self->find_matches ($row);
117 117
118 for (sort { $b->[0] <=> $a->[0] } @matches) { 118 for (sort { $b->[0] <=> $a->[0] } @matches) {
119 shift @$_; 119 shift @$_;
120 push @{ $self->{matches} }, $_; 120 push @{ $self->{matches} }, $_;
121 last if @{ $self->{matches} } == 10; 121 last if @{ $self->{matches} } == 10;
259 259
260sub find_matches { 260sub find_matches {
261 my ($self, $row, $col) = @_; 261 my ($self, $row, $col) = @_;
262 my $line = $self->line ($row); 262 my $line = $self->line ($row);
263 my $text = $line->t; 263 my $text = $line->t;
264 my $off = $line->offset_of ($row, $col) if $col;
264 265
265 my @matches; 266 my @matches;
266 for my $matcher (@{$self->{matchers}}) { 267 for my $matcher (@{$self->{matchers}}) {
267 my $launcher = $matcher->[1] || $self->{launcher}; 268 my $launcher = $matcher->[1] || $self->{launcher};
268 while (($text =~ /$matcher->[0]/g)) { 269 while ($text =~ /$matcher->[0]/g) {
269 my $match = substr $text, $-[0], $+[0] - $-[0]; 270 my $match = substr $text, $-[0], $+[0] - $-[0];
270 my @begin = @-; 271 my @begin = @-;
271 my @end = @+; 272 my @end = @+;
272 my @exec; 273 my @exec;
273 274
274 if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { 275 if (!defined($off) || ($-[0] <= $off && $+[0] >= $off)) {
275 if ($launcher !~ /\$/) { 276 if ($launcher !~ /\$/) {
276 @exec = ($launcher, $match); 277 @exec = ($launcher, $match);
277 } else { 278 } else {
278 # It'd be nice to just access a list like ($&,$1,$2...), 279 # It'd be nice to just access a list like ($&,$1,$2...),
279 # but alas, m//g behaves differently in list context. 280 # but alas, m//g behaves differently in list context.
280 @exec = map { s/\$(\d+)|\$\{(\d+)\}/ 281 @exec = map { s/\$(\d+)|\$\{(\d+)\}/
281 substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) 282 substr $text, $begin[$1 || $2], $end[$1 || $2] - $begin[$1 || $2]
282 /egx; $_ } split(/\s+/, $launcher); 283 /egx; $_ } split /\s+/, $launcher;
283 } 284 }
284 285
285 push @matches, [ $begin[0], $match, @exec ]; 286 push @matches, [ $begin[0], $match, @exec ];
286 } 287 }
287 } 288 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines