my $pastebin_cmd;
my $pastebin_url;
-sub on_start {
- my ($self) = @_;
- $pastebin_cmd =
- $self->x_resource ("selection-pastebin.cmd")
- or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
-
- $pastebin_url =
- $self->x_resource ("selection-pastebin.url")
- or "http://www.ta-sa.org/files/txt/";
-
- ()
-}
-
sub upload_paste {
my ($self) = @_;
->cb (sub { delete $timers->{ov}; delete $timers->{t1}; });
}
+sub on_start {
+ my ($self) = @_;
+ $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd")
+ || "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
+
+ $pastebin_url = $self->x_resource ("selection-pastebin.url")
+ || "http://www.ta-sa.org/files/txt/%";
+
+ push @urxvt::ext::selection_popup::hook, sub {
+ ("pastebin upload" => sub { $self->upload_paste })
+ };
+
+ ()
+}
+
sub on_keyboard_command {
my ($self, $cmd) = @_;
- $cmd eq "selection-pastebin:remote-pastebin"
- and upload_paste ($self);
+ if ($cmd eq "selection-pastebin:remote-pastebin") {
+ $self->upload_paste;
+ }
()
}
()
}
+our @hook;
+
sub on_button_press {
my ($self, $event) = @_;
/^(http|ftp|telnet|irc|news):\//
and $add_button->("run $self->{browser}" => sub { urxvt::exec_async $self->{browser}, $_ });
+ for my $hook (@hook) {
+ if (my ($title, $cb) = $hook->($popup)) {
+ $add_button->($title, $cb);
+ }
+ }
+
if (/^\s*((?:0x)?\d+)\s*$/) {
$popup->add_title (sprintf "%20s", eval $1);
$popup->add_title (sprintf "%20s", sprintf "0x%x", eval $1);
text into various other formats/action (such as uri unescaping, perl
evalution, web-browser starting etc.), depending on content.
+Other extensions can extend this popup menu by pushing a code reference onto
+C<@urxvt::ext::selection_popup::hook>, that is called whenever the popup is displayed.
+
+It's sole argument is the popup menu, which can be modified. The selection
+is in C<$_>, which can be used to decide wether to add something or not.
+It should either return nothing or a string and a code reference. The
+string will be used as button text and the code reference will be called
+when the button gets activated and should transform C<$_>.
+
+The following will add an entry C<a to b> that transforms all C<a>s in
+the selection to C<b>s, but only if the selection currently contains any
+C<a>s:
+
+ push urxvt::ext::selection_popup::hook, sub {
+ /a/ ? ("a to be" => sub { s/a/b/g }
+ : ()
+ };
+
=item searchable-scrollback<hotkey> (enabled by default)
Adds regex search functionality to the scrollback buffer, triggered