2014-07-10 21:05:51 -07:00
|
|
|
" Vim ftplugin file
|
2021-05-01 19:09:13 -07:00
|
|
|
" Language: Erlang (http://www.erlang.org)
|
|
|
|
" Maintainer: Csaba Hoch <csaba.hoch@gmail.com>
|
2021-05-01 11:23:09 -07:00
|
|
|
" Author: Oscar Hellström <oscar@oscarh.net>
|
|
|
|
" Contributors: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
|
2014-07-10 21:05:51 -07:00
|
|
|
" Eduardo Lopez (http://github.com/tapichu)
|
2021-05-01 19:09:13 -07:00
|
|
|
" Arvid Bjurklint (http://github.com/slarwise)
|
2023-12-21 09:17:17 -07:00
|
|
|
" Paweł Zacharek (http://github.com/subc2)
|
2024-06-04 00:39:28 -07:00
|
|
|
" Riley Bruins (http://github.com/ribru17) ('commentstring')
|
|
|
|
" Last Update: 2024 May 23
|
2014-07-10 21:05:51 -07:00
|
|
|
" License: Vim license
|
2021-05-01 19:09:13 -07:00
|
|
|
" URL: https://github.com/vim-erlang/vim-erlang-runtime
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
if exists('b:did_ftplugin')
|
2021-05-01 19:09:13 -07:00
|
|
|
finish
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
2021-05-01 19:09:13 -07:00
|
|
|
let b:did_ftplugin = 1
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man')
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
if get(g:, 'erlang_folding', 0)
|
|
|
|
setlocal foldmethod=expr
|
|
|
|
setlocal foldexpr=GetErlangFold(v:lnum)
|
|
|
|
setlocal foldtext=ErlangFoldText()
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
setlocal comments=:%%%,:%%,:%
|
2024-06-04 00:39:28 -07:00
|
|
|
setlocal commentstring=%\ %s
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
setlocal formatoptions+=ro
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2022-10-05 01:56:53 -07:00
|
|
|
if get(g:, 'erlang_extend_path', 1)
|
|
|
|
" typical erlang.mk paths
|
|
|
|
let &l:path = join([
|
|
|
|
\ 'deps/*/include',
|
|
|
|
\ 'deps/*/src',
|
|
|
|
\ 'deps/*/test',
|
|
|
|
\ 'deps/*/apps/*/include',
|
|
|
|
\ 'deps/*/apps/*/src',
|
|
|
|
\ &g:path], ',')
|
|
|
|
" typical rebar3 paths
|
|
|
|
let &l:path = join([
|
|
|
|
\ 'apps/*/include',
|
|
|
|
\ 'apps/*/src',
|
|
|
|
\ '_build/default/lib/*/src',
|
|
|
|
\ '_build/default/*/include',
|
|
|
|
\ &l:path], ',')
|
|
|
|
" typical erlang paths
|
|
|
|
let &l:path = join(['include', 'src', 'test', &l:path], ',')
|
|
|
|
|
|
|
|
set wildignore+=*/.erlang.mk/*,*.beam
|
|
|
|
endif
|
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
setlocal suffixesadd=.erl,.hrl
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
|
|
|
|
let &l:define = '^\s*-\%(define\|record\|type\|opaque\)'
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2023-12-21 09:17:17 -07:00
|
|
|
let s:erlang_fun_begin = '^\l[A-Za-z0-9_@]*(.*$'
|
2021-05-01 19:09:13 -07:00
|
|
|
let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$'
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
if !exists('*GetErlangFold')
|
|
|
|
function GetErlangFold(lnum)
|
|
|
|
let lnum = a:lnum
|
|
|
|
let line = getline(lnum)
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
if line =~ s:erlang_fun_end
|
|
|
|
return '<1'
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
|
|
|
|
return '1'
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
if line =~ s:erlang_fun_begin
|
|
|
|
return '>1'
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
return '='
|
|
|
|
endfunction
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
if !exists('*ErlangFoldText')
|
|
|
|
function ErlangFoldText()
|
|
|
|
let line = getline(v:foldstart)
|
|
|
|
let foldlen = v:foldend - v:foldstart + 1
|
|
|
|
let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
|
|
|
|
if foldlen < 10
|
|
|
|
let lines = ' ' . lines
|
|
|
|
endif
|
|
|
|
let retval = '+' . v:folddashes . lines
|
|
|
|
|
|
|
|
return retval
|
|
|
|
endfunction
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2024-10-12 02:23:31 -07:00
|
|
|
" The following lines enable the matchit.vim plugin for extended
|
2023-12-21 09:17:17 -07:00
|
|
|
" matching with the % key.
|
|
|
|
let b:match_ignorecase = 0
|
|
|
|
let b:match_words =
|
|
|
|
\ '\<\%(begin\|case\|fun\|if\|maybe\|receive\|try\)\>' .
|
|
|
|
\ ':\<\%(after\|catch\|else\|of\)\>' .
|
|
|
|
\ ':\<end\>,' .
|
|
|
|
\ '^\l[A-Za-z0-9_@]*' .
|
|
|
|
\ ':^\%(\%(\t\| \{' . shiftwidth() .
|
|
|
|
\ '}\)\%([^\t\ %][^%]*\)\?\)\?;\s*\%(%.*\)\?$\|\.[\t\ %]\|\.$'
|
|
|
|
let b:match_skip = 's:comment\|string\|erlangmodifier\|erlangquotedatom'
|
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
|
|
|
|
\ . " comments< commentstring< formatoptions< suffixesadd< include<"
|
|
|
|
\ . " define<"
|
2023-12-21 09:17:17 -07:00
|
|
|
\ . " | unlet b:match_ignorecase b:match_words b:match_skip"
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
let &cpo = s:cpo_save
|
|
|
|
unlet s:cpo_save
|
2021-05-01 19:09:13 -07:00
|
|
|
|
|
|
|
" vim: sw=2 et
|