1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | #:META:X_RESOURCE:url-launcher:string:shell command to use |
|
|
4 | |
|
|
5 | =head1 NAME |
|
|
6 | |
|
|
7 | selection-popup (enabled by default) |
|
|
8 | |
|
|
9 | =head1 DESCRIPTION |
|
|
10 | |
|
|
11 | Binds a popup menu to Ctrl-Button3 that lets you convert the selection |
|
|
12 | text into various other formats/action (such as uri unescaping, perl |
|
|
13 | evaluation, web-browser starting etc.), depending on content. |
|
|
14 | |
|
|
15 | Other extensions can extend this popup menu by pushing a code reference |
|
|
16 | onto C<< @{ $term->{selection_popup_hook} } >>, which gets called whenever |
|
|
17 | the popup is being displayed. |
|
|
18 | |
|
|
19 | Its sole argument is the popup menu, which can be modified. The selection |
|
|
20 | is in C<$_>, which can be used to decide whether to add something or not. |
|
|
21 | It should either return nothing or a string and a code reference. The |
|
|
22 | string will be used as button text and the code reference will be called |
|
|
23 | when the button gets activated and should transform C<$_>. |
|
|
24 | |
|
|
25 | The following will add an entry C<a to b> that transforms all C<a>s in |
|
|
26 | the selection to C<b>s, but only if the selection currently contains any |
|
|
27 | C<a>s: |
|
|
28 | |
|
|
29 | push @{ $self->{term}{selection_popup_hook} }, sub { |
|
|
30 | /a/ ? ("a to b" => sub { s/a/b/g } |
|
|
31 | : () |
|
|
32 | }; |
|
|
33 | |
|
|
34 | =cut |
2 | |
35 | |
3 | sub msg { |
36 | sub msg { |
4 | my ($self, $msg) = @_; |
37 | my ($self, $msg) = @_; |
5 | |
38 | |
6 | my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1); |
39 | my $overlay = $self->overlay (0, 0, $self->strwidth ($msg), 1); |
… | |
… | |
12 | } |
45 | } |
13 | |
46 | |
14 | sub on_start { |
47 | sub on_start { |
15 | my ($self) = @_; |
48 | my ($self) = @_; |
16 | |
49 | |
17 | $self->{browser} = $self->x_resource ("urlLauncher") || "sensible-browser"; |
50 | $self->{browser} = $self->x_resource ("url-launcher") || "sensible-browser"; |
18 | |
51 | |
19 | $self->grab_button (3, urxvt::ControlMask); |
52 | $self->grab_button (3, urxvt::ControlMask); |
20 | |
53 | |
21 | () |
54 | () |
22 | } |
55 | } |
… | |
… | |
61 | |
94 | |
62 | /./ |
95 | /./ |
63 | and $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); |
96 | and $add_button->("rot13" => sub { y/A-Za-z/N-ZA-Mn-za-m/ }); |
64 | |
97 | |
65 | /./ |
98 | /./ |
66 | and $add_button->("eval perl expression" => sub { no warnings; $_ = eval $_ }); |
99 | and $add_button->("eval perl expression" => sub { my $self = $self; no warnings; $_ = eval $_; $_ = "$@" if $@ }); |
67 | |
100 | |
68 | /./ |
101 | /./ |
69 | and $add_button->((sprintf "to unicode hex index (%x)", ord) => sub { $_ = sprintf "%x", ord }); |
102 | and $add_button->((sprintf "to unicode hex index (%x)", ord) => sub { $_ = sprintf "%x", ord }); |
70 | |
103 | |
71 | /(\S+):(\d+):?/ |
104 | /(\S+):(\d+):?/ |