Skip to content

Commit 1df765c

Browse files
committed
Do not call clang-format if buffer is empty.
closes #102 Signed-off-by: Wolfgang E. Sanyer <WolfgangSanyer@Google.com>
1 parent 2cd93a5 commit 1df765c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

autoload/codefmt/clangformat.vim

Lines changed: 3 additions & 3 deletions
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)
@@ -182,8 +182,8 @@ function! codefmt#clangformat#GetFormatter() abort
182182
let [l:new_line, l:new_col] = s:OffsetToPosition(l:offset, l:formatted)
183183
call cursor(l:new_line, l:new_col)
184184
catch
185-
call maktaba#error#Warn('Unable to parse clang-format cursor pos: %s',
186-
\ v:exception)
185+
call maktaba#error#Warn(v:exception)
186+
call maktaba#error#Warn(" Unable to parse clang-formon cursor position")
187187
endtry
188188
else
189189
call maktaba#buffer#Overwrite(1, line('$'), l:formatted)

0 commit comments

Comments
 (0)