public
Description: PySmell is an attempt to create an IDE completion helper for python.
Homepage: http://code.google.com/p/pysmell/
Clone URL: git://github.com/orestis/pysmell.git
frac (author)
Tue May 05 06:07:15 -0700 2009
orestis (committer)
Tue May 05 06:13:36 -0700 2009
pysmell / pysmell.vim
100644 103 lines (88 sloc) 3.129 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
" pysmell.vim
" Omnicompletions provider for Python, using PYSMELLTAGS files
" Copyright (C) 2008 Orestis Markou
" All rights reserved
" E-mail: orestis@orestis.gr
 
" pysmell v0.7.2
" http://orestis.gr
 
" Released subject to the BSD License
 
" Options:
" g:pysmell_debug : set to 1 and create a PYSMELL_DEBUG buffer. Info will get appended there.
" g:pysmell_matcher : one of the following, listed from stricter to fuzzier:
" 'case-sensitive'
" 'case-insensitive' "default
" 'camel-case'
" 'camel-case-sensitive'
" 'smartass'
" 'fuzzy-ci'
" 'fuzzy-cs'
                
 
if !has('python')
    echo "Error: Required vim compiled with +python"
    finish
endif
 
if !exists('g:pysmell_debug')
    let g:pysmell_debug = 0
endif
if !exists('g:pysmell_matcher')
    let g:pysmell_matcher='case-insensitive'
endif
 
python << eopython
from pysmell import vimhelper, idehelper
import vim
import string
TRANSLATEQUOTES = string.maketrans("\'\"", "\"\'")
eopython
 
function! pysmell#Complete(findstart, base)
"findstart = 1 when we need to get the text length
    if a:findstart == 1
python << eopython
row, col = vim.current.window.cursor
line = vim.current.buffer[row-1]
index = idehelper.findBase(line, col)
vim.command('let g:pysmell_origCol = %d' % col)
vim.command('let g:pysmell_origLine = %r' % line)
vim.command('return %d' % index)
eopython
"findstart = 0 when we need to return the list of completions
    else
        let g:pysmell_args = 0
        let g:pysmell_completions = []
python << eopython
origCol = int(vim.eval('g:pysmell_origCol'))
origLine = vim.eval('g:pysmell_origLine')
origSourceLines = vim.current.buffer[:]
lineno = vim.current.window.cursor[0]
origSourceLines[lineno - 1] = origLine
origSource = '\n'.join(origSourceLines)
vimcompletePYSMELL(origSource, lineno, origCol, vim.eval("a:base"))
 
eopython
        return g:pysmell_completions
    endif
endfunction
 
python << eopython
def vimcompletePYSMELL(origSource, origLineNo, origCol, base):
    fullPath = vim.current.buffer.name
    PYSMELLDICT = idehelper.findPYSMELLDICT(fullPath)
    if not PYSMELLDICT:
        vim.command("echoerr 'No PYSMELLTAGS found. You have to generate one.'")
        return
 
    try:
        options = idehelper.detectCompletionType(fullPath, origSource, origLineNo, origCol, base, PYSMELLDICT)
    except:
        f = file('pysmell_exc.txt', 'wb')
        import traceback
        f.write(traceback.format_exc())
        f.close()
        vim.command("echoerr 'Exception written out at pysmell_exc.txt'")
        return
 
    if int(vim.eval('g:pysmell_debug')):
        for b in vim.buffers:
            if b.name.endswith('PYSMELL_DEBUG'):
                b.append("%s %s %s %s" % (fullPath, origSource[origLineNo], origCol, base))
                b.append("%r" % options)
                break
 
    completions = idehelper.findCompletions(base, PYSMELLDICT, options, vim.eval('g:pysmell_matcher'))
    output = repr(completions)
    translated = output.translate(TRANSLATEQUOTES)
    vim.command('let g:pysmell_completions = %s' % (translated, ))
 
eopython