Module: VimDo
- Defined in:
- lib/vimdo.rb,
lib/vimdo/ui.rb,
lib/vimdo/cli.rb,
lib/vimdo/autocomplete.rb,
lib/vimdo/friendly_error.rb
Defined Under Namespace
Classes: CLI, PathError, UI, UndefinedCommandError, VimDoError
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.rc ⇒ Object
25
26
27
|
# File 'lib/vimdo.rb', line 25
def rc
@rc ||= File.expand_path("~/.vimdorc")
end
|
.ui ⇒ Object
21
22
23
|
# File 'lib/vimdo.rb', line 21
def ui
@ui ||= UI.new
end
|
Class Method Details
.autocomplete(words) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/vimdo/autocomplete.rb', line 6
def self.autocomplete(words)
subcommands = VimDo::CLI.tasks.keys
global_options = VimDo::CLI.class_options.values.map { |v| v.switch_name }
if words.empty?
puts (subcommands + global_options).flatten
elsif words.length == 1 && ! subcommands.include?(words[0])
puts AutoCompletion.words(subcommands).complete(words[0])
else
options = global_options
current_task = VimDo::CLI.tasks[words.shift]
if current_task && ! current_task.options.empty?
options << current_task.options.values.map { |v| v.switch_name }
end
options = options.flatten.delete_if { |o| words.include? o }
if words[-1]
puts AutoCompletion.words(options.flatten).complete(words[-1])
else
puts options.flatten
end
end
end
|
.connect(options = {}) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/vimdo.rb', line 29
def connect(options= {})
server = Vimrunner::Server.new(
options.inject({}){ |h, (n,v)| h[n.to_sym] = v; h }
)
server.running? ? server.connect : server.start
end
|
.load_recipes ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/vimdo.rb', line 37
def load_recipes
if File.exists?(rc)
settings = YAML::load( File.read(rc) )
settings.fetch(:recipes, []).map {|f| File.expand_path(f) }.each { |rp|
Dir[ File.join(rp, '*.vimdo') ].each { |r|
load r
}
}
end
end
|
.with_friendly_errors ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/vimdo/friendly_error.rb', line 2
def self.with_friendly_errors
yield
rescue VimDo::VimDoError => e
VimDo.ui.error e.message, :wrap => true
VimDo.ui.trace e
exit e.status_code
rescue LoadError => e
raise e unless e.message =~ /cannot load such file -- openssl|openssl.so|libcrypto.so/
VimDo.ui.error "\nCould not load OpenSSL."
VimDo.ui.warn " You must recompile Ruby with OpenSSL support or change the sources in your \\\n Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL \\\n using RVM are available at rvm.io/packages/openssl.\n WARN\n VimDo.ui.trace e\n exit 1\nrescue Interrupt => e\n VimDo.ui.error \"\\nQuitting...\"\n VimDo.ui.trace e\n exit 1\nrescue SystemExit => e\n exit e.status\nrescue Exception => e\n VimDo.ui.error <<-ERR, :wrap => true\n Unfortunately, a fatal error has occurred. Please see the VimDo \\\n troubleshooting documentation or raise an issue in github. Thanks!\n ERR\n raise e\nend\n", :wrap => true
|