Commits

Naoki INADA committed 62c2fa9

Support +python3 vim

  • Participants
  • Parent commits 4bd4036

Comments (0)

Files changed (2)

 """ropevim, a vim mode for using rope refactoring library"""
+from __future__ import print_function
+
 import os
 import tempfile
 import re
+import sys
 
 import ropemode.decorators
 import ropemode.environment
 import vim
 
 
+if sys.version_info[0] == 3:
+    python_cmd = 'python3'
+else:
+    python_cmd = 'python'
+
 class VimUtils(ropemode.environment.Environment):
 
     def ask(self, prompt, default=None, starting=None):
         globals()[name] = callback
         arg = 'None' if prefix else ''
         vim.command('function! %s()\n' % _vim_name(name) +
-                    'python ropevim.%s(%s)\n' % (name, arg) +
+                    '%s ropevim.%s(%s)\n' % (python_cmd, name, arg) +
                     'endfunction\n')
 
     def _completion_data(self, proposal):
 def echo(message):
     if isinstance(message, unicode):
         message = message.encode(vim.eval('&encoding'))
-    print message
+    print(message)
 
 def call(command):
     return vim.eval(command)
 
     def __init__(self):
         self.values = []
-        vim.command('python import vim')
+        vim.command('%s import vim' % python_cmd)
         vim.command('function! RopeValueCompleter(A, L, P)\n'
-                    'python args = [vim.eval("a:" + p) for p in "ALP"]\n'
-                    'python ropevim._completer(*args)\n'
+                    '%s args = [vim.eval("a:" + p) for p in "ALP"]\n'
+                    '%s ropevim._completer(*args)\n'
                     'return s:completions\n'
-                    'endfunction\n')
+                    'endfunction\n' % (python_cmd, python_cmd))
 
     def __call__(self, arg_lead, cmd_line, cursor_pos):
         # don't know if self.values can be empty but better safe then sorry
 function! LoadRope()
-python << EOF
-import ropevim
-EOF
+    if has('python')
+        python "import ropevim"
+    elseif has('python3')
+        python3 "import ropevim"
+    endif
 endfunction
 
 call LoadRope()