--- rxvt-unicode/src/perl/matcher 2012/09/04 22:41:11 1.13 +++ rxvt-unicode/src/perl/matcher 2014/05/31 19:47:42 1.17 @@ -1,13 +1,13 @@ #! perl # Author: Tim Pope -# Bob Farrell +# Bob Farrell -#:META:X_RESOURCE:%.launcher:string:default launcher command -#:META:X_RESOURCE:%.button:string:the button, yeah -#:META:X_RESOURCE:%.pattern.:string:extra pattern to match -#:META:X_RESOURCE:%.launcher.:string:custom launcher for pattern -#:META:X_RESOURCE:%.rend.:string:custom rednition for pattern +#:META:RESOURCE:%.launcher:string:default launcher command +#:META:RESOURCE:%.button:string:the button, yeah +#:META:RESOURCE:%.pattern.:string:extra pattern to match +#:META:RESOURCE:%.launcher.:string:custom launcher for pattern +#:META:RESOURCE:%.rend.:string:custom rednition for pattern =head1 NAME @@ -19,7 +19,7 @@ matching a certain pattern and make it clickable. When clicked with the mouse button specified in the C resource (default 2, or middle), the program specified in the C resource -(default, the C resource, C) will be started +(default, the C resource, C) will be started with the matched text as first argument. The default configuration is suitable for matching URLs and launching a web browser, like the former "mark-urls" extension. @@ -33,9 +33,12 @@ from the keyboard. Simply bind a keysym to "perl:matcher:last" or "perl:matcher:list" as seen in the example below. -Example configuration: +Example: load and use the matcher extension with defaults. URxvt.perl-ext: default,matcher + +Example: use a custom configuration. + URxvt.url-launcher: sensible-browser URxvt.keysym.C-Delete: perl:matcher:last URxvt.keysym.M-Delete: perl:matcher:list @@ -75,80 +78,79 @@ $self->exec_async( $self->{launcher}, @args ); } +# backwards compat sub on_user_command { my ($self, $cmd) = @_; - if($cmd =~ s/^matcher:list\b//) { - $self->matchlist(); + if ($cmd =~ s/^matcher:list\b//) { + $self->matchlist; } else { - if($cmd =~ s/^matcher:last\b//) { + if ($cmd =~ s/^matcher:last\b//) { $self->most_recent; - } - # For backward compatibility - else { - if($cmd =~ s/^matcher\b//) { + } elsif ($cmd =~ s/^matcher\b//) { + # for backward compatibility $self->most_recent; } } - } + () } sub matchlist { my ($self) = @_; if ( $self->{showing} ) { - $self->{url_overlay}->hide(); - $self->{showing} = 0; - return; - } - @{$self->{urls}} = (); - my $line; - for (my $i = 0; $i < $self->nrow; $i ++) { - $line = $self->line($i); - next if ($line->beg != $i); - for my $url ($self->get_urls_from_line($line->t)) { - if (scalar(@{$self->{urls}}) == 10) { + $self->{url_overlay}->hide; + $self->{showing} = 0; + return; + } + @{$self->{urls}} = (); + my $line; + for (my $i = 0; $i < $self->nrow; $i ++) { + $line = $self->line($i); + next if ($line->beg != $i); + for my $url ($self->get_urls_from_line($line->t)) { + if (scalar(@{$self->{urls}}) == 10) { shift @{$self->{urls}}; - } - push @{$self->{urls}}, $url; - } - } - - if (! scalar(@{$self->{urls}})) { - return; - } - - my $max = 0; - my $i = scalar( @{$self->{urls}} ) - 1 ;; - - my @temp = (); - - for my $url (@{$self->{urls}}) { - my $url = "$i-$url"; - my $xpos = 0; - - if ($self->ncol + (length $url) >= $self->ncol) { - $url = substr( $url, 0, $self->ncol ); - } - - push @temp, $url; - - if( length $url > $max ) { - $max = length $url; - } - - $i--; - } - - @temp = reverse @temp; - - $self->{url_overlay} = $self->overlay(0, 0, $max, scalar( @temp ), urxvt::OVERLAY_RSTYLE, 2); - my $i = 0; - for my $url (@temp) { - $self->{url_overlay}->set( 0, $i, $url, [(urxvt::OVERLAY_RSTYLE) x length $url]); - $self->{showing} = 1; - $i++; - } + } + push @{$self->{urls}}, $url; + } + } + + if (! scalar(@{$self->{urls}})) { + return; + } + + my $max = 0; + my $i = scalar( @{$self->{urls}} ) - 1 ;; + + my @temp = (); + + for my $url (@{$self->{urls}}) { + my $url = "$i-$url"; + my $xpos = 0; + + if ($self->ncol + (length $url) >= $self->ncol) { + $url = substr( $url, 0, $self->ncol ); + } + + push @temp, $url; + + if( length $url > $max ) { + $max = length $url; + } + + $i--; + } + + @temp = reverse @temp; + + $self->{url_overlay} = $self->overlay(0, 0, $max, scalar( @temp ), urxvt::OVERLAY_RSTYLE, 2); + my $i = 0; + for my $url (@temp) { + $self->{url_overlay}->set( 0, $i, $url, [(urxvt::OVERLAY_RSTYLE) x length $url]); + $self->{showing} = 1; + $i++; + } } @@ -230,9 +232,9 @@ my ($self, $line) = @_; my @urls; for my $matcher (@{$self->{matchers}}) { - while ($line =~ /$matcher->[0]/g) { - push @urls, substr( $line, $-[0], $+[0] - $-[0] ); - } + while ($line =~ /$matcher->[0]/g) { + push @urls, substr( $line, $-[0], $+[0] - $-[0] ); + } } return @urls; } @@ -330,7 +332,7 @@ && join("\x00", @$cmd) eq join("\x00", $self->command_for($row,$col))) { if($self->valid_button($event)) { - $self->exec_async (@$cmd); + $self->exec_async (@$cmd); } }