Merge remote-tracking branch 'vifon/master'

Conflicts:
	url-select
This commit is contained in:
Bert Münnich 2012-08-16 11:29:48 +02:00
commit 53cbf53540
2 changed files with 31 additions and 10 deletions

View File

@ -64,6 +64,8 @@ Options:
URxvt.urlLauncher: browser/command to open selected URL with
URxvt.underlineURLs: if set to true, all URLs get underlined
URvxt.urlButton: mouse button to click-open URLs (default: 2)
URxvt.autoCopyURLs: If set to true, selected URLs are automaticaly copied
to the PRIMARY clipboard
For compatibility reasons, url-select will also use any patterns defined for
the matcher extension by reading all `URxvt.matcher.pattern.[0-9]` resources.

39
url-select Normal file → Executable file
View File

@ -24,7 +24,8 @@
# URxvt.urlLauncher: Browser/command to open selected URL with
# URxvt.underlineURLs: If set to true, all URLs get underlined
# URvxt.urlButton: Mouse button to click-open URLs (default: 2)
# URxvt.autoCopyURLs: If set to true, selected URLs are copied
# to the PRIMARY clipboard
use strict;
@ -40,7 +41,10 @@ sub on_start {
if ($self->x_resource('underlineURLs') eq 'true') {
$self->enable(line_update => \&line_update);
}
if ($self->x_resource('urlButton') =~ /^\d+$/) {
if ($self->x_resource('autoCopyURLs') eq 'true') {
$self->{copy} = 1;
}
if($self->x_resource('urlButton') =~ /^\d+$/) {
$self->{button} = $self->x_resource('urlButton');
} elsif ($self->x_resource('matcher.button') =~ /^\d+$/) {
$self->{button} = $self->x_resource('matcher.button');
@ -124,17 +128,17 @@ sub key_press {
$self->selection_end(1, 0);
deactivate($self);
} elsif ($char eq 'k' || $keysym == 0xff52 || $keysym == 0xff51) {
select_next($self, -1);
select_next($self, -1, $event);
} elsif ($char eq 'j' || $keysym == 0xff54 || $keysym == 0xff53) {
select_next($self, 1);
select_next($self, 1, $event);
} elsif ($char eq 'g' || $keysym == 0xff50) {
$self->{row} = $self->top_row - 1;
delete $self->{found};
select_next($self, 1);
select_next($self, 1, $event);
} elsif ($char eq 'G' || $keysym == 0xff57) {
$self->{row} = $self->nrow;
delete $self->{found};
select_next($self, -1);
select_next($self, -1, $event);
}
return 1;
@ -189,7 +193,7 @@ sub on_button_release {
sub select_next {
# $dir < 0: up, > 0: down
my ($self, $dir) = @_;
my ($self, $dir, $event) = @_;
my $row = $self->{row};
if (($dir < 0 && $self->{n} > 0) ||
@ -197,11 +201,19 @@ sub select_next {
# another url on current line
$self->{n} += $dir;
hilight($self);
if ($self->{copy}) {
my $found = $self->{found}[$self->{n}];
$self->selection_beg(${$found}[0], ${$found}[1]);
$self->selection_end(${$found}[2], ${$found}[3]);
$self->selection_make($event->{time});
$self->selection_beg(1, 0);
$self->selection_end(1, 0);
}
return;
}
while (($dir < 0 && $row > $self->top_row) ||
($dir > 0 && $row < $self->nrow - 1)) {
($dir > 0 && $row < $self->nrow - 1)) {
my $line = $self->line($row);
$row = ($dir < 0 ? $line->beg : $line->end) + $dir;
$line = $self->line($row);
@ -221,11 +233,19 @@ sub select_next {
$self->{row} = $row;
$self->{n} = $dir < 0 ? $#{$self->{found}} : 0;
hilight($self);
if ($self->{copy}) {
my $found = $self->{found}[$self->{n}];
$self->selection_beg(${$found}[0], ${$found}[1]);
$self->selection_end(${$found}[2], ${$found}[3]);
$self->selection_make($event->{time});
$self->selection_beg(1, 0);
$self->selection_end(1, 0);
}
return;
}
}
}
deactivate($self) unless $self->{found};
()
@ -341,4 +361,3 @@ sub deactivate {
()
}