neo2vim 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/neo2vim +3 -0
  2. data/lib/neo2vim.rb +86 -0
  3. metadata +48 -0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'neo2vim'
3
+ Neo2Vim.new(ARGV[0], ARGV[1])
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+ class Neo2Vim
3
+ def neovim_annotation line
4
+ line.chomp.gsub(/^[^\(]*\('/, "").gsub(/'.*$/, "")
5
+ end
6
+ def on_neovim_line line
7
+ if line.include? "plugin"
8
+ @plugin_name = true
9
+ else
10
+ @names.each do |name|
11
+ if line.include? name
12
+ @store[name] = neovim_annotation line
13
+ end
14
+ end
15
+ end
16
+ end
17
+ def method_name line
18
+ line.chomp.gsub(/^ *[^ ]* /, "").gsub(/\(.*/, "")
19
+ end
20
+ def on_line line
21
+ line.gsub!("import neovim", "import vim")
22
+ line.gsub!(/.*if neovim$*/, "")
23
+ @dst.write line
24
+ if @plugin_name == true
25
+ @plugin_name = line.chomp.gsub(/^[^ ]* /, "").gsub(/\(.*/, "")
26
+ else
27
+ @names.each do |name|
28
+ if @store[name]
29
+ @stores[name] ||= {}
30
+ @stores[name][method_name(line)] = @store[name]
31
+ @store[name] = nil
32
+ end
33
+ end
34
+ end
35
+ end
36
+ def initialize source, destination
37
+ @names = ["function", "command", "autocmd"]
38
+ @stores = {}
39
+ @store = {}
40
+ @plugin_name = nil
41
+ run source, destination
42
+ end
43
+ def declarations
44
+ ["function", "autocmd", "command"].each do |what|
45
+ @stores[what].each do |k, v|
46
+ @dst.puts "fun! #{what == "function"?"":"En"}#{what == "function" ? v : k}(arg0, arg1)
47
+ python <<EOF
48
+ r = plugin.#{k}([vim.eval('a:arg0'), vim.eval('a:arg1')])
49
+ vim.command('let g:__result = ' + json.dumps(([] if r == None else r)))
50
+ EOF
51
+ let res = g:__result
52
+ unlet g:__result
53
+ return res
54
+ endfun"
55
+ end
56
+ end
57
+ @dst.puts "augroup Poi
58
+ autocmd!"
59
+ @stores["autocmd"].each do |k, v|
60
+ @dst.puts " autocmd #{v} * call En#{k}('', '')"
61
+ end
62
+ @dst.puts "augroup END"
63
+ @stores["command"].each do |k, v|
64
+ @dst.puts "command! -nargs=0 #{v} call En#{k}('', '')"
65
+ end
66
+ end
67
+ def run source, destination
68
+ File.open(destination, "w") do |dst|
69
+ @dst = dst
70
+ dst.puts "python <<EOF"
71
+ File.open(source) do |src|
72
+ @src = src
73
+ src.each_line do |line|
74
+ if line.include? "@neovim"
75
+ on_neovim_line line
76
+ else
77
+ on_line line
78
+ end
79
+ end
80
+ end
81
+ dst.puts "plugin = #{@plugin_name}(vim)"
82
+ dst.puts "EOF"
83
+ declarations
84
+ end
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neo2vim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Olivier 'yazgoo' Abdesselam
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-09-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: translate neovim python plugins into vim plugins
15
+ email: yazgoo@github.com
16
+ executables:
17
+ - neo2vim
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/neo2vim.rb
22
+ - bin/neo2vim
23
+ homepage: http://github.com/yazgoo/neo2vim
24
+ licenses:
25
+ - MIT
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.11
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: neo2vim
48
+ test_files: []