2012-05-07 11 views
0

當前的Python#完全不支持與下面的import語句任何python腳本:Vim的蟒蛇#完全不適用於「從.module導入」語句工作

from . import module 
from .modulea import abc 

它會顯示「來自:語法錯誤...「在vim中。

任何人有任何線索可以解決它?

我今天花了一些時間,只是通過pythoncomplete腳本來解決這個問題。我能夠通過對_parsedotname函數的一些破解來解決它。我不確定由於轉換''這個問題,我的黑客手機是多麼便攜。進入絕對路徑,但它在我的機器中工作。下面是我的變化(是的,你看到很多的print語句,我用它來了解碼流...)

def _parsedotname(self,pre=None): 
    #returns (dottedname, nexttoken) 
    name = [] 
    absolute_relative_path = False 
    if pre is None: 
     tokentype, token, indent = self.next() 
     #print tokentype, token, indent 
     if tokentype == 51 and token == '.': 
      import os 
      import sys 
      #print os.path.abspath(os.curdir) 
      fullpath = os.path.abspath(os.curdir) 
      paths = fullpath.split(os.path.sep) 
      n_ = -1 
      #print fullpath 
      pyexeindex = sys.path.index(os.path.dirname(sys.executable)) 
      #print sys.path[pyexeindex:] 
      while fullpath not in sys.path[pyexeindex:]: 
       fullpath = os.path.sep.join(paths[:n_]) 
       #print fullpath 
       n_ -= 1 
      if fullpath == '': 
       return ('', token) 
      absolute_relative_path = True 
      name = '.'.join(paths[n_+1:]) 
      #print name 
     elif tokentype != NAME and token != '*': 
      #print 'should not here' 
      return ('', token) 
    else: token = pre 
    if '.' in name: 
     name = name.split('.') 
    else: 
     name.append(token) 

    while True: 
     if not absolute_relative_path: 
      tokentype, token, indent = self.next() 
      if token != '.': break 
     tokentype, token, indent = self.next() 
     if not absolute_relative_path: 
      if tokentype != NAME: break 
     else: 
      absolute_relative_path = False 
      if tokentype == NAME and token == 'import': 
       return (".".join(name), token) 
     name.append(token) 
    return (".".join(name), token) 

現在,它的工作兩個:

from . import module 
from .moduleA import moduleB 

回答

1

我想你'使用vim內部pythoncomplete

當我寫到這裏:Python docstring with vim pythoncomplete is not displaying newlines for my own class functions

pythoncomplete是一個非常簡單的工具,通過執行import語句(這是相當危險的方式)其大部分完井。解決它可能不是最好的主意,因爲我目前正在嘗試這樣做(編寫好的 python自動完成)。

但是我不認爲我的版本會在另外一兩個月內做好你想做的事情,但它已經很遠了,我準備好後會告訴你。

+0

它是[這裏](https://github.com/davidhalter/jedi)?還有一個問題:完成後你會把它發佈到vim.org(作爲VAM-kr的維護者,我不會錯過這個事件)? – ZyX

+0

是的,它在那裏,我會告訴你這裏,最有可能發佈到vim.org,如果你真的想要一個自動完成,這比舊的更好,你可以試試它。但最終會好得多,我也不會太支持。 –

+0

我可以聽到自動完成和[Python-mode-klen](https://github.com/klen/python-mode)之間的建議功能的比較嗎?我現在正在使用它,完成比vim更好。需要繩子。 – ZyX