blob: 8ce7f12ac33aa7dc88d54ae63a255409d94dbd01 [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>
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00004" Info: $Id$
Bram Moolenaara5792f52005-11-23 21:25:05 +00005" URL: http://vim-ruby.rubyforge.org
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00006" Anon CVS: See above site
Bram Moolenaar60a795a2005-09-16 21:55:43 +00007" ----------------------------------------------------------------------------
8"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00009" Original matchit support thanks to Ned Konz. See his ftplugin/ruby.vim at
Bram Moolenaar60a795a2005-09-16 21:55:43 +000010" http://bike-nomad.com/vim/ruby.vim.
11" ----------------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +000012
13" Only do this when not done yet for this buffer
14if (exists("b:did_ftplugin"))
Bram Moolenaar60a795a2005-09-16 21:55:43 +000015 finish
Bram Moolenaar071d4272004-06-13 20:20:40 +000016endif
17let b:did_ftplugin = 1
18
Bram Moolenaar60a795a2005-09-16 21:55:43 +000019let s:cpo_save = &cpo
20set cpo&vim
21
22" Matchit support
23if exists("loaded_matchit") && !exists("b:match_words")
24 let b:match_ignorecase = 0
25
26 " TODO: improve optional do loops
27 let b:match_words =
28 \ '\%(' .
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000029 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' .
30 \ '\|' .
31 \ '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' .
Bram Moolenaar60a795a2005-09-16 21:55:43 +000032 \ '\)' .
33 \ ':' .
34 \ '\%(' .
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000035 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' .
36 \ '\|' .
37 \ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' .
Bram Moolenaar60a795a2005-09-16 21:55:43 +000038 \ '\)' .
39 \ ':' .
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000040 \ '\%(\%(\.\|\:\:\)\s*\|\:\)\@<!\<end\>'
Bram Moolenaar60a795a2005-09-16 21:55:43 +000041
42 let b:match_skip =
43 \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
44 \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" .
45 \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'"
46
47endif
48
49setlocal formatoptions-=t formatoptions+=croql
50
51setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
52setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
53setlocal suffixesadd=.rb
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +000054setlocal omnifunc=rubycomplete#Complete
Bram Moolenaar60a795a2005-09-16 21:55:43 +000055
56" TODO:
57"setlocal define=^\\s*def
58
59setlocal comments=:#
60setlocal commentstring=#\ %s
61
62if !exists("s:rubypath")
63 if executable("ruby")
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000064 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 +000065 if &shellxquote == "'"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000066 let s:rubypath = system('ruby -e "' . s:code . '"')
Bram Moolenaar60a795a2005-09-16 21:55:43 +000067 else
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000068 let s:rubypath = system("ruby -e '" . s:code . "'")
Bram Moolenaar60a795a2005-09-16 21:55:43 +000069 endif
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000070 let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
Bram Moolenaar60a795a2005-09-16 21:55:43 +000071 else
72 " If we can't call ruby to get its path, just default to using the
73 " current directory and the directory of the current file.
74 let s:rubypath = ".,,"
75 endif
76endif
77
78let &l:path = s:rubypath
79
80if has("gui_win32") && !exists("b:browsefilter")
81 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000082 \ "All Files (*.*)\t*.*\n"
Bram Moolenaar60a795a2005-09-16 21:55:43 +000083endif
84
85let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< "
86 \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
87
88let &cpo = s:cpo_save
89unlet s:cpo_save
90
91"
92" Instructions for enabling "matchit" support:
93"
94" 1. Look for the latest "matchit" plugin at
95"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000096" http://www.vim.org/scripts/script.php?script_id=39
Bram Moolenaar60a795a2005-09-16 21:55:43 +000097"
98" It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
99"
100" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
101"
102" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
103"
104" 4. Ensure this file (ftplugin/ruby.vim) is installed.
105"
106" 5. Ensure you have this line in your $HOME/.vimrc:
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000107" filetype plugin on
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000108"
109" 6. Restart Vim and create the matchit documentation:
110"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000111" :helptags ~/.vim/doc
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000112"
113" Now you can do ":help matchit", and you should be able to use "%" on Ruby
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000114" keywords. Try ":echo b:match_words" to be sure.
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000115"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000116" Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000117" locations of plugin directories, etc., as there are several options, and it
118" differs on Windows. Email gsinclair@soyabean.com.au if you need help.
119"
120
121" vim: nowrap sw=2 sts=2 ts=8 ff=unix: