From b81a14ab60afa01a8464e410cd4ba36d4f410960 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 18 Jan 2006 10:11:03 +0000 Subject: [PATCH] *** empty log message *** --- src/perl/selection-pastebin | 33 ++++++++++++++++++--------------- src/perl/selection-popup | 8 ++++++++ src/urxvt.pm | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/perl/selection-pastebin b/src/perl/selection-pastebin index 64f4a319..731dcff5 100644 --- a/src/perl/selection-pastebin +++ b/src/perl/selection-pastebin @@ -4,19 +4,6 @@ my $timers = {}; 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) = @_; @@ -61,11 +48,27 @@ sub upload_paste { ->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; + } () } diff --git a/src/perl/selection-popup b/src/perl/selection-popup index c50d520c..24c08eff 100644 --- a/src/perl/selection-popup +++ b/src/perl/selection-popup @@ -21,6 +21,8 @@ sub on_start { () } +our @hook; + sub on_button_press { my ($self, $event) = @_; @@ -71,6 +73,12 @@ sub on_button_press { /^(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); diff --git a/src/urxvt.pm b/src/urxvt.pm index 0a32ee52..f332a130 100644 --- a/src/urxvt.pm +++ b/src/urxvt.pm @@ -91,6 +91,24 @@ Binds a popup menu to Ctrl-Button3 that lets you convert the selection 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 that transforms all Cs in +the selection to Cs, but only if the selection currently contains any +Cs: + + push urxvt::ext::selection_popup::hook, sub { + /a/ ? ("a to be" => sub { s/a/b/g } + : () + }; + =item searchable-scrollback (enabled by default) Adds regex search functionality to the scrollback buffer, triggered -- 2.34.1