Created
March 1, 2013 07:09
-
-
Save squm/5062970 to your computer and use it in GitHub Desktop.
vim perl ftplugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Make sure the continuation lines below do not cause problems in | |
" compatibility mode. | |
set iskeyword+=_ | |
let s:save_cpo = &cpo | |
set cpo-=C | |
let g:perldoc_program = 'perldoc' | |
if !exists("t:plsourcerun") | |
let t:plsourcefile = expand("%:p") | |
keepalt botright 6new | |
let t:plsourcerun = bufnr("%") | |
setlocal bufhidden=hide | |
setlocal buftype=nofile | |
setlocal noswapfile | |
hide | |
endif | |
if exists("b:did_PERL_ftplugin") | finish | endif | |
let b:did_PERL_ftplugin = 1 | |
colorscheme gatom | |
compiler perl | |
"https://github.com/vim-perl/vim-perl | |
setlocal formatoptions+=crq | |
setlocal comments=:# | |
setlocal commentstring=#%s | |
setlocal include=\\<\\(use\\\|require\\)\\> | |
setlocal includeexpr=substitute(substitute(substitute(v:fname,'::','/','g'),'->\*','',''),'$','.pm','') | |
setlocal define=[^A-Za-z_] | |
set isfname+=: | |
" Set this once, globally. | |
if !exists("perlpath") | |
if executable("perl") | |
try | |
if &shellxquote != '"' | |
let perlpath = system('perl -e "print join(q/,/,@INC)"') | |
else | |
let perlpath = system("perl -e 'print join(q/,/,@INC)'") | |
endif | |
let perlpath = substitute(perlpath,',.$',',,','') | |
catch /E145:/ | |
let perlpath = ".,," | |
endtry | |
else | |
" If we can't call perl to get its path, just default to using the | |
" current directory and the directory of the current file. | |
let perlpath = ".,," | |
endif | |
endif | |
" Undo the stuff we changed. | |
let b:undo_ftplugin = "setlocal fo< com< cms< inc< inex< def< isf< kp< path<" . | |
\ " | unlet! b:browsefilter" | |
" Append perlpath to the existing path value, if it is set. Since we don't | |
" use += to do it because of the commas in perlpath, we have to handle the | |
" global / local settings, too. | |
if &l:path == "" | |
if &g:path == "" | |
let &l:path=perlpath | |
else | |
let &l:path=&g:path.",".perlpath | |
endif | |
else | |
let &l:path=&l:path.",".perlpath | |
endif | |
set foldmethod=marker | |
map <buffer> K :Perldoc<CR> | |
"map <F3> <Esc>gI#<Esc>j | |
"map <F4> <Esc>gI#<Esc>k | |
"imap <F3> <Esc>gI#<Esc>j | |
"imap <F4> <Esc>gI#<Esc>k | |
"map <S-F3> <Esc>_"_x<Esc>j | |
"map <S-F4> <Esc>_"_x<Esc>k | |
"imap <S-F3> <Esc>_"_x<Esc>j | |
"imap <S-F4> <Esc>_"_x<Esc>k | |
imap <Tab> <C-P> | |
imap <S-Tab> <C-N> | |
map <F2> :call <SID>SaveCompile()<CR> | |
imap <F2> <Esc>:call <SID>SaveCompile()<CR> | |
map <F5> :call <SID>PearlRun()<CR> | |
imap <F5> <Esc>:call <SID>PearlRun()<CR> | |
map <F6> :call <SID>PearlShowRe()<CR> | |
imap <F6> <Esc>:call <SID>PearlShowRe()<CR> | |
map :call <SID>PearlRun()<CR> | |
imap <Esc>:call <SID>PearlRun()<CR> | |
"map <Leader>\ :call <SID>PearlRun()<CR> | |
"imap <Leader>\ <Esc>:call <SID>PearlRun()<CR> | |
"map <LocalLeader>\ :call <SID>PearlRun()<CR> | |
"imap <LocalLeader>\ <Esc>:call <SID>PearlRun()<CR> | |
"map <Leader>ro <F6> | |
"imap <Leader>ro <Esc><F6> | |
"buffer b: Local to the current buffer. | |
"window w: Local to the current window. | |
"tabpage t: Local to the current tab page. | |
"global g: Global. | |
"local l: Local to a function. | |
"script s: Local to a |:source|'ed Vim script. | |
"vim v: Global, predefined by Vim. | |
"function-argument| a: Function argument (only inside a function). | |
function! s:PearlShow(plsourcerun) | |
if a:plsourcerun | |
" split | |
keepalt botright 6new | |
" switch | |
exe "b".t:plsourcerun | |
else | |
" switch | |
exe bufwinnr(t:plsourcerun)."wincmd w" | |
" This can be used to save and restore the cursor position: > | |
exe 'normal H' | |
let l:save_cursor = getpos(".") | |
" wipe | |
exe 'normal gg"_dG' | |
" run | |
silent exe '0r !perl "'.t:plsourcefile.'"' | |
call setpos('.', l:save_cursor) | |
exe 'normal ztkj' | |
endif | |
" TODO: return to current position | |
" back | |
exe bufwinnr(bufnr(t:plsourcefile))."wincmd w" | |
endfunction | |
function! s:PearlShowRe() | |
" is Hidden | |
if bufwinnr(t:plsourcerun) > 0 | |
if winnr("$") > 1 | |
exe bufwinnr(t:plsourcerun)."wincmd w" | |
" if this is last window | |
hide | |
else | |
exe "b".bufnr(t:plsourcefile) | |
endif | |
else | |
call <SID>PearlShow(1) | |
endif | |
endfunction | |
function! s:PearlRun() | |
exe bufwinnr(t:plsourcefile)."wincmd w" | |
if !<SID>SaveCompile() | |
return | |
endif | |
if bufwinnr(t:plsourcerun) > 0 | |
" if opened | |
call <SID>PearlShow(0) | |
else | |
call <SID>PearlShow(1) | |
call <SID>PearlShow(0) | |
call <SID>PearlShowRe() | |
endif | |
endfunction | |
function! s:SaveCompile() | |
update | |
if (!exists("t:plsourcefile")) | |
echo "ex" | |
return | |
endif | |
" if (t:plsourcefile != bufname("%")) | |
if (t:plsourcefile != expand("%:p")) | |
echo "ex" | |
return | |
endif | |
" exe "silent make" | |
silent exe "make" | |
redraw! | |
botright cwindow | |
if v:shell_error != 0 | |
cc | |
return 0 | |
endif | |
return 1 | |
endfunction | |
let &cpo = s:save_cpo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment