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)
|
2022-10-05 01:56:53 -07:00
|
|
|
" Last Update: 2021-Nov-22
|
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=:%%%,:%%,:%
|
|
|
|
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
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
let s:erlang_fun_begin = '^\a\w*(.*$'
|
|
|
|
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
|
|
|
|
2021-05-01 19:09:13 -07:00
|
|
|
let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
|
|
|
|
\ . " comments< commentstring< formatoptions< suffixesadd< include<"
|
|
|
|
\ . " define<"
|
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
|