root/dotfiles/vim/ukstudio/.vim/plugin/autoend.vim @ 18855

Revision 18855, 1.0 kB (checked in by ukstudio, 5 years ago)

install autoend.vim

Line 
1if !has('ruby')
2  finish
3endif
4
5ruby << RUBY
6require 'singleton'
7
8class AutoEnd
9  include Singleton
10
11  def initialize
12    @handlers = {}
13
14    AutoEnd::Handler.constants.map {|const|
15      AutoEnd::Handler.const_get(const)
16    }.each do |klass|
17      handler = klass.new
18
19      klass.filetypes.each do |type|
20        @handlers[type] = handler
21      end
22    end
23  end
24
25  def exec
26    handler = @handlers[VIM.evaluate('&filetype')] and handler.handle
27  end
28
29  module Handler; end
30
31  module Helper
32    def append_line(str, row = $curbuf.line_number)
33      return if str.nil? || str.empty?
34      $curbuf.append(row, str)
35    end
36
37    def indent(line = $curbuf.line)
38      /^\s*/.match(line).to_a.first
39    end
40
41    def eol?
42      $curwin.cursor.last.succ == $curbuf.line.size
43    end
44
45    HERE = File.join(VIM.evaluate('&runtimepath').split(',', 2).first, 'plugin')
46  end
47end
48
49Dir.glob(File.join(AutoEnd::Helper::HERE, 'autoend_*.rb')) do |f|
50  require f
51end
52RUBY
53
54inoremap <silent> <CR> <ESC>:ruby AutoEnd.instance.exec<CR>a<CR>
Note: See TracBrowser for help on using the browser.