--- rxvt-unicode/src/urxvt.pm 2006/01/19 16:07:09 1.109 +++ rxvt-unicode/src/urxvt.pm 2006/01/20 10:27:08 1.113 @@ -37,6 +37,10 @@ @@RXVT_NAME@@ -pe +Or by adding them to the resource for extensions loaded by default: + + URxvt.perl-ext-common: default,automove-background,selection-autotransform + =over 4 =item selection (enabled by default) @@ -91,8 +95,9 @@ 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. +Other extensions can extend this popup menu by pushing a code reference +onto C<@{ $term->{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. @@ -104,14 +109,11 @@ the selection to Cs, but only if the selection currently contains any Cs: - push urxvt::ext::selection_popup::hook, sub { + push @{ $self->{term}{selection_popup_hook} }, sub { /a/ ? ("a to be" => sub { s/a/b/g } : () }; -Don't run it in a hook, otherwise the menu will grow and grow. Instead put -it at the toplevel of your extension. - =item searchable-scrollback (enabled by default) Adds regex search functionality to the scrollback buffer, triggered @@ -303,9 +305,9 @@ The first argument passed to them is an extension oject as described in the in the C section. -B of these hooks must return a boolean value. If it is true, then the -event counts as being I, and the invocation of other hooks is -skipped, and the relevant action might not be carried out by the C++ code. +B of these hooks must return a boolean value. If any of the called +hooks returns true, then the event counts as being I, and the +relevant action might not be carried out by the C++ code. I<< When in doubt, return a false value (preferably C<()>). >> @@ -316,8 +318,20 @@ Called after a new terminal object has been initialized, but before windows are created or the command gets run. Most methods are unsafe to call or deliver senseless data, as terminal size and other characteristics -have not yet been determined. You can safely query and change resources, -though. +have not yet been determined. You can safely query and change resources +and options, though. For many purposes the C hook is a better +place. + +=item on_start $term + +Called at the very end of initialisation of a new terminal, just before +trying to map (display) the toplevel and returning to the mainloop. + +=item on_destroy $term + +Called whenever something tries to destroy terminal, before doing anything +yet. If this hook returns true, then destruction is skipped, but this is +rarely a good idea. =item on_reset $term @@ -325,11 +339,6 @@ control sequences. Here is where you can react on changes to size-related variables. -=item on_start $term - -Called at the very end of initialisation of a new terminal, just before -returning to the mainloop. - =item on_child_start $term, $pid Called just after the child process has been Ced. @@ -498,6 +507,8 @@ our $VERSION = 1; our $TERM; +our @TERM_INIT; +our @TERM_EXT; our @HOOKNAME; our %HOOKTYPE = map +($HOOKNAME[$_] => $_), 0..$#HOOKNAME; our %OPTION; @@ -529,6 +540,22 @@ The current terminal. This variable stores the current C object, whenever a callback/hook is executing. +=item @urxvt::TERM_INIT + +All coderefs in this array will be called as methods of the next newly +created C object (during the C phase). The array +gets cleared before the codereferences that were in it are being executed, +so coderefs can push themselves onto it again if they so desire. + +This complements to the perl-eval commandline option, but gets executed +first. + +=item @urxvt::TERM_EXT + +Works similar to C<@TERM_INIT>, but contains perl package/class names, which +get registered as normal extensions after calling the hooks in C<@TERM_INIT> +but before other extensions. Gets cleared just like C<@TERM_INIT>. + =back =head2 Functions in the C Package @@ -659,8 +686,6 @@ sub extension_package($) { my ($path) = @_; - no strict 'refs'; - $extension_pkg{$path} ||= do { $path =~ /([^\/\\]+)$/; my $pkg = $1; @@ -672,8 +697,6 @@ open my $fh, "<:raw", $path or die "$path: $!"; - @{"$pkg\::ISA"} = urxvt::term::extension::; - my $source = "package $pkg; use strict; use utf8;\n" . "#line 1 \"$path\"\n{\n" @@ -699,7 +722,16 @@ my %ext_arg; - for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { + { + my @init = @TERM_INIT; + @TERM_INIT = (); + $_->($TERM) for @init; + my @pkg = @TERM_EXT; + @TERM_EXT = (); + $TERM->register_package ($_) for @pkg; + } + + for (grep $_, map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { if ($_ eq "default") { $ext_arg{$_} ||= [] for qw(selection option-popup selection-popup searchable-scrollback); } elsif (/^-(.*)$/) { @@ -734,8 +766,8 @@ keys %$cb; while (my ($pkg, $cb) = each %$cb) { - $retval = eval { $cb->($TERM->{_pkg}{$pkg}, @_) } - and last; + my $retval_ = eval { $cb->($TERM->{_pkg}{$pkg}, @_) }; + $retval ||= $retval_; if ($@) { $TERM->ungrab; # better to lose the grab than the session @@ -904,6 +936,12 @@ sub register_package { my ($self, $pkg, $argv) = @_; + no strict 'refs'; + + urxvt::verbose 6, "register package $pkg to $self"; + + @{"$pkg\::ISA"} = urxvt::term::extension::; + my $proxy = bless { _pkg => $pkg, argv => $argv, @@ -1639,6 +1677,15 @@ =back +=cut + +package urxvt::watcher; + +@urxvt::timer::ISA = __PACKAGE__; +@urxvt::iow::ISA = __PACKAGE__; +@urxvt::pw::ISA = __PACKAGE__; +@urxvt::iw::ISA = __PACKAGE__; + =head2 The C Class This class implements timer watchers/events. Time is represented as a