Skip to content

Commit 27e5ac2

Browse files
authored
Only call clang-format if file is not empty (google#189)
Signed-off-by: Wolfgang E. Sanyer <WolfgangSanyer@Google.com>
1 parent 605dc00 commit 27e5ac2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

autoload/codefmt/clangformat.vim

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ function! codefmt#clangformat#GetFormatter() abort
129129
""
130130
" Reformat buffer with clang-format, only targeting [ranges] if given.
131131
function l:formatter.FormatRanges(ranges) abort
132+
if line('$') == 1 && getline(1) == ''
133+
" If the buffer is completely empty, there's nothing to do
134+
return
135+
endif
136+
132137
let l:Style_value = s:plugin.Flag('clang_format_style')
133138
if type(l:Style_value) is# type('')
134139
let l:style = l:Style_value

vroom/clangformat.vroom

+7
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,10 @@ current buffer.
181181

182182
The -assume-filename arg passed above is also related, used by the clang-format
183183
tool to detect any custom style rules particular to the current file.
184+
185+
186+
Bug #102. When the buffer is empty, clang-format does _not_ return a cursor
187+
position
188+
189+
@clear
190+
:FormatCode clang-format

0 commit comments

Comments
 (0)