ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/matcher
(Generate patch)

Comparing rxvt-unicode/src/perl/matcher (file contents):
Revision 1.34 by sf-exg, Tue Oct 14 09:00:43 2014 UTC vs.
Revision 1.39 by root, Sun Nov 21 19:33:32 2021 UTC

32 32
33It is possible to activate the most recently seen match or a list of matches 33It is possible to activate the most recently seen match or a list of matches
34from the keyboard. Simply bind a keysym to "matcher:last" or 34from the keyboard. Simply bind a keysym to "matcher:last" or
35"matcher:list" as seen in the example below. 35"matcher:list" as seen in the example below.
36 36
37The 'matcher:select' action enables a mode in which it is possible to 37The C<matcher:select> action enables a mode in which it is possible to
38iterate over the matches using the keyboard and either activate them 38iterate over the matches using the keyboard and either activate them
39or copy them to the clipboard. While the mode is active, normal terminal 39or copy them to the clipboard. While the mode is active, normal terminal
40input/output is suspended and the following bindings are recognized: 40input/output is suspended and the following bindings are recognized:
41 41
42=over 4 42=over
43 43
44=item C<Up> 44=item C<Up>
45 45
46Search for a match upwards. 46Search for a match upwards.
47 47
68=item C<y> 68=item C<y>
69 69
70Copy the current match to the clipboard. 70Copy the current match to the clipboard.
71 71
72=back 72=back
73
74It is also possible to cycle through the matches using a key
75combination bound to the C<matcher:select> action.
73 76
74Example: load and use the matcher extension with defaults. 77Example: load and use the matcher extension with defaults.
75 78
76 URxvt.perl-ext: default,matcher 79 URxvt.perl-ext: default,matcher
77 80
83 URxvt.matcher.button: 1 86 URxvt.matcher.button: 1
84 URxvt.matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-] 87 URxvt.matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-]
85 URxvt.matcher.pattern.2: \\B(/\\S+?):(\\d+)(?=:|$) 88 URxvt.matcher.pattern.2: \\B(/\\S+?):(\\d+)(?=:|$)
86 URxvt.matcher.launcher.2: gvim +$2 $1 89 URxvt.matcher.launcher.2: gvim +$2 $1
87 90
91=head2 Regex encoding/wide character matching
92
93Urxvt stores all text as unicode, in a special encoding that uses
94one character/code point per column. For various reasons, the regular
95expressions are matched directly against this encoding, which means there are a few things
96you need to keep in mind:
97
98=over
99
100=item X resources/command line arguments are locale-encoded
101
102The regexes taken from the command line or resources will be converted
103from locale encoding to unicode. This can change the number of code points
104per character.
105
106=item Wide characters are column-padded with C<$urxvt::NOCHAR>
107
108Wide characters (such as kanji and sometimes tabs) are padded with
109a special character value (C<$urxvt::NOCHAR>). That means that
110constructs such as C<\w> or C<.> will only match part of a character, as
111C<$urxvt::NOCHAR> is not matched by C<\w> and both only match the first
112"column" of a wide character.
113
114That means you have to incorporate C<$urxvt::NOCHAR> into parts of regexes
115that may match wide characters. For example, to match C<\w+> you might
116want to use C<[\w$urxvt::NOCHAR]+> instead, and to match a single character
117(C<.>) you might want to use C<.$urxvt::NOCHAR*> instead.
118
119=back
120
88=cut 121=cut
89 122
90my $url = 123my $url =
91 qr{ 124 qr{
92 (?:https?://|ftp://|news://|mailto:|file://|\bwww\.) 125 (?:https?://|ftp://|news://|mailto:|file://|\bwww\.)
93 [\w\-\@;\/?:&=%\$.+!*\x27,~#]* 126 [\w\-\@;\/?:&=%\$.+!*\x27,~#$urxvt::NOCHAR]*
94 ( 127 (
95 \([\w\-\@;\/?:&=%\$.+!*\x27,~#]*\)| # Allow a pair of matched parentheses 128 \([\w\-\@;\/?:&=%\$.+!*\x27,~#$urxvt::NOCHAR]*\)| # Allow a pair of matched parentheses
96 [\w\-\@;\/?:&=%\$+*~] # exclude some trailing characters (heuristic) 129 [\w\-\@;\/?:&=%\$+*~] # exclude some trailing characters (heuristic)
97 )+ 130 )+
98 }x; 131 }x;
99 132
100sub matchlist_key_press { 133sub matchlist_key_press {
248 } 281 }
249 } 282 }
250 283
251 my @defaults = ($url); 284 my @defaults = ($url);
252 my @matchers; 285 my @matchers;
253 for (my $idx = 0; defined (my $res = $self->my_resource ("pattern.$idx") || $defaults[$idx]); $idx++) { 286 for (my $idx = 0; defined (my $res = $self->locale_decode ($self->my_resource ("pattern.$idx")) || $defaults[$idx]); $idx++) {
254 $res = $self->locale_decode ($res);
255 utf8::encode $res;
256 my $launcher = $self->my_resource ("launcher.$idx"); 287 my $launcher = $self->my_resource ("launcher.$idx");
257 $launcher =~ s/\$&|\$\{&\}/\${0}/g if $launcher; 288 $launcher =~ s/\$&|\$\{&\}/\${0}/g if $launcher;
258 my $rend = $self->parse_rend($self->my_resource ("rend.$idx")); 289 my $rend = $self->parse_rend($self->my_resource ("rend.$idx"));
259 unshift @matchers, [qr($res)x,$launcher,$rend]; 290 unshift @matchers, [qr($res)x,$launcher,$rend];
260 } 291 }
420 if (@matches) { 451 if (@matches) {
421 @matches = sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] } @matches; 452 @matches = sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] } @matches;
422 $self->{matches} = \@matches; 453 $self->{matches} = \@matches;
423 $self->{cur_row} = $row; 454 $self->{cur_row} = $row;
424 $self->{id} = $dir < 0 ? @{ $self->{matches} } - 1 : 0; 455 $self->{id} = $dir < 0 ? @{ $self->{matches} } - 1 : 0;
425 $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1)); 456 $self->view_start ($row - ($self->nrow >> 1));
426 $self->want_refresh; 457 $self->want_refresh;
427 return; 458 return 1;
428 } 459 }
429 460
430 $row = $dir < 0 ? $line->beg - 1 : $line->end + 1; 461 $row = $dir < 0 ? $line->beg - 1 : $line->end + 1;
431 } 462 }
432 463
433 $self->scr_bell; 464 $self->scr_bell;
465
466 ()
434} 467}
435 468
436sub select_refresh { 469sub select_refresh {
437 my ($self) = @_; 470 my ($self) = @_;
438 471
482 } else { 515 } else {
483 my $line = $self->line ($self->{cur_row}); 516 my $line = $self->line ($self->{cur_row});
484 $self->select_search (+1, $line->end + 1) 517 $self->select_search (+1, $line->end + 1)
485 if $line->end < $self->nrow; 518 if $line->end < $self->nrow;
486 } 519 }
520 } elsif ($self->lookup_keysym ($keysym, $event->{state}) eq "matcher:select") {
521 if ($self->{id} > 0) {
522 $self->{id}--;
523 $self->want_refresh;
524 } else {
525 my $line = $self->line ($self->{cur_row});
526 $self->select_search (-1, $self->nrow - 1)
527 unless $self->select_search (-1, $line->beg - 1);
528 }
487 } 529 }
488 530
489 1 531 1
490} 532}
491 533

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines