eruby.vim 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. " Vim filetype plugin
  2. " Language: eRuby
  3. " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  4. " URL: https://github.com/vim-ruby/vim-ruby
  5. " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
  6. " Only do this when not done yet for this buffer
  7. if exists("b:did_ftplugin")
  8. finish
  9. endif
  10. let s:save_cpo = &cpo
  11. set cpo-=C
  12. " Define some defaults in case the included ftplugins don't set them.
  13. let s:undo_ftplugin = ""
  14. let s:browsefilter = "All Files (*.*)\t*.*\n"
  15. let s:match_words = ""
  16. if !exists("g:eruby_default_subtype")
  17. let g:eruby_default_subtype = "html"
  18. endif
  19. if &filetype =~ '^eruby\.'
  20. let b:eruby_subtype = matchstr(&filetype,'^eruby\.\zs\w\+')
  21. elseif !exists("b:eruby_subtype")
  22. let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
  23. let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+')
  24. if b:eruby_subtype == ''
  25. let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$')
  26. endif
  27. if b:eruby_subtype == 'rhtml'
  28. let b:eruby_subtype = 'html'
  29. elseif b:eruby_subtype == 'rb'
  30. let b:eruby_subtype = 'ruby'
  31. elseif b:eruby_subtype == 'yml'
  32. let b:eruby_subtype = 'yaml'
  33. elseif b:eruby_subtype == 'js'
  34. let b:eruby_subtype = 'javascript'
  35. elseif b:eruby_subtype == 'txt'
  36. " Conventional; not a real file type
  37. let b:eruby_subtype = 'text'
  38. elseif b:eruby_subtype == ''
  39. let b:eruby_subtype = g:eruby_default_subtype
  40. endif
  41. endif
  42. if exists("b:eruby_subtype") && b:eruby_subtype != ''
  43. exe "runtime! ftplugin/".b:eruby_subtype.".vim ftplugin/".b:eruby_subtype."_*.vim ftplugin/".b:eruby_subtype."/*.vim"
  44. else
  45. runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
  46. endif
  47. unlet! b:did_ftplugin
  48. " Override our defaults if these were set by an included ftplugin.
  49. if exists("b:undo_ftplugin")
  50. let s:undo_ftplugin = b:undo_ftplugin
  51. unlet b:undo_ftplugin
  52. endif
  53. if exists("b:browsefilter")
  54. let s:browsefilter = b:browsefilter
  55. unlet b:browsefilter
  56. endif
  57. if exists("b:match_words")
  58. let s:match_words = b:match_words
  59. unlet b:match_words
  60. endif
  61. runtime! ftplugin/ruby.vim ftplugin/ruby_*.vim ftplugin/ruby/*.vim
  62. let b:did_ftplugin = 1
  63. " Combine the new set of values with those previously included.
  64. if exists("b:undo_ftplugin")
  65. let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin
  66. endif
  67. if exists ("b:browsefilter")
  68. let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter
  69. endif
  70. if exists("b:match_words")
  71. let s:match_words = b:match_words . ',' . s:match_words
  72. endif
  73. " Change the browse dialog on Win32 to show mainly eRuby-related files
  74. if has("gui_win32")
  75. let b:browsefilter="eRuby Files (*.erb, *.rhtml)\t*.erb;*.rhtml\n" . s:browsefilter
  76. endif
  77. " Load the combined list of match_words for matchit.vim
  78. if exists("loaded_matchit")
  79. let b:match_words = s:match_words
  80. endif
  81. " TODO: comments=
  82. setlocal commentstring=<%#%s%>
  83. let b:undo_ftplugin = "setl cms< "
  84. \ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
  85. let &cpo = s:save_cpo
  86. unlet s:save_cpo
  87. " vim: nowrap sw=2 sts=2 ts=8: