Skip to content

Commit b7bf8bc

Browse files
committed
Only call clang-format if file is not empty
Signed-off-by: Wolfgang E. Sanyer <WolfgangSanyer@Google.com>
1 parent adb2804 commit b7bf8bc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

autoload/codefmt/clangformat.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function! codefmt#clangformat#GetFormatter() abort
171171
let l:result = maktaba#syscall#Create(l:cmd).WithStdin(l:input).Call()
172172
let l:formatted = split(l:result.stdout, "\n")
173173

174-
if l:supports_cursor
174+
if l:supports_cursor && !(line('$') == 1 && getline(1) == '')
175175
" With -cursor, the first line is a JSON object.
176176
let l:header = remove(l:formatted, 0)
177177
call maktaba#buffer#Overwrite(1, line('$'), l:formatted)

vroom/clangformat.vroom

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,12 @@ 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+
:call maktaba#error#TryCommand('FormatCode clang-format')
191+
! clang-format -style file .*
192+
$ echo -n

0 commit comments

Comments
 (0)