Permalink
Browse files

erlang files und vimrc.local

  • Loading branch information...
1 parent 6b668dc commit 8805a387966616f3d502c9c887cef8429d6bfb94 @TeaMoe committed May 16, 2010
Showing with 815 additions and 0 deletions.
  1. +1 −0 FIXME
  2. +37 −0 README_erlang
  3. +5 −0 TODO
  4. +112 −0 autoload/erlangcomplete.vim
  5. +200 −0 ftplugin/erlang.vim
  6. +206 −0 indent/erlang.vim
  7. +137 −0 syntax/erlang.vim
  8. +103 −0 test/test.erl
  9. +2 −0 vimrc
  10. +12 −0 vimrc.local
View
1 FIXME
@@ -0,0 +1 @@
+
View
@@ -0,0 +1,37 @@
+Vim Erlang plugin
+
+The indentation plugin is provided by Csaba Hoch and disttributed with his
+permission.
+
+Installation:
+The tarball root is vim_erlang-REL/. To remove this part of the package
+(e.g., to extract the contents to you .vim dir) use tar --strip-components 1
+-xjf vim_erlang-X.X.tar.bz2
+
+* Unix
+ - For local installation (one user only) extract the tarball to your
+ ~/.vim directory
+ - For global installation extract the tarball to your vim runtime
+ directory (e.g. /usr/share/vim/vimX/)
+
+* Win
+ - For local installation (one user only) extract the tarball to your
+ directory
+
+Settings:
+You can set various variables in your vimrc file to make the plugin behave
+differently.
+
+Syntax options:
+The options expect a 0 value for disabling and a non-zero (e.g. 1) for enabling.
+
+* Highlight all Erlang bifs as keywords: (default: 0)
+ g:erlangHighlightBif
+
+Folding options:
+The options expect a 0 value for disabling and a non-zero (e.g. 1) for enabling.
+
+* Enable/disable folding: (default: 1)
+ g:erlangFold
+* Splitting functions if a new function head appears: (default: 0)
+ g:erlangFoldSplitFunction
View
5 TODO
@@ -0,0 +1,5 @@
+ * Code skeletons for modules
+ * Fix folding
+ * I don't actually know what's not working or what's working but a note says it needs to be fixed.
+ * Omni completion
+ * Completion of local functions is implemented
View
@@ -0,0 +1,112 @@
+" ------------------------------------------------------------------------------
+" Vim omni-completion script
+" Author: Oscar Hellström
+" Email: oscar@oscarh.net
+" Version: 2006-06-23
+" ------------------------------------------------------------------------------
+
+" 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*\(%.*\)\?$'
+
+" 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, '\(\<\)\@<=[0-9A-Za-z_-]\+:\@=')
+ return s:erlangFindExternalFunc(module, a:base)
+ endif
+ endif
+
+ " 4) Local function {{{2
+ if line =~ s:erlangLocalFuncBeg
+ let funcstart = match(line, ':\@<![0-9A-Za-z_-]*$')
+ if a:findstart
+ return funcstart
+ else
+ return s:erlangFindLocalFunc(a:base)
+ endif
+ endif
+
+ " 5) Unhandled situation {{{2
+ if a:findstart
+ return -1
+ else
+ return []
+ endif
+endfunction
+
+" Auxiliary functions for completion {{{1
+" Find the next non-blank line {{{2
+function s:erlangFindNextNonBlank(lnum)
+ let lnum = nextnonblank(a:lnum + 1)
+ let line = getline(lnum)
+ while line =~ s:ErlangBlankLine && 0 != lnum
+ let lnum = nextnonblank(lnum + 1)
+ let line = getline(lnum)
+ endwhile
+ return lnum
+endfunction
+
+" vim: foldmethod=marker:
+" Find external function names {{{2
+function s:erlangFindExternalFunc(module, base)
+ let functions = []
+ return functions
+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
+
View
@@ -0,0 +1,200 @@
+" Vim ftplugin file
+" Language: Erlang
+" Maintainer: Oscar Hellström <oscar@oscarh.net>
+" URL: http://personal.oscarh.net
+" Version: 2006-06-23
+" ------------------------------------------------------------------------------
+" Usage: {{{1
+"
+" To disable folding put
+" let g:erlangFold=0
+" in your vimrc
+"
+" Folding will make only one fold for a complete function, even though it has
+" more than one function head and body
+" To change this behaviour put
+" let g:erlangFoldSplitFunction=1
+" in your vimrc file
+"
+" }}}
+" ------------------------------------------------------------------------------
+" Plugin init {{{1
+if exists("b:did_ftplugin")
+ finish
+endif
+
+" Don't load any other
+let b:did_ftplugin=1
+
+if exists('s:doneFunctionDefinitions')
+ call s:SetErlangOptions()
+ finish
+endif
+
+let s:doneFunctionDefinitions=1
+" }}}
+
+" Local settings {{{1
+" Run Erlang make instead of GNU Make
+function s:SetErlangOptions()
+ if version >= 700
+ setlocal omnifunc=erlangcomplete#Complete
+ endif
+
+ " {{{2 Settings for folding
+ if (!exists("g:erlangFold")) || g:erlangFold
+ setlocal foldmethod=expr
+ setlocal foldexpr=GetErlangFold(v:lnum)
+ setlocal foldtext=ErlangFoldText()
+ "setlocal fml=2
+ endif
+endfunction
+
+
+" Define folding functions {{{1
+if !exists("*GetErlangFold")
+ " Folding params {{{2
+ " FIXME: Could these be shared between scripts?
+ let s:ErlangFunEnd = '^[^%]*\.\s*\(%.*\)\?$'
+ let s:ErlangFunHead = '^\a\w*(.*)\(\s+when\s+.*\)\?\s\+->\s*$'
+ let s:ErlangBeginHead = '^\a\w*(.*$'
+ let s:ErlangEndHead = '^\s\+[a-zA-Z-_{}\[\], ]\+)\(\s+when\s+.*\)\?\s\+->\s\(%.*\)\?*$'
+ let s:ErlangBlankLine = '^\s*\(%.*\)\?$'
+
+ " Auxiliary fold functions {{{2
+ function s:GetNextNonBlank(lnum)
+ let lnum = nextnonblank(a:lnum + 1)
+ let line = getline(lnum)
+ while line =~ s:ErlangBlankLine && 0 != lnum
+ let lnum = nextnonblank(lnum + 1)
+ let line = getline(lnum)
+ endwhile
+ return lnum
+ endfunction
+
+ function s:GetFunName(str)
+ return matchstr(a:str, '^\a\w*(\@=')
+ endfunction
+
+ function s:GetFunArgs(str, lnum)
+ let str = a:str
+ let lnum = a:lnum
+ while str !~ '->\s*\(%.*\)\?$'
+ let lnum = s:GetNextNonBlank(lnum)
+ if 0 == lnum " EOF
+ return ""
+ endif
+ let str .= getline(lnum)
+ endwhile
+ return matchstr(str,
+ \ '\(^(\s*\)\@<=.*\(\s*)\(\s\+when\s\+.*\)\?\s\+->\s*\(%.*\)\?$\)\@=')
+ endfunction
+
+ function s:CountFunArgs(arguments)
+ let pos = 0
+ let ac = 0 " arg count
+ let arguments = a:arguments
+
+ " Change list / tuples into just one A(rgument)
+ let erlangTuple = '{\([A-Za-z_,|=\-\[\]]\|\s\)*}'
+ let erlangList = '\[\([A-Za-z_,|=\-{}]\|\s\)*\]'
+
+ " FIXME: Use searchpair?
+ while arguments =~ erlangTuple
+ let arguments = substitute(arguments, erlangTuple, "A", "g")
+ endwhile
+ " FIXME: Use searchpair?
+ while arguments =~ erlangList
+ let arguments = substitute(arguments, erlangList, "A", "g")
+ endwhile
+
+ let len = strlen(arguments)
+ while pos < len && pos > -1
+ let ac += 1
+ let pos = matchend(arguments, ',\s*', pos)
+ endwhile
+ return ac
+ endfunction
+
+ " Main fold function {{{2
+ function GetErlangFold(lnum)
+ let lnum = a:lnum
+ let line = getline(lnum)
+
+ " Function head gives fold level 1 {{{3
+ if line=~ s:ErlangBeginHead
+ while line !~ s:ErlangEndHead
+ if 0 == lnum " EOF / BOF
+ retun '='
+ endif
+ if line =~ s:ErlangFunEnd
+ return '='
+ endif
+ endif
+ let lnum = s:GetNextNonBlank(lnum)
+ let line = getline(lnum)
+ endwhile
+ " check if prev line was really end of function
+ let lnum = s:GetPrevNonBlank(a:lnum)
+ if exists("g:erlangFoldSplitFunction") && g:erlangFoldSplitFunction
+ if getline(lnum) !~ s:ErlangFunEnd
+ return '='
+ endif
+ endif
+ return '1>'
+ endif
+
+ " End of function (only on . not ;) gives fold level 0 {{{3
+ if line =~ s:ErlangFunEnd
+ return '<1'
+ endif
+
+ " Check if line below is a new function head {{{3
+ " Only used if we want to split folds for different function heads
+ " Ignores blank lines
+ if exists("g:erlangFoldSplitFunction") && g:erlangFoldSplitFunction
+ let lnum = s:GetNextNonBlank(lnum)
+
+ if 0 == lnum " EOF
+ return '<1'
+ endif
+
+ let line = getline(lnum)
+
+ " End of prev function head (new function here), ending fold level 1
+ if line =~ s:ErlangFunHead || line =~ s:ErlangBeginHead
+ return '<1'
+ endif
+ endif
+
+ " Otherwise use fold from previous line
+ return '='
+ endfunction
+
+ " Erlang fold description (foldtext function) {{{2
+ function ErlangFoldText()
+ let foldlen = v:foldend - v:foldstart
+ if 1 < foldlen
+ let lines = "lines"
+ else
+ let lines = "line"
+ endif
+ let line = getline(v:foldstart)
+ let name = s:GetFunName(line)
+ let arguments = s:GetFunArgs(strpart(line, strlen(name)), v:foldstart)
+ let argcount = s:CountFunArgs(arguments)
+ let retval = v:folddashes . " " . name . "/" . argcount
+ let retval .= " (" . foldlen . " " . lines . ")"
+ return retval
+ endfunction " }}}
+endif " }}}
+
+call s:SetErlangOptions()
+
+" Skeletons {{{1
+function GenServer()
+ echo foo
+endfunction
+" }}}
+
+" vim: set foldmethod=marker:
Oops, something went wrong.

0 comments on commit 8805a38

Please sign in to comment.