From 0fcd056648da760f727a7296bae364ea5c4b5e98 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Tue, 17 Sep 2013 02:02:37 +0200 Subject: fix: Switch erlang to oscarh/vimerl (it doesnt use plugin dir) --- autoload/erlang_complete.vim | 219 ------------------------------------------- autoload/erlangcomplete.vim | 161 +++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 219 deletions(-) delete mode 100644 autoload/erlang_complete.vim create mode 100644 autoload/erlangcomplete.vim (limited to 'autoload') diff --git a/autoload/erlang_complete.vim b/autoload/erlang_complete.vim deleted file mode 100644 index 9d108fbc..00000000 --- a/autoload/erlang_complete.vim +++ /dev/null @@ -1,219 +0,0 @@ -" 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() diff --git a/autoload/erlangcomplete.vim b/autoload/erlangcomplete.vim new file mode 100644 index 00000000..3e4208e8 --- /dev/null +++ b/autoload/erlangcomplete.vim @@ -0,0 +1,161 @@ +" ------------------------------------------------------------------------------ +" Vim omni-completion script +" Author: Oscar Hellström +" Email: oscar@oscarh.net +" Version: 2010-08-10 +" Contributors: kTT (http://github.com/kTT) +" Ricardo Catalinas Jiménez +" ------------------------------------------------------------------------------ + +" Patterns for completions {{{1 +let s:erlangLocalFuncBeg = '\(\<[0-9A-Za-z_-]*\|\s*\)$' +let s:erlangExternalFuncBeg = '\<[0-9A-Za-z_-]\+:[0-9A-Za-z_-]*$' +let s:ErlangBlankLine = '^\s*\(%.*\)\?$' +let s:erlangCompletionPath = expand(':p:h') . '/erlang_completion.erl' + +if !exists('g:erlangCompletionGrep') + let g:erlangCompletionGrep = 'grep' +endif + +if !exists('g:erlangManSuffix') + let g:erlangManSuffix = '' +endif + +if !exists('g:erlangManPath') + let g:erlangManPath = '/usr/lib/erlang/man' +endif + +if !exists('g:erlangCompletionDisplayDoc') + let g:erlangCompletionDisplayDoc = 1 +endif + +" Main function for completion {{{1 +function! erlangcomplete#Complete(findstart, base) + " 0) Init {{{2 + let lnum = line('.') + let column = col('.') + let line = strpart(getline('.'), 0, column - 1) + + " 1) First, check if completion is impossible {{{2 + if line =~ '[^~\\]%' + return -1 + endif + + "echo "line[col - 1]:" . line[column - 1] . " line[col - 2]:" . line[column - 2] . "\n" . line . "\n" + + " 2) Check if the char to the left of us are part of a function call {{{2 + " + " 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 + + + " 3) Function in external module {{{2 + if line =~ s:erlangExternalFuncBeg + 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 + + " 4) Local function {{{2 + if line =~ s:erlangLocalFuncBeg + let funcstart = match(line, ':\@/dev/null' '2>/dev/null' + redraw! + endif + let functions = system(s:erlangCompletionPath . ' ' . a:module) + for element in sort(split(functions, '\n')) + if match(element, a:base) == 0 + let function_name = matchstr(element, a:base . '\w\+') + let number_of_args = matchstr(element, '\d\+', len(function_name)) + let number_of_comma = max([number_of_args - 1, 0]) + let file_path = g:erlangManPath . '/man?/' . a:module . '\.?' . g:erlangManSuffix + " [:-2] cutting some weird characters at the end + " becouse grep doesn't support multilines, we have to filter + " first by .B and next by looking via function name + " if someone have better idea, please change it + let description = '' + " Don't look man pages if the module is present in the current directory + if g:erlangCompletionDisplayDoc != 0 && !filereadable(a:module . '.erl') + let system_command = g:erlangCompletionGrep . ' -A 1 "\.B" ' . file_path . ' | grep -EZo "\<' . +\ function_name . '\>\((\w+, ){' . number_of_comma . '}[^),]*\) -> .*"' + let description = system(system_command) + let description = description[:-2] + endif + if description == '' + let description = element " if function doesn't have description e.g. lists:rmerge, put rmerge/2 instead + endif + let field = {'word': function_name . '(', 'abbr': description, 'kind': 'f', 'dup': 1} " always duplicate functions + call complete_add(field) + endif + endfor + return [] +endfunction + +" Find local function names {{{2 +function s:erlangFindLocalFunc(base) + " begin at line 1 + let lnum = s:erlangFindNextNonBlank(1) + if "" == a:base + let base = '\w' " used to match against word symbol + else + let base = a:base + endif + while 0 != lnum && !complete_check() + let line = getline(lnum) + let function_name = matchstr(line, '^' . base . '[0-9A-Za-z_-]\+(\@=') + if function_name != "" + call complete_add(function_name) + endif + let lnum = s:erlangFindNextNonBlank(lnum) + endwhile + return [] +endfunction + -- cgit v1.2.3