bond 0.4.2-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemspec +28 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.rdoc +91 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +242 -0
- data/Rakefile +47 -0
- data/lib/bond.rb +127 -0
- data/lib/bond/agent.rb +108 -0
- data/lib/bond/completion.rb +16 -0
- data/lib/bond/completions/activerecord.rb +12 -0
- data/lib/bond/completions/array.rb +1 -0
- data/lib/bond/completions/bond.rb +6 -0
- data/lib/bond/completions/hash.rb +3 -0
- data/lib/bond/completions/kernel.rb +15 -0
- data/lib/bond/completions/module.rb +10 -0
- data/lib/bond/completions/object.rb +21 -0
- data/lib/bond/completions/struct.rb +1 -0
- data/lib/bond/input.rb +28 -0
- data/lib/bond/m.rb +146 -0
- data/lib/bond/mission.rb +151 -0
- data/lib/bond/missions/anywhere_mission.rb +15 -0
- data/lib/bond/missions/default_mission.rb +21 -0
- data/lib/bond/missions/method_mission.rb +197 -0
- data/lib/bond/missions/object_mission.rb +44 -0
- data/lib/bond/missions/operator_method_mission.rb +27 -0
- data/lib/bond/rc.rb +48 -0
- data/lib/bond/readline.rb +38 -0
- data/lib/bond/readlines/jruby.rb +13 -0
- data/lib/bond/readlines/rawline.rb +15 -0
- data/lib/bond/readlines/ruby.rb +9 -0
- data/lib/bond/search.rb +74 -0
- data/lib/bond/version.rb +3 -0
- data/test/agent_test.rb +235 -0
- data/test/anywhere_mission_test.rb +34 -0
- data/test/bond_test.rb +141 -0
- data/test/completion_test.rb +148 -0
- data/test/completions_test.rb +98 -0
- data/test/deps.rip +4 -0
- data/test/m_test.rb +34 -0
- data/test/method_mission_test.rb +246 -0
- data/test/mission_test.rb +51 -0
- data/test/object_mission_test.rb +59 -0
- data/test/operator_method_mission_test.rb +66 -0
- data/test/search_test.rb +140 -0
- data/test/test_helper.rb +69 -0
- metadata +167 -0
data/.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'rubygems' unless Object.const_defined?(:Gem)
|
3
|
+
require File.dirname(__FILE__) + "/lib/bond/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "bond"
|
7
|
+
s.version = Bond::VERSION
|
8
|
+
s.platform = ENV['GEM_PLATFORM'] if ENV['GEM_PLATFORM']
|
9
|
+
s.authors = ["Gabriel Horner"]
|
10
|
+
s.email = "gabriel.horner@gmail.com"
|
11
|
+
s.homepage = "http://tagaholic.me/bond/"
|
12
|
+
s.summary = "Mission: Easy custom autocompletion for arguments, methods and beyond. Accomplished for irb and any other readline-like console environments."
|
13
|
+
s.description = "Bond is on a mission to improve autocompletion in ruby, especially for irb/ripl. Aside from doing everything irb's can do and fixing its quirks, Bond can autocomplete argument(s) to methods, uniquely completing per module, per method and per argument. Bond brings ruby autocompletion closer to bash/zsh as it provides a configuration system and a DSL for creating custom completions and completion rules. With this configuration system, users can customize their autocompletions and share it with others. Bond can also load completions that ship with gems. Bond is able to offer more than irb's completion since it uses the full line of input when completing as opposed to irb's last-word approach."
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.has_rdoc = 'yard'
|
16
|
+
s.rdoc_options = ['--title', "Bond #{Bond::VERSION} Documentation"]
|
17
|
+
s.add_development_dependency 'bacon', '>= 1.1.0'
|
18
|
+
s.add_development_dependency 'mocha', '>= 0.9.8'
|
19
|
+
s.add_development_dependency 'mocha-on-bacon'
|
20
|
+
s.add_development_dependency 'bacon-bits'
|
21
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} **/deps.rip]) + %w{Rakefile .gemspec .travis.yml}
|
22
|
+
if ENV['GEM_PLATFORM'] != 'java'
|
23
|
+
s.files += Dir.glob("ext/**/*.{rb,c}")
|
24
|
+
s.extensions = ["ext/readline_line_buffer/extconf.rb"]
|
25
|
+
end
|
26
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
27
|
+
s.license = 'MIT'
|
28
|
+
end
|
data/.travis.yml
ADDED
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
== 0.4.2
|
2
|
+
* Start also releasing java version of gem
|
3
|
+
* Put tests on travis
|
4
|
+
* Fix tests for jruby
|
5
|
+
|
6
|
+
== 0.4.1
|
7
|
+
* Fix install on jruby 1.6
|
8
|
+
|
9
|
+
== 0.4.0
|
10
|
+
* Improve extconf.rb: support --without-readline, fail hard, detect windows
|
11
|
+
* Add rb-readline support for windows and non-readline users
|
12
|
+
* Rename :readline_plugin option to :readline
|
13
|
+
* Allow :readline option to take a symbol
|
14
|
+
|
15
|
+
== 0.3.5
|
16
|
+
* Move yard-related functionality to bond-yard gem
|
17
|
+
|
18
|
+
== 0.3.4
|
19
|
+
* Add gem plugin completion
|
20
|
+
* Add jruby support thanks to @headius
|
21
|
+
* Add bare option to Bond.start
|
22
|
+
|
23
|
+
== 0.3.3
|
24
|
+
* Add Bond.restart
|
25
|
+
|
26
|
+
== 0.3.2
|
27
|
+
* Add Bond.started?
|
28
|
+
|
29
|
+
== 0.3.1
|
30
|
+
* Fix install for non-readline platforms
|
31
|
+
* Fix install for rubinius
|
32
|
+
|
33
|
+
== 0.3.0
|
34
|
+
* Fixes for tests to pass in rubinius and 1.9.2.
|
35
|
+
* Add support for a proc :eval_binding.
|
36
|
+
* Add instance variables to default completion.
|
37
|
+
* Add DefaultMission.completions to make default completions reusable
|
38
|
+
* Remove unused Mission#eval_binding.
|
39
|
+
|
40
|
+
== 0.2.2
|
41
|
+
* Moved documentation to yard.
|
42
|
+
* Better extconf.rb thanks to @timcharper
|
43
|
+
* Better error when failing to require extension.
|
44
|
+
|
45
|
+
== 0.2.1
|
46
|
+
* Added Bond.load_yard_gems which generates argument completions from yard documentation.
|
47
|
+
* Added Bond.load_gems which loads completions from gem's directory.
|
48
|
+
* Added compatibility within emacs' inf-ruby mode (thanks to @pd).
|
49
|
+
* Added :eval_debug to Bond.config for debugging completions.
|
50
|
+
* Doesn't build or load c extension for ruby 1.9.2.
|
51
|
+
* Fixed argument completion of object containing method names bug.
|
52
|
+
* Fixed nested constants completion bug.
|
53
|
+
* Updated completions for Kernel#system, Module#public, Module#protected and Module#private.
|
54
|
+
|
55
|
+
== 0.2.0
|
56
|
+
* Added comprehensive argument completion per module, method and argument.
|
57
|
+
* Added 60+ default method argument completions.
|
58
|
+
* Added configuration system and DSL.
|
59
|
+
* Added user-friendly completion error handling.
|
60
|
+
* Improved Bond.spy.
|
61
|
+
* Fixed several 1.9 bugs.
|
62
|
+
* Replaced require 'bond/completion' with Bond.start.
|
63
|
+
* Changed underscore_search to use '_' instead of '-'.
|
64
|
+
* Removed Bond.debrief and Bond.reset.
|
65
|
+
* Switched to bacon for tests.
|
66
|
+
|
67
|
+
== 0.1.4
|
68
|
+
* Added Bond.recomplete to make redefinition of completion missions easy.
|
69
|
+
* Added flag to readline extension building so that installing bond doesn't fail for
|
70
|
+
users without readline.
|
71
|
+
* bond/completion allows require to autocomplete gems and within gems.
|
72
|
+
|
73
|
+
== 0.1.3
|
74
|
+
* Fixing deployment mistake
|
75
|
+
|
76
|
+
== 0.1.2
|
77
|
+
* Added bond/completion which is a drop-in enhancement of irb/completion
|
78
|
+
* Added ability to define predefined actions in Bond::Actions
|
79
|
+
* Fixed underscore search bug
|
80
|
+
* Fixed word breaking completion bug
|
81
|
+
* Fixed irb's completion inconsistencies
|
82
|
+
* Added ability to specify :default_search for Bond.debrief
|
83
|
+
* Added placement of completions with :place for Bond.complete
|
84
|
+
|
85
|
+
== 0.1.1
|
86
|
+
* Added Bond.spy to debug completions
|
87
|
+
* Fixed object completion failing in irbrc
|
88
|
+
* Allow regex characters in completions
|
89
|
+
|
90
|
+
== 0.1.0
|
91
|
+
* Intial release. Whoop!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2010 Gabriel Horner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
== Description
|
2
|
+
|
3
|
+
Bond is on a mission to improve autocompletion in ruby, especially for irb/ripl. Aside from doing
|
4
|
+
everything irb's can do and fixing its quirks, Bond can autocomplete argument(s) to methods,
|
5
|
+
uniquely completing per module, per method and per argument. Bond brings ruby autocompletion closer
|
6
|
+
to bash/zsh as it provides a configuration system and a DSL for creating custom completions and
|
7
|
+
completion rules. With this configuration system, users can customize their autocompletions and
|
8
|
+
share it with others. Bond can also load completions that ship with gems. Bond is able to offer
|
9
|
+
more than irb's completion since it uses the full line of input when completing as opposed to irb's
|
10
|
+
last-word approach.
|
11
|
+
|
12
|
+
== Install
|
13
|
+
|
14
|
+
To use bond with {Readline}[http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html] (version >=
|
15
|
+
5.6 recommended) or JLine for JRuby users, install the gem with:
|
16
|
+
|
17
|
+
gem install bond
|
18
|
+
|
19
|
+
To use bond with {a pure ruby readline}[https://github.com/luislavena/rb-readline] i.e. Windows
|
20
|
+
users or users without Readline:
|
21
|
+
|
22
|
+
gem install bond rb-readline -- --without-readline
|
23
|
+
|
24
|
+
To use bond without readline support (and presumably use your own readline plugin):
|
25
|
+
|
26
|
+
gem install bond -- --without-readline
|
27
|
+
|
28
|
+
== Setup
|
29
|
+
|
30
|
+
If you're using {ripl}[https://github.com/cldwalker/ripl] instead of irb, bond is already setup.
|
31
|
+
|
32
|
+
To start off, replace irb's completion (require 'irb/completion') with Bond's enhanced version in your irbrc:
|
33
|
+
|
34
|
+
require 'bond'
|
35
|
+
Bond.start
|
36
|
+
# For users using a pure ruby readline
|
37
|
+
Bond.start :readline => :ruby
|
38
|
+
|
39
|
+
This setup gives you more consistent method completion on any object, customizable completions
|
40
|
+
and argument completion of some 80+ methods including Hash#[], Kernel#system, Kernel#require and some Rails methods.
|
41
|
+
|
42
|
+
== Method Argument Completion
|
43
|
+
|
44
|
+
By default, Bond autocompletes arguments for a number of core methods:
|
45
|
+
|
46
|
+
$ ripl
|
47
|
+
# require completes gems and anything in $LOAD_PATH
|
48
|
+
>> require 'rb[TAB]
|
49
|
+
rbconfig.rb rbconfig/
|
50
|
+
>> require 'rbconfig
|
51
|
+
>> require 'rbconfig.rb'
|
52
|
+
|
53
|
+
# hash methods can complete their keys
|
54
|
+
>> CONFIG::CONFIG[TAB]
|
55
|
+
>> CONFIG::CONFIG['m[TAB]
|
56
|
+
>> CONFIG::CONFIG['mandir'
|
57
|
+
>> CONFIG::CONFIG['mandir']
|
58
|
+
|
59
|
+
>> ENV['CO[TAB]
|
60
|
+
COLUMNS COMMAND_MODE
|
61
|
+
>> ENV['COL[TAB]
|
62
|
+
>> ENV['COLUMNS'
|
63
|
+
>> ENV['COLUMNS']
|
64
|
+
|
65
|
+
# array methods can complete their elements
|
66
|
+
>> %w{ab bc cd de}.delete '[TAB]
|
67
|
+
ab bc cd de
|
68
|
+
>> %w{ab bc cd de}.delete 'a[TAB]
|
69
|
+
>> %w{ab bc cd de}.delete 'ab'
|
70
|
+
|
71
|
+
# system can complete shell commands
|
72
|
+
>> system 'ec[TAB]
|
73
|
+
>> system 'echo
|
74
|
+
>> system 'echo'
|
75
|
+
|
76
|
+
Bond also comes with some basic Rails completions, mostly for attributes/columns of models:
|
77
|
+
|
78
|
+
$ script/console
|
79
|
+
>> Url.column_names
|
80
|
+
=> ["id", "name", "description", "created_at", "updated_at"]
|
81
|
+
>> Url.create :n[TAB]
|
82
|
+
>> Url.create :name
|
83
|
+
...
|
84
|
+
>> Url.first.update_attribute :d[TAB]
|
85
|
+
>> Url.first.update_attribute :description
|
86
|
+
...
|
87
|
+
|
88
|
+
To see more methods whose arguments can be completed:
|
89
|
+
>> puts Bond.list_methods
|
90
|
+
ActiveRecord::Base#[]
|
91
|
+
ActiveRecord::Base#attribute_for_inspect
|
92
|
+
...
|
93
|
+
|
94
|
+
== Multiple Arguments
|
95
|
+
Every time a comma appears after a method, Bond starts a new completion. This allows a method to
|
96
|
+
complete multiple arguments. *Each* argument can be have a unique set of completions since a completion action
|
97
|
+
is aware of what argument it is currently completing. Take for example the completion for Object#send:
|
98
|
+
|
99
|
+
>> Bond.send :me[TAB]
|
100
|
+
>> Bond.send :method
|
101
|
+
>> Bond.send :method, [TAB]
|
102
|
+
agent complete config recomplete spy start
|
103
|
+
>> Bond.send :method, :a[TAB]
|
104
|
+
>> Bond.send :method, :agent
|
105
|
+
=> #<Method: Module#agent>
|
106
|
+
|
107
|
+
Notice the arguments were completed differently: the first completing for Bond.send and the second for Bond.method. The second
|
108
|
+
argument was only able to complete because there's a completion for Module#method. Using Object#send it's possible to
|
109
|
+
use completions defined for private methods i.e. Module#remove_const:
|
110
|
+
>> Bond.send :remove_const, :A[TAB]
|
111
|
+
:Agent :AnywhereMission
|
112
|
+
>> Bond.send :remove_const, :Ag[TAB]
|
113
|
+
>> Bond.send :remove_const, :Agent
|
114
|
+
|
115
|
+
Since Bond uses a comma to delimit completions, methods whose last argument is a hash can have their hash keys
|
116
|
+
autocompleted. Revisiting the above Rails example:
|
117
|
+
>> Url.create :n[TAB]
|
118
|
+
>> Url.create :name
|
119
|
+
>> Url.create :name=>'example.com', :d[TAB]
|
120
|
+
>> Url.create :name=>'example.com', :description
|
121
|
+
...
|
122
|
+
>> Url.first.update_attributes :d[TAB]
|
123
|
+
>> Url.first.update_attributes :description
|
124
|
+
>> Url.first.update_attributes :description=>'zzz', :u[TAB]
|
125
|
+
>> Url.first.update_attributes :description=>'zzz', :updated_at
|
126
|
+
...
|
127
|
+
|
128
|
+
== Creating Completions
|
129
|
+
Bond's completion resembles bash/zsh's. When Bond.start is called, Bond looks up completion files in multiple places:
|
130
|
+
~/.bondrc and ~/.bond/completions/*.rb. Here's how bash and bond completion definitions compare in their config files:
|
131
|
+
# Bash
|
132
|
+
complete -W "one two three" example
|
133
|
+
complete -F _example example
|
134
|
+
|
135
|
+
# Bond
|
136
|
+
complete(:method=>'example') { %w{one two three} }
|
137
|
+
complete(:method=>'example', :action=>'_example')
|
138
|
+
|
139
|
+
To read up on the wealth of completion types one can make, see the docs for Bond.complete.
|
140
|
+
|
141
|
+
=== Creating Argument Completions for Methods
|
142
|
+
While the above method completion was a static list, most completions will dynamically generate completions based on the method's
|
143
|
+
receiver (object). Let's look at such an example with Hash#[] :
|
144
|
+
complete(:method=>"Hash#[]") {|e| e.object.keys }
|
145
|
+
|
146
|
+
As you can see, the currently typed object is available as the :object attribute of the block's argument, a Bond::Input object.
|
147
|
+
This object can offer other useful attributes describing what the user has typed. For example, the :argument attribute holds the
|
148
|
+
current argument number being completed. Here's a completion that uses this attribute to complete differently for the first argument
|
149
|
+
and remaining arguments:
|
150
|
+
complete(:method=>'example') {|e| e.argument > 1 ? %w{verbose force noop} : %w{one two three} }
|
151
|
+
|
152
|
+
=== Creating Other Completions
|
153
|
+
First you should know Bond works: A user creates completion missions with Bond.start and its config files (which are just
|
154
|
+
Bond.complete calls). When a user autocompletes, Bond.agent looks up missions in the *order* they were defined and completes
|
155
|
+
with the first one that matches. The exception to this ordering are :method completions.
|
156
|
+
|
157
|
+
To create a completion, Bond.complete needs a regexp to match the user input and an action to generate completions when
|
158
|
+
it matches. If the completion isn't working, use Bond.spy to see which completion is executing. If a completion needs to be placed
|
159
|
+
before existing completions, use the :place option.
|
160
|
+
|
161
|
+
== Irb's Incorrect Completions
|
162
|
+
|
163
|
+
There are a number of incorrect completions irb gives for object methods. Bond fixes all of the ones described below.
|
164
|
+
|
165
|
+
Irb completes anything surrounded with '{}' the same:
|
166
|
+
|
167
|
+
$ irb
|
168
|
+
>> proc {}.c[TAB]
|
169
|
+
}.call }.class }.clear }.clone }.collect
|
170
|
+
>> %w{ab bc}.c[TAB]
|
171
|
+
}.call }.class }.clear }.clone }.collect
|
172
|
+
>> %r{ab bc}.c[TAB]
|
173
|
+
}.call }.class }.clear }.clone }.collect
|
174
|
+
>> {}.c[TAB]
|
175
|
+
}.call }.class }.clear }.clone }.collect
|
176
|
+
>> {}.call
|
177
|
+
NoMethodError: undefined method `call' for {}:Hash
|
178
|
+
from (irb):1
|
179
|
+
|
180
|
+
There are a number of cases where irb gives a default completion because it doesn't know what else to do.
|
181
|
+
# The default completion
|
182
|
+
>> self.[TAB]
|
183
|
+
Display all 496 possibilities? (y or n)
|
184
|
+
|
185
|
+
# And all of these cases are apparently the same:
|
186
|
+
>> nil.[TAB]
|
187
|
+
Display all 496 possibilities? (y or n)
|
188
|
+
>> false.[TAB]
|
189
|
+
Display all 496 possibilities? (y or n)
|
190
|
+
>> true.[TAB]
|
191
|
+
Display all 496 possibilities? (y or n)
|
192
|
+
# Regular expressions with spaces
|
193
|
+
>> /man oh man/.[TAB]
|
194
|
+
Display all 496 possibilities? (y or n)
|
195
|
+
# Grouped expressions
|
196
|
+
>> (3 + 4).[TAB]
|
197
|
+
Display all 496 possibilities? (y or n)
|
198
|
+
|
199
|
+
# Nested hashes and arrays
|
200
|
+
>> {:a=>{:a=>1}}.[TAB]
|
201
|
+
Display all 496 possibilities? (y or n)
|
202
|
+
>> [[1,2], [3,4]].[TAB]
|
203
|
+
Display all 496 possibilities? (y or n)
|
204
|
+
|
205
|
+
# Any object produced from a method call
|
206
|
+
>> 'awesome'.to_sym.[TAB]
|
207
|
+
Display all 496 possibilities? (y or n)
|
208
|
+
>> :dude.to_s.[TAB]
|
209
|
+
Display all 496 possibilities? (y or n)
|
210
|
+
|
211
|
+
Ranges don't get much love
|
212
|
+
>> (2..4).[TAB]
|
213
|
+
# Nothing happens
|
214
|
+
|
215
|
+
== Limitations
|
216
|
+
If on a Mac and using Editline as a Readline replacement (Readline::VERSION =~ /editline/i), Bond will probably not work consistently. I strongly recommend switching to the official Readline. If using rvm, {this post}[http://niwos.com/2010/03/19/rvm-on-osx-snow-leopard-readline-errors/]
|
217
|
+
has good instructions for reinstalling ruby with the official Readline.
|
218
|
+
|
219
|
+
== Credits
|
220
|
+
* Csaba Hank for {providing the C extension}[http://www.creo.hu/~csaba/ruby/irb-enhancements/doc/files/README.html] which Bond uses to read Readline's full buffer.
|
221
|
+
* Takao Kouji for {commiting}[http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/readline/readline.c?view=diff&r1=24018&r2=24019] this Readline enhancement to ruby 1.9.2.
|
222
|
+
* pd for compatibility with emacs' inf-ruby mode.
|
223
|
+
* timcharper for improving extconf.rb.
|
224
|
+
* headius for jruby support
|
225
|
+
* tobias for a java version of the gem
|
226
|
+
|
227
|
+
== Bugs/Issues
|
228
|
+
Please report them {on github}[http://github.com/cldwalker/bond/issues].
|
229
|
+
|
230
|
+
== Contributing
|
231
|
+
{See here}[http://tagaholic.me/contributing.html]
|
232
|
+
|
233
|
+
== Links
|
234
|
+
* http://tagaholic.me/2010/05/07/screencast-of-argument-autocompletion-for-methods-in-irb.html
|
235
|
+
* http://tagaholic.me/2009/07/16/bond-from-irb-with-completion-love.html
|
236
|
+
* http://tagaholic.me/2009/07/22/better-irb-completion-with-bond.html
|
237
|
+
* http://tagaholic.me/2009/07/23/mini-irb-and-mini-script-console.html
|
238
|
+
|
239
|
+
== Todo
|
240
|
+
* Make completion actions more synonymous with argument types.
|
241
|
+
* Cache expensive completion actions.
|
242
|
+
* Ensure completions work when there is additional, unrelated text to the right of a completion.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
def gemspec
|
5
|
+
@gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
|
6
|
+
end
|
7
|
+
|
8
|
+
def gem_file
|
9
|
+
"#{gemspec.name}-#{gemspec.version}#{ENV['GEM_PLATFORM'] == 'java' ? '-java' : ''}.gem"
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Build the gem"
|
13
|
+
task :gem=>:gemspec do
|
14
|
+
sh "gem build .gemspec"
|
15
|
+
FileUtils.mkdir_p 'pkg'
|
16
|
+
FileUtils.mv gem_file, 'pkg'
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Build gems for the default and java platforms"
|
20
|
+
task :all_gems => :gem do
|
21
|
+
ENV['GEM_PLATFORM'] = 'java'
|
22
|
+
@gemspec = nil
|
23
|
+
Rake::Task["gem"].reenable
|
24
|
+
Rake::Task["gem"].invoke
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Install the gem locally"
|
28
|
+
task :install => :gem do
|
29
|
+
sh %{gem install pkg/#{gem_file}}
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Generate the gemspec"
|
33
|
+
task :generate do
|
34
|
+
puts gemspec.to_ruby
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Validate the gemspec"
|
38
|
+
task :gemspec do
|
39
|
+
gemspec.validate
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Run tests'
|
43
|
+
task :test do |t|
|
44
|
+
sh 'bacon -q -Ilib -I. test/*_test.rb'
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :test
|
data/lib/bond.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'bond/m'
|
2
|
+
require 'bond/version'
|
3
|
+
require 'bond/readline'
|
4
|
+
require 'bond/readlines/rawline'
|
5
|
+
require 'bond/readlines/ruby'
|
6
|
+
require 'bond/readlines/jruby'
|
7
|
+
require 'bond/agent'
|
8
|
+
require 'bond/search'
|
9
|
+
require 'bond/input'
|
10
|
+
require 'bond/rc'
|
11
|
+
require 'bond/mission'
|
12
|
+
require 'bond/missions/default_mission'
|
13
|
+
require 'bond/missions/method_mission'
|
14
|
+
require 'bond/missions/object_mission'
|
15
|
+
require 'bond/missions/anywhere_mission'
|
16
|
+
require 'bond/missions/operator_method_mission'
|
17
|
+
|
18
|
+
module Bond
|
19
|
+
extend self
|
20
|
+
|
21
|
+
# Creates a completion rule (Mission). A valid Mission consists of a condition and an action. A
|
22
|
+
# condition is specified with one of the following options: :on, :object, :anywhere or :method(s). Each
|
23
|
+
# of these options creates a different Mission class. An action is either the method's block or :action.
|
24
|
+
# An action takes what the user has typed (Input) and returns an array of possible completions. Bond
|
25
|
+
# searches these completions and returns matching completions. This searching behavior can be configured
|
26
|
+
# or turned off per mission with :search. If turned off, the action must also handle searching.
|
27
|
+
#
|
28
|
+
# ==== Examples:
|
29
|
+
# Bond.complete(:method => 'shoot') {|input| %w{to kill} }
|
30
|
+
# Bond.complete(:on => /^((([a-z][^:.\(]*)+):)+/, :search => false) {|input| Object.constants.grep(/#{input.matched[1]}/) }
|
31
|
+
# Bond.complete(:object => ActiveRecord::Base, :search => :underscore, :place => :last)
|
32
|
+
# Bond.complete(:method => 'you', :search => proc {|input, list| list.grep(/#{input}/i)} ) {|input| %w{Only Live Twice} }
|
33
|
+
# Bond.complete(:method => 'system', :action => :shell_commands)
|
34
|
+
#
|
35
|
+
# @param [Hash] options When using :method(s) or :object, some hash keys may have different behavior. See
|
36
|
+
# Bond.complete sections of {MethodMission} and {ObjectMission} respectively.
|
37
|
+
# @option options [Regexp] :on Matches the full line of input to create a {Mission} object.
|
38
|
+
# @option options [String] :method An instance (Class#method) or class method (Class.method). Creates
|
39
|
+
# {MethodMission} object. A method's class can be set by :class or detected automatically if '#' or '.' is
|
40
|
+
# present. If no class is detected, 'Kernel#' is assumed.
|
41
|
+
# @option options [Array<String>] :methods Instance or class method(s) in the format of :method. Creates
|
42
|
+
# {MethodMission} objects.
|
43
|
+
# @option options [String] :class Optionally used with :method or :methods to represent module/class.
|
44
|
+
# Must end in '#' or '.' to indicate instance/class method. Suggested for use with :methods.
|
45
|
+
# @option options [String] :object Module or class of an object whose methods are completed. Creates
|
46
|
+
# {ObjectMission} object.
|
47
|
+
# @option options [String] :anywhere String representing a regular expression to match a mission. Creates
|
48
|
+
# {AnywhereMission} object.
|
49
|
+
# @option options [String] :prefix Optional string to prefix :anywhere.
|
50
|
+
# @option options [Symbol,false] :search Determines how completions are searched. Defaults to
|
51
|
+
# Search.default_search. If false, search is turned off and assumed to be done in the action.
|
52
|
+
# Possible symbols are :anywhere, :ignore_case, :underscore, :normal, :files and :modules.
|
53
|
+
# See {Search} for more info.
|
54
|
+
# @option options [String,Symbol] :action Rc method name that takes an Input and returns possible completions.
|
55
|
+
# See {MethodMission} for specific behavior with :method(s).
|
56
|
+
# @option options [Integer,:last] :place Indicates where a mission is inserted amongst existing
|
57
|
+
# missions. If the symbol :last, places the mission at the end regardless of missions defined
|
58
|
+
# after it. Multiple declarations of :last are kept last in the order they are defined.
|
59
|
+
# @option options [Symbol,String] :name Unique id for a mission which can be passed by
|
60
|
+
# Bond.recomplete to identify and replace the mission.
|
61
|
+
def complete(options={}, &block); M.complete(options, &block); end
|
62
|
+
|
63
|
+
# Redefines an existing completion mission to have a different action. The condition can only be varied if :name is
|
64
|
+
# used to identify and replace a mission. Takes same options as {#complete}.
|
65
|
+
# ==== Example:
|
66
|
+
# Bond.recomplete(:on => /man/, :name => :count) { %w{4 5 6}}
|
67
|
+
def recomplete(options={}, &block); M.recomplete(options, &block); end
|
68
|
+
|
69
|
+
# Reports what completion mission matches for a given input. Helpful for debugging missions.
|
70
|
+
# ==== Example:
|
71
|
+
# >> Bond.spy "shoot oct"
|
72
|
+
# Matches completion mission for method matching "shoot".
|
73
|
+
# Possible completions: ["octopussy"]
|
74
|
+
def spy(*args); M.spy(*args); end
|
75
|
+
|
76
|
+
# @return [Hash] Global config
|
77
|
+
def config; M.config; end
|
78
|
+
|
79
|
+
# Starts Bond with a default set of completions that replace and improve irb's completion. Loads completions
|
80
|
+
# in this order: lib/bond/completion.rb, lib/bond/completions/*.rb and the following optional completions:
|
81
|
+
# completions from :gems, ~/.bondrc, ~/.bond/completions/*.rb and from block. See
|
82
|
+
# {Rc} for the DSL to use in completion files and in the block.
|
83
|
+
#
|
84
|
+
# ==== Examples:
|
85
|
+
# Bond.start :gems => %w{hirb}
|
86
|
+
# Bond.start(:default_search => :ignore_case) do
|
87
|
+
# complete(:method => "Object#respond_to?") {|e| e.object.methods }
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# @param [Hash] options Sets global keys in {#config}, some which specify what completions to load.
|
91
|
+
# @option options [Array<String>] :gems Gems which have their completions loaded from
|
92
|
+
# @gem_source/lib/bond/completions/*.rb. If gem is a plugin gem i.e. ripl-plugin, completion will be loaded
|
93
|
+
# from @gem_source/lib/ripl/completions/plugin.rb.
|
94
|
+
# @option options [Module, Symbol] :readline (Bond::Readline) Specifies a Bond readline plugin.
|
95
|
+
# A symbol points to a capitalized Bond constant i.e. :ruby -> Bond::Ruby.
|
96
|
+
# Available plugins are Bond::Readline, Bond::Ruby, Bond::Jruby and Bond::Rawline.
|
97
|
+
# @option options [Proc] :default_mission (DefaultMission) Sets default completion to use when no missions match.
|
98
|
+
# See {Agent#default_mission}.
|
99
|
+
# @option options [Symbol] :default_search (:underscore) Name of a *_search method in Rc to use as the default
|
100
|
+
# search in completions. See {#complete}'s :search option for valid values.
|
101
|
+
# @option options [Binding, Proc] :eval_binding (TOPLEVEL_BINDING) Binding to use when evaluating objects in
|
102
|
+
# ObjectMission and MethodMission. When in irb, defaults to irb's current binding. When proc,
|
103
|
+
# binding is evaluated each time by calling proc.
|
104
|
+
# @option options [Boolean] :debug (false) Shows the stacktrace when autocompletion fails and raises exceptions
|
105
|
+
# in Rc.eval.
|
106
|
+
# @option options [Boolean] :eval_debug (false) Raises eval errors occuring when finding a matching completion.
|
107
|
+
# Useful to debug an incorrect completion
|
108
|
+
# @option options [Boolean] :bare (false) Doesn't load default ruby completions and completions in
|
109
|
+
# ~/.bond*. Useful for non-ruby completions
|
110
|
+
def start(options={}, &block); M.start(options, &block); end
|
111
|
+
|
112
|
+
# Restarts completions with given options, ensuring to delete current completions.
|
113
|
+
# Takes same options as Bond#start.
|
114
|
+
def restart(options={}, &block); M.restart(options, &block); end
|
115
|
+
|
116
|
+
# Indicates if Bond has already started
|
117
|
+
def started?; M.started?; end
|
118
|
+
|
119
|
+
# Loads completions for gems that ship with them under lib/bond/completions/, relative to the gem's base directory.
|
120
|
+
def load_gems(*gems); M.load_gems(*gems); end
|
121
|
+
|
122
|
+
# An Agent who saves all Bond.complete missions and executes the correct one when a completion is called.
|
123
|
+
def agent; M.agent; end
|
124
|
+
|
125
|
+
# Lists all methods that have argument completion.
|
126
|
+
def list_methods; MethodMission.all_methods; end
|
127
|
+
end
|