1" Vim ftplugin file 2" Language: Erlang 3" Author: Oscar Hellstr�m <[email protected]> 4" Contributors: Ricardo Catalinas Jim�nez <[email protected]> 5" Eduardo Lopez (http://github.com/tapichu) 6" License: Vim license 7" Version: 2012/01/25 8 9if exists('b:did_ftplugin') 10 finish 11else 12 let b:did_ftplugin = 1 13endif 14 15if exists('s:did_function_definitions') 16 call s:SetErlangOptions() 17 finish 18else 19 let s:did_function_definitions = 1 20endif 21 22if !exists('g:erlang_keywordprg') 23 let g:erlang_keywordprg = 'erl -man' 24endif 25 26if !exists('g:erlang_folding') 27 let g:erlang_folding = 0 28endif 29 30let s:erlang_fun_begin = '^\a\w*(.*$' 31let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$' 32 33function s:SetErlangOptions() 34 if g:erlang_folding 35 setlocal foldmethod=expr 36 setlocal foldexpr=GetErlangFold(v:lnum) 37 setlocal foldtext=ErlangFoldText() 38 endif 39 40 setlocal comments=:%%%,:%%,:% 41 setlocal commentstring=%%s 42 43 setlocal formatoptions+=ro 44 let &l:keywordprg = g:erlang_keywordprg 45endfunction 46 47function GetErlangFold(lnum) 48 let lnum = a:lnum 49 let line = getline(lnum) 50 51 if line =~ s:erlang_fun_end 52 return '<1' 53 endif 54 55 if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1 56 return '1' 57 endif 58 59 if line =~ s:erlang_fun_begin 60 return '>1' 61 endif 62 63 return '=' 64endfunction 65 66function ErlangFoldText() 67 let line = getline(v:foldstart) 68 let foldlen = v:foldend - v:foldstart + 1 69 let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '') 70 if foldlen < 10 71 let lines = ' ' . lines 72 endif 73 let retval = '+' . v:folddashes . lines 74 75 return retval 76endfunction 77 78call s:SetErlangOptions() 79