diff options
| author | Stephen Hines <srhines@google.com> | 2019-07-02 16:25:20 -0700 |
|---|---|---|
| committer | Ali B <abittin@gmail.com> | 2019-07-05 19:33:16 +0300 |
| commit | 9afee4e65dc5f9f5eb371683729ff67b8df81d03 (patch) | |
| tree | 4cf241d6c9044f91ee8c06e6920174d06f8de0b6 /clang-r353983e/share/clang/clang-rename.py | |
| parent | 2f19bd722c4c825320d1511c1ed83161b7f95d51 (diff) | |
clang 9.0.5 (based on r353983e) from build 5696680.
Bug: http://b/135931688
Bug: http://b/136008926
Test: N/A
Change-Id: I922d17410047d2e2df4625615352c588ee71b203
Diffstat (limited to 'clang-r353983e/share/clang/clang-rename.py')
| -rwxr-xr-x | clang-r353983e/share/clang/clang-rename.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/clang-r353983e/share/clang/clang-rename.py b/clang-r353983e/share/clang/clang-rename.py new file mode 100755 index 00000000..3381c526 --- /dev/null +++ b/clang-r353983e/share/clang/clang-rename.py @@ -0,0 +1,66 @@ +''' +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 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 +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 absolute_import, division, print_function +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_path') + + # Get arguments for clang-rename binary. + offset = int(vim.eval('line2byte(line("."))+col(".")')) - 2 + if offset < 0: + print('Couldn\'t determine cursor position. Is your file empty?', + file=sys.stderr) + 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("checktime") + + +if __name__ == '__main__': + main() |
