Skip to content

Commit

Permalink
Prevent #edit in edited file from triggering edit action
Browse files Browse the repository at this point in the history
  • Loading branch information
hoelzro committed Sep 9, 2014
1 parent 7f09948 commit 658db61
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/Devel/REPL/Plugin/Editor.pm
Expand Up @@ -8,6 +8,11 @@ use File::Temp ();

use namespace::clean -except => 'meta';

has evaluating_file_contents => (
is => 'rw',
default => 0,
);

sub command_edit {
my ( $self, undef, $filename ) = @_;

Expand Down Expand Up @@ -39,13 +44,30 @@ sub command_edit {
$self->term->addhistory($pristine_code);
}

return $self->formatted_eval($code);
$self->evaluating_file_contents(1);
my @result = $self->formatted_eval($code);
$self->evaluating_file_contents(0);
return @result;
}

sub dont_allow_edit_in_file {
my ( $self, $line ) = @_;

my $prefix = $self->default_command_prefix;

if($self->evaluating_file_contents && $line =~ /^${prefix}edit/) {
return {}; # this will be processed by Turtles' formatted_eval, which
# should ignore it
}

return;
}

sub BEFORE_PLUGIN {
my ( $repl ) = @_;

$repl->load_plugin('Turtles');
$repl->add_turtles_matcher(sub { $repl->dont_allow_edit_in_file(@_) });
}

1;
Expand Down

0 comments on commit 658db61

Please sign in to comment.