[clang] 6bf9e88 - [clang-format] update comments in clang-format.py for python3 compatibility

via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 8 05:17:27 PST 2019


Author: paulhoad
Date: 2019-11-08T13:17:04Z
New Revision: 6bf9e88ae4a45ee43eef3c7978040d33cead59ce

URL: https://github.com/llvm/llvm-project/commit/6bf9e88ae4a45ee43eef3c7978040d33cead59ce
DIFF: https://github.com/llvm/llvm-project/commit/6bf9e88ae4a45ee43eef3c7978040d33cead59ce.diff

LOG: [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

Added: 
    

Modified: 
    clang/tools/clang-format/clang-format.py

Removed: 
    


################################################################################
diff  --git a/clang/tools/clang-format/clang-format.py b/clang/tools/clang-format/clang-format.py
index 0c772f91f6f2..976c222df055 100644
--- a/clang/tools/clang-format/clang-format.py
+++ b/clang/tools/clang-format/clang-format.py
@@ -2,11 +2,19 @@
 # - Change 'binary' if clang-format is not on the path (see below).
 # - Add to your .vimrc:
 #
-#   map <C-I> :pyf <path-to-this-file>/clang-format.py<cr>
-#   imap <C-I> <c-o>:pyf <path-to-this-file>/clang-format.py<cr>
+#   if has('python')
+#     map <C-I> :pyf <path-to-this-file>/clang-format.py<cr>
+#     imap <C-I> <c-o>:pyf <path-to-this-file>/clang-format.py<cr>
+#   elseif has('python3')
+#     map <C-I> :py3f <path-to-this-file>/clang-format.py<cr>
+#     imap <C-I> <c-o>:py3f <path-to-this-file>/clang-format.py<cr>
+#   endif
 #
-# The first line enables clang-format for NORMAL and VISUAL mode, the second
-# line adds support for INSERT mode. Change "C-I" to another binding if you
+# The if-elseif-endif conditional should pick either the python3 or python2 
+# integration depending on your vim setup.
+# 
+# The first mapping enables clang-format for NORMAL and VISUAL mode, the second
+# mapping adds support for INSERT mode. Change "C-I" to another binding if you
 # need clang-format on a 
diff erent key (C-I stands for Ctrl+i).
 #
 # With this integration you can press the bound key and clang-format will
@@ -20,7 +28,11 @@
 # like:
 # :function FormatFile()
 # :  let l:lines="all"
-# :  pyf <path-to-this-file>/clang-format.py
+# :  if has('python')
+# :    pyf <path-to-this-file>/clang-format.py
+# :  elseif has('python3')
+# :    py3f <path-to-this-file>/clang-format.py
+# :  endif
 # :endfunction
 #
 # It operates on the current, potentially unsaved buffer and does not create


        


More information about the cfe-commits mailing list