formatting now doesn't mess with cursor position

This commit is contained in:
Talha Qamar 2024-09-30 08:10:18 +05:00
parent 46b7b8db45
commit dd7b0fd2a5

View file

@ -1,16 +1,18 @@
setlocal commentstring=//\ %s setlocal commentstring=//\ %s
function Hbformat() function HBformat()
silent! !hbc --fmt-stdout <afile> silent! !hbc --fmt-stdout <afile>
if v:shell_error if v:shell_error
echom "Errors in file" echom "Errors in file"
!hbc --fmt-stdout <afile> !hbc --fmt-stdout <afile>
else else
let save_cursor = getcurpos()
silent! %!hbc --fmt-stdout <afile> silent! %!hbc --fmt-stdout <afile>
call setpos('.', save_cursor)
endif endif
endfunction endfunction
augroup hblang_group augroup hblang_group
autocmd! autocmd!
autocmd BufWritePost *.hb :call Hbformat() autocmd BufWritePost *.hb :call HBformat()
augroup END augroup END