home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / runtime / ftplugin / erlang.vim < prev    next >
Encoding:
Text File  |  2012-05-31  |  1.8 KB  |  88 lines

  1. " Vim ftplugin file
  2. " Language:     Erlang
  3. " Author:       Oscar Hellstr÷m <oscar@oscarh.net>
  4. " Contributors: Ricardo Catalinas JimΘnez <jimenezrick@gmail.com>
  5. "               Eduardo Lopez (http://github.com/tapichu)
  6. " License:      Vim license
  7. " Version:      2012/01/25
  8.  
  9. if exists('b:did_ftplugin')
  10.     finish
  11. else
  12.     let b:did_ftplugin = 1
  13. endif
  14.  
  15. if exists('s:did_function_definitions')
  16.     call s:SetErlangOptions()
  17.     finish
  18. else
  19.     let s:did_function_definitions = 1
  20. endif
  21.  
  22. let s:cpo_save = &cpo
  23. set cpo&vim
  24.  
  25. if !exists('g:erlang_keywordprg')
  26.     let g:erlang_keywordprg = 'erl -man'
  27. endif
  28.  
  29. if !exists('g:erlang_folding')
  30.     let g:erlang_folding = 0
  31. endif
  32.  
  33. let s:erlang_fun_begin = '^\a\w*(.*$'
  34. let s:erlang_fun_end   = '^[^%]*\.\s*\(%.*\)\?$'
  35.  
  36. function 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
  48. endfunction
  49.  
  50. function 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 '='
  67. endfunction
  68.  
  69. function 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
  79. endfunction
  80.  
  81. call s:SetErlangOptions()
  82.  
  83. let b:undo_ftplugin = "setlocal foldmethod< foldexpr< foldtext<"
  84.     \ . " comments< commentstring< formatoptions<"
  85.  
  86. let &cpo = s:cpo_save
  87. unlet s:cpo_save
  88.