Skip to content

Commit

Permalink
More customizable options for the code completion. See the README.
Browse files Browse the repository at this point in the history
This makes grep work on Ubuntu with gzip man pages.
  • Loading branch information
Ricardo committed Aug 9, 2010
1 parent 87b8a7b commit d6ded34
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
26 changes: 24 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
== Vim Erlang plugin ==
=== Vim Erlang plugin ===

The indentation plugin is provided by Csaba Hoch and disttributed with his
permission.
Expand All @@ -18,7 +18,9 @@ The tarball root is vim_erlang-REL/. To remove this part of the package
- For local installation (one user only) extract the tarball to your
directory

Settings:

== Settings ==

You can set various variables in your vimrc file to make the plugin behave
differently.

Expand All @@ -43,3 +45,23 @@ The options expect a string with the path or an integer value like before.
g:erlangManPath
* Enable/disable using Erlang man pages in the code completion: (default: 1)
g:erlangCompletionDisplayDoc

More completion options:
The options expect a string as below is explained.

* Set the `grep' command to be use when scanning the man pages: (default: "grep")
g:erlangCompletionGrep
* Set the suffix of the man page names: (default: "")
g:erlangManSuffix

- On Ubuntu, Erlang man pages are placed like this:
/ERLANG/PATH/man/man3/lists.3erl.gz

** So, you must set:
let g:erlangCompletionGrep='zgrep'
let g:erlangManSuffix='erl\.gz'

- In another systems, Erlang man pages are placed like this:
/ERLANG/PATH/man/man3/lists.3

** In this case, use the default options value **
14 changes: 11 additions & 3 deletions autoload/erlangcomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
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 = '~/.vim/autoload/erlang_completion.erl'
let s:erlangCompletionPath = '~/.vim/autoload/erlang_completion.erl'

if !exists('g:erlangCompletionGrep')
g:erlangCompletionGrep = 'grep'
endif

if !exists('g:erlangManSuffix')
g:erlangManSuffix = ''
endif

if !exists('g:erlangManPath')
let g:erlangManPath = '/usr/lib/erlang/man'
Expand Down Expand Up @@ -101,14 +109,14 @@ function s:erlangFindExternalFunc(module, base)
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 . '\.?'
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 = ''
if g:erlangCompletionDisplayDoc != 0
let system_command = 'grep -A 1 "\.B" ' . file_path . ' | grep -EZo "\<' . function_name . '\>\((\w+, ){' . number_of_comma . '}[^),]*\) -> .*"'
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
Expand Down

0 comments on commit d6ded34

Please sign in to comment.