diff options
author | svnmir <svnmir@FreeBSD.org> | 2015-08-07 23:02:56 +0000 |
---|---|---|
committer | svnmir <svnmir@FreeBSD.org> | 2015-08-07 23:02:56 +0000 |
commit | 6416b56f5a3923c6c264b46365e16718ccabf081 (patch) | |
tree | ca13cf9e2e8c2499f61f1246e455efd2804abd36 /tools/clang-format | |
parent | e7bcad327814a78ecb8d5f5545d2e3df84c67a5c (diff) | |
download | FreeBSD-src-6416b56f5a3923c6c264b46365e16718ccabf081.zip FreeBSD-src-6416b56f5a3923c6c264b46365e16718ccabf081.tar.gz |
Vendor import of clang trunk r242221:
https://llvm.org/svn/llvm-project/cfe/trunk@242221
Diffstat (limited to 'tools/clang-format')
-rw-r--r-- | tools/clang-format/clang-format.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tools/clang-format/clang-format.py b/tools/clang-format/clang-format.py index 49ca773..5cb41fc 100644 --- a/tools/clang-format/clang-format.py +++ b/tools/clang-format/clang-format.py @@ -14,6 +14,15 @@ # VISUAL mode. The line or region is extended to the next bigger syntactic # entity. # +# You can also pass in the variable "l:lines" to choose the range for +# formatting. This variable can either contain "<start line>:<end line>" or +# "all" to format the full file. So, to format the full file, write a function +# like: +# :function FormatFile() +# : let l:lines="all" +# : pyf <path-to-this-file>/clang-format.py +# :endfunction +# # It operates on the current, potentially unsaved buffer and does not create # or save any files. To revert a formatting, just undo. @@ -44,7 +53,10 @@ def main(): text = '\n'.join(buf) # Determine range to format. - lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1) + if vim.eval('exists("l:lines")') == '1': + lines = vim.eval('l:lines') + else: + lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1) # Determine the cursor position. cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2 @@ -60,7 +72,9 @@ def main(): startupinfo.wShowWindow = subprocess.SW_HIDE # Call formatter. - command = [binary, '-lines', lines, '-style', style, '-cursor', str(cursor)] + command = [binary, '-style', style, '-cursor', str(cursor)] + if lines != 'all': + command.extend(['-lines', lines]) if fallback_style: command.extend(['-fallback-style', fallback_style]) if vim.current.buffer.name: |