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.39 by root, Sun Nov 21 19:33:32 2021 UTC vs.
Revision 1.41 by sf-exg, Sun May 28 10:40:41 2023 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
220 220
221 $self->enable (key_press => \&matchlist_key_press); 221 $self->enable (key_press => \&matchlist_key_press);
222} 222}
223 223
224sub most_recent { 224sub most_recent {
225 my ($self) = shift; 225 my ($self) = @_;
226 my $row = $self->nrow - 1; 226 my $row = $self->nrow - 1;
227 my @exec; 227
228 while ($row >= $self->top_row) { 228 while ($row >= $self->top_row) {
229 my $line = $self->line ($row); 229 my $line = $self->line ($row);
230 @exec = $self->command_for($row); 230 my @exec = $self->command_for ($row);
231 last if(@exec); 231 if (@exec) {
232 return $self->exec_async (@exec);
233 }
232 234
233 $row = $line->beg - 1; 235 $row = $line->beg - 1;
234 } 236 }
235 if(@exec) { 237
236 return $self->exec_async (@exec);
237 }
238 () 238 ()
239} 239}
240 240
241sub my_resource { 241sub my_resource {
242 $_[0]->x_resource ("%.$_[1]") 242 $_[0]->x_resource ("%.$_[1]")
341 my $match = substr $text, $-[0], $+[0] - $-[0]; 341 my $match = substr $text, $-[0], $+[0] - $-[0];
342 my @begin = @-; 342 my @begin = @-;
343 my @end = @+; 343 my @end = @+;
344 my @exec; 344 my @exec;
345 345
346 if (!defined($off) || ($-[0] <= $off && $+[0] >= $off)) { 346 if (!(defined $off) || ($-[0] <= $off && $+[0] >= $off)) {
347 if ($launcher !~ /\$/) { 347 if ($launcher !~ /\$/) {
348 @exec = ($launcher, $match); 348 @exec = ($launcher, $match);
349 } else { 349 } else {
350 # It'd be nice to just access a list like ($&,$1,$2...), 350 # It'd be nice to just access a list like ($&,$1,$2...),
351 # but alas, m//g behaves differently in list context. 351 # but alas, m//g behaves differently in list context.
352 @exec = map { s/\$(\d+)|\$\{(\d+)\}/ 352 @exec = map {
353 s{\$(\d+)|\$\{(\d+)\}}{
353 substr $text, $begin[$1 || $2], $end[$1 || $2] - $begin[$1 || $2] 354 substr $text, $begin[$1 || $2], $end[$1 || $2] - $begin[$1 || $2]
355 }egx;
356 $_
354 /egx; $_ } split /\s+/, $launcher; 357 } split /\s+/, $launcher;
355 } 358 }
356 359
357 push @matches, [ $line->coord_of ($begin[0]), $line->coord_of ($end[0]), $match, @exec ]; 360 push @matches, [ $line->coord_of ($begin[0]), $line->coord_of ($end[0]), $match, @exec ];
358 } 361 }
359 } 362 }
360 } 363 }
361 364
362 @matches; 365 @matches
363} 366}
364 367
365sub command_for { 368sub command_for {
366 my ($self, $row, $col) = @_; 369 my ($self, $row, $col) = @_;
367 370
374 () 377 ()
375} 378}
376 379
377sub on_button_press { 380sub on_button_press {
378 my ($self, $event) = @_; 381 my ($self, $event) = @_;
382
383 if (
379 if($self->valid_button($event) 384 $self->valid_button ($event)
380 && (my @exec = $self->command_for($event->{row},$event->{col}))) { 385 && (my @exec = $self->command_for ($event->{row}, $event->{col}))
386 ) {
381 $self->{row} = $event->{row}; 387 $self->{row} = $event->{row};
382 $self->{col} = $event->{col}; 388 $self->{col} = $event->{col};
383 $self->{cmd} = \@exec; 389 $self->{cmd} = \@exec;
384 return 1; 390 return 1;
385 } else { 391 } else {
398 my $col = delete $self->{col}; 404 my $col = delete $self->{col};
399 my $cmd = delete $self->{cmd}; 405 my $cmd = delete $self->{cmd};
400 406
401 return if !defined $row; 407 return if !defined $row;
402 408
403 if($row == $event->{row} && abs($col-$event->{col}) < 2 409 if (
410 $row == $event->{row}
411 && (abs $col-$event->{col}) < 2
404 && join("\x00", @$cmd) eq join("\x00", $self->command_for($row,$col))) { 412 && (join "\x00", @$cmd) eq (join "\x00", $self->command_for ($row, $col))
413 ) {
405 if($self->valid_button($event)) { 414 if ($self->valid_button ($event)) {
406
407 $self->exec_async (@$cmd); 415 $self->exec_async (@$cmd);
408
409 } 416 }
410 } 417 }
411 418
412 1; 419 1;
413} 420}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines