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 22let s:cpo_save = &cpo 23set cpo&vim 24 25if !exists('g:erlang_keywordprg') 26 let g:erlang_keywordprg = 'erl -man' 27endif 28 29if !exists('g:erlang_folding') 30 let g:erlang_folding = 0 31endif 32 33let s:erlang_fun_begin = '^\a\w*(.*$' 34let s:erlang_fun_end = '^[^%]*\.\s*\(%.*\)\?$' 35 36function s:SetErlangOptions() 37 if g:erlang_folding 38 setlocal foldmethod=expr 39 setlocal foldexpr=GetErlangFold(v:lnum) 40 setlocal foldtext=ErlangFoldText() 41 endif 42 43 setlocal comments=:%%%,:%%,:% 44 setlocal commentstring=%%s 45 46 setlocal formatoptions+=ro 47 let &l:keywordprg = g:erlang_keywordprg 48endfunction 49 50function GetErlangFold(lnum) 51 let lnum = a:lnum 52 let line = getline(lnum) 53 54 if line =~ s:erlang_fun_end 55 return '<1' 56 endif 57 58 if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1 59 return '1' 60 endif 61 62 if line =~ s:erlang_fun_begin 63 return '>1' 64 endif 65 66 return '=' 67endfunction 68 69function ErlangFoldText() 70 let line = getline(v:foldstart) 71 let foldlen = v:foldend - v:foldstart + 1 72 let lines = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '') 73 if foldlen < 10 74 let lines = ' ' . lines 75 endif 76 let retval = '+' . v:folddashes . lines 77 78 return retval 79endfunction 80 81call s:SetErlangOptions() 82 83let b:undo_ftplugin = "setlocal foldmethod< foldexpr< foldtext<" 84 \ . " comments< commentstring< formatoptions<" 85 86let &cpo = s:cpo_save 87unlet s:cpo_save 88