blob: 32f3fb868fc9d98328d967154acb2c68fddf321a [file] [log] [blame]
Bram Moolenaar6b730e12005-09-16 21:47:57 +00001" Vim filetype plugin
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00002" Language: eRuby
Bram Moolenaar1d689522010-05-28 20:54:39 +02003" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
Bram Moolenaarec7944a2013-06-12 21:29:15 +02004" URL: https://github.com/vim-ruby/vim-ruby
Bram Moolenaarc6249bb2006-04-15 20:25:09 +00005" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
Bram Moolenaar6b730e12005-09-16 21:47:57 +00006
7" Only do this when not done yet for this buffer
Bram Moolenaar29466f22007-05-10 17:45:37 +00008if exists("b:did_ftplugin")
Bram Moolenaar6b730e12005-09-16 21:47:57 +00009 finish
10endif
11
12let s:save_cpo = &cpo
13set cpo-=C
14
15" Define some defaults in case the included ftplugins don't set them.
16let s:undo_ftplugin = ""
Bram Moolenaar29466f22007-05-10 17:45:37 +000017let s:browsefilter = "All Files (*.*)\t*.*\n"
Bram Moolenaar6b730e12005-09-16 21:47:57 +000018let s:match_words = ""
19
Bram Moolenaar29466f22007-05-10 17:45:37 +000020if !exists("g:eruby_default_subtype")
21 let g:eruby_default_subtype = "html"
22endif
23
Bram Moolenaarec7944a2013-06-12 21:29:15 +020024if &filetype =~ '^eruby\.'
25 let b:eruby_subtype = matchstr(&filetype,'^eruby\.\zs\w\+')
26elseif !exists("b:eruby_subtype")
Bram Moolenaar29466f22007-05-10 17:45:37 +000027 let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
28 let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+')
29 if b:eruby_subtype == ''
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020030 let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$')
Bram Moolenaar29466f22007-05-10 17:45:37 +000031 endif
32 if b:eruby_subtype == 'rhtml'
33 let b:eruby_subtype = 'html'
34 elseif b:eruby_subtype == 'rb'
35 let b:eruby_subtype = 'ruby'
36 elseif b:eruby_subtype == 'yml'
37 let b:eruby_subtype = 'yaml'
38 elseif b:eruby_subtype == 'js'
39 let b:eruby_subtype = 'javascript'
40 elseif b:eruby_subtype == 'txt'
41 " Conventional; not a real file type
42 let b:eruby_subtype = 'text'
43 elseif b:eruby_subtype == ''
44 let b:eruby_subtype = g:eruby_default_subtype
45 endif
46endif
47
48if exists("b:eruby_subtype") && b:eruby_subtype != ''
49 exe "runtime! ftplugin/".b:eruby_subtype.".vim ftplugin/".b:eruby_subtype."_*.vim ftplugin/".b:eruby_subtype."/*.vim"
50else
51 runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
52endif
53unlet! b:did_ftplugin
Bram Moolenaar6b730e12005-09-16 21:47:57 +000054
55" Override our defaults if these were set by an included ftplugin.
56if exists("b:undo_ftplugin")
Bram Moolenaar29466f22007-05-10 17:45:37 +000057 let s:undo_ftplugin = b:undo_ftplugin
58 unlet b:undo_ftplugin
Bram Moolenaar6b730e12005-09-16 21:47:57 +000059endif
60if exists("b:browsefilter")
Bram Moolenaar29466f22007-05-10 17:45:37 +000061 let s:browsefilter = b:browsefilter
62 unlet b:browsefilter
Bram Moolenaar6b730e12005-09-16 21:47:57 +000063endif
64if exists("b:match_words")
Bram Moolenaar29466f22007-05-10 17:45:37 +000065 let s:match_words = b:match_words
66 unlet b:match_words
Bram Moolenaar6b730e12005-09-16 21:47:57 +000067endif
68
69runtime! ftplugin/ruby.vim ftplugin/ruby_*.vim ftplugin/ruby/*.vim
70let b:did_ftplugin = 1
71
72" Combine the new set of values with those previously included.
73if exists("b:undo_ftplugin")
Bram Moolenaar29466f22007-05-10 17:45:37 +000074 let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin
Bram Moolenaar6b730e12005-09-16 21:47:57 +000075endif
76if exists ("b:browsefilter")
Bram Moolenaar29466f22007-05-10 17:45:37 +000077 let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter
Bram Moolenaar6b730e12005-09-16 21:47:57 +000078endif
79if exists("b:match_words")
Bram Moolenaar29466f22007-05-10 17:45:37 +000080 let s:match_words = b:match_words . ',' . s:match_words
Bram Moolenaar6b730e12005-09-16 21:47:57 +000081endif
82
83" Change the browse dialog on Win32 to show mainly eRuby-related files
84if has("gui_win32")
Bram Moolenaar29466f22007-05-10 17:45:37 +000085 let b:browsefilter="eRuby Files (*.erb, *.rhtml)\t*.erb;*.rhtml\n" . s:browsefilter
Bram Moolenaar6b730e12005-09-16 21:47:57 +000086endif
87
88" Load the combined list of match_words for matchit.vim
89if exists("loaded_matchit")
Bram Moolenaar29466f22007-05-10 17:45:37 +000090 let b:match_words = s:match_words
Bram Moolenaar6b730e12005-09-16 21:47:57 +000091endif
92
93" TODO: comments=
94setlocal commentstring=<%#%s%>
95
96let b:undo_ftplugin = "setl cms< "
97 \ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
98
99let &cpo = s:save_cpo
Bram Moolenaar84f72352012-03-11 15:57:40 +0100100unlet s:save_cpo
Bram Moolenaar6b730e12005-09-16 21:47:57 +0000101
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000102" vim: nowrap sw=2 sts=2 ts=8: