*** empty log message ***
authorroot <root>
Wed, 18 Jan 2006 10:11:03 +0000 (10:11 +0000)
committerroot <root>
Wed, 18 Jan 2006 10:11:03 +0000 (10:11 +0000)
src/perl/selection-pastebin
src/perl/selection-popup
src/urxvt.pm

index 64f4a3193a39417dd12b8bc387cc9718d2efd1cb..731dcff524e3f65ebb40e57ffc6389abfe6b9f2c 100644 (file)
@@ -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;
+   }
 
    ()
 }
index c50d520ca80363bf568b017684f8798a844128ca..24c08eff9ad4eeffceb9948ed6fed7050d07138c 100644 (file)
@@ -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);
index 0a32ee5217fc05c2ef6e8a2f70fa83f197d8aced..f332a1307d85af31c06189950e2c9dd101ed0cb9 100644 (file)
@@ -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<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