This is an archive of the discontinued LLVM Phabricator instance.

[vim clang-format.py] python3 support
ClosedPublic

Authored by ldrumm on Aug 9 2016, 7:31 AM.

Details

Summary

clang-format.py currently only works in vim compiled against python2. This patch adds the necessary syntax changes to make this work with python3. Ubuntu16 and Arch (at least) ship vim compiled against python3 by default, so this affected me during my recent upgrade.

I've tested this with python3 on ASCII scripts, but have not taken the time to verify this with non-ascii characters in the source. Following the advice here the text piped to clang-format is encoded in the same encoding vim is using. If someone more familiar with clang-format proper is able to comment on the correctness of this behaviour, I'd appreciate it.

Diff Detail

Repository
rL LLVM

Event Timeline

ldrumm updated this revision to Diff 67340.Aug 9 2016, 7:31 AM
ldrumm retitled this revision from to [vim clang-format.py] python3 support.
ldrumm updated this object.
ldrumm added reviewers: djasper, ahmedcharles.
ldrumm added a project: Restricted Project.
ldrumm updated this revision to Diff 67348.Aug 9 2016, 7:46 AM

Make print output the same 2-3

djasper accepted this revision.Aug 10 2016, 7:01 AM
djasper edited edge metadata.

Looks good.

This revision is now accepted and ready to land.Aug 10 2016, 7:01 AM

@djasper, I don't seem to have commit access to cfe so awould you be willing to commit this on my behalf?

Many thanks

Luke

This revision was automatically updated to reflect the committed changes.
scottmg added inline comments.
cfe/trunk/tools/clang-format/clang-format.py
87

Hi, I'm using py2 and I get the problem I described here https://bugs.chromium.org/p/chromium/issues/detail?id=651204 with this change.

Wouldn't we want to be first decode()ing from Vim's buffer format in the specified encoding to get to a Python string, and then encode()ing to whatever format we want to interact with clang-format in?

pseyfert added inline comments.
cfe/trunk/tools/clang-format/clang-format.py
6

For python3 usage, should these lines updated to :py3f instead of :pyf?

pseyfert added inline comments.Oct 1 2017, 5:55 AM
cfe/trunk/tools/clang-format/clang-format.py
6

searching around, maybe even better to put it in if statements:

(following https://vi.stackexchange.com/a/10915)

if has('python')
  map <C-K> :pyf <path-to-this-file>/clang-format.py<cr>
elseif has('python3')
  map <C-K> :py3f <path-to-this-file>/clang-format.py<cr>
endif

created D38446