Lines Matching +full:file +full:- +full:lines
1 # This file is a minimal clang-format vim-integration. To install:
2 # - Change 'binary' if clang-format is not on the path (see below).
3 # - Add to your .vimrc:
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>
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
10 # need clang-format on a different key (C-I stands for Ctrl+i).
12 # With this integration you can press the bound key and clang-format will
17 # You can also pass in the variable "l:lines" to choose the range for
19 # "all" to format the full file. So, to format the full file, write a function
22 # : let l:lines="all"
23 # : pyf <path-to-this-file>/clang-format.py
35 # set g:clang_format_path to the path to clang-format if it is not on the path
36 # Change this to the full path if clang-format is not on the path.
37 binary = 'clang-format'
42 # 'clang-format --help' for a list of supported styles. The default looks for
43 # a '.clang-format' or '_clang-format' file to indicate the style that should be
45 style = 'file'
56 if vim.eval('exists("l:lines")') == '1':
57 lines = vim.eval('l:lines')
59 lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1)
62 cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2
64 print 'Couldn\'t determine cursor position. Is your file empty?'
67 # Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format.
75 command = [binary, '-style', style, '-cursor', str(cursor)]
76 if lines != 'all':
77 command.extend(['-lines', lines])
79 command.extend(['-fallback-style', fallback_style])
81 command.extend(['-assume-filename', vim.current.buffer.name])
92 print ('No output from clang-format (crashed?).\n' +
95 lines = stdout.split('\n')
96 output = json.loads(lines[0])
97 lines = lines[1:]
98 sequence = difflib.SequenceMatcher(None, vim.current.buffer, lines)
101 vim.current.buffer[op[1]:op[2]] = lines[op[3]:op[4]]
103 print 'clang-format: incomplete (syntax errors)'