7
|
1 " Vim filetype plugin
|
831
|
2 " Language: Ruby
|
867
|
3 " Maintainer: Gavin Sinclair <gsinclair at gmail.com>
|
831
|
4 " Info: $Id$
|
|
5 " URL: http://vim-ruby.rubyforge.org
|
|
6 " Anon CVS: See above site
|
1123
|
7 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
530
|
8 " ----------------------------------------------------------------------------
|
|
9 "
|
1123
|
10 " Original matchit support thanks to Ned Konz. See his ftplugin/ruby.vim at
|
530
|
11 " http://bike-nomad.com/vim/ruby.vim.
|
|
12 " ----------------------------------------------------------------------------
|
7
|
13
|
|
14 " Only do this when not done yet for this buffer
|
|
15 if (exists("b:did_ftplugin"))
|
530
|
16 finish
|
7
|
17 endif
|
|
18 let b:did_ftplugin = 1
|
|
19
|
530
|
20 let s:cpo_save = &cpo
|
|
21 set cpo&vim
|
|
22
|
1123
|
23 if has("gui_running") && !has("gui_win32")
|
|
24 setlocal keywordprg=ri\ -T
|
|
25 else
|
|
26 setlocal keywordprg=ri
|
|
27 endif
|
|
28
|
530
|
29 " Matchit support
|
|
30 if exists("loaded_matchit") && !exists("b:match_words")
|
|
31 let b:match_ignorecase = 0
|
|
32
|
|
33 " TODO: improve optional do loops
|
1123
|
34 let b:match_words =
|
|
35 \ '\%(' .
|
|
36 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
|
|
37 \ '\|' .
|
|
38 \ '\%(\%(^\|\.\.\.\=\|[{\:\,;([<>~\*/%&^|+-]\|\%(\<[_[\:lower\:]][_[\:alnum\:]]*\)\@<![!=?]\)\s*\)\@<=\%(if\|unless\|while\|until\)\>' .
|
|
39 \ '\)' .
|
|
40 \ ':' .
|
|
41 \ '\%(' .
|
|
42 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
|
|
43 \ '\|' .
|
|
44 \ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
|
|
45 \ '\)' .
|
|
46 \ ':' .
|
|
47 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<end\>' .
|
|
48 \ ',{:},\[:\],(:)'
|
530
|
49
|
|
50 let b:match_skip =
|
1123
|
51 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
|
|
52 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .
|
|
53 \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'"
|
530
|
54
|
|
55 endif
|
|
56
|
|
57 setlocal formatoptions-=t formatoptions+=croql
|
|
58
|
|
59 setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
|
|
60 setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
|
|
61 setlocal suffixesadd=.rb
|
831
|
62
|
1123
|
63 if exists("&ofu") && has("ruby")
|
831
|
64 setlocal omnifunc=rubycomplete#Complete
|
|
65 endif
|
530
|
66
|
1123
|
67 " To activate, :set ballooneval
|
|
68 if has('balloon_eval') && exists('+balloonexpr')
|
|
69 setlocal balloonexpr=RubyBalloonexpr()
|
|
70 endif
|
|
71
|
|
72
|
530
|
73 " TODO:
|
|
74 "setlocal define=^\\s*def
|
|
75
|
|
76 setlocal comments=:#
|
|
77 setlocal commentstring=#\ %s
|
|
78
|
|
79 if !exists("s:rubypath")
|
1123
|
80 if has("ruby") && has("win32")
|
|
81 ruby VIM::command( 'let s:rubypath = "%s"' % ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,}) )
|
|
82 let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
|
|
83 elseif executable("ruby")
|
548
|
84 let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})"
|
530
|
85 if &shellxquote == "'"
|
548
|
86 let s:rubypath = system('ruby -e "' . s:code . '"')
|
530
|
87 else
|
548
|
88 let s:rubypath = system("ruby -e '" . s:code . "'")
|
530
|
89 endif
|
548
|
90 let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
|
530
|
91 else
|
|
92 " If we can't call ruby to get its path, just default to using the
|
|
93 " current directory and the directory of the current file.
|
|
94 let s:rubypath = ".,,"
|
|
95 endif
|
|
96 endif
|
|
97
|
|
98 let &l:path = s:rubypath
|
|
99
|
|
100 if has("gui_win32") && !exists("b:browsefilter")
|
|
101 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
|
1123
|
102 \ "All Files (*.*)\t*.*\n"
|
530
|
103 endif
|
|
104
|
1123
|
105 let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< kp<"
|
530
|
106 \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
|
1123
|
107 \ "| if exists('&ofu') && has('ruby') | setl ofu< | endif"
|
|
108 \ "| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif"
|
530
|
109
|
|
110 let &cpo = s:cpo_save
|
|
111 unlet s:cpo_save
|
|
112
|
1123
|
113 if exists("g:did_ruby_ftplugin_functions")
|
|
114 finish
|
|
115 endif
|
|
116 let g:did_ruby_ftplugin_functions = 1
|
|
117
|
|
118 function! RubyBalloonexpr()
|
|
119 if !exists('s:ri_found')
|
|
120 let s:ri_found = executable('ri')
|
|
121 endif
|
|
122 if s:ri_found
|
|
123 let line = getline(v:beval_lnum)
|
|
124 let b = matchstr(strpart(line,0,v:beval_col),'\%(\w\|[:.]\)*$')
|
|
125 let a = substitute(matchstr(strpart(line,v:beval_col),'^\w*\%([?!]\|\s*=\)\?'),'\s\+','','g')
|
|
126 let str = b.a
|
|
127 let before = strpart(line,0,v:beval_col-strlen(b))
|
|
128 let after = strpart(line,v:beval_col+strlen(a))
|
|
129 if str =~ '^\.'
|
|
130 let str = substitute(str,'^\.','#','g')
|
|
131 if before =~ '\]\s*$'
|
|
132 let str = 'Array'.str
|
|
133 elseif before =~ '}\s*$'
|
|
134 " False positives from blocks here
|
|
135 let str = 'Hash'.str
|
|
136 elseif before =~ "[\"'`]\\s*$" || before =~ '\$\d\+\s*$'
|
|
137 let str = 'String'.str
|
|
138 elseif before =~ '\$\d\+\.\d\+\s*$'
|
|
139 let str = 'Float'.str
|
|
140 elseif before =~ '\$\d\+\s*$'
|
|
141 let str = 'Integer'.str
|
|
142 elseif before =~ '/\s*$'
|
|
143 let str = 'Regexp'.str
|
|
144 else
|
|
145 let str = substitute(str,'^#','.','')
|
|
146 endif
|
|
147 endif
|
|
148 let str = substitute(str,'.*\.\s*to_f\s*\.\s*','Float#','')
|
|
149 let str = substitute(str,'.*\.\s*to_i\%(nt\)\=\s*\.\s*','Integer#','')
|
|
150 let str = substitute(str,'.*\.\s*to_s\%(tr\)\=\s*\.\s*','String#','')
|
|
151 let str = substitute(str,'.*\.\s*to_sym\s*\.\s*','Symbol#','')
|
|
152 let str = substitute(str,'.*\.\s*to_a\%(ry\)\=\s*\.\s*','Array#','')
|
|
153 let str = substitute(str,'.*\.\s*to_proc\s*\.\s*','Proc#','')
|
|
154 if str !~ '^\w'
|
|
155 return ''
|
|
156 endif
|
|
157 silent! let res = substitute(system("ri -f simple -T \"".str.'"'),'\n$','','')
|
|
158 if res =~ '^Nothing known about' || res =~ '^Bad argument:'
|
|
159 return ''
|
|
160 endif
|
|
161 return res
|
|
162 else
|
|
163 return ""
|
|
164 endif
|
|
165 endfunction
|
|
166
|
|
167
|
530
|
168 "
|
|
169 " Instructions for enabling "matchit" support:
|
|
170 "
|
|
171 " 1. Look for the latest "matchit" plugin at
|
|
172 "
|
1123
|
173 " http://www.vim.org/scripts/script.php?script_id=39
|
530
|
174 "
|
|
175 " It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
|
|
176 "
|
|
177 " 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
|
|
178 "
|
|
179 " 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
|
|
180 "
|
|
181 " 4. Ensure this file (ftplugin/ruby.vim) is installed.
|
|
182 "
|
|
183 " 5. Ensure you have this line in your $HOME/.vimrc:
|
1123
|
184 " filetype plugin on
|
530
|
185 "
|
|
186 " 6. Restart Vim and create the matchit documentation:
|
|
187 "
|
1123
|
188 " :helptags ~/.vim/doc
|
530
|
189 "
|
|
190 " Now you can do ":help matchit", and you should be able to use "%" on Ruby
|
1123
|
191 " keywords. Try ":echo b:match_words" to be sure.
|
530
|
192 "
|
1123
|
193 " Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
|
530
|
194 " locations of plugin directories, etc., as there are several options, and it
|
|
195 " differs on Windows. Email gsinclair@soyabean.com.au if you need help.
|
|
196 "
|
|
197
|
|
198 " vim: nowrap sw=2 sts=2 ts=8 ff=unix:
|