robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0bb2f5cc08
master
1" Vim filetype plugin 2" Language: eRuby 3" Maintainer: Tim Pope <vimNOSPAM@tpope.org> 4" URL: https://github.com/vim-ruby/vim-ruby 5" Last Change: 2022 May 15 6" 2024 Jan 14 by Vim Project (browsefilter) 7" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring') 8 9" Only do this when not done yet for this buffer 10if exists ( "b:did_ftplugin" ) 11finish 12endif 13 14let s: save_cpo = & cpo 15set cpo -= C 16 17" Define some defaults in case the included ftplugins don't set them. 18let s: undo_ftplugin = "" 19if has ( "win32" ) 20let s: browsefilter = "All Files (*.*)\t*\n" 21else 22let s: browsefilter = "All Files (*)\t*\n" 23endif 24let s: match_words = "" 25 26if ! exists ( "g:eruby_default_subtype" ) 27let g: eruby_default_subtype = "html" 28endif 29 30if & filetype =~ '^eruby\.' 31let b: eruby_subtype = matchstr ( & filetype , '^eruby\.\zs\w\+' ) 32elseif ! exists ( "b:eruby_subtype" ) 33let s: lines = getline ( 1 ) . "\n" . getline ( 2 ) . "\n" . getline ( 3 ) . "\n" . getline ( 4 ) . "\n" . getline ( 5 ) . "\n" . getline ( "$" ) 34let b: eruby_subtype = matchstr ( s: lines , 'eruby_subtype=\zs\w\+' ) 35if b: eruby_subtype == '' 36let b: eruby_subtype = matchstr ( substitute ( expand ( "%:t" ), '\c\%(\.erb\|\.eruby\|\.erubis\|\.example\)\+$' , '' , '' ), '\.\zs\w\+\%(\ze+\w\+\)\=$' ) 37endif 38if b: eruby_subtype == 'rhtml' 39let b: eruby_subtype = 'html' 40elseif b: eruby_subtype == 'rb' 41let b: eruby_subtype = 'ruby' 42elseif b: eruby_subtype == 'yml' 43let b: eruby_subtype = 'yaml' 44elseif b: eruby_subtype == 'js' 45let b: eruby_subtype = 'javascript' 46elseif b: eruby_subtype == 'txt' 47" Conventional; not a real file type 48let b: eruby_subtype = 'text' 49elseif b: eruby_subtype == '' 50let b: eruby_subtype = g: eruby_default_subtype 51endif 52endif 53 54if exists ( "b:eruby_subtype" ) && b: eruby_subtype != '' && b: eruby_subtype !=? 'eruby' 55exe "runtime! ftplugin/" . b: eruby_subtype . "[.]{vim,lua} ftplugin/" . b: eruby_subtype . "_*.{vim,lua} ftplugin/" . b: eruby_subtype . "/*.{vim,lua}" 56else 57runtime ! ftplugin/html[.]{vim,lua} ftplugin/html_*.{vim,lua} ftplugin/html/*.{vim,lua} 58endif 59unlet ! b: did_ftplugin 60 61" Override our defaults if these were set by an included ftplugin. 62if exists ( "b:undo_ftplugin" ) 63let s: undo_ftplugin = b: undo_ftplugin 64unlet b: undo_ftplugin 65endif 66if exists ( "b:browsefilter" ) 67let s: browsefilter = b: browsefilter 68unlet b: browsefilter 69endif 70if exists ( "b:match_words" ) 71let s: match_words = b: match_words 72unlet b: match_words 73endif 74 75let s: cfilemap = v: version >= 704 ? maparg ( '<Plug><cfile>' , 'c' , 0 , 1 ) : {} 76if ! get ( s: cfilemap , 'buffer' ) || ! s: cfilemap . expr || s: cfilemap . rhs =~# 'ErubyAtCursor()' 77let s: cfilemap = {} 78endif 79if ! has_key ( s: cfilemap , 'rhs' ) 80let s: cfilemap . rhs = "substitute(&l:inex =~# '\\<v:fname\\>' && len(expand('<cfile>')) ? eval(substitute(&l:inex, '\\<v:fname\\>', '\\=string(expand(\"<cfile>\"))', 'g')) : '', '^$', \"\\022\\006\",'')" 81endif 82let s: ctagmap = v: version >= 704 ? maparg ( '<Plug><ctag>' , 'c' , 0 , 1 ) : {} 83if ! get ( s: ctagmap , 'buffer' ) || ! s: ctagmap . expr || s: ctagmap . rhs =~# 'ErubyAtCursor()' 84let s: ctagmap = {} 85endif 86let s: include = & l: include 87let s: path = & l: path 88let s: suffixesadd = & l: suffixesadd 89 90runtime ! ftplugin/ruby[.]{vim,lua} ftplugin/ruby_*.{vim,lua} ftplugin/ruby/*.{vim,lua} 91let b: did_ftplugin = 1 92 93" Combine the new set of values with those previously included. 94if ! exists ( 'b:undo_ftplugin' ) 95" No-op 96let b: undo_ftplugin = 'exe' 97endif 98if ! empty ( s: undo_ftplugin ) 99let b: undo_ftplugin .= '|' . s: undo_ftplugin 100endif 101if exists ( "b:browsefilter" ) 102let s: browsefilter = substitute ( b: browsefilter , '\cAll Files (\*\.\*)\t\*\.\*\n' , '' , '' ) . s: browsefilter 103endif 104if exists ( "b:match_words" ) 105let s: match_words = b: match_words . ',' . s: match_words 106endif 107 108if len ( s: include ) 109let & l: include = s: include 110endif 111let & l: path = s: path . ( s: path =~# ',$\|^$' ? '' : ',' ) . & l: path 112let & l: suffixesadd = s: suffixesadd . ( s: suffixesadd =~# ',$\|^$' ? '' : ',' ) . & l: suffixesadd 113exe 'cmap <buffer><script><expr> <Plug><cfile> ErubyAtCursor() ? ' . maparg ( '<Plug><cfile>' , 'c' ) . ' : ' . s: cfilemap . rhs 114exe 'cmap <buffer><script><expr> <Plug><ctag> ErubyAtCursor() ? ' . maparg ( '<Plug><ctag>' , 'c' ) . ' : ' . get ( s: ctagmap , 'rhs' , '"\022\027"' ) 115unlet s: cfilemap s: ctagmap s: include s: path s: suffixesadd 116 117" Change the browse dialog on Win32 and GTK to show mainly eRuby-related files 118if ( has ( "gui_win32" ) || has ( "gui_gtk" )) && ! exists ( "b:browsefilter" ) 119let b: browsefilter = "eRuby Files (*.erb, *.rhtml)\t*.erb;*.rhtml\n" . s: browsefilter 120endif 121 122" Load the combined list of match_words for matchit.vim 123if exists ( "loaded_matchit" ) 124let b: match_words = s: match_words 125endif 126 127" TODO: comments= 128setlocal commentstring = <%#\ %s\ %> 129 130let b: undo_ftplugin = "setl cms< " . 131 \" | unlet! b:browsefilter b:match_words | " . b: undo_ftplugin 132 133let & cpo = s: save_cpo 134unlet s: save_cpo 135 136function ! ErubyAtCursor () abort 137let groups = map ([ 'erubyBlock' , 'erubyComment' , 'erubyExpression' , 'erubyOneLiner' ], 'hlID(v:val)' ) 138return ! empty ( filter ( synstack ( line ( '.' ), col ( '.' )), 'index(groups, v:val) >= 0' )) 139endfunction 140 141" vim: nowrap sw=2 sts=2 ts=8: