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

.rcObject



25
26
27
# File 'lib/vimdo.rb', line 25

def rc
  @rc ||= File.expand_path("~/.vimdorc")
end

.uiObject



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(
    # symbolize keys
    options.inject({}){ |h, (n,v)| h[n.to_sym] = v; h }
  )
  server.running? ? server.connect : server.start
end

.load_recipesObject



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_errorsObject



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 <<-WARN, :wrap => true
    You must recompile Ruby with OpenSSL support or change the sources in your \
    Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL \
    using RVM are available at rvm.io/packages/openssl.
  WARN
  VimDo.ui.trace e
  exit 1
rescue Interrupt => e
  VimDo.ui.error "\nQuitting..."
  VimDo.ui.trace e
  exit 1
rescue SystemExit => e
  exit e.status
rescue Exception => e
  VimDo.ui.error <<-ERR, :wrap => true
    Unfortunately, a fatal error has occurred. Please see the VimDo \
    troubleshooting documentation or raise an issue in github. Thanks!
  ERR
  raise e
end