… | |
… | |
196 | relevant action might not be carried out by the C++ code. |
196 | relevant action might not be carried out by the C++ code. |
197 | |
197 | |
198 | I<< When in doubt, return a false value (preferably C<()>). >> |
198 | I<< When in doubt, return a false value (preferably C<()>). >> |
199 | |
199 | |
200 | =over |
200 | =over |
|
|
201 | |
|
|
202 | =item on_attach $term |
|
|
203 | |
|
|
204 | Called when an extension package is attached to a running terminal |
|
|
205 | instance. Must return true in all cases, and runs with the same |
|
|
206 | limitations as C<on_init>. |
|
|
207 | |
|
|
208 | Unlike C<on_init> or C<on_start>, this is called when the extension is |
|
|
209 | attached to a terminal, regardless of whether the extension is loaded |
|
|
210 | before or after the terminal is started. Extensions that need to do |
|
|
211 | something before they work can do it in this callback, as opposed to e.g. |
|
|
212 | C<on_init>, which might not be called. |
201 | |
213 | |
202 | =item on_init $term |
214 | =item on_init $term |
203 | |
215 | |
204 | Called after a new terminal object has been initialized, but before |
216 | Called after a new terminal object has been initialized, but before |
205 | windows are created or the command gets run. Most methods are unsafe to |
217 | windows are created or the command gets run. Most methods are unsafe to |
… | |
… | |
1180 | # find on_xxx subs in the package and register them |
1192 | # find on_xxx subs in the package and register them |
1181 | # as hooks |
1193 | # as hooks |
1182 | sub register_package { |
1194 | sub register_package { |
1183 | my ($self, $pkg, $argv) = @_; |
1195 | my ($self, $pkg, $argv) = @_; |
1184 | |
1196 | |
|
|
1197 | return if $self->{_pkg}{$pkg}; |
|
|
1198 | |
1185 | no strict 'refs'; |
1199 | no strict 'refs'; |
1186 | |
1200 | |
1187 | urxvt::verbose 6, "register package $pkg to $self"; |
1201 | urxvt::verbose 6, "register package $pkg to $self"; |
1188 | |
1202 | |
1189 | @{"$pkg\::ISA"} = urxvt::term::extension::; |
1203 | @{"$pkg\::ISA"} = urxvt::term::extension::; |
… | |
… | |
1199 | |
1213 | |
1200 | for my $name (@HOOKNAME) { |
1214 | for my $name (@HOOKNAME) { |
1201 | if (my $ref = $pkg->can ("on_" . lc $name)) { |
1215 | if (my $ref = $pkg->can ("on_" . lc $name)) { |
1202 | $proxy->enable ($name => $ref); |
1216 | $proxy->enable ($name => $ref); |
1203 | } |
1217 | } |
|
|
1218 | } |
|
|
1219 | |
|
|
1220 | if (my $attach_hook = $pkg->can ("on_attach")) { |
|
|
1221 | $attach_hook->($proxy) |
|
|
1222 | or urxvt::verbose 1, "$pkg->on_attach returned false, extension failed to attach"; |
1204 | } |
1223 | } |
1205 | } |
1224 | } |
1206 | |
1225 | |
1207 | # map extension name to filesystem path |
1226 | # map extension name to filesystem path |
1208 | sub extension_path { |
1227 | sub extension_path { |