blob: b5690d45ea99df1856aef066cfc5dd08c44d1812 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package Reply::Plugin::Autocomplete::Functions;
use strict;
use warnings;
# ABSTRACT: tab completion for function names
use base 'Reply::Plugin';
use Module::Runtime '$module_name_rx';
use Package::Stash;
=head1 SYNOPSIS
; .replyrc
[ReadLine]
[Autocomplete::Functions]
=head1 DESCRIPTION
This plugin registers a tab key handler to autocomplete function names in Perl
code, including imported functions.
=cut
sub tab_handler {
my $self = shift;
my ($line) = @_;
my ($before, $fragment) = $line =~ /(.*?)(${module_name_rx}(::)?)$/;
return unless $fragment;
my ($package, $func) = ($fragment =~ /^(.+:)(\w+)$/);
$func = '' unless defined $func;
$package = $self->{'package'} unless $package;
$package =~ s/::$//;
return
map { $package eq $self->{'package'} ? $_ : "$package\::$_" }
grep { /^\Q$func/ }
'Package::Stash'->new($package)->list_all_symbols('CODE');
}
sub package {
my $self = shift;
my ($pkg) = @_;
$self->{'package'} = $pkg;
}
1;
|