--- rxvt-unicode/src/perl/matcher 2014/06/22 07:51:21 1.31 +++ rxvt-unicode/src/perl/matcher 2015/03/17 09:25:16 1.35 @@ -2,9 +2,10 @@ # Author: Tim Pope # Bob Farrell +# Emanuele Giaquinta #:META:RESOURCE:%.launcher:string:default launcher command -#:META:RESOURCE:%.button:string:the button, yeah +#:META:RESOURCE:%.button:string:the mouse button used to activate a match #:META:RESOURCE:%.pattern.:string:extra pattern to match #:META:RESOURCE:%.launcher.:string:custom launcher for pattern #:META:RESOURCE:%.rend.:string:custom rendition for pattern @@ -33,7 +34,7 @@ from the keyboard. Simply bind a keysym to "matcher:last" or "matcher:list" as seen in the example below. -The 'matcher:select' action enables a mode in which it is possible to +The C action enables a mode in which it is possible to iterate over the matches using the keyboard and either activate them or copy them to the clipboard. While the mode is active, normal terminal input/output is suspended and the following bindings are recognized: @@ -70,6 +71,9 @@ =back +It is also possible to cycle through the matches using a key +combination bound to the C action. + Example: load and use the matcher extension with defaults. URxvt.perl-ext: default,matcher @@ -115,15 +119,15 @@ sub on_user_command { my ($self, $cmd) = @_; - if ($cmd =~ s/^matcher:list\b//) { + if ($cmd eq "matcher:list") { $self->matchlist; - } else { - if ($cmd =~ s/^matcher:last\b//) { - $self->most_recent; - } elsif ($cmd =~ s/^matcher\b//) { - # for backward compatibility - $self->most_recent; - } + } elsif ($cmd eq "matcher:last") { + $self->most_recent; + } elsif ($cmd eq "matcher:select") { + $self->select_enter; + } elsif ($cmd eq "matcher") { + # for backward compatibility + $self->most_recent; } () @@ -189,11 +193,14 @@ sub most_recent { my ($self) = shift; - my $row = $self->nrow; + my $row = $self->nrow - 1; my @exec; - while($row-- > $self->top_row) { + while ($row >= $self->top_row) { + my $line = $self->line ($row); @exec = $self->command_for($row); last if(@exec); + + $row = $line->beg - 1; } if(@exec) { return $self->exec_async (@exec); @@ -265,22 +272,23 @@ # fetch the line that has changed my $line = $self->line ($row); my $text = $line->t; + my $rend; # find all urls (if any) for my $matcher (@{$self->{matchers}}) { while ($text =~ /$matcher->[0]/g) { #print "$&\n"; - my $rend = $line->r; + $rend ||= $line->r; # mark all characters as underlined. we _must_ not toggle underline, # as we might get called on an already-marked url. &{$matcher->[2]} for @{$rend}[$-[0] .. $+[0] - 1]; - - $line->r ($rend); } } + $line->r ($rend) if $rend; + () } @@ -419,13 +427,15 @@ $self->{id} = $dir < 0 ? @{ $self->{matches} } - 1 : 0; $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1)); $self->want_refresh; - return; + return 1; } $row = $dir < 0 ? $line->beg - 1 : $line->end + 1; } $self->scr_bell; + + () } sub select_refresh { @@ -479,6 +489,15 @@ $self->select_search (+1, $line->end + 1) if $line->end < $self->nrow; } + } elsif ($self->lookup_keysym ($keysym, $event->{state}) eq "matcher:select") { + if ($self->{id} > 0) { + $self->{id}--; + $self->want_refresh; + } else { + my $line = $self->line ($self->{cur_row}); + $self->select_search (-1, $self->nrow - 1) + unless $self->select_search (-1, $line->beg - 1); + } } 1