erlang.vim 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. " Vim ftplugin file
  2. " Language: Erlang
  3. " Author: Oscar Hellström <oscar@oscarh.net>
  4. " Contributors: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
  5. " Eduardo Lopez (http://github.com/tapichu)
  6. " License: Vim license
  7. " Version: 2012/01/25
  8. if exists('b:did_ftplugin')
  9. finish
  10. else
  11. let b:did_ftplugin = 1
  12. endif
  13. if exists('s:did_function_definitions')
  14. call s:SetErlangOptions()
  15. finish
  16. else
  17. let s:did_function_definitions = 1
  18. endif
  19. let s:cpo_save = &cpo
  20. set cpo&vim
  21. if !exists('g:erlang_keywordprg')
  22. let g:erlang_keywordprg = 'erl -man'
  23. endif
  24. if !exists('g:erlang_folding')
  25. let g:erlang_folding = 0
  26. endif
  27. let s:erlang_fun_begin = '^\a\w*(.*$'
  28. let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$'
  29. function s:SetErlangOptions()
  30. if g:erlang_folding
  31. setlocal foldmethod=expr
  32. setlocal foldexpr=GetErlangFold(v:lnum)
  33. setlocal foldtext=ErlangFoldText()
  34. endif
  35. setlocal comments=:%%%,:%%,:%
  36. setlocal commentstring=%%s
  37. setlocal formatoptions+=ro
  38. let &l:keywordprg = g:erlang_keywordprg
  39. endfunction
  40. function GetErlangFold(lnum)
  41. let lnum = a:lnum
  42. let line = getline(lnum)
  43. if line =~ s:erlang_fun_end
  44. return '<1'
  45. endif
  46. if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
  47. return '1'
  48. endif
  49. if line =~ s:erlang_fun_begin
  50. return '>1'
  51. endif
  52. return '='
  53. endfunction
  54. function ErlangFoldText()
  55. let line = getline(v:foldstart)
  56. let foldlen = v:foldend - v:foldstart + 1
  57. let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
  58. if foldlen < 10
  59. let lines = ' ' . lines
  60. endif
  61. let retval = '+' . v:folddashes . lines
  62. return retval
  63. endfunction
  64. call s:SetErlangOptions()
  65. let b:undo_ftplugin = "setlocal foldmethod< foldexpr< foldtext<"
  66. \ . " comments< commentstring< formatoptions<"
  67. let &cpo = s:cpo_save
  68. unlet s:cpo_save