ats-vim/ftplugin/ats.vim

49 lines
1 KiB
VimL
Raw Normal View History

2017-12-23 15:28:24 -05:00
if exists('b:ats_ftplugin')
finish
endif
let b:ats_ftplugin = 1
2017-12-23 16:28:28 -05:00
" set config values
2017-12-23 15:28:24 -05:00
if !exists('g:ats_autoformat')
2017-12-23 15:57:59 -05:00
if executable('atsfmt') == 1
let g:ats_autoformat = 1
else
let g:ats_autoformat = 0
endif
2017-12-23 15:28:24 -05:00
endif
2017-12-23 16:28:28 -05:00
" indentation rules
2017-12-23 15:28:24 -05:00
set smarttab
au BufNewFile,BufRead *.*ats
\ set shiftwidth=2
2017-12-23 16:28:28 -05:00
" set comment string to something prettier
2017-12-23 15:28:24 -05:00
setlocal commentstring=(*\ %s\ *)
2017-12-23 16:40:09 -05:00
" use patscc as a checker
let g:syntastic_ats_checkers = [ 'patscc' ]
2017-12-23 16:28:28 -05:00
" function to format our buffer
2017-12-23 15:28:24 -05:00
function! AtsFormat()
2017-12-23 15:54:08 -05:00
let cursor = getpos('.')
2017-12-23 15:28:24 -05:00
exec 'normal! gg'
exec 'silent !atsfmt -i ' . expand('%')
exec 'e'
2017-12-23 15:54:08 -05:00
call setpos('.', cursor)
2017-12-23 15:28:24 -05:00
endfunction
2017-12-23 17:15:39 -05:00
augroup ats
autocmd BufWritePre *.ats,*.dats,*.cats,*.sats execute 'lcd %:p:h'
augroup END
2017-12-23 16:28:28 -05:00
" format on write
2017-12-23 15:28:24 -05:00
if g:ats_autoformat == 1
augroup ats
autocmd BufWritePost *.ats,*.dats,*.sats,*.cats call AtsFormat()
augroup END
endif
2017-12-23 16:28:28 -05:00
" commands
2017-12-23 15:50:03 -05:00
command -nargs=0 Format call AtsFormat()
2017-12-23 16:40:09 -05:00
command -nargs=0 Check SyntasticCheck patscc