Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type error when using vim.eval #15

Merged
merged 1 commit into from
Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ let g:completor_{filetype}_omni_trigger = '<python regex>'

For example to use css omnifunc:
```vim
let g:completor_css_omni_trigger = '(\w+|@\w*|\w+:\s*\w*)$'
let g:completor_css_omni_trigger = '([\w-]+|@[\w-]*|[\w-]+:\s*[\w-]*)$'
```

Install
Expand Down
2 changes: 1 addition & 1 deletion doc/completor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Other *completor-other*
<
For example to use css omnifunc:
>
let g:completor_css_omni_trigger = '(\w+|@\w*|\w+:\s*\w*)$'
let g:completor_css_omni_trigger = '([\w-]+|@[\w-]*|[\w-]+:\s*[\w-]*)$'
<
==============================================================================
4. Options *completor-options*
Expand Down
13 changes: 12 additions & 1 deletion pythonx/completers/_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def test_subseq(src, target):
return score


def getftime(nr):
try:
bufname = vim.Function('bufname')
ftime = vim.Function('getftime')
return ftime(bufname(nr))
except vim.error:
return -1


class TokenStore(object):
pat = re.compile('\w+')

Expand Down Expand Up @@ -56,7 +65,9 @@ def store_buffer(self, buffer, base, cur_nr, cur_line):
self.current = set(self.pat.findall(data))
self.current.difference_update([base])
elif buffer.valid and len(buffer) <= 10000:
ftime = vim.eval('getftime(bufname({}))'.format(nr))
ftime = getftime(nr)
if ftime < 0:
return
if nr not in self.cache or ftime > self.cache[nr]['t']:
self.cache[nr] = {'t': ftime}
data = ' '.join(buffer[:])
Expand Down
20 changes: 9 additions & 11 deletions pythonx/completers/_omni.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from completor import Completor, start_column
from completor import Completor

import vim
import re
Expand Down Expand Up @@ -37,16 +37,14 @@ def parse(self, base):
return []

try:
start = vim.eval('function(&omnifunc)(1,"")')
if start < 0:
func_name = vim.eval('&omnifunc')
if not func_name:
return []
codepoint = start_column(ft, base)
res = vim.eval('function(&omnifunc)(0,"{}")'.format(
base[codepoint:len(base)]))
if isinstance(res, dict) and 'words' in res:
res = res['words']
if not isinstance(res, list):

omnifunc = vim.Function(func_name)
start = omnifunc(1, '')
if start < 0:
return []
return [r for r in res if r]
except vim.error:
return omnifunc(0, base[start:len(base)])
except (vim.error, ValueError, KeyboardInterrupt):
return []
4 changes: 2 additions & 2 deletions pythonx/completor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def commons(cls):

@property
def current_directory(self):
return vim.eval('expand("%:p:h")')
return vim.Function('expand')('%:p:h')

@property
def tempname(self):
return vim.eval('completor#utils#tempname()')
return vim.Function('completor#utils#tempname')()

@property
def filename(self):
Expand Down