summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2016-07-07 14:35:32 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2016-07-07 14:35:32 +0000
commit3a12ca57ca9dcc7d130f754db7767c3ed3721bde (patch)
tree674d02da35aa8f3d2ed3d9a110a5beebc1b00ae5
parent7435a910b56344d19033bea84b2040be90c05062 (diff)
downloadbcm5719-llvm-3a12ca57ca9dcc7d130f754db7767c3ed3721bde.tar.gz
bcm5719-llvm-3a12ca57ca9dcc7d130f754db7767c3ed3721bde.zip
[clang-rename] add basic vim integration
This patch introduces basic Vim integration for clang-rename tool. For setup reference see clang-rename/tool/clang-rename.py Patch by Kirill Bobyrev! Differential revision: http://reviews.llvm.org/D22087 llvm-svn: 274759
-rw-r--r--clang-tools-extra/clang-rename/tool/clang-rename.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-rename/tool/clang-rename.py b/clang-tools-extra/clang-rename/tool/clang-rename.py
new file mode 100644
index 00000000000..b4dedb32cef
--- /dev/null
+++ b/clang-tools-extra/clang-rename/tool/clang-rename.py
@@ -0,0 +1,61 @@
+'''
+Minimal clang-rename integration with Vim.
+
+Before installing make sure one of the following is satisfied:
+
+* clang-rename is in your PATH
+* `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
+
+ map ,cr :pyf <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
+you would like to rename and press ',cr'. You will be promted a new name if the
+cursor points to a valid symbol.
+'''
+
+import vim
+import subprocess
+import sys
+
+def main():
+ binary = 'clang-rename'
+ if vim.eval('exists("g:clang_rename_path")') == "1":
+ binary = vim.eval('g:clang_rename')
+
+ # 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?'''
+ return
+ filename = vim.current.buffer.name
+
+ new_name_request_message = 'type new name:'
+ new_name = vim.eval("input('{}\n')".format(new_name_request_message))
+
+ # Call clang-rename.
+ command = [binary,
+ filename,
+ '-i',
+ '-offset', str(offset),
+ '-new-name', str(new_name)]
+ # FIXME: make it possible to run the tool on unsaved file.
+ p = subprocess.Popen(command,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+
+ if stderr:
+ print stderr
+
+ # Reload all buffers in Vim.
+ vim.command("bufdo edit")
+
+
+if __name__ == '__main__':
+ main()
OpenPOWER on IntegriCloud