1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | #:META:X_RESOURCE:url-launcher:string:shell command to use |
3 | #:META:RESOURCE:url-launcher:string:shell command to use |
4 | |
4 | |
5 | =head1 NAME |
5 | =head1 NAME |
6 | |
6 | |
7 | selection-popup (enabled by default) |
7 | selection-popup (enabled by default) |
8 | |
8 | |
9 | =head1 DESCRIPTION |
9 | =head1 DESCRIPTION |
10 | |
10 | |
11 | Binds a popup menu to Ctrl-Button3 that lets you convert the selection |
11 | Binds a popup menu to Ctrl-Button3 that lets you paste the X |
12 | text into various other formats/action (such as uri unescaping, perl |
12 | selections and either modify or use the internal selection text in |
|
|
13 | various ways (such as uri unescaping, perl evaluation, web-browser |
13 | evaluation, web-browser starting etc.), depending on content. |
14 | starting etc.), depending on content. |
14 | |
15 | |
15 | Other extensions can extend this popup menu by pushing a code reference |
16 | Other extensions can extend this popup menu by pushing a code reference |
16 | onto C<< @{ $term->{selection_popup_hook} } >>, which gets called whenever |
17 | onto C<< @{ $term->{selection_popup_hook} } >>, which gets called whenever |
17 | the popup is being displayed. |
18 | the popup is being displayed. |
18 | |
19 | |
… | |
… | |
36 | sub msg { |
37 | sub msg { |
37 | my ($self, $msg) = @_; |
38 | my ($self, $msg) = @_; |
38 | |
39 | |
39 | my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1); |
40 | my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1); |
40 | $overlay->set (0, 0, $msg); |
41 | $overlay->set (0, 0, $msg); |
41 | my $iow; $iow = urxvt::timer->new->after (1)->cb (sub { |
42 | $self->{timer} = urxvt::timer->new->after (1)->cb (sub { |
|
|
43 | delete $self->{timer}; |
42 | undef $overlay; |
44 | undef $overlay; |
43 | undef $iow; |
|
|
44 | }); |
45 | }); |
45 | } |
46 | } |
46 | |
47 | |
47 | sub on_start { |
48 | sub on_start { |
48 | my ($self) = @_; |
49 | my ($self) = @_; |
… | |
… | |
59 | |
60 | |
60 | if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) { |
61 | if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) { |
61 | my $popup = $self->popup ($event) |
62 | my $popup = $self->popup ($event) |
62 | or return 1; |
63 | or return 1; |
63 | |
64 | |
64 | $popup->add_title ("Convert Selection"); |
65 | $popup->add_title ("Selection"); |
65 | |
66 | |
66 | my $text = $self->selection; |
67 | my $text = $self->selection; |
67 | |
68 | |
68 | my $title = $text; |
69 | my $title = $text; |
69 | $title =~ s/[\x00-\x1f\x80-\x9f]/·/g; |
70 | $title =~ s/[\x00-\x1f\x80-\x9f]/·/g; |
… | |
… | |
88 | }); |
89 | }); |
89 | }; |
90 | }; |
90 | |
91 | |
91 | for ($text) { |
92 | for ($text) { |
92 | /\n/ |
93 | /\n/ |
|
|
94 | and $add_button->("paste primary selection" => sub { $self->selection_request (urxvt::CurrentTime, 1) }); |
|
|
95 | |
|
|
96 | /./ |
|
|
97 | and $add_button->("paste clipboard selection" => sub { $self->selection_request (urxvt::CurrentTime, 3) }); |
|
|
98 | |
|
|
99 | /./ |
|
|
100 | and $add_button->("copy selection to clipboard" => sub { $self->selection ($self->selection, 1); |
|
|
101 | $self->selection_grab (urxvt::CurrentTime, 1) }); |
|
|
102 | |
|
|
103 | /./ |
93 | and $add_button->("newlines to spaces" => sub { y/\n/ / }); |
104 | and $add_button->("newlines to spaces" => sub { y/\n/ / }); |
94 | |
105 | |
95 | /./ |
106 | /./ |
96 | and $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); |
107 | and $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); |
97 | |
108 | |