|
Revision 18855, 1.0 kB
(checked in by ukstudio, 5 years ago)
|
|
install autoend.vim
|
| Line | |
|---|
| 1 | if !has('ruby') |
|---|
| 2 | finish |
|---|
| 3 | endif |
|---|
| 4 | |
|---|
| 5 | ruby << RUBY |
|---|
| 6 | require 'singleton' |
|---|
| 7 | |
|---|
| 8 | class 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 |
|---|
| 47 | end |
|---|
| 48 | |
|---|
| 49 | Dir.glob(File.join(AutoEnd::Helper::HERE, 'autoend_*.rb')) do |f| |
|---|
| 50 | require f |
|---|
| 51 | end |
|---|
| 52 | RUBY |
|---|
| 53 | |
|---|
| 54 | inoremap <silent> <CR> <ESC>:ruby AutoEnd.instance.exec<CR>a<CR> |
|---|