xref: /vim-8.2.3635/runtime/ftplugin/eruby.vim (revision 4d8f4761)
16b730e11SBram Moolenaar" Vim filetype plugin
26b730e11SBram Moolenaar" Language:		eRuby
31d68952aSBram Moolenaar" Maintainer:		Tim Pope <[email protected]>
4ec7944aaSBram Moolenaar" URL:			https://github.com/vim-ruby/vim-ruby
5c6249bb2SBram Moolenaar" Release Coordinator:	Doug Kearns <[email protected]>
6*4d8f4761SBram Moolenaar" Last Change:		2020 Jun 28
76b730e11SBram Moolenaar
86b730e11SBram Moolenaar" Only do this when not done yet for this buffer
929466f2bSBram Moolenaarif exists("b:did_ftplugin")
106b730e11SBram Moolenaar  finish
116b730e11SBram Moolenaarendif
126b730e11SBram Moolenaar
136b730e11SBram Moolenaarlet s:save_cpo = &cpo
146b730e11SBram Moolenaarset cpo-=C
156b730e11SBram Moolenaar
166b730e11SBram Moolenaar" Define some defaults in case the included ftplugins don't set them.
176b730e11SBram Moolenaarlet s:undo_ftplugin = ""
1829466f2bSBram Moolenaarlet s:browsefilter = "All Files (*.*)\t*.*\n"
196b730e11SBram Moolenaarlet s:match_words = ""
206b730e11SBram Moolenaar
2129466f2bSBram Moolenaarif !exists("g:eruby_default_subtype")
2229466f2bSBram Moolenaar  let g:eruby_default_subtype = "html"
2329466f2bSBram Moolenaarendif
2429466f2bSBram Moolenaar
25ec7944aaSBram Moolenaarif &filetype =~ '^eruby\.'
26ec7944aaSBram Moolenaar  let b:eruby_subtype = matchstr(&filetype,'^eruby\.\zs\w\+')
27ec7944aaSBram Moolenaarelseif !exists("b:eruby_subtype")
2829466f2bSBram Moolenaar  let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
2929466f2bSBram Moolenaar  let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+')
3029466f2bSBram Moolenaar  if b:eruby_subtype == ''
31d09091d4SBram Moolenaar    let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\|\.example\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$')
3229466f2bSBram Moolenaar  endif
3329466f2bSBram Moolenaar  if b:eruby_subtype == 'rhtml'
3429466f2bSBram Moolenaar    let b:eruby_subtype = 'html'
3529466f2bSBram Moolenaar  elseif b:eruby_subtype == 'rb'
3629466f2bSBram Moolenaar    let b:eruby_subtype = 'ruby'
3729466f2bSBram Moolenaar  elseif b:eruby_subtype == 'yml'
3829466f2bSBram Moolenaar    let b:eruby_subtype = 'yaml'
3929466f2bSBram Moolenaar  elseif b:eruby_subtype == 'js'
4029466f2bSBram Moolenaar    let b:eruby_subtype = 'javascript'
4129466f2bSBram Moolenaar  elseif b:eruby_subtype == 'txt'
4229466f2bSBram Moolenaar    " Conventional; not a real file type
4329466f2bSBram Moolenaar    let b:eruby_subtype = 'text'
4429466f2bSBram Moolenaar  elseif b:eruby_subtype == ''
4529466f2bSBram Moolenaar    let b:eruby_subtype = g:eruby_default_subtype
4629466f2bSBram Moolenaar  endif
4729466f2bSBram Moolenaarendif
4829466f2bSBram Moolenaar
49d09091d4SBram Moolenaarif exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=? 'eruby'
5029466f2bSBram Moolenaar  exe "runtime! ftplugin/".b:eruby_subtype.".vim ftplugin/".b:eruby_subtype."_*.vim ftplugin/".b:eruby_subtype."/*.vim"
5129466f2bSBram Moolenaarelse
526b730e11SBram Moolenaar  runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
5329466f2bSBram Moolenaarendif
5429466f2bSBram Moolenaarunlet! b:did_ftplugin
556b730e11SBram Moolenaar
566b730e11SBram Moolenaar" Override our defaults if these were set by an included ftplugin.
576b730e11SBram Moolenaarif exists("b:undo_ftplugin")
586b730e11SBram Moolenaar  let s:undo_ftplugin = b:undo_ftplugin
596b730e11SBram Moolenaar  unlet b:undo_ftplugin
606b730e11SBram Moolenaarendif
616b730e11SBram Moolenaarif exists("b:browsefilter")
626b730e11SBram Moolenaar  let s:browsefilter = b:browsefilter
636b730e11SBram Moolenaar  unlet b:browsefilter
646b730e11SBram Moolenaarendif
656b730e11SBram Moolenaarif exists("b:match_words")
666b730e11SBram Moolenaar  let s:match_words = b:match_words
676b730e11SBram Moolenaar  unlet b:match_words
686b730e11SBram Moolenaarendif
696b730e11SBram Moolenaar
70d09091d4SBram Moolenaarlet s:cfilemap = v:version >= 704 ? maparg('<Plug><cfile>', 'c', 0, 1) : {}
71d09091d4SBram Moolenaarif !get(s:cfilemap, 'buffer') || !s:cfilemap.expr || s:cfilemap.rhs =~# 'ErubyAtCursor()'
72d09091d4SBram Moolenaar  let s:cfilemap = {}
73d09091d4SBram Moolenaarendif
74d09091d4SBram Moolenaarif !has_key(s:cfilemap, 'rhs')
75d09091d4SBram Moolenaar  let s:cfilemap.rhs = "substitute(&l:inex =~# '\\<v:fname\\>' && len(expand('<cfile>')) ? eval(substitute(&l:inex, '\\<v:fname\\>', '\\=string(expand(\"<cfile>\"))', 'g')) : '', '^$', \"\\022\\006\",'')"
76d09091d4SBram Moolenaarendif
77d09091d4SBram Moolenaarlet s:ctagmap = v:version >= 704 ? maparg('<Plug><ctag>', 'c', 0, 1) : {}
78d09091d4SBram Moolenaarif !get(s:ctagmap, 'buffer') || !s:ctagmap.expr || s:ctagmap.rhs =~# 'ErubyAtCursor()'
79d09091d4SBram Moolenaar  let s:ctagmap = {}
80d09091d4SBram Moolenaarendif
81d09091d4SBram Moolenaarlet s:include = &l:include
82d09091d4SBram Moolenaarlet s:path = &l:path
83d09091d4SBram Moolenaarlet s:suffixesadd = &l:suffixesadd
84d09091d4SBram Moolenaar
856b730e11SBram Moolenaarruntime! ftplugin/ruby.vim ftplugin/ruby_*.vim ftplugin/ruby/*.vim
866b730e11SBram Moolenaarlet b:did_ftplugin = 1
876b730e11SBram Moolenaar
886b730e11SBram Moolenaar" Combine the new set of values with those previously included.
896b730e11SBram Moolenaarif exists("b:undo_ftplugin")
906b730e11SBram Moolenaar  let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin
916b730e11SBram Moolenaarendif
926b730e11SBram Moolenaarif exists ("b:browsefilter")
9329466f2bSBram Moolenaar  let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter
946b730e11SBram Moolenaarendif
956b730e11SBram Moolenaarif exists("b:match_words")
966b730e11SBram Moolenaar  let s:match_words = b:match_words . ',' . s:match_words
976b730e11SBram Moolenaarendif
986b730e11SBram Moolenaar
99d09091d4SBram Moolenaarif len(s:include)
100d09091d4SBram Moolenaar  let &l:include = s:include
101d09091d4SBram Moolenaarendif
102d09091d4SBram Moolenaarlet &l:path = s:path . (s:path =~# ',$\|^$' ? '' : ',') . &l:path
103d09091d4SBram Moolenaarlet &l:suffixesadd = s:suffixesadd . (s:suffixesadd =~# ',$\|^$' ? '' : ',') . &l:suffixesadd
104d09091d4SBram Moolenaarexe 'cmap <buffer><script><expr> <Plug><cfile> ErubyAtCursor() ? ' . maparg('<Plug><cfile>', 'c') . ' : ' . s:cfilemap.rhs
105d09091d4SBram Moolenaarexe 'cmap <buffer><script><expr> <Plug><ctag> ErubyAtCursor() ? ' . maparg('<Plug><ctag>', 'c') . ' : ' . get(s:ctagmap, 'rhs', '"\022\027"')
106d09091d4SBram Moolenaarunlet s:cfilemap s:ctagmap s:include s:path s:suffixesadd
107d09091d4SBram Moolenaar
1086b730e11SBram Moolenaar" Change the browse dialog on Win32 to show mainly eRuby-related files
1096b730e11SBram Moolenaarif has("gui_win32")
11029466f2bSBram Moolenaar  let b:browsefilter="eRuby Files (*.erb, *.rhtml)\t*.erb;*.rhtml\n" . s:browsefilter
1116b730e11SBram Moolenaarendif
1126b730e11SBram Moolenaar
1136b730e11SBram Moolenaar" Load the combined list of match_words for matchit.vim
1146b730e11SBram Moolenaarif exists("loaded_matchit")
1156b730e11SBram Moolenaar  let b:match_words = s:match_words
1166b730e11SBram Moolenaarendif
1176b730e11SBram Moolenaar
1186b730e11SBram Moolenaar" TODO: comments=
1196b730e11SBram Moolenaarsetlocal commentstring=<%#%s%>
1206b730e11SBram Moolenaar
121*4d8f4761SBram Moolenaarlet b:undo_ftplugin = "setl cms< " .
1226b730e11SBram Moolenaar      \ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
1236b730e11SBram Moolenaar
1246b730e11SBram Moolenaarlet &cpo = s:save_cpo
12584f7235bSBram Moolenaarunlet s:save_cpo
1266b730e11SBram Moolenaar
127d09091d4SBram Moolenaarfunction! ErubyAtCursor() abort
128d09091d4SBram Moolenaar  let groups = map(['erubyBlock', 'erubyComment', 'erubyExpression', 'erubyOneLiner'], 'hlID(v:val)')
129d09091d4SBram Moolenaar  return !empty(filter(synstack(line('.'), col('.')), 'index(groups, v:val) >= 0'))
130d09091d4SBram Moolenaarendfunction
131d09091d4SBram Moolenaar
1323577c6faSBram Moolenaar" vim: nowrap sw=2 sts=2 ts=8:
133