Permalink
Browse files

Add Bond completion (when available) cirwin++

  • Loading branch information...
1 parent 8c9c38e commit 6617856b064883a671629c88244d6f9e461fdeb7 @rking rking committed with rking@sharpsaw.org Aug 18, 2012
Showing with 35 additions and 5 deletions.
  1. +2 −0 Rakefile
  2. +8 −0 lib/pry.rb
  3. +8 −2 lib/pry/completion.rb
  4. +3 −0 lib/pry/config.rb
  5. +1 −1 lib/pry/pry_instance.rb
  6. +4 −1 pry.gemspec
  7. +9 −1 test/test_completion.rb
View
@@ -25,6 +25,8 @@ def apply_spec_defaults(s)
s.add_development_dependency('bacon', '~> 1.1')
s.add_development_dependency('open4', '~> 1.3')
s.add_development_dependency('rake', '~> 0.9')
+ # TODO: make this a plain dependency:
+ s.add_development_dependency('bond', '~> 0.4.2')
end
def check_dependencies
View
@@ -222,3 +222,11 @@ module ExtendCommandBundle
require 'pry/pry_instance'
require 'pry/cli'
require 'pry/pager'
+
+begin
+ require 'bond'
+rescue LoadError
+ Pry.config.completer = Pry::InputCompleter
+else
+ Pry.config.completer = Pry::BondCompleter
+end
View
@@ -1,9 +1,14 @@
# taken from irb
-require "readline"
-
class Pry
+ module BondCompleter
+ def self.build_completion_proc(target, pry=nil, commands=[""])
+ Bond.start
+ proc{ |*a| Bond.agent.call(*a) }
+ end
+ end
+
# Implements tab completion for Readline in Pry
module InputCompleter
@@ -42,6 +47,7 @@ module InputCompleter
# @param [Binding] target The current binding context.
# @param [Array<String>] commands The array of Pry commands.
def self.build_completion_proc(target, pry=nil, commands=[""])
+
proc do |input|
# if there are multiple contexts e.g. cd 1/2/3
View
@@ -228,6 +228,9 @@ def hooks=(v)
# Pry.config.extra_sticky_locals = { :random_number => proc {
# rand(10) } }
attr_accessor :extra_sticky_locals
+
+ # @return [#build_completion_proc] A completer to use.
+ attr_accessor :completer
end
end
View
@@ -360,7 +360,7 @@ def retrieve_line(eval_string, target)
@indent.reset if eval_string.empty?
current_prompt = select_prompt(eval_string, target)
- completion_proc = Pry::InputCompleter.build_completion_proc(target, self,
+ completion_proc = Pry.config.completer.build_completion_proc(target, self,
instance_eval(&custom_completions))
View
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Mair (banisterfiend)", "Conrad Irwin"]
- s.date = "2012-08-13"
+ s.date = "2012-08-18"
s.description = "An IRB alternative and runtime developer console"
s.email = ["jrmair@gmail.com", "conrad.irwin@gmail.com"]
s.executables = ["pry"]
@@ -27,13 +27,15 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<bacon>, ["~> 1.1"])
s.add_development_dependency(%q<open4>, ["~> 1.3"])
s.add_development_dependency(%q<rake>, ["~> 0.9"])
+ s.add_development_dependency(%q<bond>, ["~> 0.4.2"])
else
s.add_dependency(%q<coderay>, ["~> 1.0.5"])
s.add_dependency(%q<slop>, ["~> 3.3.1"])
s.add_dependency(%q<method_source>, ["~> 0.8"])
s.add_dependency(%q<bacon>, ["~> 1.1"])
s.add_dependency(%q<open4>, ["~> 1.3"])
s.add_dependency(%q<rake>, ["~> 0.9"])
+ s.add_dependency(%q<bond>, ["~> 0.4.2"])
end
else
s.add_dependency(%q<coderay>, ["~> 1.0.5"])
@@ -42,5 +44,6 @@ Gem::Specification.new do |s|
s.add_dependency(%q<bacon>, ["~> 1.1"])
s.add_dependency(%q<open4>, ["~> 1.3"])
s.add_dependency(%q<rake>, ["~> 0.9"])
+ s.add_dependency(%q<bond>, ["~> 0.4.2"])
end
end
View
@@ -10,6 +10,11 @@ def completer_test(bind, pry=nil, assert_flag=true)
return proc {|*symbols| symbols.each(&test) }
end
+describe 'bond-based completion' do
+ it 'should pull in Bond by default' do
+ Pry.config.completer.should == Pry::BondCompleter
+ end
+end
describe Pry::InputCompleter do
@@ -20,9 +25,13 @@ def completer_test(bind, pry=nil, assert_flag=true)
module SymbolyName
def self.name; :symboly_name; end
end
+
+ $default_completer = Pry.config.completer
+ Pry.config.completer = Pry::InputCompleter
end
after do
+ Pry.config.completer = $default_completer
Object.remove_const :SymbolyName
end
@@ -216,4 +225,3 @@ module Baz
end
end
-

0 comments on commit 6617856

Please sign in to comment.