--- rxvt-unicode/src/perl/matcher 2014/06/12 12:13:52 1.21 +++ rxvt-unicode/src/perl/matcher 2014/06/15 21:06:53 1.29 @@ -7,7 +7,7 @@ #:META:RESOURCE:%.button:string:the button, yeah #:META:RESOURCE:%.pattern.:string:extra pattern to match #:META:RESOURCE:%.launcher.:string:custom launcher for pattern -#:META:RESOURCE:%.rend.:string:custom rednition for pattern +#:META:RESOURCE:%.rend.:string:custom rendition for pattern =head1 NAME @@ -59,18 +59,16 @@ )+ }x; -sub on_key_press { +sub matchlist_key_press { my ($self, $event, $keysym, $octets) = @_; - return unless $self->{overlay}; - delete $self->{overlay}; + $self->disable ("key_press"); my $i = ($keysym == 96 ? 0 : $keysym - 48); if ($i >= 0 && $i < @{ $self->{matches} }) { my @exec = @{ $self->{matches}[$i] }; - shift @exec; - $self->exec_async (@exec); + $self->exec_async (@exec[5 .. $#exec]); } 1 @@ -109,14 +107,13 @@ sub matchlist { my ($self) = @_; - @{ $self->{matches} } = (); + $self->{matches} = []; my $row = $self->nrow - 1; while ($row >= 0 && @{ $self->{matches} } < 10) { my $line = $self->line ($row); - my @matches = $self->find_matches ($row, 0); + my @matches = $self->find_matches ($row); - for (sort { $b->[0] <=> $a->[0] } @matches) { - shift @$_; + for (sort { $b->[0] <=> $a->[0] or $b->[1] <=> $a->[1] } @matches) { push @{ $self->{matches} }, $_; last if @{ $self->{matches} } == 10; } @@ -130,7 +127,7 @@ my $i = 0; for my $match (@{ $self->{matches} }) { - my $text = $match->[0]; + my $text = $match->[4]; my $w = $self->strwidth ("$i-$text"); $width = $w if $w > $width; @@ -142,12 +139,13 @@ $self->{overlay} = $self->overlay (0, 0, $width, scalar (@{ $self->{matches} }), urxvt::OVERLAY_RSTYLE, 2); my $i = 0; for my $match (@{ $self->{matches} }) { - my $text = $match->[0]; + my $text = $match->[4]; $self->{overlay}->set (0, $i, "$i-$text"); $i++; } + $self->enable (key_press => \&matchlist_key_press); } sub most_recent { @@ -188,7 +186,6 @@ $self->{launcher} = $self->my_resource ("launcher") || $self->x_resource("url-launcher") || "sensible-browser"; - $self->{matches} = []; $self->{button} = 2; $self->{state} = 0; if($self->{argv}[0] || $self->my_resource ("button")) { @@ -229,7 +226,6 @@ # fetch the line that has changed my $line = $self->line ($row); my $text = $line->t; - my $i = 0; # find all urls (if any) for my $matcher (@{$self->{matchers}}) { @@ -261,28 +257,29 @@ my ($self, $row, $col) = @_; my $line = $self->line ($row); my $text = $line->t; + my $off = $line->offset_of ($row, $col) if defined $col; my @matches; for my $matcher (@{$self->{matchers}}) { my $launcher = $matcher->[1] || $self->{launcher}; - while (($text =~ /$matcher->[0]/g)) { + while ($text =~ /$matcher->[0]/g) { my $match = substr $text, $-[0], $+[0] - $-[0]; my @begin = @-; my @end = @+; my @exec; - if (!defined($col) || ($-[0] <= $col && $+[0] >= $col)) { + if (!defined($off) || ($-[0] <= $off && $+[0] >= $off)) { if ($launcher !~ /\$/) { @exec = ($launcher, $match); } else { # It'd be nice to just access a list like ($&,$1,$2...), # but alas, m//g behaves differently in list context. @exec = map { s/\$(\d+)|\$\{(\d+)\}/ - substr($text,$begin[$1||$2],$end[$1||$2]-$begin[$1||$2]) - /egx; $_ } split(/\s+/, $launcher); + substr $text, $begin[$1 || $2], $end[$1 || $2] - $begin[$1 || $2] + /egx; $_ } split /\s+/, $launcher; } - push @matches, [ $begin[0], $match, @exec ]; + push @matches, [ $line->coord_of ($begin[0]), $line->coord_of ($end[0]), $match, @exec ]; } } } @@ -296,7 +293,7 @@ my @matches = $self->find_matches ($row, $col); if (@matches) { my @match = @{ $matches[0] }; - return @match[2 .. $#match]; + return @match[5 .. $#match]; } ()