neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

erlang.vim (3344B)


      1 " Vim ftplugin file
      2 " Language:     Erlang (http://www.erlang.org)
      3 " Maintainer:   Csaba Hoch <csaba.hoch@gmail.com>
      4 " Author:       Oscar Hellström <oscar@oscarh.net>
      5 " Contributors: Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
      6 "               Eduardo Lopez (http://github.com/tapichu)
      7 "               Arvid Bjurklint (http://github.com/slarwise)
      8 "               Paweł Zacharek (http://github.com/subc2)
      9 "               Riley Bruins (http://github.com/ribru17) ('commentstring')
     10 " Last Update:  2024 May 23
     11 " License:      Vim license
     12 " URL:          https://github.com/vim-erlang/vim-erlang-runtime
     13 
     14 if exists('b:did_ftplugin')
     15  finish
     16 endif
     17 let b:did_ftplugin = 1
     18 
     19 let s:cpo_save = &cpo
     20 set cpo&vim
     21 
     22 let &l:keywordprg = get(g:, 'erlang_keywordprg', 'erl -man')
     23 
     24 if get(g:, 'erlang_folding', 0)
     25  setlocal foldmethod=expr
     26  setlocal foldexpr=GetErlangFold(v:lnum)
     27  setlocal foldtext=ErlangFoldText()
     28 endif
     29 
     30 setlocal comments=:%%%,:%%,:%
     31 setlocal commentstring=%\ %s
     32 
     33 setlocal formatoptions+=ro
     34 
     35 if get(g:, 'erlang_extend_path', 1)
     36  " typical erlang.mk paths
     37  let &l:path = join([
     38        \ 'deps/*/include',
     39        \ 'deps/*/src',
     40        \ 'deps/*/test',
     41        \ 'deps/*/apps/*/include',
     42        \ 'deps/*/apps/*/src',
     43        \ &g:path], ',')
     44  " typical rebar3 paths
     45  let &l:path = join([
     46        \ 'apps/*/include',
     47        \ 'apps/*/src',
     48        \ '_build/default/lib/*/src',
     49        \ '_build/default/*/include',
     50        \ &l:path], ',')
     51  " typical erlang paths
     52  let &l:path = join(['include', 'src', 'test', &l:path], ',')
     53 
     54  set wildignore+=*/.erlang.mk/*,*.beam
     55 endif
     56 
     57 setlocal suffixesadd=.erl,.hrl
     58 
     59 let &l:include = '^\s*-\%(include\|include_lib\)\s*("\zs\f*\ze")'
     60 let &l:define  = '^\s*-\%(define\|record\|type\|opaque\)'
     61 
     62 let s:erlang_fun_begin = '^\l[A-Za-z0-9_@]*(.*$'
     63 let s:erlang_fun_end   = '^[^%]*\.\s*\(%.*\)\?$'
     64 
     65 if !exists('*GetErlangFold')
     66  function GetErlangFold(lnum)
     67    let lnum = a:lnum
     68    let line = getline(lnum)
     69 
     70    if line =~ s:erlang_fun_end
     71      return '<1'
     72    endif
     73 
     74    if line =~ s:erlang_fun_begin && foldlevel(lnum - 1) == 1
     75      return '1'
     76    endif
     77 
     78    if line =~ s:erlang_fun_begin
     79      return '>1'
     80    endif
     81 
     82    return '='
     83  endfunction
     84 endif
     85 
     86 if !exists('*ErlangFoldText')
     87  function ErlangFoldText()
     88    let line    = getline(v:foldstart)
     89    let foldlen = v:foldend - v:foldstart + 1
     90    let lines   = ' ' . foldlen . ' lines: ' . substitute(line, "[\ \t]*", '', '')
     91    if foldlen < 10
     92      let lines = ' ' . lines
     93    endif
     94    let retval = '+' . v:folddashes . lines
     95 
     96    return retval
     97  endfunction
     98 endif
     99 
    100 " The following lines enable the matchit.vim plugin for extended
    101 " matching with the % key.
    102 let b:match_ignorecase = 0
    103 let b:match_words =
    104  \ '\<\%(begin\|case\|fun\|if\|maybe\|receive\|try\)\>' .
    105  \ ':\<\%(after\|catch\|else\|of\)\>' .
    106  \ ':\<end\>,' .
    107  \ '^\l[A-Za-z0-9_@]*' .
    108  \ ':^\%(\%(\t\| \{' . shiftwidth() .
    109  \ '}\)\%([^\t\ %][^%]*\)\?\)\?;\s*\%(%.*\)\?$\|\.[\t\ %]\|\.$'
    110 let b:match_skip = 's:comment\|string\|erlangmodifier\|erlangquotedatom'
    111 
    112 let b:undo_ftplugin = "setlocal keywordprg< foldmethod< foldexpr< foldtext<"
    113      \ . " comments< commentstring< formatoptions< suffixesadd< include<"
    114      \ . " define<"
    115      \ . " | unlet b:match_ignorecase b:match_words b:match_skip"
    116 
    117 let &cpo = s:cpo_save
    118 unlet s:cpo_save
    119 
    120 " vim: sw=2 et