comparison runtime/ftplugin/ruby.vim @ 1123:c4cd8ad60bee

updated for version 7.1a
author vimboss
date Sat, 05 May 2007 17:59:48 +0000
parents a5677b7ce858
children 1d08aac0aea9
comparison
equal deleted inserted replaced
1122:2ad54fcf37e3 1123:c4cd8ad60bee
2 " Language: Ruby 2 " Language: Ruby
3 " Maintainer: Gavin Sinclair <gsinclair at gmail.com> 3 " Maintainer: Gavin Sinclair <gsinclair at gmail.com>
4 " Info: $Id$ 4 " Info: $Id$
5 " URL: http://vim-ruby.rubyforge.org 5 " URL: http://vim-ruby.rubyforge.org
6 " Anon CVS: See above site 6 " Anon CVS: See above site
7 " Release Coordinator: Doug Kearns <dougkearns@gmail.com> 7 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
8 " ---------------------------------------------------------------------------- 8 " ----------------------------------------------------------------------------
9 " 9 "
10 " Original matchit support thanks to Ned Konz. See his ftplugin/ruby.vim at 10 " Original matchit support thanks to Ned Konz. See his ftplugin/ruby.vim at
11 " http://bike-nomad.com/vim/ruby.vim. 11 " http://bike-nomad.com/vim/ruby.vim.
12 " ---------------------------------------------------------------------------- 12 " ----------------------------------------------------------------------------
13 13
14 " Only do this when not done yet for this buffer 14 " Only do this when not done yet for this buffer
15 if (exists("b:did_ftplugin")) 15 if (exists("b:did_ftplugin"))
18 let b:did_ftplugin = 1 18 let b:did_ftplugin = 1
19 19
20 let s:cpo_save = &cpo 20 let s:cpo_save = &cpo
21 set cpo&vim 21 set cpo&vim
22 22
23 if has("gui_running") && !has("gui_win32")
24 setlocal keywordprg=ri\ -T
25 else
26 setlocal keywordprg=ri
27 endif
28
23 " Matchit support 29 " Matchit support
24 if exists("loaded_matchit") && !exists("b:match_words") 30 if exists("loaded_matchit") && !exists("b:match_words")
25 let b:match_ignorecase = 0 31 let b:match_ignorecase = 0
26 32
27 " TODO: improve optional do loops 33 " TODO: improve optional do loops
28 let b:match_words = 34 let b:match_words =
29 \ '\%(' . 35 \ '\%(' .
30 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' . 36 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
31 \ '\|' . 37 \ '\|' .
32 \ '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' . 38 \ '\%(\%(^\|\.\.\.\=\|[{\:\,;([<>~\*/%&^|+-]\|\%(\<[_[\:lower\:]][_[\:alnum\:]]*\)\@<![!=?]\)\s*\)\@<=\%(if\|unless\|while\|until\)\>' .
33 \ '\)' . 39 \ '\)' .
34 \ ':' . 40 \ ':' .
35 \ '\%(' . 41 \ '\%(' .
36 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' . 42 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
37 \ '\|' . 43 \ '\|' .
38 \ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' . 44 \ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
39 \ '\)' . 45 \ '\)' .
40 \ ':' . 46 \ ':' .
41 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<end\>' . 47 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<end\>' .
42 \ ',{:},\[:\],(:)' 48 \ ',{:},\[:\],(:)'
43 49
44 let b:match_skip = 50 let b:match_skip =
45 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" . 51 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
46 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" . 52 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .
47 \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'" 53 \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'"
48 54
49 endif 55 endif
50 56
51 setlocal formatoptions-=t formatoptions+=croql 57 setlocal formatoptions-=t formatoptions+=croql
52 58
53 setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\> 59 setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
54 setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','') 60 setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
55 setlocal suffixesadd=.rb 61 setlocal suffixesadd=.rb
56 62
57 if version >= 700 63 if exists("&ofu") && has("ruby")
58 setlocal omnifunc=rubycomplete#Complete 64 setlocal omnifunc=rubycomplete#Complete
59 endif 65 endif
66
67 " To activate, :set ballooneval
68 if has('balloon_eval') && exists('+balloonexpr')
69 setlocal balloonexpr=RubyBalloonexpr()
70 endif
71
60 72
61 " TODO: 73 " TODO:
62 "setlocal define=^\\s*def 74 "setlocal define=^\\s*def
63 75
64 setlocal comments=:# 76 setlocal comments=:#
65 setlocal commentstring=#\ %s 77 setlocal commentstring=#\ %s
66 78
67 if !exists("s:rubypath") 79 if !exists("s:rubypath")
68 if executable("ruby") 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")
69 let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})" 84 let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})"
70 if &shellxquote == "'" 85 if &shellxquote == "'"
71 let s:rubypath = system('ruby -e "' . s:code . '"') 86 let s:rubypath = system('ruby -e "' . s:code . '"')
72 else 87 else
73 let s:rubypath = system("ruby -e '" . s:code . "'") 88 let s:rubypath = system("ruby -e '" . s:code . "'")
82 97
83 let &l:path = s:rubypath 98 let &l:path = s:rubypath
84 99
85 if has("gui_win32") && !exists("b:browsefilter") 100 if has("gui_win32") && !exists("b:browsefilter")
86 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" . 101 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
87 \ "All Files (*.*)\t*.*\n" 102 \ "All Files (*.*)\t*.*\n"
88 endif 103 endif
89 104
90 let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< " 105 let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< kp<"
91 \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip" 106 \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
107 \ "| if exists('&ofu') && has('ruby') | setl ofu< | endif"
108 \ "| if has('balloon_eval') && exists('+bexpr') | setl bexpr< | endif"
92 109
93 let &cpo = s:cpo_save 110 let &cpo = s:cpo_save
94 unlet s:cpo_save 111 unlet s:cpo_save
112
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
95 167
96 " 168 "
97 " Instructions for enabling "matchit" support: 169 " Instructions for enabling "matchit" support:
98 " 170 "
99 " 1. Look for the latest "matchit" plugin at 171 " 1. Look for the latest "matchit" plugin at
100 " 172 "
101 " http://www.vim.org/scripts/script.php?script_id=39 173 " http://www.vim.org/scripts/script.php?script_id=39
102 " 174 "
103 " It is also packaged with Vim, in the $VIMRUNTIME/macros directory. 175 " It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
104 " 176 "
105 " 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc). 177 " 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
106 " 178 "
107 " 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin). 179 " 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
108 " 180 "
109 " 4. Ensure this file (ftplugin/ruby.vim) is installed. 181 " 4. Ensure this file (ftplugin/ruby.vim) is installed.
110 " 182 "
111 " 5. Ensure you have this line in your $HOME/.vimrc: 183 " 5. Ensure you have this line in your $HOME/.vimrc:
112 " filetype plugin on 184 " filetype plugin on
113 " 185 "
114 " 6. Restart Vim and create the matchit documentation: 186 " 6. Restart Vim and create the matchit documentation:
115 " 187 "
116 " :helptags ~/.vim/doc 188 " :helptags ~/.vim/doc
117 " 189 "
118 " Now you can do ":help matchit", and you should be able to use "%" on Ruby 190 " Now you can do ":help matchit", and you should be able to use "%" on Ruby
119 " keywords. Try ":echo b:match_words" to be sure. 191 " keywords. Try ":echo b:match_words" to be sure.
120 " 192 "
121 " Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the 193 " Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
122 " locations of plugin directories, etc., as there are several options, and it 194 " locations of plugin directories, etc., as there are several options, and it
123 " differs on Windows. Email gsinclair@soyabean.com.au if you need help. 195 " differs on Windows. Email gsinclair@soyabean.com.au if you need help.
124 " 196 "
125 197
126 " vim: nowrap sw=2 sts=2 ts=8 ff=unix: 198 " vim: nowrap sw=2 sts=2 ts=8 ff=unix: