summaryrefslogtreecommitdiff
path: root/ftplugin/rust.vim
blob: 5007055fd8eb692091ff5bab23abf1c92ca47192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
setlocal ts=4 sts=4 sw=4 expandtab

set formatprg=rustfmt

" set makeprg=cargo\ clippy
set errorformat=
            \%-G,
            \%-Gerror:\ aborting\ %.%#,
            \%-Gerror:\ Could\ not\ compile\ %.%#,
            \%Eerror:\ %m,
            \%Eerror[E%n]:\ %m,
            \%Wwarning:\ %m,
            \%Inote:\ %m,
            \%C\ %#-->\ %f:%l:%c,
            \%E\ \ left:%m,%C\ right:%m\ %f:%l:%c,%Z

function! RustMake() abort
    set makeprg=nix-shell\ --run\ \"cargo\ build\"
    silent! make
    set makeprg=nix-shell\ --run\ \"cargo\ clippy\"
    silent! make
endfunction

nnoremap <leader>r :call RustMake() <bar> silent! redraw <bar> cwindow<cr>

if exists('*RustFmtSimple')
    finish
endif

function! RustFmtSimple() abort
    let s = winsaveview()
    bufdo! silent! !rustfmt %
    bufdo! edit
    call winrestview(s)
endfunction

augroup SimpleRustFmt
    autocmd!
    autocmd BufWritePost *.rs call RustFmtSimple()
augroup END