blob: 5a3ab717d9f0fdb02eb11896ea7929d5df279f7a [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)
Riley Bruins0a083062024-06-03 20:40:45 +02009" Riley Bruins (http://github.com/ribru17) ('commentstring')
10" Last Update: 2024 May 23
Bram Moolenaar6be7f872012-01-20 21:08:56 +010011" License: Vim license
Bram Moolenaar82be4842021-01-11 19:40:15 +010012" URL: https://github.com/vim-erlang/vim-erlang-runtime
Bram Moolenaar6be7f872012-01-20 21:08:56 +010013
14if exists('b:did_ftplugin')
Bram Moolenaar82be4842021-01-11 19:40:15 +010015 finish
Bram Moolenaar6be7f872012-01-20 21:08:56 +010016endif
Bram Moolenaar82be4842021-01-11 19:40:15 +010017let b:did_ftplugin = 1
Bram Moolenaar6be7f872012-01-20 21:08:56 +010018
Bram Moolenaar84f72352012-03-11 15:57:40 +010019let s:cpo_save = &cpo
20set cpo&vim
21
Bram Moolenaar82be4842021-01-11 19:40:15 +010022let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man')
23
24if get(g:, 'erlang_folding', 0)
25 setlocal foldmethod=expr
26 setlocal foldexpr=GetErlangFold(v:lnum)
27 setlocal foldtext=ErlangFoldText()
Bram Moolenaar6be7f872012-01-20 21:08:56 +010028endif
29
Bram Moolenaar82be4842021-01-11 19:40:15 +010030setlocal comments=:%%%,:%%,:%
Riley Bruins0a083062024-06-03 20:40:45 +020031setlocal commentstring=%\ %s
Bram Moolenaar82be4842021-01-11 19:40:15 +010032
33setlocal formatoptions+=ro
34
Bram Moolenaarf269eab2022-10-03 18:04:35 +010035if get(g:, 'erlang_extend_path', 1)
36 " typical erlang.mk paths
37 let &l:path = join([
38 \ 'deps/*/include',
39 \ 'deps/*/src',
40 \ 'deps/*/test',
41 \ 'deps/*/apps/*/include',
42 \ 'deps/*/apps/*/src',
43 \ &g:path], ',')
44 " typical rebar3 paths
45 let &l:path = join([
46 \ 'apps/*/include',
47 \ 'apps/*/src',
48 \ '_build/default/lib/*/src',
49 \ '_build/default/*/include',
50 \ &l:path], ',')
51 " typical erlang paths
52 let &l:path = join(['include', 'src', 'test', &l:path], ',')
53
54 set wildignore+=*/.erlang.mk/*,*.beam
55endif
56
Bram Moolenaar82be4842021-01-11 19:40:15 +010057setlocal suffixesadd=.erl,.hrl
58
59let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
60let &l:define = '^\s*-\%(define\|record\|type\|opaque\)'
Bram Moolenaar6be7f872012-01-20 21:08:56 +010061
Csaba Hoch18ab6c32023-12-21 17:16:28 +010062let s:erlang_fun_begin = '^\l[A-Za-z0-9_@]*(.*$'
Bram Moolenaar5dc62522012-02-13 00:05:22 +010063let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$'
Bram Moolenaar6be7f872012-01-20 21:08:56 +010064
Bram Moolenaar82be4842021-01-11 19:40:15 +010065if !exists('*GetErlangFold')
66 function GetErlangFold(lnum)
67 let lnum = a:lnum
68 let line = getline(lnum)
Bram Moolenaar6be7f872012-01-20 21:08:56 +010069
Bram Moolenaar82be4842021-01-11 19:40:15 +010070 if line =~ s:erlang_fun_end
71 return '<1'
72 endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010073
Bram Moolenaar82be4842021-01-11 19:40:15 +010074 if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
75 return '1'
76 endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010077
Bram Moolenaar82be4842021-01-11 19:40:15 +010078 if line =~ s:erlang_fun_begin
79 return '>1'
80 endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010081
Bram Moolenaar82be4842021-01-11 19:40:15 +010082 return '='
83 endfunction
84endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010085
Bram Moolenaar82be4842021-01-11 19:40:15 +010086if !exists('*ErlangFoldText')
87 function ErlangFoldText()
88 let line = getline(v:foldstart)
89 let foldlen = v:foldend - v:foldstart + 1
90 let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
91 if foldlen < 10
92 let lines = ' ' . lines
93 endif
94 let retval = '+' . v:folddashes . lines
Bram Moolenaar6be7f872012-01-20 21:08:56 +010095
Bram Moolenaar82be4842021-01-11 19:40:15 +010096 return retval
97 endfunction
98endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +010099
Csaba Hoch18ab6c32023-12-21 17:16:28 +0100100" The following lines enable the macros/matchit.vim plugin for extended
101" matching with the % key.
102let b:match_ignorecase = 0
103let b:match_words =
104 \ '\<\%(begin\|case\|fun\|if\|maybe\|receive\|try\)\>' .
105 \ ':\<\%(after\|catch\|else\|of\)\>' .
106 \ ':\<end\>,' .
107 \ '^\l[A-Za-z0-9_@]*' .
108 \ ':^\%(\%(\t\| \{' . shiftwidth() .
109 \ '}\)\%([^\t\ %][^%]*\)\?\)\?;\s*\%(%.*\)\?$\|\.[\t\ %]\|\.$'
110let b:match_skip = 's:comment\|string\|erlangmodifier\|erlangquotedatom'
111
Bram Moolenaar82be4842021-01-11 19:40:15 +0100112let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
113 \ . " comments< commentstring< formatoptions< suffixesadd< include<"
114 \ . " define<"
Csaba Hoch18ab6c32023-12-21 17:16:28 +0100115 \ . " | unlet b:match_ignorecase b:match_words b:match_skip"
Bram Moolenaar84f72352012-03-11 15:57:40 +0100116
117let &cpo = s:cpo_save
118unlet s:cpo_save
Bram Moolenaar82be4842021-01-11 19:40:15 +0100119
120" vim: sw=2 et