From: Chris Marshall Date: Sun, 13 Jun 2010 18:15:32 +0000 (-0400) Subject: Default for Completion is *no* filename completion X-Git-Tag: v1.003015~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=commitdiff_plain;h=fd81abf13426f0eea8915247e7909d20a4f98661 Default for Completion is *no* filename completion The default for the Completion plugin is now to specifically disable the standard Term::ReadLine::Gnu and Term::ReadLine::Perl filename expansion when it is loaded. A new attribute do_readline_filename_completion is available to re-enable the Term::ReadLine functionality. --- diff --git a/lib/Devel/REPL/Plugin/Completion.pm b/lib/Devel/REPL/Plugin/Completion.pm index 91424ae..1e2b09a 100644 --- a/lib/Devel/REPL/Plugin/Completion.pm +++ b/lib/Devel/REPL/Plugin/Completion.pm @@ -5,48 +5,55 @@ use PPI; use namespace::clean -except => [ 'meta' ]; has current_matches => ( - is => 'rw', - isa => 'ArrayRef', - lazy => 1, - default => sub { [] }, + is => 'rw', + isa => 'ArrayRef', + lazy => 1, + default => sub { [] }, ); has match_index => ( - is => 'rw', - isa => 'Int', - lazy => 1, - default => sub { 0 }, + is => 'rw', + isa => 'Int', + lazy => 1, + default => sub { 0 }, ); has no_term_class_warning => ( - isa => "Bool", - is => "rw", - default => 0, + isa => "Bool", + is => "rw", + default => 0, +); + +has do_readline_filename_completion => ( # so default is no if Completion loaded + isa => "Bool", + is => "rw", + lazy => 1, + default => sub { 0 }, ); before 'read' => sub { - my ($self) = @_; + my ($self) = @_; - if ((!$self->term->isa("Term::ReadLine::Gnu") and !$self->term->isa("Term::ReadLine::Perl")) - and !$self->no_term_class_warning) { - warn "Term::ReadLine::Gnu or Term::ReadLine::Perl is required for the Completion plugin to work"; - $self->no_term_class_warning(1); - } + if ((!$self->term->isa("Term::ReadLine::Gnu") and !$self->term->isa("Term::ReadLine::Perl")) + and !$self->no_term_class_warning) { + warn "Term::ReadLine::Gnu or Term::ReadLine::Perl is required for the Completion plugin to work"; + $self->no_term_class_warning(1); + } - my $weakself = $self; - weaken($weakself); + my $weakself = $self; + weaken($weakself); - if ($self->term->isa("Term::ReadLine::Gnu")) { - $self->term->Attribs->{attempted_completion_function} = sub { - $weakself->_completion(@_); - }; - } + if ($self->term->isa("Term::ReadLine::Gnu")) { + $self->term->Attribs->{attempted_completion_function} = sub { + $weakself->_completion(@_); + }; + } - if ($self->term->isa("Term::ReadLine::Perl")) { - $self->term->Attribs->{completion_function} = sub { - $weakself->_completion(@_); - }; - } + if ($self->term->isa("Term::ReadLine::Perl")) { + $self->term->Attribs->{completion_function} = sub { + $weakself->_completion(@_); + }; + } }; @@ -72,9 +79,10 @@ sub _completion { if (scalar(@matches)) { return @matches; } else { - return readline::rl_filename_list($text); + return ($self->do_readline_filename_completion) ? readline::rl_filename_list($text) : () ; } } else { + $self->term->Attribs->{attempted_completion_over} = 1 unless $self->do_readline_filename_completion; if (scalar(@matches)) { return $self->term->completion_matches($text, sub { my ($text, $state) = @_; @@ -90,25 +98,24 @@ sub _completion { return $self->current_matches->[$self->match_index]; }); } else { - # fall back to filename completion for Term::ReadLine::Gnu return; } } } sub complete { - return (); + return (); } # recursively find the last element sub last_ppi_element { - my ($self, $document, $type) = @_; - my $last = $document; - while ($last->can('last_element') && defined($last->last_element)) { - $last = $last->last_element; - return $last if $type && $last->isa($type); - } - return $last; + my ($self, $document, $type) = @_; + my $last = $document; + while ($last->can('last_element') && defined($last->last_element)) { + $last = $last->last_element; + return $last if $type && $last->isa($type); + } + return $last; } 1;