erlang.vim 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. " Paweł Zacharek (http://github.com/subc2)
  9. " Riley Bruins (http://github.com/ribru17) ('commentstring')
  10. " Last Update: 2024 May 23
  11. " License: Vim license
  12. " URL: https://github.com/vim-erlang/vim-erlang-runtime
  13. if exists('b:did_ftplugin')
  14. finish
  15. endif
  16. let b:did_ftplugin = 1
  17. let s:cpo_save = &cpo
  18. set cpo&vim
  19. let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man')
  20. if get(g:, 'erlang_folding', 0)
  21. setlocal foldmethod=expr
  22. setlocal foldexpr=GetErlangFold(v:lnum)
  23. setlocal foldtext=ErlangFoldText()
  24. endif
  25. setlocal comments=:%%%,:%%,:%
  26. setlocal commentstring=%\ %s
  27. setlocal formatoptions+=ro
  28. if get(g:, 'erlang_extend_path', 1)
  29. " typical erlang.mk paths
  30. let &l:path = join([
  31. \ 'deps/*/include',
  32. \ 'deps/*/src',
  33. \ 'deps/*/test',
  34. \ 'deps/*/apps/*/include',
  35. \ 'deps/*/apps/*/src',
  36. \ &g:path], ',')
  37. " typical rebar3 paths
  38. let &l:path = join([
  39. \ 'apps/*/include',
  40. \ 'apps/*/src',
  41. \ '_build/default/lib/*/src',
  42. \ '_build/default/*/include',
  43. \ &l:path], ',')
  44. " typical erlang paths
  45. let &l:path = join(['include', 'src', 'test', &l:path], ',')
  46. set wildignore+=*/.erlang.mk/*,*.beam
  47. endif
  48. setlocal suffixesadd=.erl,.hrl
  49. let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
  50. let &l:define = '^\s*-\%(define\|record\|type\|opaque\)'
  51. let s:erlang_fun_begin = '^\l[A-Za-z0-9_@]*(.*$'
  52. let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$'
  53. if !exists('*GetErlangFold')
  54. function GetErlangFold(lnum)
  55. let lnum = a:lnum
  56. let line = getline(lnum)
  57. if line =~ s:erlang_fun_end
  58. return '<1'
  59. endif
  60. if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
  61. return '1'
  62. endif
  63. if line =~ s:erlang_fun_begin
  64. return '>1'
  65. endif
  66. return '='
  67. endfunction
  68. endif
  69. if !exists('*ErlangFoldText')
  70. function ErlangFoldText()
  71. let line = getline(v:foldstart)
  72. let foldlen = v:foldend - v:foldstart + 1
  73. let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
  74. if foldlen < 10
  75. let lines = ' ' . lines
  76. endif
  77. let retval = '+' . v:folddashes . lines
  78. return retval
  79. endfunction
  80. endif
  81. " The following lines enable the matchit.vim plugin for extended
  82. " matching with the % key.
  83. let b:match_ignorecase = 0
  84. let b:match_words =
  85. \ '\<\%(begin\|case\|fun\|if\|maybe\|receive\|try\)\>' .
  86. \ ':\<\%(after\|catch\|else\|of\)\>' .
  87. \ ':\<end\>,' .
  88. \ '^\l[A-Za-z0-9_@]*' .
  89. \ ':^\%(\%(\t\| \{' . shiftwidth() .
  90. \ '}\)\%([^\t\ %][^%]*\)\?\)\?;\s*\%(%.*\)\?$\|\.[\t\ %]\|\.$'
  91. let b:match_skip = 's:comment\|string\|erlangmodifier\|erlangquotedatom'
  92. let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
  93. \ . " comments< commentstring< formatoptions< suffixesadd< include<"
  94. \ . " define<"
  95. \ . " | unlet b:match_ignorecase b:match_words b:match_skip"
  96. let &cpo = s:cpo_save
  97. unlet s:cpo_save
  98. " vim: sw=2 et