[cfe-dev] Slightly improved clang-format vim integration

Steffen Prohaska prohaska at zib.de
Mon Sep 16 10:04:43 PDT 2013


Hello,

On Sep 16, 2013, at 5:17 PM, Sean Silva <silvas at purdue.edu> wrote:

> What version of vim are you using?

I'm using a recent MacVim, which is based on vim version 7.4.


> There seem to be a number of things that don't work for me (I'm on Ubuntu Linux):

I've checked in the vim history when the necessary features were introduced:


> - `vim.vars` doesn't exist

This has been introduced in version 7.3.911:

http://code.google.com/p/vim/source/detail?r=f1eab4f77a6fe4b77508d86a68a6681195806607

An alternative is to use vim.eval("g:...").


> - `:help python-special-path` isn't available
> - Putting the file in `~/.vim/pythonx` doesn't seem to work (`ImportError: No module named clang_format`)

The import search path has been introduced in version 7.3.1163:

http://code.google.com/p/vim/source/detail?r=70b1178dec7919120632cdeee6056e38108356a7


> Overall, I think that being able to configure the formatting behavior from e.g. `autocmd FileType` is a win, but this patch doesn't seem to work for me.

I've attached a revised script that should work with much older vim versions.  See suggested commit message for details:


'''
clang-format: Use a Python module in vim with config via 'g:' globals

clang-format.py is changed to a Python module (therefore renamed to
'clang_format.py'), which is imported once into vim and then directly
called from vim mappings.  Configuration now works via global vim
variables 'g:clang_format_binary' and 'g:clang_format_style'.  Using
global variables is more flexible than hard-coded values in the Python
script.  For example, the style can be changed on-the-fly in 'autocmd
FileType'.

The implementation should work with vim 7.1 and later (maybe even 7.0).
It has been tested with 7.2.330 (Ubuntu 10.04), 7.3.429 (Ubuntu 12.04),
and MacVim 7.4.

Note also that unnamed buffers are now properly handled.  Previously,
a Python exception was raised for unnamed buffers by subprocess.Popen,
because it was called with None for vim.current.buffer.name.
'''

-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang_format.py
Type: text/x-python-script
Size: 4504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130916/06bebd88/attachment.bin>


More information about the cfe-dev mailing list