--- rxvt-unicode/src/urxvt.pm 2012/06/19 18:17:56 1.220 +++ rxvt-unicode/src/urxvt.pm 2013/10/29 14:12:58 1.228 @@ -2,7 +2,7 @@ =head1 NAME -@@RXVT_NAME@@perl - rxvt-unicode's embedded perl interpreter +urxvtperl - rxvt-unicode's embedded perl interpreter =head1 SYNOPSIS @@ -13,9 +13,9 @@ () } - # start a @@RXVT_NAME@@ using it: + # start a urxvt using it: - @@RXVT_NAME@@ --perl-lib $HOME -pe grab_test + urxvt --perl-lib $HOME -pe grab_test =head1 DESCRIPTION @@ -25,7 +25,7 @@ Scripts are compiled in a 'use strict "vars"' and 'use utf8' environment, and thus must be encoded as UTF-8. -Each script will only ever be loaded once, even in @@RXVT_NAME@@d, where +Each script will only ever be loaded once, even in urxvtd, where scripts will be shared (but not enabled) for all terminals. You can disable the embedded perl interpreter by setting both "perl-ext" @@ -34,12 +34,12 @@ =head1 PREPACKAGED EXTENSIONS A number of extensions are delivered with this release. You can find them -in F<@@RXVT_LIBDIR@@/urxvt/perl/>, and the documentation can be viewed -using F<< man urxvt- >>. +in F<< /urxvt/perl/ >>, and the documentation can be viewed using +F<< man urxvt- >>. You can activate them like this: - @@RXVT_NAME@@ -pe + urxvt -pe Or by adding them to the resource for extensions loaded by default: @@ -105,37 +105,8 @@ Although it isn't a C object, you can call all methods of the C class on this object. -It has the following methods and data members: - -=over 4 - -=item $urxvt_term = $self->{term} - -Returns the C object associated with this instance of the -extension. This member I be changed in any way. - -=item $self->enable ($hook_name => $cb[, $hook_name => $cb..]) - -Dynamically enable the given hooks (named without the C prefix) for -this extension, replacing any previous hook. This is useful when you want -to overwrite time-critical hooks only temporarily. - -To install additional callbacks for the same hook, you cna use the C -method of the C class. - -=item $self->disable ($hook_name[, $hook_name..]) - -Dynamically disable the given hooks. - -=item $self->x_resource ($pattern) - -=item $self->x_resource_boolean ($pattern) - -These methods support an additional C<%> prefix when called on an -extension object - see the description of these methods in the -C class for details. - -=back +Additional methods only supported for extension objects are described in +the C section below. =head2 Hooks @@ -316,7 +287,7 @@ Called whenever a user-configured event is being activated (e.g. via a C action bound to a key, see description of the B -resource in the @@RXVT_NAME@@(1) manpage). +resource in the urxvt(1) manpage). The event is simply the action string. This interface is assumed to change slightly in the future. @@ -600,7 +571,7 @@ $term->scan_meta; my $r = $term->{meta}{resource}; - keys %$r; # reste iterator + keys %$r; # reset iterator while (my ($pattern, $v) = each %$r) { if ( $pattern =~ /\.$/ @@ -803,6 +774,73 @@ package urxvt::term::extension; +=head2 The C class + +Each extension attached to a terminal object is represented by +a C object. + +You can use these objects, which are passed to all callbacks to store any +state related to the terminal and extension instance. + +The methods (And data members) documented below can be called on extension +objects, in addition to call methods documented for the +class. + +=over 4 + +=item $urxvt_term = $self->{term} + +Returns the C object associated with this instance of the +extension. This member I be changed in any way. + +=cut + +our $AUTOLOAD; + +sub AUTOLOAD { + $AUTOLOAD =~ /:([^:]+)$/ + or die "FATAL: \$AUTOLOAD '$AUTOLOAD' unparsable"; + + eval qq{ + sub $AUTOLOAD { + my \$proxy = shift; + \$proxy->{term}->$1 (\@_) + } + 1 + } or die "FATAL: unable to compile method forwarder: $@"; + + goto &$AUTOLOAD; +} + +sub DESTROY { + # nop +} + +# urxvt::destroy_hook (basically a cheap Guard:: implementation) + +sub urxvt::destroy_hook::DESTROY { + ${$_[0]}->(); +} + +sub urxvt::destroy_hook(&) { + bless \shift, urxvt::destroy_hook:: +} + +=item $self->enable ($hook_name => $cb[, $hook_name => $cb..]) + +Dynamically enable the given hooks (named without the C prefix) for +this extension, replacing any previous hook. This is useful when you want +to overwrite time-critical hooks only temporarily. + +To install additional callbacks for the same hook, you can use the C +method of the C class. + +=item $self->disable ($hook_name[, $hook_name..]) + +Dynamically disable the given hooks. + +=cut + sub enable { my ($self, %hook) = @_; my $pkg = $self->{_pkg}; @@ -833,37 +871,56 @@ } } -our $AUTOLOAD; +=item $guard = $self->on ($hook_name => $cb[, $hook_name => $cb..]) -sub AUTOLOAD { - $AUTOLOAD =~ /:([^:]+)$/ - or die "FATAL: \$AUTOLOAD '$AUTOLOAD' unparsable"; +Similar to the C enable, but installs additional callbacks for +the given hook(s) (that is, it doesn't replace existing callbacks), and +returns a guard object. When the guard object is destroyed the callbacks +are disabled again. - eval qq{ - sub $AUTOLOAD { - my \$proxy = shift; - \$proxy->{term}->$1 (\@_) - } - 1 - } or die "FATAL: unable to compile method forwarder: $@"; +=cut - goto &$AUTOLOAD; -} +sub urxvt::extension::on_disable::DESTROY { + my $disable = shift; -sub DESTROY { - # nop + my $term = delete $disable->{""}; + + while (my ($htype, $id) = each %$disable) { + delete $term->{_hook}[$htype]{$id}; + $term->set_should_invoke ($htype, -1); + } } -# urxvt::destroy_hook +sub on { + my ($self, %hook) = @_; -sub urxvt::destroy_hook::DESTROY { - ${$_[0]}->(); -} + my $term = $self->{term}; -sub urxvt::destroy_hook(&) { - bless \shift, urxvt::destroy_hook:: + my %disable = ( "" => $term ); + + while (my ($name, $cb) = each %hook) { + my $htype = $HOOKTYPE{uc $name}; + defined $htype + or Carp::croak "unsupported hook type '$name'"; + + $term->set_should_invoke ($htype, +1); + $term->{_hook}[$htype]{ $disable{$htype} = $cb+0 } + = sub { shift; $cb->($self, @_) }; # very ugly indeed + } + + bless \%disable, "urxvt::extension::on_disable" } +=item $self->x_resource ($pattern) + +=item $self->x_resource_boolean ($pattern) + +These methods support an additional C<%> prefix when called on an +extension object - see the description of these methods in the +C class for details. + +=cut + sub x_resource { my ($self, $name) = @_; $name =~ s/^%(\.|$)/$_[0]{_name}$1/; @@ -876,6 +933,10 @@ $self->{term}->x_resource_boolean ($name) } +=back + +=cut + package urxvt::anyevent; =head2 The C Class @@ -1018,8 +1079,7 @@ opendir my $fh, $dir or next; for my $ext (readdir $fh) { - $ext ne "." - and $ext ne ".." + $ext !~ /^\./ and open my $fh, "<", "$dir/$ext" or next; @@ -1068,52 +1128,9 @@ =item $term->destroy Destroy the terminal object (close the window, free resources -etc.). Please note that @@RXVT_NAME@@ will not exit as long as any event +etc.). Please note that urxvt will not exit as long as any event watchers (timers, io watchers) are still active. -=item $guard = $self->on ($hook_name => $cb[, $hook_name => $cb..]) - -Similar to the extension method C, but installs additional -callbacks for the givne hook(s) (existing ones are not replaced), and -returns a guard object. When the guard object is destroyed the callbacks -are disabled again. - -Note that these callbacks receive the normal paramaters, but the first -argument (normally the extension) is currently undefined. - -=cut - -sub urxvt::term::on_disable::DESTROY { - my $disable = shift; - - my $self = delete $disable->{""}; - - while (my ($htype, $id) = each %$disable) { - delete $self->{_hook}[$htype]{$id}; - $self->set_should_invoke ($htype, -1); - } -} - -sub on { - my ($self, %hook) = @_; - - my %disable = ( "" => $self ); - - while (my ($name, $cb) = each %hook) { - my $htype = $HOOKTYPE{uc $name}; - defined $htype - or Carp::croak "unsupported hook type '$name'"; - - my $id = $cb+0; - - $self->set_should_invoke ($htype, +1); - $disable{$htype} = $id; - $self->{_hook}[$htype]{$id} = $cb; - } - - bless \%disable, "urxvt::term::on_disable" -} - =item $term->exec_async ($cmd[, @args]) Works like the combination of the C/C builtins, which executes @@ -1240,7 +1257,7 @@ =item $success = $term->parse_keysym ($key, $octets) Adds a key binding exactly as specified via a resource. See the -C resource in the @@RXVT_NAME@@(1) manpage. +C resource in the urxvt(1) manpage. =item $term->register_command ($keysym, $modifiermask, $string) @@ -1680,11 +1697,10 @@ sub urxvt::line::t { my ($self) = @_; - if (@_ > 1) - { - $self->{term}->ROW_t ($_, $_[1], 0, ($_ - $self->{beg}) * $self->{ncol}, $self->{ncol}) - for $self->{beg} .. $self->{end}; - } + if (@_ > 1) { + $self->{term}->ROW_t ($_, $_[1], 0, ($_ - $self->{beg}) * $self->{ncol}, $self->{ncol}) + for $self->{beg} .. $self->{end}; + } defined wantarray && substr +(join "", map $self->{term}->ROW_t ($_), $self->{beg} .. $self->{end}), @@ -1694,11 +1710,10 @@ sub urxvt::line::r { my ($self) = @_; - if (@_ > 1) - { - $self->{term}->ROW_r ($_, $_[1], 0, ($_ - $self->{beg}) * $self->{ncol}, $self->{ncol}) - for $self->{beg} .. $self->{end}; - } + if (@_ > 1) { + $self->{term}->ROW_r ($_, $_[1], 0, ($_ - $self->{beg}) * $self->{ncol}, $self->{ncol}) + for $self->{beg} .. $self->{end}; + } if (defined wantarray) { my $rend = [