Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / tools / clang-rename / clang-rename.py
blob1cbabaf859a5e8d67cdc6a057f3bf2e4d80cf646
1 """
2 Minimal clang-rename integration with Vim.
4 Before installing make sure one of the following is satisfied:
6 * clang-rename is in your PATH
7 * `g:clang_rename_path` in ~/.vimrc points to valid clang-rename executable
8 * `binary` in clang-rename.py points to valid to clang-rename executable
10 To install, simply put this into your ~/.vimrc for python2 support
12 noremap <leader>cr :pyf <path-to>/clang-rename.py<cr>
14 For python3 use the following command (note the change from :pyf to :py3f)
16 noremap <leader>cr :py3f <path-to>/clang-rename.py<cr>
18 IMPORTANT NOTE: Before running the tool, make sure you saved the file.
20 All you have to do now is to place a cursor on a variable/function/class which
21 you would like to rename and press '<leader>cr'. You will be prompted for a new
22 name if the cursor points to a valid symbol.
23 """
25 from __future__ import absolute_import, division, print_function
26 import vim
27 import subprocess
28 import sys
31 def main():
32 binary = "clang-rename"
33 if vim.eval('exists("g:clang_rename_path")') == "1":
34 binary = vim.eval("g:clang_rename_path")
36 # Get arguments for clang-rename binary.
37 offset = int(vim.eval('line2byte(line("."))+col(".")')) - 2
38 if offset < 0:
39 print(
40 "Couldn't determine cursor position. Is your file empty?", file=sys.stderr
42 return
43 filename = vim.current.buffer.name
45 new_name_request_message = "type new name:"
46 new_name = vim.eval("input('{}\n')".format(new_name_request_message))
48 # Call clang-rename.
49 command = [
50 binary,
51 filename,
52 "-i",
53 "-offset",
54 str(offset),
55 "-new-name",
56 str(new_name),
58 # FIXME: make it possible to run the tool on unsaved file.
59 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
60 stdout, stderr = p.communicate()
62 if stderr:
63 print(stderr)
65 # Reload all buffers in Vim.
66 vim.command("checktime")
69 if __name__ == "__main__":
70 main()