7
|
1 " Vim filetype plugin
|
831
|
2 " Language: Ruby
|
|
3 " Maintainer: Gavin Sinclair <gsinclair at soyabean.com.au>
|
|
4 " Info: $Id$
|
|
5 " URL: http://vim-ruby.rubyforge.org
|
|
6 " Anon CVS: See above site
|
|
7 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
530
|
8 " ----------------------------------------------------------------------------
|
|
9 "
|
548
|
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
|
|
23 " Matchit support
|
|
24 if exists("loaded_matchit") && !exists("b:match_words")
|
|
25 let b:match_ignorecase = 0
|
|
26
|
|
27 " TODO: improve optional do loops
|
|
28 let b:match_words =
|
|
29 \ '\%(' .
|
548
|
30 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
|
|
31 \ '\|' .
|
|
32 \ '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' .
|
530
|
33 \ '\)' .
|
|
34 \ ':' .
|
|
35 \ '\%(' .
|
548
|
36 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
|
|
37 \ '\|' .
|
|
38 \ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
|
530
|
39 \ '\)' .
|
|
40 \ ':' .
|
548
|
41 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<end\>'
|
530
|
42
|
|
43 let b:match_skip =
|
|
44 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
|
|
45 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .
|
|
46 \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'"
|
|
47
|
|
48 endif
|
|
49
|
|
50 setlocal formatoptions-=t formatoptions+=croql
|
|
51
|
|
52 setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
|
|
53 setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
|
|
54 setlocal suffixesadd=.rb
|
831
|
55
|
|
56 if version >= 700
|
|
57 setlocal omnifunc=rubycomplete#Complete
|
|
58 endif
|
530
|
59
|
|
60 " TODO:
|
|
61 "setlocal define=^\\s*def
|
|
62
|
|
63 setlocal comments=:#
|
|
64 setlocal commentstring=#\ %s
|
|
65
|
|
66 if !exists("s:rubypath")
|
|
67 if executable("ruby")
|
548
|
68 let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})"
|
530
|
69 if &shellxquote == "'"
|
548
|
70 let s:rubypath = system('ruby -e "' . s:code . '"')
|
530
|
71 else
|
548
|
72 let s:rubypath = system("ruby -e '" . s:code . "'")
|
530
|
73 endif
|
548
|
74 let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
|
530
|
75 else
|
|
76 " If we can't call ruby to get its path, just default to using the
|
|
77 " current directory and the directory of the current file.
|
|
78 let s:rubypath = ".,,"
|
|
79 endif
|
|
80 endif
|
|
81
|
|
82 let &l:path = s:rubypath
|
|
83
|
|
84 if has("gui_win32") && !exists("b:browsefilter")
|
|
85 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
|
548
|
86 \ "All Files (*.*)\t*.*\n"
|
530
|
87 endif
|
|
88
|
|
89 let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< "
|
|
90 \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
|
|
91
|
|
92 let &cpo = s:cpo_save
|
|
93 unlet s:cpo_save
|
|
94
|
|
95 "
|
|
96 " Instructions for enabling "matchit" support:
|
|
97 "
|
|
98 " 1. Look for the latest "matchit" plugin at
|
|
99 "
|
548
|
100 " http://www.vim.org/scripts/script.php?script_id=39
|
530
|
101 "
|
|
102 " It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
|
|
103 "
|
|
104 " 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
|
|
105 "
|
|
106 " 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
|
|
107 "
|
|
108 " 4. Ensure this file (ftplugin/ruby.vim) is installed.
|
|
109 "
|
|
110 " 5. Ensure you have this line in your $HOME/.vimrc:
|
548
|
111 " filetype plugin on
|
530
|
112 "
|
|
113 " 6. Restart Vim and create the matchit documentation:
|
|
114 "
|
548
|
115 " :helptags ~/.vim/doc
|
530
|
116 "
|
|
117 " Now you can do ":help matchit", and you should be able to use "%" on Ruby
|
548
|
118 " keywords. Try ":echo b:match_words" to be sure.
|
530
|
119 "
|
548
|
120 " Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
|
530
|
121 " locations of plugin directories, etc., as there are several options, and it
|
|
122 " differs on Windows. Email gsinclair@soyabean.com.au if you need help.
|
|
123 "
|
|
124
|
|
125 " vim: nowrap sw=2 sts=2 ts=8 ff=unix:
|