blob: b262258d851fbb866a66e459c2c7266e63100489 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin
Bram Moolenaar60a795a2005-09-16 21:55:43 +00002" Language: Ruby
3" Maintainer: Gavin Sinclair <gsinclair at soyabean.com.au>
4" Info: $Id$
5" URL: http://vim-ruby.sourceforge.net
6" Anon CVS: See above site
7" Licence: GPL (http://www.gnu.org)
8" Disclaimer:
9" This program is distributed in the hope that it will be useful,
10" but WITHOUT ANY WARRANTY; without even the implied warranty of
11" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12" GNU General Public License for more details.
13" ----------------------------------------------------------------------------
14"
15" Original matchit support thanks to Ned Konz. See his ftplugin/ruby.vim at
16" http://bike-nomad.com/vim/ruby.vim.
17" ----------------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +000018
19" Only do this when not done yet for this buffer
20if (exists("b:did_ftplugin"))
Bram Moolenaar60a795a2005-09-16 21:55:43 +000021 finish
Bram Moolenaar071d4272004-06-13 20:20:40 +000022endif
23let b:did_ftplugin = 1
24
Bram Moolenaar60a795a2005-09-16 21:55:43 +000025let s:cpo_save = &cpo
26set cpo&vim
27
28" Matchit support
29if exists("loaded_matchit") && !exists("b:match_words")
30 let b:match_ignorecase = 0
31
32 " TODO: improve optional do loops
33 let b:match_words =
34 \ '\%(' .
35 \ '\%(\%(\.\|\:\:\)\s*\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
36 \ '\|' .
37 \ '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' .
38 \ '\)' .
39 \ ':' .
40 \ '\%(' .
41 \ '\%(\%(\.\|\:\:\)\s*\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
42 \ '\|' .
43 \ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
44 \ '\)' .
45 \ ':' .
46 \ '\%(\%(\.\|\:\:\)\s*\)\@<!\<end\>'
47
48 let b:match_skip =
49 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
50 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .
51 \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'"
52
53endif
54
55setlocal formatoptions-=t formatoptions+=croql
56
57setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
58setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
59setlocal suffixesadd=.rb
60
61" TODO:
62"setlocal define=^\\s*def
63
64setlocal comments=:#
65setlocal commentstring=#\ %s
66
67if !exists("s:rubypath")
68 if executable("ruby")
69 if &shellxquote == "'"
70 let s:rubypath = system('ruby -e "puts (begin; require %q{rubygems}; Gem.all_load_paths; rescue LoadError; []; end + $:).join(%q{,})"')
71 else
72 let s:rubypath = system("ruby -e 'puts (begin; require %q{rubygems}; Gem.all_load_paths; rescue LoadError; []; end + $:).join(%q{,})'")
73 endif
74 let s:rubypath = substitute(s:rubypath,',.$',',,','')
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
80endif
81
82let &l:path = s:rubypath
83
84if has("gui_win32") && !exists("b:browsefilter")
85 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
86 \ "All Files (*.*)\t*.*\n"
87endif
88
89let 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
92let &cpo = s:cpo_save
93unlet s:cpo_save
94
95"
96" Instructions for enabling "matchit" support:
97"
98" 1. Look for the latest "matchit" plugin at
99"
100" http://www.vim.org/scripts/script.php?script_id=39
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:
111" filetype plugin on
112"
113" 6. Restart Vim and create the matchit documentation:
114"
115" :helptags ~/.vim/doc
116"
117" Now you can do ":help matchit", and you should be able to use "%" on Ruby
118" keywords. Try ":echo b:match_words" to be sure.
119"
120" Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
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: