lib/bond/completion.rb in bond-0.1.4 vs lib/bond/completion.rb in bond-0.2.0
- old
+ new
@@ -1,28 +1,16 @@
-# You shouldn't place Bond.complete statements before requiring this file
-# unless you're also reproducing this Bond.debrief
-Bond.debrief(:default_search=>:underscore) unless Bond.config[:default_search]
-Bond.debrief(:default_mission=>:default) unless Bond.config[:default_mission]
-Bond.complete(:method=>/system|`/, :action=>:shell_commands)
-Bond.complete(:method=>'require', :action=>:method_require, :search=>false)
-
-# irb/completion reproduced without the completion quirks
-# Completes classes and constants
-Bond.complete(:on=>/(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/, :action=>:constants, :search=>false)
-# Completes absolute constants
-Bond.complete(:on=>/::([A-Z][^:\.\(]*)$/, :search=>false) {|e|
- Object.constants.grep(/^#{Regexp.escape(e.matched[1])}/).collect{|f| "::" + f}
+# any object's methods
+complete :object=>"Object"
+# method arguments
+complete :all_methods=>true
+complete :all_operator_methods=>true
+# classes and constants
+complete(:name=>:constants, :anywhere=>'(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)') {|e|
+ receiver = e.matched[2]
+ candidates = eval("#{receiver}.constants | #{receiver}.methods") || []
+ normal_search(e.matched[5], candidates).map {|e| receiver + "::" + e}
}
-# Completes symbols
-Bond.complete(:on=>/(:[^:\s.]*)$/) {|e|
- Symbol.respond_to?(:all_symbols) ? Symbol.all_symbols.map {|f| ":#{f}" } : []
-}
-# Completes global variables
-Bond.complete(:on=>/(\$[^\s.]*)$/, :search=>false) {|e|
- global_variables.grep(/^#{Regexp.escape(e.matched[1])}/)
-}
-# Completes files
-Bond.complete(:on=>/[\s(]["']([^'"]*)$/, :search=>false, :action=>:quoted_files, :place=>:last)
-# Completes any object's methods
-Bond.complete(:object=>"Object", :place=>:last)
-# Completes method completion anywhere in the line
-Bond.complete(:on=>/([^.\s]+)\.([^.\s]*)$/, :object=>"Object", :place=>:last)
+# absolute constants
+complete(:prefix=>'::', :anywhere=>'[A-Z][^:\.\(]*') {|e| Object.constants }
+complete(:anywhere=>':[^:\s.]*') {|e| Symbol.all_symbols.map {|f| ":#{f}" } rescue [] }
+complete(:anywhere=>'\$[^\s.]*') {|e| global_variables }
+complete(:name=>:quoted_files, :on=>/[\s(]["']([^'"]*)$/, :search=>false, :place=>:last) {|e| files(e.matched[1]) }
\ No newline at end of file