erlang.vim 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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-Nov-22
  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. if get(g:, 'erlang_extend_path', 1)
  27. " typical erlang.mk paths
  28. let &l:path = join([
  29. \ 'deps/*/include',
  30. \ 'deps/*/src',
  31. \ 'deps/*/test',
  32. \ 'deps/*/apps/*/include',
  33. \ 'deps/*/apps/*/src',
  34. \ &g:path], ',')
  35. " typical rebar3 paths
  36. let &l:path = join([
  37. \ 'apps/*/include',
  38. \ 'apps/*/src',
  39. \ '_build/default/lib/*/src',
  40. \ '_build/default/*/include',
  41. \ &l:path], ',')
  42. " typical erlang paths
  43. let &l:path = join(['include', 'src', 'test', &l:path], ',')
  44. set wildignore+=*/.erlang.mk/*,*.beam
  45. endif
  46. setlocal suffixesadd=.erl,.hrl
  47. let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
  48. let &l:define = '^\s*-\%(define\|record\|type\|opaque\)'
  49. let s:erlang_fun_begin = '^\a\w*(.*$'
  50. let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$'
  51. if !exists('*GetErlangFold')
  52. function GetErlangFold(lnum)
  53. let lnum = a:lnum
  54. let line = getline(lnum)
  55. if line =~ s:erlang_fun_end
  56. return '<1'
  57. endif
  58. if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
  59. return '1'
  60. endif
  61. if line =~ s:erlang_fun_begin
  62. return '>1'
  63. endif
  64. return '='
  65. endfunction
  66. endif
  67. if !exists('*ErlangFoldText')
  68. function ErlangFoldText()
  69. let line = getline(v:foldstart)
  70. let foldlen = v:foldend - v:foldstart + 1
  71. let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
  72. if foldlen < 10
  73. let lines = ' ' . lines
  74. endif
  75. let retval = '+' . v:folddashes . lines
  76. return retval
  77. endfunction
  78. endif
  79. let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
  80. \ . " comments< commentstring< formatoptions< suffixesadd< include<"
  81. \ . " define<"
  82. let &cpo = s:cpo_save
  83. unlet s:cpo_save
  84. " vim: sw=2 et