From 52f7260090ae8875103107832f418890c11359d4 Mon Sep 17 00:00:00 2001 From: Robert Gleeson Date: Mon, 20 Jan 2014 09:08:38 +0100 Subject: [PATCH] add Pry.config.file_completer, Pry.config.command_completer --- lib/pry.rb | 1 - lib/pry/commands/shell_mode.rb | 4 ++-- lib/pry/config/default.rb | 2 ++ lib/pry/custom_completions.rb | 6 ------ lib/pry/pry_class.rb | 1 - lib/pry/pry_instance.rb | 6 +++--- 6 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 lib/pry/custom_completions.rb diff --git a/lib/pry.rb b/lib/pry.rb index 8ba3f954..2edec674 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -177,7 +177,6 @@ require 'pry/history' require 'pry/command' require 'pry/command_set' require 'pry/commands' -require 'pry/custom_completions' require 'pry/completion' require 'pry/plugins' require 'pry/core_extensions' diff --git a/lib/pry/commands/shell_mode.rb b/lib/pry/commands/shell_mode.rb index db5e69fa..64db7668 100644 --- a/lib/pry/commands/shell_mode.rb +++ b/lib/pry/commands/shell_mode.rb @@ -12,10 +12,10 @@ class Pry case _pry_.prompt when Pry::SHELL_PROMPT _pry_.pop_prompt - _pry_.custom_completions = Pry::DEFAULT_CUSTOM_COMPLETIONS + _pry_.custom_completions = _pry_.config.file_completer else _pry_.push_prompt Pry::SHELL_PROMPT - _pry_.custom_completions = Pry::FILE_COMPLETIONS + _pry_.custom_completions = _pry_.config.command_completer end end end diff --git a/lib/pry/config/default.rb b/lib/pry/config/default.rb index d944a39d..40b92ac4 100644 --- a/lib/pry/config/default.rb +++ b/lib/pry/config/default.rb @@ -31,6 +31,8 @@ class Pry::Config::Default < Pry::Config :control_d_handler => proc { Pry::DEFAULT_CONTROL_D_HANDLER }, :memory_size => proc { 100 }, :extra_sticky_locals => proc { {} }, + :command_completer => proc { Pry.commands.commands.keys }, + :file_completer => proc { Dir["."] }, :completer => proc { if defined?(Bond) && Readline::VERSION !~ /editline/i Pry::BondCompleter.start diff --git a/lib/pry/custom_completions.rb b/lib/pry/custom_completions.rb deleted file mode 100644 index 7a2bb7a8..00000000 --- a/lib/pry/custom_completions.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Pry - - # This proc will be instance_eval's against the active Pry instance - DEFAULT_CUSTOM_COMPLETIONS = proc { commands.commands.keys } - FILE_COMPLETIONS = proc { commands.commands.keys + Dir.entries('.') } -end diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 28721b72..60399cac 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -248,7 +248,6 @@ Readline version #{ver} detected - will not auto_resize! correctly. # Set all the configurable options back to their default values def self.reset_defaults @initial_session = true - self.custom_completions = DEFAULT_CUSTOM_COMPLETIONS self.cli = false self.current_line = 1 self.line_buffer = [""] diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index c6cb290a..cba7bc67 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -25,6 +25,7 @@ require "pry/indent" class Pry attr_accessor :binding_stack + attr_accessor :custom_completions attr_accessor :eval_string attr_accessor :backtrace attr_accessor :suppress_output @@ -72,11 +73,10 @@ class Pry @config.merge!(options) @input_array = Pry::HistoryArray.new config.memory_size @output_array = Pry::HistoryArray.new config.memory_size - + @custom_completions = config.command_completer push_initial_binding(options[:target]) set_last_result nil - @input_array << nil # add empty input so _in_ and _out_ match - # yield the binding_stack to the hook for modification + @input_array << nil exec_hook(:when_started, options[:target], options, self) end