"haskellcomplete.vim - Omni Completion for haskell " " Version: 0.7 " Last Updated: 19 Oct 2006 " " Changes " TODO: " User defined docstrings aren't handled right... " 'info' item output can use some formatting work " Add an "unsafe eval" mode, to allow for return type evaluation " Complete basic syntax along with import statements " i.e. "import url" if !has('python') echo "Error: Required vim compiled with +python" finish endif function! haskellcomplete#Complete(findstart, base) "findstart = 1 when we need to get the text length if a:findstart == 1 let line = getline('.') let idx = col('.') while idx > 0 let idx -= 1 let c = line[idx] if c =~ '\w' continue elseif ! c =~ '\.' let idx = -1 break else break endif endwhile return idx "findstart = 0 when we need to return the list of completions else "vim no longer moves the cursor upon completion... fix that let line = getline('.') let idx = col('.') let cword = '' while idx > 0 let idx -= 1 let c = line[idx] if c =~ '\w' || c =~ '\.' || c == '(' let cword = c . cword continue elseif strlen(cword) > 0 || idx == 0 break endif endwhile execute "python vimcomplete('" . cword . "', '" . a:base . "')" return g:haskellcomplete_completions endif endfunction function! s:DefPython() python << PYTHONEOF import sys, tokenize, cStringIO, types, socket from token import NAME, DEDENT, NEWLINE, STRING debugstmts=[] shimsocket = None def dbg(s): debugstmts.append(s) def showdbg(): for d in debugstmts: print "DBG: %s " % d def vimcomplete(context,match): global debugstmts global shimsocket debugstmts = [] try: import vim filename = vim.current.buffer.name if (shimsocket == None): shimsocket = connectshim("/tmp/shim-io") dictstr = evalshim(shimsocket,completesexp(filename, context)) dbg("dict: %s" % dictstr) vim.command("silent let g:haskellcomplete_completions = %s" % dictstr) except vim.error: dbg("VIM Error: %s" % vim.error) def connectshim(socketfile): su = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) su.connect(defaultsock) return su def evalshim(su, sexp): su.send(netencode(sexp)) len = int(su.recv(6),16) res = recvall(len,su) return res def recvall(nlen,su): res = "" reslen = nlen while (reslen >0): buf = su.recv(reslen) res += buf reslen -= len(buf) return res defaultsock = "/tmp/shim-io" def completesexp(filename, prefix): return "(:vim-rex (fuzzy-complete-identifier \"%s\" \"%s\"))\n"%(filename,prefix) def netencode(s): return "%06x%s"%(len(s),s) sys.path.extend(['.','..']) PYTHONEOF endfunction call s:DefPython() " vim: set et ts=4: