From 8d1f3342a9ea3e8a2f9b97304ac64a06aa06a7c2 Mon Sep 17 00:00:00 2001 From: David Halter Date: Tue, 6 Mar 2012 00:30:02 +0100 Subject: [PATCH] started with the vim interface --- functions.py | 16 ++++++++++++ py_functions.vim | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 functions.py create mode 100644 py_functions.vim diff --git a/functions.py b/functions.py new file mode 100644 index 00000000..7cedf027 --- /dev/null +++ b/functions.py @@ -0,0 +1,16 @@ +import pyfuzzyparser + +def complete(source, row, colum, file_callback=None): + """ + An auto completer for python files. + + :param source: The source code of the current file + :type source: string + :param row: The row to complete in. + :type row: int + :param col: The column to complete in. + :type col: int + :return: list + :rtype: list + """ + return [] diff --git a/py_functions.vim b/py_functions.vim new file mode 100644 index 00000000..88cdff6a --- /dev/null +++ b/py_functions.vim @@ -0,0 +1,63 @@ +"py_fuzzycomplete.vim - Omni Completion for python in vim +" Maintainer: David Halter +" Version: 0.1 +" +" This part of the software is just the vim interface. The main source code +" lies in the python files around it. + +if !has('python') + echo "Error: Required vim compiled with +python" + finish +endif + +function! pythoncomplete#Complete(findstart, base) + "findstart = 1 when we need to get the text length + " TODO check wheter this is really needed + 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 + execute "python vimcomplete()" + return g:pythoncomplete_completions + endif +endfunction + +function! s:DefPython() +python << PYTHONEOF +import functions + +def vimcomplete(): + (row, column) = vim.current.window.cursor + code = '\n'.join(vim.current.buffer) + all = functions.complete(code, row, column) + + dictstr = '[' + # have to do this for double quoting + for cmpl in all: + dictstr += '{' + for x in cmpl: dictstr += '"%s":"%s",' % (x,cmpl[x]) + dictstr += '"icase":0},' + if dictstr[-1] == ',': dictstr = dictstr[:-1] + dictstr += ']' + vim.command("silent let g:pythoncomplete_completions = %s" % dictstr) + +PYTHONEOF +endfunction + +call s:DefPython() +" vim: set et ts=4: