forked from AdaCore/libadalang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.lvimrc
78 lines (63 loc) · 1.97 KB
/
.lvimrc
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
" This script is meant to be used in combination with the vim-localvimrc
" plug-in, see https://github.com/embear/vim-localvimrc
" It will run stylechecks on relevant files on file save in vim, and show the
" results in the command window.
" The code is inspired from the vim-flake8 plug-in:
" https://github.com/nvie/vim-flake8
if g:localvimrc_sourced_once
finish
endif
let s:local_path = expand('<sfile>:p:h')
let s:cmd=s:local_path . '/langkit/langkit/stylechecks/__init__.py'
let s:lalcmd=s:local_path . '/ada/manage.py --verbosity=none -Dgnu-full generate --check-only'
function Lalcheck()
hi Red ctermfg=red
echohl Red
echon "Running checks"
echohl
call Stylechecks(s:lalcmd, 0)
endfunction
function Stylechecks(cmd, file_specific)
hi Green ctermfg=green
set lazyredraw " delay redrawing
cclose " close any existing cwindows
" store old grep settings (to restore later)
let l:old_gfm=&grepformat
let l:old_gp=&grepprg
" write any changes before continuing
if &readonly == 0
update
endif
" perform the grep itself
let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
let &grepprg=a:cmd
if a:file_specific
silent! grep! %
else
silent! grep!
endif
" restore grep settings
let &grepformat=l:old_gfm
let &grepprg=l:old_gp
" open cwindow
let has_results=getqflist() != []
if has_results
execute 'belowright copen'
setlocal wrap
nnoremap <buffer> <silent> c :cclose<CR>
nnoremap <buffer> <silent> q :cclose<CR>
endif
set nolazyredraw
redraw!
if has_results == 0
" Show OK status
echohl Green
echon "Style checks OK"
echohl
endif
endfunction
autocmd BufWritePost *.py call Stylechecks(s:cmd, 1)
autocmd BufWritePost *.adb call Stylechecks(s:cmd, 1)
autocmd BufWritePost *.ads call Stylechecks(s:cmd, 1)
autocmd BufWritePost *.mako call Stylechecks(s:cmd, 1)
map <F3> :call Lalcheck()<CR>