blob: 66cfcc787696d554e2f0ce888f6c02620e5615bc [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00002" Language: Ruby
Bram Moolenaar91170f82006-05-05 21:15:17 +00003" Maintainer: Gavin Sinclair <gsinclair at gmail.com>
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00004" Info: $Id$
5" URL: http://vim-ruby.rubyforge.org
6" Anon CVS: See above site
7" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
Bram Moolenaar60a795a2005-09-16 21:55:43 +00008" ----------------------------------------------------------------------------
9"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000010" Original matchit support thanks to Ned Konz. See his ftplugin/ruby.vim at
Bram Moolenaar60a795a2005-09-16 21:55:43 +000011" http://bike-nomad.com/vim/ruby.vim.
12" ----------------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +000013
14" Only do this when not done yet for this buffer
15if (exists("b:did_ftplugin"))
Bram Moolenaar60a795a2005-09-16 21:55:43 +000016 finish
Bram Moolenaar071d4272004-06-13 20:20:40 +000017endif
18let b:did_ftplugin = 1
19
Bram Moolenaar60a795a2005-09-16 21:55:43 +000020let s:cpo_save = &cpo
21set cpo&vim
22
23" Matchit support
24if 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 \ '\%(' .
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000030 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
31 \ '\|' .
32 \ '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' .
Bram Moolenaar60a795a2005-09-16 21:55:43 +000033 \ '\)' .
34 \ ':' .
35 \ '\%(' .
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000036 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
37 \ '\|' .
38 \ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
Bram Moolenaar60a795a2005-09-16 21:55:43 +000039 \ '\)' .
40 \ ':' .
Bram Moolenaar91170f82006-05-05 21:15:17 +000041 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<end\>' .
42 \ ',{:},\[:\],(:)'
Bram Moolenaar60a795a2005-09-16 21:55:43 +000043
44 let b:match_skip =
45 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
46 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .
47 \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'"
48
49endif
50
51setlocal formatoptions-=t formatoptions+=croql
52
53setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
54setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
55setlocal suffixesadd=.rb
Bram Moolenaarc6249bb2006-04-15 20:25:09 +000056
57if version >= 700
58 setlocal omnifunc=rubycomplete#Complete
59endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +000060
61" TODO:
62"setlocal define=^\\s*def
63
64setlocal comments=:#
65setlocal commentstring=#\ %s
66
67if !exists("s:rubypath")
68 if executable("ruby")
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000069 let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})"
Bram Moolenaar60a795a2005-09-16 21:55:43 +000070 if &shellxquote == "'"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000071 let s:rubypath = system('ruby -e "' . s:code . '"')
Bram Moolenaar60a795a2005-09-16 21:55:43 +000072 else
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000073 let s:rubypath = system("ruby -e '" . s:code . "'")
Bram Moolenaar60a795a2005-09-16 21:55:43 +000074 endif
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000075 let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
Bram Moolenaar60a795a2005-09-16 21:55:43 +000076 else
77 " If we can't call ruby to get its path, just default to using the
78 " current directory and the directory of the current file.
79 let s:rubypath = ".,,"
80 endif
81endif
82
83let &l:path = s:rubypath
84
85if has("gui_win32") && !exists("b:browsefilter")
86 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000087 \ "All Files (*.*)\t*.*\n"
Bram Moolenaar60a795a2005-09-16 21:55:43 +000088endif
89
90let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< "
91 \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
92
93let &cpo = s:cpo_save
94unlet s:cpo_save
95
96"
97" Instructions for enabling "matchit" support:
98"
99" 1. Look for the latest "matchit" plugin at
100"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000101" http://www.vim.org/scripts/script.php?script_id=39
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000102"
103" It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
104"
105" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
106"
107" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
108"
109" 4. Ensure this file (ftplugin/ruby.vim) is installed.
110"
111" 5. Ensure you have this line in your $HOME/.vimrc:
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000112" filetype plugin on
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000113"
114" 6. Restart Vim and create the matchit documentation:
115"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000116" :helptags ~/.vim/doc
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000117"
118" Now you can do ":help matchit", and you should be able to use "%" on Ruby
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000119" keywords. Try ":echo b:match_words" to be sure.
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000120"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000121" Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000122" 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.
124"
125
126" vim: nowrap sw=2 sts=2 ts=8 ff=unix: