Skip to content

Commit 6bf9e88

Browse files
[clang-format] update comments in clang-format.py for python3 compatibility
Summary: D23319 introduced python3 compatibility to clang-format.py, this is however not reflected by the documentation in the comments at the beginning of the file, which show how to use the script with python2 in .vimrc. While the actual mapping a user might want to use may well differ from my suggestion, I think it's nice to show the python2 and python3 version, such that a user can pick from the suggestions instead of googeling the python3 replacement for `:pyf` which they might not be familiar with. EDIT: picking reviewers according to https://llvm.org/docs/Phabricator.html#finding-potential-reviewers Reviewers: klimek, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: ilya-biryukov, cfe-commits, llvm-commits, ychen Patch By: pseyfert Tags: #clang-tools-extra, #llvm, #clang Differential Revision: https://reviews.llvm.org/D38446
1 parent c0a7732 commit 6bf9e88

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

clang/tools/clang-format/clang-format.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
# - Change 'binary' if clang-format is not on the path (see below).
33
# - Add to your .vimrc:
44
#
5-
# map <C-I> :pyf <path-to-this-file>/clang-format.py<cr>
6-
# imap <C-I> <c-o>:pyf <path-to-this-file>/clang-format.py<cr>
5+
# if has('python')
6+
# map <C-I> :pyf <path-to-this-file>/clang-format.py<cr>
7+
# imap <C-I> <c-o>:pyf <path-to-this-file>/clang-format.py<cr>
8+
# elseif has('python3')
9+
# map <C-I> :py3f <path-to-this-file>/clang-format.py<cr>
10+
# imap <C-I> <c-o>:py3f <path-to-this-file>/clang-format.py<cr>
11+
# endif
712
#
8-
# The first line enables clang-format for NORMAL and VISUAL mode, the second
9-
# line adds support for INSERT mode. Change "C-I" to another binding if you
13+
# The if-elseif-endif conditional should pick either the python3 or python2
14+
# integration depending on your vim setup.
15+
#
16+
# The first mapping enables clang-format for NORMAL and VISUAL mode, the second
17+
# mapping adds support for INSERT mode. Change "C-I" to another binding if you
1018
# need clang-format on a different key (C-I stands for Ctrl+i).
1119
#
1220
# With this integration you can press the bound key and clang-format will
@@ -20,7 +28,11 @@
2028
# like:
2129
# :function FormatFile()
2230
# : let l:lines="all"
23-
# : pyf <path-to-this-file>/clang-format.py
31+
# : if has('python')
32+
# : pyf <path-to-this-file>/clang-format.py
33+
# : elseif has('python3')
34+
# : py3f <path-to-this-file>/clang-format.py
35+
# : endif
2436
# :endfunction
2537
#
2638
# It operates on the current, potentially unsaved buffer and does not create

0 commit comments

Comments
 (0)