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.20 by sf-exg, Thu Jun 12 06:03:49 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 $text = $line->t; 116 my @matches = $self->find_matches ($row);
117
118 # FIXME: code duplicated from 'command_for'
119 my @matches;
120 for my $matcher (@{$self->{matchers}}) {
121 my $launcher = $matcher->[1] || $self->{launcher};
122 while ($text =~ /$matcher->[0]/g) {
123 my $match = substr ($text, $-[0], $+[0] - $-[0]);
124 my @beg = @-;
125 my @end = @+;
126 my @exec;
127
128 if ($launcher !~ /\$/) {
129 @exec = ($launcher, $match);
130 } else {
131 @exec = map { s/\$(\d+)|\$\{(\d+)\}/
132 substr ($text, $beg[$1 || $2], $end[$1 || $2] - $beg[$1 || $2])
133 /egx; $_ } split /\s+/, $launcher;
134 }
135
136 push @matches, [ $beg[0], $match, @exec ];
137 }
138 }
139 117
140 for (sort { $b->[0] <=> $a->[0] } @matches) { 118 for (sort { $b->[0] <=> $a->[0] } @matches) {
141 shift @$_; 119 shift @$_;
142 push @{ $self->{matches} }, $_; 120 push @{ $self->{matches} }, $_;
143 last if @{ $self->{matches} } == 10; 121 last if @{ $self->{matches} } == 10;
277 | urxvt::ShiftMask | urxvt::ControlMask; 255 | urxvt::ShiftMask | urxvt::ControlMask;
278 return ($event->{button} == $self->{button} && 256 return ($event->{button} == $self->{button} &&
279 ($event->{state} & $mask) == $self->{state}); 257 ($event->{state} & $mask) == $self->{state});
280} 258}
281 259
282sub command_for { 260sub find_matches {
283 my ($self, $row, $col) = @_; 261 my ($self, $row, $col) = @_;
284 my $line = $self->line ($row); 262 my $line = $self->line ($row);
285 my $text = $line->t; 263 my $text = $line->t;
264 my $off = $line->offset_of ($row, $col) if $col;
286 265
266 my @matches;
287 for my $matcher (@{$self->{matchers}}) { 267 for my $matcher (@{$self->{matchers}}) {
288 my $launcher = $matcher->[1] || $self->{launcher}; 268 my $launcher = $matcher->[1] || $self->{launcher};
289 while (($text =~ /$matcher->[0]/g)) { 269 while ($text =~ /$matcher->[0]/g) {
290 my $match = $&; 270 my $match = substr $text, $-[0], $+[0] - $-[0];
291 my @begin = @-; 271 my @begin = @-;
292 my @end = @+; 272 my @end = @+;
273 my @exec;
274
293 if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { 275 if (!defined($off) || ($-[0] <= $off && $+[0] >= $off)) {
294 if ($launcher !~ /\$/) { 276 if ($launcher !~ /\$/) {
295 return ($launcher,$match); 277 @exec = ($launcher, $match);
296 } else { 278 } else {
297 # 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...),
298 # but alas, m//g behaves differently in list context. 280 # but alas, m//g behaves differently in list context.
299 my @exec = map { s/\$(\d+)|\$\{(\d+)\}/ 281 @exec = map { s/\$(\d+)|\$\{(\d+)\}/
300 substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) 282 substr $text, $begin[$1 || $2], $end[$1 || $2] - $begin[$1 || $2]
301 /egx; $_ } split(/\s+/, $launcher); 283 /egx; $_ } split /\s+/, $launcher;
302 return @exec;
303 } 284 }
285
286 push @matches, [ $begin[0], $match, @exec ];
304 } 287 }
305 } 288 }
289 }
290
291 @matches;
292}
293
294sub command_for {
295 my ($self, $row, $col) = @_;
296
297 my @matches = $self->find_matches ($row, $col);
298 if (@matches) {
299 my @match = @{ $matches[0] };
300 return @match[2 .. $#match];
306 } 301 }
307 302
308 () 303 ()
309} 304}
310 305

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines