… | |
… | |
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, 0); |
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 | |
282 | sub command_for { |
260 | sub 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; |
286 | |
264 | |
|
|
265 | my @matches; |
287 | for my $matcher (@{$self->{matchers}}) { |
266 | for my $matcher (@{$self->{matchers}}) { |
288 | my $launcher = $matcher->[1] || $self->{launcher}; |
267 | my $launcher = $matcher->[1] || $self->{launcher}; |
289 | while (($text =~ /$matcher->[0]/g)) { |
268 | while (($text =~ /$matcher->[0]/g)) { |
290 | my $match = $&; |
269 | my $match = substr $text, $-[0], $+[0] - $-[0]; |
291 | my @begin = @-; |
270 | my @begin = @-; |
292 | my @end = @+; |
271 | my @end = @+; |
|
|
272 | my @exec; |
|
|
273 | |
293 | if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { |
274 | if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { |
294 | if ($launcher !~ /\$/) { |
275 | if ($launcher !~ /\$/) { |
295 | return ($launcher,$match); |
276 | @exec = ($launcher, $match); |
296 | } else { |
277 | } else { |
297 | # It'd be nice to just access a list like ($&,$1,$2...), |
278 | # It'd be nice to just access a list like ($&,$1,$2...), |
298 | # but alas, m//g behaves differently in list context. |
279 | # but alas, m//g behaves differently in list context. |
299 | my @exec = map { s/\$(\d+)|\$\{(\d+)\}/ |
280 | @exec = map { s/\$(\d+)|\$\{(\d+)\}/ |
300 | substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) |
281 | substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) |
301 | /egx; $_ } split(/\s+/, $launcher); |
282 | /egx; $_ } split(/\s+/, $launcher); |
302 | return @exec; |
|
|
303 | } |
283 | } |
|
|
284 | |
|
|
285 | push @matches, [ $begin[0], $match, @exec ]; |
304 | } |
286 | } |
305 | } |
287 | } |
|
|
288 | } |
|
|
289 | |
|
|
290 | @matches; |
|
|
291 | } |
|
|
292 | |
|
|
293 | sub command_for { |
|
|
294 | my ($self, $row, $col) = @_; |
|
|
295 | |
|
|
296 | my @matches = $self->find_matches ($row, $col); |
|
|
297 | if (@matches) { |
|
|
298 | my @match = @{ $matches[0] }; |
|
|
299 | return @match[2 .. $#match]; |
306 | } |
300 | } |
307 | |
301 | |
308 | () |
302 | () |
309 | } |
303 | } |
310 | |
304 | |