-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathperltidy.vim
44 lines (38 loc) · 1.14 KB
/
perltidy.vim
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
if exists('g:perltidy')
finish
en
function! s:TrimEndLines()
let save_cursor = getpos(".")
:silent! %s#\($\n\s*\)\+\%$##
call setpos('.', save_cursor)
endfunction
function!s:PerlTidy()
let old_shell = &shell
let &shell = old_shell
let b:firstline = a:firstline
let b:lastline = a:lastline
if b:firstline == b:lastline
let b:firstline = 1
let b:lastline = line('$')
endif
let lines = join(getline(b:firstline, b:lastline), "\n")
let b:perltidy_output = system('perltidy -q ', lines)
let &shell = old_shell
let prevcur = getpos(".")
let prevx = getpos("'x")
let prevy = getpos("'y")
call setpos("'x", [0, b:firstline, 0, 0])
call setpos("'y", [0, b:lastline, 0, 0])
exec "'x,'yd"
set paste
call setpos(".", [0, b:firstline, 0, 0])
exec ":normal i" . b:perltidy_output
call s:TrimEndLines()
call setpos(".", prevcur)
call setpos("'x", prevx)
call setpos("'y", prevy)
endfunction
command! -nargs=* -range -bang PerlTidy <line1>,<line2>call s:PerlTidy()
vnoremap :call PerlTidy() t
au BufWritePre *.p[lm],*.t call s:PerlTidy()
let g:perltidy = 1