blob: 4c8db852b11af7993703d7391a037362bbf2f42e [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
54
55" TODO:
56"setlocal define=^\\s*def
57
58setlocal comments=:#
59setlocal commentstring=#\ %s
60
61if !exists("s:rubypath")
62 if executable("ruby")
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000063 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 +000064 if &shellxquote == "'"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000065 let s:rubypath = system('ruby -e "' . s:code . '"')
Bram Moolenaar60a795a2005-09-16 21:55:43 +000066 else
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000067 let s:rubypath = system("ruby -e '" . s:code . "'")
Bram Moolenaar60a795a2005-09-16 21:55:43 +000068 endif
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000069 let s:rubypath = '.,' . substitute(s:rubypath, '\%(^\|,\)\.\%(,\|$\)', ',,', '')
Bram Moolenaar60a795a2005-09-16 21:55:43 +000070 else
71 " If we can't call ruby to get its path, just default to using the
72 " current directory and the directory of the current file.
73 let s:rubypath = ".,,"
74 endif
75endif
76
77let &l:path = s:rubypath
78
79if has("gui_win32") && !exists("b:browsefilter")
80 let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000081 \ "All Files (*.*)\t*.*\n"
Bram Moolenaar60a795a2005-09-16 21:55:43 +000082endif
83
84let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< "
85 \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
86
87let &cpo = s:cpo_save
88unlet s:cpo_save
89
90"
91" Instructions for enabling "matchit" support:
92"
93" 1. Look for the latest "matchit" plugin at
94"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +000095" http://www.vim.org/scripts/script.php?script_id=39
Bram Moolenaar60a795a2005-09-16 21:55:43 +000096"
97" It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
98"
99" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
100"
101" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
102"
103" 4. Ensure this file (ftplugin/ruby.vim) is installed.
104"
105" 5. Ensure you have this line in your $HOME/.vimrc:
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000106" filetype plugin on
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000107"
108" 6. Restart Vim and create the matchit documentation:
109"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000110" :helptags ~/.vim/doc
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000111"
112" Now you can do ":help matchit", and you should be able to use "%" on Ruby
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000113" keywords. Try ":echo b:match_words" to be sure.
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000114"
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +0000115" Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000116" locations of plugin directories, etc., as there are several options, and it
117" differs on Windows. Email gsinclair@soyabean.com.au if you need help.
118"
119
120" vim: nowrap sw=2 sts=2 ts=8 ff=unix: