--- rxvt-unicode/src/perl/matcher 2014/10/14 09:00:43 1.34 +++ rxvt-unicode/src/perl/matcher 2021/11/21 17:08:57 1.38 @@ -34,12 +34,12 @@ 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: -=over 4 +=over =item C @@ -71,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 @@ -90,9 +93,9 @@ my $url = qr{ (?:https?://|ftp://|news://|mailto:|file://|\bwww\.) - [\w\-\@;\/?:&=%\$.+!*\x27,~#]* + [\w\-\@;\/?:&=%\$.+!*\x27,~#$urxvt::NOCHAR]* ( - \([\w\-\@;\/?:&=%\$.+!*\x27,~#]*\)| # Allow a pair of matched parentheses + \([\w\-\@;\/?:&=%\$.+!*\x27,~#$urxvt::NOCHAR]*\)| # Allow a pair of matched parentheses [\w\-\@;\/?:&=%\$+*~] # exclude some trailing characters (heuristic) )+ }x; @@ -250,9 +253,7 @@ my @defaults = ($url); my @matchers; - for (my $idx = 0; defined (my $res = $self->my_resource ("pattern.$idx") || $defaults[$idx]); $idx++) { - $res = $self->locale_decode ($res); - utf8::encode $res; + for (my $idx = 0; defined (my $res = $self->locale_decode ($self->my_resource ("pattern.$idx")) || $defaults[$idx]); $idx++) { my $launcher = $self->my_resource ("launcher.$idx"); $launcher =~ s/\$&|\$\{&\}/\${0}/g if $launcher; my $rend = $self->parse_rend($self->my_resource ("rend.$idx")); @@ -422,15 +423,17 @@ $self->{matches} = \@matches; $self->{cur_row} = $row; $self->{id} = $dir < 0 ? @{ $self->{matches} } - 1 : 0; - $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1)); + $self->view_start ($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 { @@ -484,6 +487,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