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.38 by sf-exg, Sun Nov 21 17:08:57 2021 UTC vs.
Revision 1.40 by root, Fri Dec 9 05:06:46 2022 UTC

19Uses per-line display filtering (C<on_line_update>) to underline text 19Uses per-line display filtering (C<on_line_update>) to underline text
20matching a certain pattern and make it clickable. When clicked with the 20matching a certain pattern and make it clickable. When clicked with the
21mouse button specified in the C<matcher.button> resource (default 2, or 21mouse button specified in the C<matcher.button> resource (default 2, or
22middle), the program specified in the C<matcher.launcher> resource 22middle), the program specified in the C<matcher.launcher> resource
23(default, the C<url-launcher> resource, C<sensible-browser>) will be started 23(default, the C<url-launcher> resource, C<sensible-browser>) will be started
24with the matched text as first argument. The default configuration is 24with the matched text as first argument. The default configuration is
25suitable for matching URLs and launching a web browser, like the 25suitable for matching URLs and launching a web browser, like the
26former "mark-urls" extension. 26former "mark-urls" extension.
27 27
28The default pattern to match URLs can be overridden with the 28The default pattern to match URLs can be overridden with the
29C<matcher.pattern.0> resource, and additional patterns can be specified 29C<matcher.pattern.0> resource, and additional patterns can be specified
30with numbered patterns, in a manner similar to the "selection" extension. 30with numbered patterns, in a manner similar to the "selection" extension.
31The launcher can also be overridden on a per-pattern basis. 31The launcher can also be overridden on a per-pattern basis.
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 C<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
85 URxvt.keysym.M-Delete: matcher:list 85 URxvt.keysym.M-Delete: matcher:list
86 URxvt.matcher.button: 1 86 URxvt.matcher.button: 1
87 URxvt.matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-] 87 URxvt.matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-]
88 URxvt.matcher.pattern.2: \\B(/\\S+?):(\\d+)(?=:|$) 88 URxvt.matcher.pattern.2: \\B(/\\S+?):(\\d+)(?=:|$)
89 URxvt.matcher.launcher.2: gvim +$2 $1 89 URxvt.matcher.launcher.2: gvim +$2 $1
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
90 120
91=cut 121=cut
92 122
93my $url = 123my $url =
94 qr{ 124 qr{
193 223
194sub most_recent { 224sub most_recent {
195 my ($self) = shift; 225 my ($self) = shift;
196 my $row = $self->nrow - 1; 226 my $row = $self->nrow - 1;
197 my @exec; 227 my @exec;
228
198 while ($row >= $self->top_row) { 229 while ($row >= $self->top_row) {
199 my $line = $self->line ($row); 230 my $line = $self->line ($row);
200 @exec = $self->command_for($row); 231 @exec = $self->command_for ($row);
201 last if(@exec); 232 last if @exec;
202 233
203 $row = $line->beg - 1; 234 $row = $line->beg - 1;
204 } 235 }
236
205 if(@exec) { 237 if (@exec) {
206 return $self->exec_async (@exec); 238 return $self->exec_async (@exec);
207 } 239 }
240
208 () 241 ()
209} 242}
210 243
211sub my_resource { 244sub my_resource {
212 $_[0]->x_resource ("%.$_[1]") 245 $_[0]->x_resource ("%.$_[1]")
311 my $match = substr $text, $-[0], $+[0] - $-[0]; 344 my $match = substr $text, $-[0], $+[0] - $-[0];
312 my @begin = @-; 345 my @begin = @-;
313 my @end = @+; 346 my @end = @+;
314 my @exec; 347 my @exec;
315 348
316 if (!defined($off) || ($-[0] <= $off && $+[0] >= $off)) { 349 if (!(defined $off) || ($-[0] <= $off && $+[0] >= $off)) {
317 if ($launcher !~ /\$/) { 350 if ($launcher !~ /\$/) {
318 @exec = ($launcher, $match); 351 @exec = ($launcher, $match);
319 } else { 352 } else {
320 # It'd be nice to just access a list like ($&,$1,$2...), 353 # It'd be nice to just access a list like ($&,$1,$2...),
321 # but alas, m//g behaves differently in list context. 354 # but alas, m//g behaves differently in list context.
322 @exec = map { s/\$(\d+)|\$\{(\d+)\}/ 355 @exec = map {
356 s{\$(\d+)|\$\{(\d+)\}}{
323 substr $text, $begin[$1 || $2], $end[$1 || $2] - $begin[$1 || $2] 357 substr $text, $begin[$1 || $2], $end[$1 || $2] - $begin[$1 || $2]
358 }egx;
359 $_
324 /egx; $_ } split /\s+/, $launcher; 360 } split /\s+/, $launcher;
325 } 361 }
326 362
327 push @matches, [ $line->coord_of ($begin[0]), $line->coord_of ($end[0]), $match, @exec ]; 363 push @matches, [ $line->coord_of ($begin[0]), $line->coord_of ($end[0]), $match, @exec ];
328 } 364 }
329 } 365 }
330 } 366 }
331 367
332 @matches; 368 @matches
333} 369}
334 370
335sub command_for { 371sub command_for {
336 my ($self, $row, $col) = @_; 372 my ($self, $row, $col) = @_;
337 373
344 () 380 ()
345} 381}
346 382
347sub on_button_press { 383sub on_button_press {
348 my ($self, $event) = @_; 384 my ($self, $event) = @_;
385
386 if (
349 if($self->valid_button($event) 387 $self->valid_button ($event)
350 && (my @exec = $self->command_for($event->{row},$event->{col}))) { 388 && (my @exec = $self->command_for ($event->{row}, $event->{col}))
389 ) {
351 $self->{row} = $event->{row}; 390 $self->{row} = $event->{row};
352 $self->{col} = $event->{col}; 391 $self->{col} = $event->{col};
353 $self->{cmd} = \@exec; 392 $self->{cmd} = \@exec;
354 return 1; 393 return 1;
355 } else { 394 } else {
368 my $col = delete $self->{col}; 407 my $col = delete $self->{col};
369 my $cmd = delete $self->{cmd}; 408 my $cmd = delete $self->{cmd};
370 409
371 return if !defined $row; 410 return if !defined $row;
372 411
373 if($row == $event->{row} && abs($col-$event->{col}) < 2 412 if (
413 $row == $event->{row}
414 && (abs $col-$event->{col}) < 2
374 && join("\x00", @$cmd) eq join("\x00", $self->command_for($row,$col))) { 415 && (join "\x00", @$cmd) eq (join "\x00", $self->command_for ($row, $col))
416 ) {
375 if($self->valid_button($event)) { 417 if ($self->valid_button ($event)) {
376
377 $self->exec_async (@$cmd); 418 $self->exec_async (@$cmd);
378
379 } 419 }
380 } 420 }
381 421
382 1; 422 1;
383} 423}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines