1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # Author: Tim Pope <rxvt-unicodeNOSPAM@tpope.org> |
3 | # Author: Tim Pope <rxvt-unicodeNOSPAM@tpope.org> |
4 | # Bob Farrell <robertanthonyfarrell@gmail.com> |
4 | # Bob Farrell <robertanthonyfarrell@gmail.com> |
|
|
5 | # Emanuele Giaquinta |
5 | |
6 | |
6 | #:META:RESOURCE:%.launcher:string:default launcher command |
7 | #:META:RESOURCE:%.launcher:string:default launcher command |
7 | #:META:RESOURCE:%.button:string:the button, yeah |
8 | #:META:RESOURCE:%.button:string:the mouse button used to activate a match |
8 | #:META:RESOURCE:%.pattern.:string:extra pattern to match |
9 | #:META:RESOURCE:%.pattern.:string:extra pattern to match |
9 | #:META:RESOURCE:%.launcher.:string:custom launcher for pattern |
10 | #:META:RESOURCE:%.launcher.:string:custom launcher for pattern |
10 | #:META:RESOURCE:%.rend.:string:custom rendition for pattern |
11 | #:META:RESOURCE:%.rend.:string:custom rendition for pattern |
11 | |
12 | |
12 | =head1 NAME |
13 | =head1 NAME |
… | |
… | |
31 | |
32 | |
32 | It is possible to activate the most recently seen match or a list of matches |
33 | It is possible to activate the most recently seen match or a list of matches |
33 | from the keyboard. Simply bind a keysym to "matcher:last" or |
34 | from the keyboard. Simply bind a keysym to "matcher:last" or |
34 | "matcher:list" as seen in the example below. |
35 | "matcher:list" as seen in the example below. |
35 | |
36 | |
36 | The 'matcher:select' action enables a mode in which it is possible to |
37 | The C<matcher:select> action enables a mode in which it is possible to |
37 | iterate over the matches using the keyboard and either activate them |
38 | iterate over the matches using the keyboard and either activate them |
38 | or copy them to the clipboard. While the mode is active, normal terminal |
39 | or copy them to the clipboard. While the mode is active, normal terminal |
39 | input/output is suspended and the following bindings are recognized: |
40 | input/output is suspended and the following bindings are recognized: |
40 | |
41 | |
41 | =over 4 |
42 | =over |
42 | |
43 | |
43 | =item C<Up> |
44 | =item C<Up> |
44 | |
45 | |
45 | Search for a match upwards. |
46 | Search for a match upwards. |
46 | |
47 | |
… | |
… | |
67 | =item C<y> |
68 | =item C<y> |
68 | |
69 | |
69 | Copy the current match to the clipboard. |
70 | Copy the current match to the clipboard. |
70 | |
71 | |
71 | =back |
72 | =back |
|
|
73 | |
|
|
74 | It is also possible to cycle through the matches using a key |
|
|
75 | combination bound to the C<matcher:select> action. |
72 | |
76 | |
73 | Example: load and use the matcher extension with defaults. |
77 | Example: load and use the matcher extension with defaults. |
74 | |
78 | |
75 | URxvt.perl-ext: default,matcher |
79 | URxvt.perl-ext: default,matcher |
76 | |
80 | |
… | |
… | |
113 | |
117 | |
114 | # backwards compat |
118 | # backwards compat |
115 | sub on_user_command { |
119 | sub on_user_command { |
116 | my ($self, $cmd) = @_; |
120 | my ($self, $cmd) = @_; |
117 | |
121 | |
118 | if ($cmd =~ s/^matcher:list\b//) { |
122 | if ($cmd eq "matcher:list") { |
119 | $self->matchlist; |
123 | $self->matchlist; |
120 | } else { |
124 | } elsif ($cmd eq "matcher:last") { |
121 | if ($cmd =~ s/^matcher:last\b//) { |
|
|
122 | $self->most_recent; |
125 | $self->most_recent; |
|
|
126 | } elsif ($cmd eq "matcher:select") { |
|
|
127 | $self->select_enter; |
123 | } elsif ($cmd =~ s/^matcher\b//) { |
128 | } elsif ($cmd eq "matcher") { |
124 | # for backward compatibility |
129 | # for backward compatibility |
125 | $self->most_recent; |
130 | $self->most_recent; |
126 | } |
|
|
127 | } |
131 | } |
128 | |
132 | |
129 | () |
133 | () |
130 | } |
134 | } |
131 | |
135 | |
… | |
… | |
419 | if (@matches) { |
423 | if (@matches) { |
420 | @matches = sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] } @matches; |
424 | @matches = sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] } @matches; |
421 | $self->{matches} = \@matches; |
425 | $self->{matches} = \@matches; |
422 | $self->{cur_row} = $row; |
426 | $self->{cur_row} = $row; |
423 | $self->{id} = $dir < 0 ? @{ $self->{matches} } - 1 : 0; |
427 | $self->{id} = $dir < 0 ? @{ $self->{matches} } - 1 : 0; |
424 | $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1)); |
428 | $self->view_start ($row - ($self->nrow >> 1)); |
425 | $self->want_refresh; |
429 | $self->want_refresh; |
426 | return; |
430 | return 1; |
427 | } |
431 | } |
428 | |
432 | |
429 | $row = $dir < 0 ? $line->beg - 1 : $line->end + 1; |
433 | $row = $dir < 0 ? $line->beg - 1 : $line->end + 1; |
430 | } |
434 | } |
431 | |
435 | |
432 | $self->scr_bell; |
436 | $self->scr_bell; |
|
|
437 | |
|
|
438 | () |
433 | } |
439 | } |
434 | |
440 | |
435 | sub select_refresh { |
441 | sub select_refresh { |
436 | my ($self) = @_; |
442 | my ($self) = @_; |
437 | |
443 | |
… | |
… | |
481 | } else { |
487 | } else { |
482 | my $line = $self->line ($self->{cur_row}); |
488 | my $line = $self->line ($self->{cur_row}); |
483 | $self->select_search (+1, $line->end + 1) |
489 | $self->select_search (+1, $line->end + 1) |
484 | if $line->end < $self->nrow; |
490 | if $line->end < $self->nrow; |
485 | } |
491 | } |
|
|
492 | } elsif ($self->lookup_keysym ($keysym, $event->{state}) eq "matcher:select") { |
|
|
493 | if ($self->{id} > 0) { |
|
|
494 | $self->{id}--; |
|
|
495 | $self->want_refresh; |
|
|
496 | } else { |
|
|
497 | my $line = $self->line ($self->{cur_row}); |
|
|
498 | $self->select_search (-1, $self->nrow - 1) |
|
|
499 | unless $self->select_search (-1, $line->beg - 1); |
|
|
500 | } |
486 | } |
501 | } |
487 | |
502 | |
488 | 1 |
503 | 1 |
489 | } |
504 | } |
490 | |
505 | |