public
Description: quick look up the Ruby reference manual from Vim.
Homepage: http://deadbeaf.org/
Clone URL: git://github.com/mootoh/refe2-vim.git
refe2-vim / refe2.vim
100644 88 lines (72 sloc) 1.928 kb
1
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"
" some codes are from 'refe.vim':
" http://rails2u.com/projects/refe.vim/
"
if exists("g:loaded_refe2")
  finish
endif
let g:loaded_refe2 = 1
 
if !has('ruby')
  echo "---------------------------------------"
  echo "Error: Required vim compiled with +ruby"
  echo "---------------------------------------"
  finish
endif
 
let s:bitclust_path="/Users/moto/src/ruby/ruby-refm-1.9.0-dynamic/bitclust"
 
function! s:Refe2Clear()
"call s:ErrorMsg('call Refe2Clear')
"unlet! s:Refe2Stack
"let s:Refe2Stack = []
endfunction
 
 
let s:Refe2BufNo = -1
function! s:Refe2ViewBufShow()
  if s:Refe2BufNo == -1 || s:Refe2BufNo != bufnr('%')
    exec 'to sp' . '[Refe2]'
    let s:Refe2BufNo = bufnr('%')
  end
 
  setlocal nomodifiable
  setlocal nobuflisted
  setlocal nonumber
  setlocal noswapfile
  setlocal buftype=nofile
  setlocal bufhidden=delete
  setlocal noshowcmd
  setlocal nowrap
" setlocal foldmethod=syntax
 
  au BufHidden <buffer> call <SID>Refe2Clear()
endfunction
 
function! s:RubyRefe2(args)
  ruby << EOR
  bitclust_path = VIM::evaluate("s:bitclust_path")
  db_path = bitclust_path + '/../db-1_9_0'
  args = ['-d', db_path, VIM::evaluate("a:args")]
  $LOAD_PATH << bitclust_path + '/lib'
 
  require 'stringio'
  old_stdout = $stdout
  $stdout = StringIO.new
 
  require 'bitclust/searcher'
  require 'kconv'
  refe = BitClust::Searcher.new('refe.rb')
  refe.parse args
  refe.exec nil, args
  str = $stdout.string.toutf8
 
  buf = VIM::Buffer.current
  while buf.count > 1
    puts buf.count
    buf.delete 1
  end
  buf.delete 1
 
  str.split(/\n/).each do |line|
    buf.append buf.count, line.toutf8
  end
 
  $stdout = old_stdout
EOR
endfunction
 
function! Refe2(args)
  call s:Refe2ViewBufShow()
  setlocal modifiable
  call s:RubyRefe2(a:args)
  setlocal nomodifiable
endfunction
 
"nnoremap K :<C-u>call Refe2(expand('<cword>'))<Return>
nnoremap K :<C-u>call Refe2(expand('<cWORD>'))<Return>