Class: NeoBundle::Vimscript

Inherits:
Object
  • Object
show all
Defined in:
lib/neobundle/vimscript.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Vimscript

Returns a new instance of Vimscript.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/neobundle/vimscript.rb', line 8

def initialize(config={})
  @config = {
    vim: 'vim',
    bundlefile: nil,
    verbose: 0,
  }
  @config.merge!(config)
  begin
    out, err, status = Open3.capture3('%s --version' % Shellwords.escape(@config[:vim]))
    unless out =~ /^VIM - Vi IMproved / and status == 0 then
      raise NeoBundle::VimCommandError, 'command is not vim!' 
    end
  rescue SystemCallError 
    raise NeoBundle::VimCommandError, 'vim command not found!'
  end
end

Instance Method Details

#exec(cmd, io = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/neobundle/vimscript.rb', line 25

def exec(cmd, io=nil)
  raise NeoBundle::VimscriptError, 'Command is empty!' if cmd.to_s.strip.empty?
  is_displaying_log = @config[:verbose] > 0
  $stderr.puts '### Command: %s' % cmd if is_displaying_log
  
  log_file = Tempfile.open('neobundle-cmd_vimscript_exec')
  command = ERB.new("    <%= Shellwords.escape @config[:vim] %> -u NONE -U NONE -i NONE -N -e -s -V1\n      --cmd \"\n        <% unless @config[:bundlefile].to_s.strip.empty? then %>\n          set verbosefile=<%= log_file.path %> |\n          <%= @config[:verbose] %>verbose source <%= @config[:bundlefile] %> |\n          set verbosefile= |\n        <% end %>\n        <%= cmd %>\n      \"\n      --cmd \"\n        qall!\n      \"\n  SH\n  \n  log_thread = Thread.new do\n    while true do\n      line = log_file.gets.to_s.chomp\n      $stderr.puts line unless line.empty?\n    end\n  end\n  \n  stdin, stdout, stderr, process = Open3.popen3(command)\n  result = []\n  \n  stderr.each_line do |line|\n    line = line.chomp\n    next if line.empty?\n    io.puts line unless io.nil?\n    result.push line\n  end\n  \n  process.join\n  log_thread.kill\n  log_file.close\n  $stderr.print \"\\n\\n\" if is_displaying_log\n  \n  result = result.join(\"\\n\")\n  raise NeoBundle::VimscriptError, result if process.value != 0\n  result\nend\n").result(binding).gsub(/\s+/,' ').strip