summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Inkster <mail@tobyinkster.co.uk>2013-06-28 10:13:04 +0100
committerJesse Luehrs <doy@tozt.net>2013-06-28 10:39:12 -0400
commitbe18d16c78830d9fe69ed2d26f73f94cca03c956 (patch)
tree497b3bb164260427351c56ae20df75c573e1beb0
parent3c80d9cb9c7c095b7d176a3dd225083f0e9706fb (diff)
downloadreply-be18d16c78830d9fe69ed2d26f73f94cca03c956.tar.gz
reply-be18d16c78830d9fe69ed2d26f73f94cca03c956.zip
autocomplete for function names
-rw-r--r--lib/Reply/Plugin/Autocomplete/Functions.pm48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/Reply/Plugin/Autocomplete/Functions.pm b/lib/Reply/Plugin/Autocomplete/Functions.pm
new file mode 100644
index 0000000..b5690d4
--- /dev/null
+++ b/lib/Reply/Plugin/Autocomplete/Functions.pm
@@ -0,0 +1,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;