blob: 1cb57f4c8501c921692d7c4596239021dcdbf989 [file] [log] [blame]
Bram Moolenaar6be7f872012-01-20 21:08:56 +01001" Vim ftplugin file
Bram Moolenaar82be4842021-01-11 19:40:15 +01002" Language: Erlang (http://www.erlang.org)
3" Maintainer: Csaba Hoch <csaba.hoch@gmail.com>
Bram Moolenaarcb80aa22020-10-26 21:12:46 +01004" Author: Oscar Hellström <oscar@oscarh.net>
5" Contributors: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
Bram Moolenaar6be7f872012-01-20 21:08:56 +01006" Eduardo Lopez (http://github.com/tapichu)
Bram Moolenaar82be4842021-01-11 19:40:15 +01007" Arvid Bjurklint (http://github.com/slarwise)
Csaba Hoch18ab6c32023-12-21 17:16:28 +01008" Paweł Zacharek (http://github.com/subc2)
9" Last Update: 2023-Dec-20
Bram Moolenaar6be7f872012-01-20 21:08:56 +010010" License: Vim license
Bram Moolenaar82be4842021-01-11 19:40:15 +010011" URL: https://github.com/vim-erlang/vim-erlang-runtime
Bram Moolenaar6be7f872012-01-20 21:08:56 +010012
13if exists('b:did_ftplugin')
Bram Moolenaar82be4842021-01-11 19:40:15 +010014 finish
Bram Moolenaar6be7f872012-01-20 21:08:56 +010015endif
Bram Moolenaar82be4842021-01-11 19:40:15 +010016let b:did_ftplugin = 1
Bram Moolenaar6be7f872012-01-20 21:08:56 +010017
Bram Moolenaar84f72352012-03-11 15:57:40 +010018let s:cpo_save = &cpo
19set cpo&vim
20
Bram Moolenaar82be4842021-01-11 19:40:15 +010021let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man')
22
23if get(g:, 'erlang_folding', 0)
24 setlocal foldmethod=expr
25 setlocal foldexpr=GetErlangFold(v:lnum)
26 setlocal foldtext=ErlangFoldText()
Bram Moolenaar6be7f872012-01-20 21:08:56 +010027endif
28
Bram Moolenaar82be4842021-01-11 19:40:15 +010029setlocal comments=:%%%,:%%,:%
30setlocal commentstring=%%s
31
32setlocal formatoptions+=ro
33
Bram Moolenaarf269eab2022-10-03 18:04:35 +010034if get(g:, 'erlang_extend_path', 1)
35 " typical erlang.mk paths
36 let &l:path = join([
37 \ 'deps/*/include',
38 \ 'deps/*/src',
39 \ 'deps/*/test',
40 \ 'deps/*/apps/*/include',
41 \ 'deps/*/apps/*/src',
42 \ &g:path], ',')
43 " typical rebar3 paths
44 let &l:path = join([
45 \ 'apps/*/include',
46 \ 'apps/*/src',
47 \ '_build/default/lib/*/src',
48 \ '_build/default/*/include',
49 \ &l:path], ',')
50 " typical erlang paths
51 let &l:path = join(['include', 'src', 'test', &l:path], ',')
52
53 set wildignore+=*/.erlang.mk/*,*.beam
54endif
55
Bram Moolenaar82be4842021-01-11 19:40:15 +010056setlocal suffixesadd=.erl,.hrl
57
58let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
59let &l:define = '^\s*-\%(define\|record\|type\|opaque\)'
Bram Moolenaar6be7f872012-01-20 21:08:56 +010060
Csaba Hoch18ab6c32023-12-21 17:16:28 +010061let s:erlang_fun_begin = '^\l[A-Za-z0-9_@]*(.*$'
Bram Moolenaar5dc62522012-02-13 00:05:22 +010062let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$'
Bram Moolenaar6be7f872012-01-20 21:08:56 +010063
Bram Moolenaar82be4842021-01-11 19:40:15 +010064if !exists('*GetErlangFold')
65 function GetErlangFold(lnum)
66 let lnum = a:lnum
67 let line = getline(lnum)
Bram Moolenaar6be7f872012-01-20 21:08:56 +010068
Bram Moolenaar82be4842021-01-11 19:40:15 +010069 if line =~ s:erlang_fun_end
70 return '<1'
71 endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010072
Bram Moolenaar82be4842021-01-11 19:40:15 +010073 if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
74 return '1'
75 endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010076
Bram Moolenaar82be4842021-01-11 19:40:15 +010077 if line =~ s:erlang_fun_begin
78 return '>1'
79 endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010080
Bram Moolenaar82be4842021-01-11 19:40:15 +010081 return '='
82 endfunction
83endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010084
Bram Moolenaar82be4842021-01-11 19:40:15 +010085if !exists('*ErlangFoldText')
86 function ErlangFoldText()
87 let line = getline(v:foldstart)
88 let foldlen = v:foldend - v:foldstart + 1
89 let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
90 if foldlen < 10
91 let lines = ' ' . lines
92 endif
93 let retval = '+' . v:folddashes . lines
Bram Moolenaar6be7f872012-01-20 21:08:56 +010094
Bram Moolenaar82be4842021-01-11 19:40:15 +010095 return retval
96 endfunction
97endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010098
Csaba Hoch18ab6c32023-12-21 17:16:28 +010099" The following lines enable the macros/matchit.vim plugin for extended
100" matching with the % key.
101let b:match_ignorecase = 0
102let b:match_words =
103 \ '\<\%(begin\|case\|fun\|if\|maybe\|receive\|try\)\>' .
104 \ ':\<\%(after\|catch\|else\|of\)\>' .
105 \ ':\<end\>,' .
106 \ '^\l[A-Za-z0-9_@]*' .
107 \ ':^\%(\%(\t\| \{' . shiftwidth() .
108 \ '}\)\%([^\t\ %][^%]*\)\?\)\?;\s*\%(%.*\)\?$\|\.[\t\ %]\|\.$'
109let b:match_skip = 's:comment\|string\|erlangmodifier\|erlangquotedatom'
110
Bram Moolenaar82be4842021-01-11 19:40:15 +0100111let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
112 \ . " comments< commentstring< formatoptions< suffixesadd< include<"
113 \ . " define<"
Csaba Hoch18ab6c32023-12-21 17:16:28 +0100114 \ . " | unlet b:match_ignorecase b:match_words b:match_skip"
Bram Moolenaar84f72352012-03-11 15:57:40 +0100115
116let &cpo = s:cpo_save
117unlet s:cpo_save
Bram Moolenaar82be4842021-01-11 19:40:15 +0100118
119" vim: sw=2 et