]> granicus.if.org Git - clang/commitdiff
[clang-rename] make clang-rename.py vim integration python3 compatible
authorJonas Toth <jonas.toth@gmail.com>
Mon, 6 Aug 2018 09:08:06 +0000 (09:08 +0000)
committerJonas Toth <jonas.toth@gmail.com>
Mon, 6 Aug 2018 09:08:06 +0000 (09:08 +0000)
Summary:
This patch makes the clang-rename.py script useable for vim with only python3
support. It uses the print-function and adjust the doc slightly to mention
the correct python3 command for the letter mapping in vim.

Reviewers: arphaman, klimek, aaron.ballman, hokein

Reviewed By: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D50307

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338996 91177308-0d34-0410-b5e6-96231b3b80d8

tools/clang-rename/clang-rename.py

index 3cc6644ff8f0a93a6da137a5f0b833d27c663b8d..0cb8a26d27fc5a9c059b1347f77e1f689c15e787 100644 (file)
@@ -7,10 +7,14 @@ Before installing make sure one of the following is satisfied:
 * `g:clang_rename_path` in ~/.vimrc points to valid clang-rename executable
 * `binary` in clang-rename.py points to valid to clang-rename executable
 
-To install, simply put this into your ~/.vimrc
+To install, simply put this into your ~/.vimrc for python2 support
 
     noremap <leader>cr :pyf <path-to>/clang-rename.py<cr>
 
+For python3 use the following command (note the change from :pyf to :py3f)
+
+    noremap <leader>cr :py3f <path-to>/clang-rename.py<cr>
+
 IMPORTANT NOTE: Before running the tool, make sure you saved the file.
 
 All you have to do now is to place a cursor on a variable/function/class which
@@ -18,6 +22,7 @@ you would like to rename and press '<leader>cr'. You will be prompted for a new
 name if the cursor points to a valid symbol.
 '''
 
+from __future__ import print_function
 import vim
 import subprocess
 import sys
@@ -30,8 +35,8 @@ def main():
     # Get arguments for clang-rename binary.
     offset = int(vim.eval('line2byte(line("."))+col(".")')) - 2
     if offset < 0:
-        print >> sys.stderr, '''Couldn\'t determine cursor position.
-                                Is your file empty?'''
+        print('Couldn\'t determine cursor position. Is your file empty?',
+              file=sys.stderr)
         return
     filename = vim.current.buffer.name
 
@@ -51,7 +56,7 @@ def main():
     stdout, stderr = p.communicate()
 
     if stderr:
-        print stderr
+        print(stderr)
 
     # Reload all buffers in Vim.
     vim.command("checktime")