--- rxvt-unicode/src/urxvt.pm 2014/12/26 18:58:19 1.246 +++ rxvt-unicode/src/urxvt.pm 2014/12/27 19:27:42 1.252 @@ -47,11 +47,10 @@ Extensions may add additional resources and C, i.e., methods which can be bound to a key and invoked by the user. An extension can -define the resources it support and also default bindings for one or -more actions it provides using so called META comments, described -below. Similarly to builtin resources, extension resources can also be -specified on the command line as long options (with C<.> replaced by -C<->), in which case the corresponding extension is loaded +define the resources it support using so called META comments, +described below. Similarly to builtin resources, extension resources +can also be specified on the command line as long options (with C<.> +replaced by C<->), in which case the corresponding extension is loaded automatically. For this to work the extension B define META comments for its resources. @@ -117,8 +116,10 @@ =head2 META comments -rxvt-unicode recognizes special comments in extensions that define -different types of metadata: +Rxvt-unicode recognizes special meta comments in extensions that define +different types of metadata. + +Currently, it recognises only one such comment: =over 4 @@ -128,14 +129,6 @@ C is the resource name, C is the resource type, C or C, and C is the resource description. -=item #:META:BINDING:sym:action - -The BINDING comment defines a default binding for an action provided -by the extension, where C is the key combination that triggers -the action, whose format is defined in the description of the -B resource in the urxvt(1) manpage, and C is the name -of the action method. - =back =head2 Hooks @@ -723,9 +716,7 @@ if ($_ eq "default") { $ext_arg{$_} = [] - for - qw(selection option-popup selection-popup readline searchable-scrollback), - map $_->[0], values %{ $TERM->{meta}{binding} }; + for qw(selection option-popup selection-popup readline searchable-scrollback); for ($TERM->_keysym_resources) { next if /^(?:string|command|builtin|builtin-string|perl)/; @@ -747,13 +738,6 @@ } } - # now register default key bindings - for my $ext (sort keys %ext_arg) { - while (my ($k, $v) = each %{ $TERM->{meta}{ext}{$ext}{binding} }) { - $TERM->bind_action ($k, "$v->[0]:$v->[1]"); - } - } - for my $ext (sort keys %ext_arg) { my @files = grep -f $_, map "$_/$ext", @dirs; @@ -983,16 +967,25 @@ bless \%disable, "urxvt::extension::on_disable" } +=item $self->bind_action ($hotkey, $action) + =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. +These methods support an additional C<%> prefix for C<$action> or +C<$pattern> when called on an extension object, compared to the +C methods of the same name - see the description of these +methods in the C class for details. =cut +sub bind_action { + my ($self, $hotkey, $action) = @_; + $action =~ s/^%:/$_[0]{_name}:/; + $self->{term}->bind_action ($hotkey, $action) +} + sub x_resource { my ($self, $name) = @_; $name =~ s/^%(\.|$)/$_[0]{_name}$1/; @@ -1142,20 +1135,30 @@ return if exists $self->{meta}; - my @libdirs = perl_libdirs $self; + my @urxvtdirs = perl_libdirs $self; +# my @cpandirs = grep -d, map "$_/URxvt/Ext", @INC; -# return if $self->{meta_libdirs} eq join "\x00", @libdirs;#d# - -# $self->{meta_libdirs} = join "\x00", @libdirs;#d# $self->{meta} = \my %meta; # first gather extensions - for my $dir (reverse @libdirs) { + + my $gather = sub { + my ($dir, $core) = @_; + opendir my $fh, $dir - or next; + or return; + for my $ext (readdir $fh) { $ext !~ /^\./ - and open my $fh, "<", "$dir/$ext" + or next; + + open my $fh, "<", "$dir/$ext" + or next; + + -f $fh + or next; + + $ext =~ s/\.uext$// or $core or next; my %ext = (dir => $dir); @@ -1169,9 +1172,6 @@ } else { $ext{resource}{$pattern} = [$ext, $type, $desc]; } - } elsif (/^#:META:BINDING:(.*)/) { - my ($keysym, $action) = split /:/, $1; - $ext{binding}{$keysym} = [$ext, $action]; } elsif (/^\s*(?:#|$)/) { # skip other comments and empty lines } else { @@ -1181,13 +1181,18 @@ $meta{ext}{$ext} = \%ext; } - } + }; + +# $gather->($_, 0) for @cpandirs; + $gather->($_, 1) for @urxvtdirs; + + # and now merge resources + + $meta{resource} = \my %resource; - # and now merge resources and bindings while (my ($k, $v) = each %{ $meta{ext} }) { #TODO: should check for extensions overriding each other - %{ $meta{resource} } = (%{ $meta{resource} }, %{ $v->{resource} }); - %{ $meta{binding} } = (%{ $meta{binding} }, %{ $v->{binding} }); + %resource = (%resource, %{ $v->{resource} }); } } @@ -1343,11 +1348,26 @@ $res =~ /^\s*(?:true|yes|on|1)\s*$/i ? 1 : defined $res && 0 } -=item $success = $term->bind_action ($key, $octets) +=item $success = $term->bind_action ($key, $action) Adds a key binding exactly as specified via a C resource. See the C resource in the urxvt(1) manpage. +To add default bindings for actions, an extension should call C<< +->bind_action >> in its C hook for every such binding. Doing it +in the C hook allows users to override or remove the binding +again. + +Example: the C by default binds itself +on C, using C<< $self->bind_action >>, which calls C<< +$term->bind_action >>. + + sub init { + my ($self) = @_; + + $self->bind_action ("M-s" => "%:start"); + } + =item $rend = $term->rstyle ([$new_rstyle]) Return and optionally change the current rendition. Text that is output by