erlang.vim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. " Vim ftplugin file
  2. " Language: Erlang (http://www.erlang.org)
  3. " Maintainer: Csaba Hoch <csaba.hoch@gmail.com>
  4. " Author: Oscar Hellström <oscar@oscarh.net>
  5. " Contributors: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
  6. " Eduardo Lopez (http://github.com/tapichu)
  7. " Arvid Bjurklint (http://github.com/slarwise)
  8. " Last Update: 2021-Jan-08
  9. " License: Vim license
  10. " URL: https://github.com/vim-erlang/vim-erlang-runtime
  11. if exists('b:did_ftplugin')
  12. finish
  13. endif
  14. let b:did_ftplugin = 1
  15. let s:cpo_save = &cpo
  16. set cpo&vim
  17. let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man')
  18. if get(g:, 'erlang_folding', 0)
  19. setlocal foldmethod=expr
  20. setlocal foldexpr=GetErlangFold(v:lnum)
  21. setlocal foldtext=ErlangFoldText()
  22. endif
  23. setlocal comments=:%%%,:%%,:%
  24. setlocal commentstring=%%s
  25. setlocal formatoptions+=ro
  26. setlocal suffixesadd=.erl,.hrl
  27. let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
  28. let &l:define = '^\s*-\%(define\|record\|type\|opaque\)'
  29. let s:erlang_fun_begin = '^\a\w*(.*$'
  30. let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$'
  31. if !exists('*GetErlangFold')
  32. function GetErlangFold(lnum)
  33. let lnum = a:lnum
  34. let line = getline(lnum)
  35. if line =~ s:erlang_fun_end
  36. return '<1'
  37. endif
  38. if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
  39. return '1'
  40. endif
  41. if line =~ s:erlang_fun_begin
  42. return '>1'
  43. endif
  44. return '='
  45. endfunction
  46. endif
  47. if !exists('*ErlangFoldText')
  48. function ErlangFoldText()
  49. let line = getline(v:foldstart)
  50. let foldlen = v:foldend - v:foldstart + 1
  51. let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
  52. if foldlen < 10
  53. let lines = ' ' . lines
  54. endif
  55. let retval = '+' . v:folddashes . lines
  56. return retval
  57. endfunction
  58. endif
  59. let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
  60. \ . " comments< commentstring< formatoptions< suffixesadd< include<"
  61. \ . " define<"
  62. let &cpo = s:cpo_save
  63. unlet s:cpo_save
  64. " vim: sw=2 et