" Vim omni completion file " Language: Erlang " Author: Oscar Hellström " Contributors: kTT (http://github.com/kTT) " Ricardo Catalinas Jiménez " Eduardo Lopez (http://github.com/tapichu) " Zhihui Jiao (http://github.com/onlychoice) " License: Vim license " Version: 2012/11/26 if !exists('g:erlang_completion_cache') let g:erlang_completion_cache = 1 endif " Completion program path let s:erlang_complete_file = expand(':p:h') . '/erlang_complete.erl' " Modules cache used to speed up the completion let s:modules_cache = {} " File cache for persistence between Vim sessions if filewritable(expand(':p:h')) == 2 let s:file_cache = expand(':p:h') . '/vimerl_cache' else let s:file_cache = '/tmp/vimerl_cache' endif " Patterns for completions let s:erlang_local_func_beg = '\(\<[0-9A-Za-z_-]*\|\s*\)$' let s:erlang_external_func_beg = '\<[0-9A-Za-z_-]\+:[0-9A-Za-z_-]*$' let s:erlang_blank_line = '^\s*\(%.*\)\?$' " Main function for completion function erlang_complete#Complete(findstart, base) let lnum = line('.') let column = col('.') let line = strpart(getline('.'), 0, column - 1) " 1) Check if the char to the left of us are part of a function call " " Nothing interesting is written at the char just before the cursor " This means _anything_ could be started here " In this case, keyword completion should probably be used, " for now we'll only try and complete local functions. " " TODO: Examine if we can stare Identifiers end complete on them " Is this worth it? Is /completion/ of a "blank" wanted? Can we consider " `(' interesting and check if we are in a function call etc.? if line[column - 2] !~ '[0-9A-Za-z:_-]' if a:findstart return column else return s:ErlangFindLocalFunc(a:base) endif endif " 2) Function in external module if line =~ s:erlang_external_func_beg let delimiter = match(line, ':[0-9A-Za-z_-]*$') + 1 if a:findstart return delimiter else let module = matchstr(line[:-2], '\<\k*\>$') return s:ErlangFindExternalFunc(module, a:base) endif endif " 3) Local function if line =~ s:erlang_local_func_beg let funcstart = match(line, ':\@ 0 let cache_entry = {a:module : func_list} execute 'redir >>' . s:file_cache silent echon cache_entry silent echon "\n" redir END endif endif endfunction function s:ErlangPurgeCache(...) for mod_name in a:000 if has_key(s:modules_cache, mod_name) call remove(s:modules_cache, mod_name) endif endfor " Delete the old cache file call delete(s:file_cache) " Write a new one for mod_name in keys(s:modules_cache) call s:ErlangWriteCache(mod_name) endfor endfunction " Load the file cache when this script is autoloaded call s:ErlangLoadCache() " Command for removing modules from the cache command -nargs=+ ErlangPurgeCache silent call s:ErlangPurgeCache()