xref: /vim-8.2.3635/runtime/ftplugin/erlang.vim (revision 82be4849)
1" Vim ftplugin file
2" Language:     Erlang (http://www.erlang.org)
3" Maintainer:   Csaba Hoch <[email protected]>
4" Author:       Oscar Hellström <[email protected]>
5" Contributors: Ricardo Catalinas Jiménez <[email protected]>
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
12if exists('b:did_ftplugin')
13  finish
14endif
15let b:did_ftplugin = 1
16
17let s:cpo_save = &cpo
18set cpo&vim
19
20let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man')
21
22if get(g:, 'erlang_folding', 0)
23  setlocal foldmethod=expr
24  setlocal foldexpr=GetErlangFold(v:lnum)
25  setlocal foldtext=ErlangFoldText()
26endif
27
28setlocal comments=:%%%,:%%,:%
29setlocal commentstring=%%s
30
31setlocal formatoptions+=ro
32
33setlocal suffixesadd=.erl,.hrl
34
35let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
36let &l:define  = '^\s*-\%(define\|record\|type\|opaque\)'
37
38let s:erlang_fun_begin = '^\a\w*(.*$'
39let s:erlang_fun_end   = '^[^%]*\.\s*\(%.*\)\?$'
40
41if !exists('*GetErlangFold')
42  function GetErlangFold(lnum)
43    let lnum = a:lnum
44    let line = getline(lnum)
45
46    if line =~ s:erlang_fun_end
47      return '<1'
48    endif
49
50    if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
51      return '1'
52    endif
53
54    if line =~ s:erlang_fun_begin
55      return '>1'
56    endif
57
58    return '='
59  endfunction
60endif
61
62if !exists('*ErlangFoldText')
63  function ErlangFoldText()
64    let line    = getline(v:foldstart)
65    let foldlen = v:foldend - v:foldstart + 1
66    let lines   = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
67    if foldlen < 10
68      let lines = ' ' . lines
69    endif
70    let retval = '+' . v:folddashes . lines
71
72    return retval
73  endfunction
74endif
75
76let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
77      \ . " comments< commentstring< formatoptions< suffixesadd< include<"
78      \ . " define<"
79
80let &cpo = s:cpo_save
81unlet s:cpo_save
82
83" vim: sw=2 et
84